
     hp                     8   d Z ddlmZmZmZmZ ddlZddlmZ 	 ddl	m
Z
 ddlmZmZ ddlZ ej"                  e      ZddlZddlZddlmZ ddlmZmZmZmZ dd	lmZmZmZ dd
l m!Z! g dZ" e#ddddd      Z$d Z%d Z&d(dZ'e(e)fZ*e+e,fZ- e+       Z.d)dZ/ G d de0      Z1 e#dddd      Z2 G d de1      Z3d*dZ4d  Z5 G d! d"e
      Z6 e6       Z7d#jq                         D ]  Z9e7ju                  e9d$e9z           G d% d&e1      Z;d*d'Z<y# e$ r	 ddlm
Z
 Y w xY w)+z*passlib.pwd -- password generation helpers    )absolute_importdivisionprint_functionunicode_literalsN)defaultdict)MutableMapping)ceillog)exc)PY2irange
itervalues	int_types)rng
getrandstr
to_unicode)memoized_property)genworddefault_charsets	genphrasedefault_wordsets      $   0   <   )unsafeweakfairstrongsecurec                 Z    t        |       j                  }||j                  |      dz   d S )z2return remaining classes in object's MRO after cls   N)type__mro__index)objclsmros      M/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/passlib/pwd.py_superclassesr+   8   s,    
s)

Csyy~a !!    c                    	 t        |       }t        t              }| D ]  }||xx   dz  cc<    ||j	                         }t        |      }nt        |      }|syt        |d      t        d |D              |z  z
  S # t        $ r d}Y ~w xY w)a  
    returns 'rate of self-information' --
    i.e. average (per-symbol) entropy of the sequence **source**,
    where probability of a given symbol occurring is calculated based on
    the number of occurrences within the sequence itself.

    if all elements of the source are unique, this should equal ``log(len(source), 2)``.

    :arg source:
        iterable containing 0+ symbols
        (e.g. list of strings or ints, string of characters, etc).

    :returns:
        float bits of entropy
    Nr#   r      c              3   :   K   | ]  }|t        |d       z    yw)r.   N)logf).0values     r*   	<genexpr>z"_self_info_rate.<locals>.<genexpr>_   s     J%utE1~5Js   )len	TypeErrorr   intvaluessumr   r0   )sourcesizecountscharr7   s        r*   _self_info_rater=   >   s     6{ F t|6{F# a=3J6JJTQQQ  s   A> >BBc                    |r$ t        j                  |      t        |             S t        j                  j                  |       rt        | d      S | j                  d      \  }}}|st        d|       t        j                  ||      S )a  
    :param asset_path:
        string containing absolute path to file,
        or package-relative path using format
        ``"python.module:relative/file/path"``.

    :returns:
        filehandle opened in 'rb' mode
        (unless encoding explicitly specified)
    rb:zIasset path must be absolute file path or use 'pkg.name:sub/path' format: )codecs	getreader_open_asset_pathospathisabsopen	partition
ValueErrorpkg_resourcesresource_stream)rE   encodingpackagesepsubpaths        r*   rC   rC   j   s     )v)*:4*@AA	ww}}TD$ NN3/GS'DHK L 	L(('::r,   c                 &   t         }d}	 | |v ry	 t        | t              s t	        t        |             t	        |       k(  r|r	 |j                  |        yyt               }t               }| D ]  }||v r|n|j                  |        t        |      }d}t	        |      |kD  rd}dj                  d |d| D              }t	        |      |kD  r|dt	        |      |z
  z  z  }t        d	|d
|      # t        $ r d}Y w xY w# t        $ r Y yw xY w)z
    helper for generators --
    Throws ValueError if source elements aren't unique.
    Error message will display (abbreviated) repr of the duplicates in a string/list
    TF      , c              3   D   K   | ]  }t        t        |              y wN)reprstrr1   words     r*   r3   z!_ensure_unique.<locals>.<genexpr>   s     BTc$iBs    Nz, ... plus %d others`z%` cannot contain duplicate elements: )
_ensure_unique_cacher5   
isinstance
_set_typesr4   setaddsortedjoinrI   )	r9   paramcachehashableseendupselemtruncdup_reprs	            r*   _ensure_uniquerj      s5    !EHU?  &*%S[)9S[)H		&!
  5D5D 34,,T23$<DE
4y5yyBT&5\BBH
4y5*c$i%.?@@ X' ( (9     	s#   C3 D 3D D	DDc                   z     e Zd ZdZdZdZeZdZd fd	Ze	d        Z
e	d        Zd ZddZd	 Zerd
 Z xZS  xZS )SequenceGeneratoraY  
    Base class used by word & phrase generators.

    These objects take a series of options, corresponding
    to those of the :func:`generate` function.
    They act as callables which can be used to generate a password
    or a list of 1+ passwords. They also expose some read-only
    informational attributes.

    Parameters
    ----------
    :param entropy:
        Optionally specify the amount of entropy the resulting passwords
        should contain (as measured with respect to the generator itself).
        This will be used to auto-calculate the required password size.

    :param length:
        Optionally specify the length of password to generate,
        measured as count of whatever symbols the subclass uses (characters or words).
        Note if ``entropy`` requires a larger minimum length,
        that will be used instead.

    :param rng:
        Optionally provide a custom RNG source to use.
        Should be an instance of :class:`random.Random`,
        defaults to :class:`random.SystemRandom`.

    Attributes
    ----------
    .. autoattribute:: length
    .. autoattribute:: symbol_count
    .. autoattribute:: entropy_per_symbol
    .. autoattribute:: entropy

    Subclassing
    -----------
    Subclasses must implement the ``.__next__()`` method,
    and set ``.symbol_count`` before calling base ``__init__`` method.
    Nr    c                    | j                   J d       ||^|| j                  }t        j                  ||      }|dk  rt	        d      t        t        || j                  z              }|||k  r|}|| _        |dk  rt	        d      || _        ||| _	        |rCt        | t              t        fk(  r+t        ddj                  |j                               z        t!        t        | F  di | y )	Nzsubclass must set .symbol_countr   z!`entropy` must be positive numberr#   z!`length` must be positive integerzUnexpected keyword(s): %srS    )symbol_countrequested_entropyentropy_aliasesgetrI   r6   r	   entropy_per_symbollengthr   r+   rl   objectr5   ra   keyssuper__init__)selfentropyrt   r   kwds
min_length	__class__s         r*   rx   zSequenceGenerator.__init__   s       ,O.OO &.00%))'7;G!| !DEET'D,C,C"CDEJ~*!4#!(A:@AA ?DH M$(9:viG7$))DIIK:PPQQ/7$7r,   c                 .    t        | j                  d      S )zZ
        Average entropy per symbol (assuming all symbols have equal probability)
        r.   )r0   ro   ry   s    r*   rs   z$SequenceGenerator.entropy_per_symbol  s    
 D%%q))r,   c                 4    | j                   | j                  z  S )a+  
        Effective entropy of generated passwords.

        This value will always be a multiple of :attr:`entropy_per_symbol`.
        If entropy is specified in constructor, :attr:`length` will be chosen so
        so that this value is the smallest multiple >= :attr:`requested_entropy`.
        )rt   rs   r   s    r*   rz   zSequenceGenerator.entropy  s     {{T4444r,   c                     t        d      )z;main generation function, should create one password/phrasezimplement in subclass)NotImplementedErrorr   s    r*   __next__zSequenceGenerator.__next__)  s    !"9::r,   c                     |t        |       S t        |t              r"t        |      D cg c]  }t        |        c}S |t        u r| S t        j                  |dd      c c}w )zN
        frontend used by genword() / genphrase() to create passwords
        z<None>, int, or <iter>returns)nextr\   r   r   iterr   ExpectedTypeError)ry   r   _s      r*   __call__zSequenceGenerator.__call__-  s]     ?:+(.w81DJ88_K''1I9UU	 9s   A!c                     | S rU   rn   r   s    r*   __iter__zSequenceGenerator.__iter__:  s    r,   c                 "    | j                         S rU   )r   r   s    r*   r   zSequenceGenerator.next>  s    ==?"r,   NNNrU   )__name__
__module____qualname____doc__rt   rp   r   ro   rx   r   rs   rz   r   r   r   r   r   __classcell__r}   s   @r*   rl   rl      ss    &X F ! C L
8F * * 5 5;V 	# r,   rl   zH0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*?/>0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ2234679abcdefghjkmnpqrstuvwxyzACDEFGHJKMNPQRTUVWXYZ0123456789abcdef)ascii_72ascii_62ascii_50hexc                   B     e Zd ZdZdZdZd fd	Zed        Zd Z	 xZ
S )WordGeneratora  
    Class which generates passwords by randomly choosing from a string of unique characters.

    Parameters
    ----------
    :param chars:
        custom character string to draw from.

    :param charset:
        predefined charset to draw from.

    :param \*\*kwds:
        all other keywords passed to the :class:`SequenceGenerator` parent class.

    Attributes
    ----------
    .. autoattribute:: chars
    .. autoattribute:: charset
    .. autoattribute:: default_charsets
    r   Nc                     |r|r&t        d      |s| j                  }|sJ t        |   }|| _        t        |d      }t	        |d       || _        t        t        | "  di | y )Nz,`chars` and `charset` are mutually exclusivecharsrb   rn   )	r5   charsetr   r   rj   r   rw   r   rx   )ry   r   r   r{   r}   s       r*   rx   zWordGenerator.__init__~  sj      NOO,,$W-E50uG,
 	mT+3d3r,   c                 ,    t        | j                        S rU   )r4   r   r   s    r*   ro   zWordGenerator.symbol_count      4::r,   c                 X    t        | j                  | j                  | j                        S rU   )r   r   r   rt   r   s    r*   r   zWordGenerator.__next__  s     $((DJJ<<r,   )NN)r   r   r   r   r   r   rx   r   ro   r   r   r   s   @r*   r   r   \  s4    2 G E
40  =r,   r   c                 .    t        d|| d|} ||      S )a
  Generate one or more random passwords.

    This function uses :mod:`random.SystemRandom` to generate
    one or more passwords using various character sets.
    The complexity of the password can be specified
    by size, or by the desired amount of entropy.

    Usage Example::

        >>> # generate a random alphanumeric string with 48 bits of entropy (the default)
        >>> from passlib import pwd
        >>> pwd.genword()
        'DnBHvDjMK6'

        >>> # generate a random hexadecimal string with 52 bits of entropy
        >>> pwd.genword(entropy=52, charset="hex")
        '310f1a7ac793f'

    :param entropy:
        Strength of resulting password, measured in 'guessing entropy' bits.
        An appropriate **length** value will be calculated
        based on the requested entropy amount, and the size of the character set.

        This can be a positive integer, or one of the following preset
        strings: ``"weak"`` (24), ``"fair"`` (36),
        ``"strong"`` (48), and ``"secure"`` (56).

        If neither this or **length** is specified, **entropy** will default
        to ``"strong"`` (48).

    :param length:
        Size of resulting password, measured in characters.
        If omitted, the size is auto-calculated based on the **entropy** parameter.

        If both **entropy** and **length** are specified,
        the stronger value will be used.

    :param returns:
        Controls what this function returns:

        * If ``None`` (the default), this function will generate a single password.
        * If an integer, this function will return a list containing that many passwords.
        * If the ``iter`` constant, will return an iterator that yields passwords.

    :param chars:

        Optionally specify custom string of characters to use when randomly
        generating a password. This option cannot be combined with **charset**.

    :param charset:

        The predefined character set to draw from (if not specified by **chars**).
        There are currently four presets available:

        * ``"ascii_62"`` (the default) -- all digits and ascii upper & lowercase letters.
          Provides ~5.95 entropy per character.

        * ``"ascii_50"`` -- subset which excludes visually similar characters
          (``1IiLl0Oo5S8B``). Provides ~5.64 entropy per character.

        * ``"ascii_72"`` -- all digits and ascii upper & lowercase letters,
          as well as some punctuation. Provides ~6.17 entropy per character.

        * ``"hex"`` -- Lower case hexadecimal.  Providers 4 bits of entropy per character.

    :returns:
        :class:`!unicode` string containing randomly generated password;
        or list of 1+ passwords if :samp:`returns={int}` is specified.
    )rt   rz   rn   )r   rz   rt   r   r{   gens        r*   r   r     s#    L 
?vw
?$
?Cw<r,   c                     t        | d      5 }d |D        }t        d |D              }ddd       t        j                  dt	              |        |S # 1 sw Y   +xY w)a2  
    load wordset from compressed datafile within package data.
    file should be utf-8 encoded

    :param asset_path:
        string containing  absolute path to wordset file,
        or "python.module:relative/file/path".

    :returns:
        tuple of words, as loaded from specified words file.
    zutf-8c              3   <   K   | ]  }|j                           y wrU   )striprX   s     r*   r3   z _load_wordset.<locals>.<genexpr>  s     +tzz|+s   c              3   &   K   | ]	  }|s|  y wrU   rn   rX   s     r*   r3   z _load_wordset.<locals>.<genexpr>  s     3tdd3s   Nz!loaded %d-element wordset from %r)rC   tupler
   debugr4   )
asset_pathfhr   wordss       r*   _load_wordsetr     s[     
*g	. 4"++3s334$ II13u:zJL'4 4s   AAc                   d     e Zd ZdZdZdZ fdZd Zd Zd Z	d Z
ed        Zd	 Zd
 Zd Z xZS )WordsetDictz
    Special mapping used to store dictionary of wordsets.
    Different from a regular dict in that some wordsets
    may be lazy-loaded from an asset path.
    Nc                 H    i | _         i | _        t        t        |   |i | y rU   )paths_loadedrw   r   rx   )ry   argsr{   r}   s      r*   rx   zWordsetDict.__init__%  s%    
k4)4848r,   c                     	 | j                   |   S # t        $ r Y nw xY w| j                  |   }t        |      x}| j                   |<   |S rU   )r   KeyErrorr   r   )ry   keyrE   r2   s       r*   __getitem__zWordsetDict.__getitem__*  sR    	<<$$ 		zz#$1$$77S!s    	c                 "    || j                   |<   y)z;
        set asset path to lazy-load wordset from.
        N)r   )ry   r   rE   s      r*   set_pathzWordsetDict.set_path3  s     

3r,   c                 "    || j                   |<   y rU   )r   )ry   r   r2   s      r*   __setitem__zWordsetDict.__setitem__9  s    !Sr,   c                 z    || v r*| j                   |= | j                  j                  |d        y | j                  |= y rU   )r   r   popry   r   s     r*   __delitem__zWordsetDict.__delitem__<  s2    $;S!JJNN3%

3r,   c                 f    t        | j                        }|j                  | j                         |S rU   )r^   r   updater   )ry   rv   s     r*   _keysetzWordsetDict._keysetC  s%    4<< DJJr,   c                 ,    t        | j                        S rU   )r   r   r   s    r*   r   zWordsetDict.__iter__I  s    DLL!!r,   c                 ,    t        | j                        S rU   )r4   r   r   s    r*   __len__zWordsetDict.__len__L  s    4<<  r,   c                 >    || j                   v xs || j                  v S rU   )r   r   r   s     r*   __contains__zWordsetDict.__contains__P  s    dll"7cTZZ&77r,   )r   r   r   r   r   r   rx   r   r   r   r   propertyr   r   r   r   r   r   s   @r*   r   r     sR     E G9
"   
"!8r,   r   z%eff_long eff_short eff_prefixed bip39zpasslib:_data/wordsets/%s.txtc                   F     e Zd ZdZdZdZdZd fd	Zed        Z	d Z
 xZS )	PhraseGeneratora  class which generates passphrases by randomly choosing
    from a list of unique words.

    :param wordset:
        wordset to draw from.
    :param preset:
        name of preset wordlist to use instead of ``wordset``.
    :param spaces:
        whether to insert spaces between words in output (defaults to ``True``).
    :param \*\*kwds:
        all other keywords passed to the :class:`SequenceGenerator` parent class.

    .. autoattribute:: wordset
    eff_longN c                 0   ||&t        d      || j                  }|sJ t        |   }|| _        t        |t              st        |      }t        |d       || _        || j                  }t        |d      }|| _        t        t        | 2  di | y )Nz,`words` and `wordset` are mutually exclusiver   r   rN   rn   )r5   wordsetr   r\   _sequence_typesr   rj   r   rN   r   rw   r   rx   )ry   r   r   rN   r{   r}   s        r*   rx   zPhraseGenerator.__init__~  s     " NOO,,$W-E %1%LEuG,
 ;((CE* 	ot-55r,   c                 ,    t        | j                        S rU   )r4   r   r   s    r*   ro   zPhraseGenerator.symbol_count  r   r,   c                 v      fdt         j                        D        } j                  j                  |      S )Nc              3   h   K   | ])  }j                   j                  j                         + y wrU   )r   choicer   )r1   r   ry   s     r*   r3   z+PhraseGenerator.__next__.<locals>.<genexpr>  s"     J,Js   /2)r   rt   rN   ra   )ry   r   s   ` r*   r   zPhraseGenerator.__next__  s)    JfT[[6IJxx}}U##r,   r   )r   r   r   r   r   r   rN   rx   r   ro   r   r   r   s   @r*   r   r   _  s<    & G E C
6D  $r,   r   c                 .    t        d| |d|} ||      S )am  Generate one or more random password / passphrases.

    This function uses :mod:`random.SystemRandom` to generate
    one or more passwords; it can be configured to generate
    alphanumeric passwords, or full english phrases.
    The complexity of the password can be specified
    by size, or by the desired amount of entropy.

    Usage Example::

        >>> # generate random phrase with 48 bits of entropy
        >>> from passlib import pwd
        >>> pwd.genphrase()
        'gangly robbing salt shove'

        >>> # generate a random phrase with 52 bits of entropy
        >>> # using a particular wordset
        >>> pwd.genword(entropy=52, wordset="bip39")
        'wheat dilemma reward rescue diary'

    :param entropy:
        Strength of resulting password, measured in 'guessing entropy' bits.
        An appropriate **length** value will be calculated
        based on the requested entropy amount, and the size of the word set.

        This can be a positive integer, or one of the following preset
        strings: ``"weak"`` (24), ``"fair"`` (36),
        ``"strong"`` (48), and ``"secure"`` (56).

        If neither this or **length** is specified, **entropy** will default
        to ``"strong"`` (48).

    :param length:
        Length of resulting password, measured in words.
        If omitted, the size is auto-calculated based on the **entropy** parameter.

        If both **entropy** and **length** are specified,
        the stronger value will be used.

    :param returns:
        Controls what this function returns:

        * If ``None`` (the default), this function will generate a single password.
        * If an integer, this function will return a list containing that many passwords.
        * If the ``iter`` builtin, will return an iterator that yields passwords.

    :param words:

        Optionally specifies a list/set of words to use when randomly generating a passphrase.
        This option cannot be combined with **wordset**.

    :param wordset:

        The predefined word set to draw from (if not specified by **words**).
        There are currently four presets available:

        ``"eff_long"`` (the default)

            Wordset containing 7776 english words of ~7 letters.
            Constructed by the EFF, it offers ~12.9 bits of entropy per word.

            This wordset (and the other ``"eff_"`` wordsets)
            were `created by the EFF <https://www.eff.org/deeplinks/2016/07/new-wordlists-random-passphrases>`_
            to aid in generating passwords.  See their announcement page
            for more details about the design & properties of these wordsets.

        ``"eff_short"``

            Wordset containing 1296 english words of ~4.5 letters.
            Constructed by the EFF, it offers ~10.3 bits of entropy per word.

        ``"eff_prefixed"``

            Wordset containing 1296 english words of ~8 letters,
            selected so that they each have a unique 3-character prefix.
            Constructed by the EFF, it offers ~10.3 bits of entropy per word.

        ``"bip39"``

            Wordset of 2048 english words of ~5 letters,
            selected so that they each have a unique 4-character prefix.
            Published as part of Bitcoin's `BIP 39 <https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt>`_,
            this wordset has exactly 11 bits of entropy per word.

            This list offers words that are typically shorter than ``"eff_long"``
            (at the cost of slightly less entropy); and much shorter than
            ``"eff_prefixed"`` (at the cost of a longer unique prefix).

    :param sep:
        Optional separator to use when joining words.
        Defaults to ``" "`` (a space), but can be an empty string, a hyphen, etc.

    :returns:
        :class:`!unicode` string containing randomly generated passphrase;
        or list of 1+ passphrases if :samp:`returns={int}` is specified.
    )rz   rt   rn   )r   r   s        r*   r   r     s#    B 
A'&
AD
ACw<r,   rU   )r9   r   )=r   
__future__r   r   r   r   rA   collectionsr   collections.abcr   ImportErrormathr	   r
   r0   logging	getLoggerr   rJ   rD   passlibr   passlib.utils.compatr   r   r   r   passlib.utilsr   r   r   passlib.utils.decorr   __all__dictrq   r+   r=   rC   listr   r   r^   	frozensetr]   r[   rj   ru   rl   r   r   r   r   r   r   splitnamer   r   r   rn   r,   r*   <module>r      st   0 S R  #+. # 'g''1  	  C C 5 5 1  
 
  *"!RX;. -9
 u )(\I# I#h W N B 	 $E=% E=XGZ F98. 98| =  499; LDd$Cd$JKLK$' K$dbM  +*+s   D DD