
Lac           @   s  d  Z  d d l m Z d d l m Z m Z m Z d d l m	 Z	 m
 Z
 y$ d d l m Z d d l m Z Wn1 e k
 r d d l m Z d d l m Z n Xd d l m Z d d l m Z d d	 l Z d d	 l Z d d	 l Z e j e  Z d d	 l Z d d	 l Z d d	 l Z d d	 l Z d d	 l Z e rhy d d	 l  Z  Wqte k
 rdd	 Z  d
 Z" qtXn d d	 l  Z  d d	 l# Z# e  rd d	 l$ Z$ n  y d d	 l% Z% Wn e k
 rd	 Z% n Xd d	 l& Z& d d	 l' Z' d d l( m) Z) d d l* m+ Z+ m, Z, m- Z- m. Z. m/ Z/ m0 Z0 m1 Z1 m2 Z2 m3 Z3 m4 Z4 m5 Z5 m6 Z6 m7 Z7 d d l8 m9 Z9 m: Z: m; Z; m< Z< m= Z= d d l> m? Z? m@ Z@ d d l mA ZA mB ZB mC ZC mD ZD mE ZE mF ZF mG ZG mH ZH mI ZI mJ ZJ mK ZK mL ZL mM ZM mN ZN mO ZO mP ZP mQ ZQ d d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( g ZR eS e j eG rVe jT n e jU d)  d*  ZV d+ d, d- d. d/ d0 d1 g ZW d2 d3 g ZX d d4 l> mY ZY d5 ZZ eH d5  Z[ eH d6  Z\ eS e j] j^ d7  pd8  Z_ d9 e` f d:     YZa eG r+e jb jc Zd ee ed e jb jf g  Zg d;   Zh n	 d<   Zh d	 d	 ei d	 d	 ei d=  Zj d>   Zk d?   Zl el Zm y d d@ ln mo Zl Wn e k
 rn XdA dB  Zp dC dD  Zq e  d	 k rdC dE  Zq n  dF   Zr eG rdG   Zs dH   Zt n( d dI l mu Zu mv Zv dJ   Zs dK   Zt eA es dL  eA et dM  dN   Zw dO   Zx dP   Zy dQ Zz eH dQ  Z{ d	 dR  Z| dS   Z} dT Z~ e~ j dU  Z dV   Z dW   Z d Z eH dX  Z dZ   Z d[ dC d	 d\  Z d[ dC d]  Z eG rd[ dC d^  Z n d[ dC d_  Z eA e d`  e9 da db dc dd  dU de   Z ee df j    Z ee dg j    Z ee d5 dh g  Z d	 di dj  Z dk   Z y d dl l m Z Wn8 e k
 rd	 Z ei Z ei Z ei Z d	 Z dm   Z n Xe Z dQ Z e% reQ rd e j k od k n re% j   Z e Z n d dp l m Z e   Z ei Z eH dq  Z eG re Z y e dr ds  Wn e k
 rlei Z n n Xdt   Z n e Z du   Z eA e dv  dw   Z e& j Z e Z dx   Z y e j dy  e Z Wn e k
 rei Z n Xd	 dz  Z e re j   Z n e j e    Z d{   Z d|   Z d} Z e9 da dd dc d~ d d  d e d   Z d Z d   Z d Z d   Z d   Z d   Z d	 S(   s4   passlib.utils -- helpers for writing password hashesi(   t   JYTHON(   t
   b2a_base64t
   a2b_base64t   Error(   t	   b64encodet	   b64decode(   t   Sequence(   t   Iterable(   t   lookup(   t   update_wrapperNs   not present under Jython(   t   warn(   t   BASE64_CHARSt
   AB64_CHARSt   HASH64_CHARSt   BCRYPT_CHARSt   Base64Enginet   LazyBase64Enginet   h64t   h64bigt   bcrypt64t   ab64_encodet   ab64_decodet   b64s_encodet   b64s_decode(   t   deprecated_functiont   deprecated_methodt   memoized_propertyt   classpropertyt   hybrid_method(   t   ExpectedStringErrort   ExpectedTypeError(   t   add_doct
   join_bytest   join_byte_valuest   join_byte_elemst   iranget   imapt   PY3t   ut   join_unicodet   unicodet   byte_elem_valuet
   nextgettert   unicode_or_strt   unicode_or_bytes_typest   get_method_functiont   suppress_causet   PYPYR    t   sys_bitst   unix_crypt_schemest   rounds_cost_valuest   consteqt   saslprept	   xor_bytest   render_bytest   is_same_codect   is_ascii_safet   to_bytest
   to_unicodet   to_native_strt	   has_cryptt
   test_cryptt
   safe_cryptt   tickt   rngt   getrandbytest
   getrandstrt   generate_passwordt   is_crypt_handlert   is_crypt_contextt   has_rounds_infot   has_salt_infoi   g      ?t   sha512_cryptt   sha256_cryptt
   sha1_cryptt   bcryptt	   md5_cryptt
   bsdi_cryptt	   des_cryptt   lineart   log2(   t   MissingBackendErrort    t    t   PASSLIB_MAX_PASSWORD_SIZEi   t   SequenceMixinc           B   sM   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   s   
    helper which lets result object act like a fixed-length sequence.
    subclass just needs to provide :meth:`_as_tuple()`.
    c         C   s   t  d   d  S(   Ns   implement in subclass(   t   NotImplementedError(   t   self(    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt	   _as_tuple   s    c         C   s   t  |  j    S(   N(   t   reprRX   (   RW   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   __repr__   s    c         C   s   |  j    | S(   N(   RX   (   RW   t   idx(    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   __getitem__   s    c         C   s   t  |  j    S(   N(   t   iterRX   (   RW   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   __iter__   s    c         C   s   t  |  j    S(   N(   t   lenRX   (   RW   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   __len__   s    c         C   s   |  j    | k S(   N(   RX   (   RW   t   other(    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   __eq__   s    c         C   s   |  j  |  S(   N(   Rb   (   RW   Ra   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   __ne__   s    (
   t   __name__t
   __module__t   __doc__RX   RZ   R\   R^   R`   Rb   Rc   (    (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyRU      s   						c         C   se   t  j t |    j } | s" t S| j |  } | rJ | j t k rJ t S| t	 |  d j t
 k S(   s*   test if function accepts specified keywordi(   t   inspectt	   signatureR-   t
   parameterst   Falset   gett   kindt   _VAR_ANY_SETt   Truet   listt   _VAR_KEYWORD(   t   funct   keyt   paramst   arg(    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   accepts_keyword   s    c         C   s1   t  j t |    } | | j k p0 | j d k	 S(   s*   test if function accepts specified keywordN(   Rg   t
   getargspecR-   t   argst   keywordst   None(   Rq   Rr   t   spec(    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyRu      s    c            s  t  | t  r | g } n  t |  j  } | r t  | t  rK | g } n  xE | D]:   | rp   | k rp qR n    | k rR | j    qR qR Wn  | rx| D]  t   f d   | D  r q n  | r&x t |  D]8 \ } }	 t   |	  r Pn  | r t |	 |  r Pq q Wt |  } nu | rxl t t	 |   D]I \ }
 }	 t |	 |  r?t |  |
 } | | d |	 k st
  Pq?q?Wd } n d } | j |    q Wn  | st |  |  _ n  d S(   s  
    helper to update mixin classes installed in target class.

    :param target:
        target class whose bases will be modified.

    :param add:
        class / classes to install into target's base class list.

    :param remove:
        class / classes to remove from target's base class list.

    :param append:
        by default, prepends mixins to front of list.
        if True, appends to end of list instead.

    :param after:
        optionally make sure all mixins are inserted after
        this class / classes.

    :param before:
        optionally make sure all mixins are inserted before
        this class / classes.

    :param dryrun:
        optionally perform all calculations / raise errors,
        but don't actually modify the class.
    c         3   s   |  ] } t  |    Vq d  S(   N(   t
   issubclass(   t   .0t   base(   t   mixin(    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pys	   <genexpr>   s    i   i    N(   t
   isinstancet   typeRo   t	   __bases__t   removet   anyt	   enumerateR{   R_   t   reversedt   AssertionErrort   insertt   tuple(   t   targett   addR   t   appendt   beforet   aftert   dryrunt   basesR[   R}   t   end_idx(    (   R~   sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   update_mixin_classes   sB    	c         c   s   | d k  r t  d   n  t |  t  rn t |   } d } x | | k  rj | | } |  | | !V| } q? Wn t |  t  r t |   } xd t r t j | |  } y t	 |  } Wn t
 k
 r Pn Xt j | f |  Vq Wn t d   d S(   s8   
    split iterable into chunks of <size> elements.
    i   s   size must be positive integeri    s   source must be iterableN(   t
   ValueErrorR   R   R_   R   R]   Rn   t	   itertoolst   islicet   nextt   StopIterationt   chaint	   TypeError(   t   sourcet   sizet   endt   it   nt   itrt	   chunk_itrt   first(    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   batch  s&    
	c         C   s5  t  |  t  r6 t  | t  s- t d   n  t } nB t  |  t  rl t  | t  sc t d   n  t } n t d   t |   t |  k } | r |  } d } n  | s | } d } n  | r xh t | |  D] \ } } | | | AO} q Wn: x7 t | |  D]& \ } } | t |  t |  AO} qW| d k S(   s  Check two strings/bytes for equality.

    This function uses an approach designed to prevent
    timing analysis, making it appropriate for cryptography.
    a and b must both be of the same type: either str (ASCII only),
    or any type that supports the buffer protocol (e.g. bytes).

    Note: If a and b are of different lengths, or if an error occurs,
    a timing attack could theoretically reveal information about the
    types and lengths of a and b--but not their values.
    s)   inputs must be both unicode or both bytesi    i   (	   R   R(   R   Rj   t   bytesR%   R_   t   zipt   ord(   t   leftt   rightt   is_py3_bytest	   same_sizet   tmpt   resultt   lt   r(    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR3   ;  s,    				(   t   compare_digestt   ,c         C   sX   |  j    }  |  j |  r( |  d  }  n  |  s2 g  Sg  |  j |  D] } | j    ^ qB S(   sR   split comma-separated string into list of elements,
    stripping whitespace.
    i(   t   stript   endswitht   split(   R   t   sept   elem(    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt
   splitcomma  s    t   valuec            s  t  |  t  s+ t d t |   f   n  t j  t j   t    f d   |  D  } t j	 d |  } | sx t
 St j } | | d  r | | d  s t d |   n  t j } n | } t j } t j } t j } t j } t j }	 t j }
 t j } t j } t j } xv| D]n}   |  s=t d    |  sVt d   | |  rut d	 |   n  | |  rt d
 |   n  | |  rt d |   n  | |  rt d |   n  |	 |  rt d |   n  |
 |  rt d |   n  | |  r/t d |   n  | |  rNt d |   n  | |  rmt d |   n  | |  rt d |   qqW| S(   s  Normalizes unicode strings using SASLPrep stringprep profile.

    The SASLPrep profile is defined in :rfc:`4013`.
    It provides a uniform scheme for normalizing unicode usernames
    and passwords before performing byte-value sensitive operations
    such as hashing. Among other things, it normalizes diacritic
    representations, removes non-printing characters, and forbids
    invalid characters such as ``\n``. Properly internationalized
    applications should run user passwords through this function
    before hashing.

    :arg source:
        unicode string to normalize & validate

    :param param:
        Optional noun identifying source parameter in error messages
        (Defaults to the string ``"value"``). This is mainly useful to make the caller's error
        messages make more sense contextually.

    :raises ValueError:
        if any characters forbidden by the SASLPrep profile are encountered.

    :raises TypeError:
        if input is not :class:`!unicode`

    :returns:
        normalized unicode string

    .. note::

        This function is not available under Jython,
        as the Jython stdlib is missing the :mod:`!stringprep` module
        (`Jython issue 1758320 <http://bugs.jython.org/issue1758320>`_).

    .. versionadded:: 1.6
    s$   input must be unicode string, not %sc         3   s3   |  ]) }   |  s  |  r' t  n | Vq d  S(   N(   t   _USPACE(   R|   t   c(   t   in_table_b1t   in_table_c12(    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pys	   <genexpr>  s   t   NFKCi    is   malformed bidi sequence in s$   failed to strip B.1 in mapping stages(   failed to replace C.1.2 in mapping stages$   unassigned code points forbidden in s    control characters forbidden in s$   private use characters forbidden in s"   non-char code points forbidden in s   surrogate codes forbidden in s!   non-plaintext chars forbidden in s!   non-canonical chars forbidden in s1   display-modifying / deprecated chars forbidden ins   tagged characters forbidden in s   forbidden bidi character in (   R   R(   R   R   t
   stringprepR   R   R'   t   unicodedatat	   normalizet   _UEMPTYt   in_table_d1R   t   in_table_d2t   in_table_a1t   in_table_c21_c22t   in_table_c3t   in_table_c4t   in_table_c5t   in_table_c6t   in_table_c7t   in_table_c8t   in_table_c9R   (   R   t   paramt   datat   is_ral_chart   is_forbidden_bidi_charR   R   R   R   R   R   R   R   R   R   (    (   R   R   sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR4     sf    ,												c         C   s   t  d t   d S(   s   stub for saslprep()s>   saslprep() support requires the 'stringprep' module, which is N(   RV   t   _stringprep_missing_reason(   R   R   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR4     s    c         G   sH   t  |  t  r! |  j d  }  n  |  t d   | D  } | j d  S(   s  Peform ``%`` formating using bytes in a uniform manner across Python 2/3.

    This function is motivated by the fact that
    :class:`bytes` instances do not support ``%`` or ``{}`` formatting under Python 3.
    This function is an attempt to provide a replacement:
    it converts everything to unicode (decoding bytes instances as ``latin-1``),
    performs the required formatting, then encodes the result to ``latin-1``.

    Calling ``render_bytes(source, *args)`` should function roughly the same as
    ``source % args`` under Python 2.

    .. todo::
        python >= 3.5 added back limited support for bytes %,
        can revisit when 3.3/3.4 is dropped.
    s   latin-1c         s   s3   |  ]) } t  | t  r' | j d   n | Vq d S(   s   latin-1N(   R   R   t   decode(   R|   Rt   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pys	   <genexpr>,  s   (   R   R   R   R   t   encode(   R   Rw   R   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR6     s
    c         C   s   t  j |  d  S(   Nt   big(   t   intt
   from_bytes(   R   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   bytes_to_int2  s    c         C   s   |  j  | d  S(   NR   (   R9   (   R   t   count(    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   int_to_bytes4  s    (   t   hexlifyt	   unhexlifyc         C   s   t  t |   d  S(   Ni   (   R   R   (   R   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR   9  s    c         C   s   t  d | d >|   S(   Ns   %%0%dxi   (   R   (   R   R   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR   ;  s    s/   decode byte string as single big-endian integers/   encode integer as single big-endian byte stringc         C   s#   t  t |   t |  At |    S(   s;   Perform bitwise-xor of two byte strings (must be same size)(   R   R   R_   (   R   R   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR5   A  s    c         C   s$   d | d t  |   } |  | |  S(   sE   
    repeat or truncate <source> string, so it has length <size>
    i   (   R_   (   R   R   t   mult(    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   repeat_stringE  s    c         C   s)   d | d t  |   } t |  | |  S(   sN   
    variant of repeat_string() which truncates to nearest UTF8 boundary.
    i   (   R_   t   utf8_truncate(   R   R   R   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   utf8_repeat_stringM  s    s    c         C   s^   t  |   } | | k rR | d k rB t |  t  r9 t n t } n  |  | | | S|  |  Sd S(   s>   right-pad or truncate <source> string, so it has length <size>N(   R_   Ry   R   R(   t   _UNULLt   _BNULL(   R   R   t   padt   cur(    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   right_pad_stringX  s    c            s   t   t  s$ t  t d   n  t   } | d k  rR t d | |  } n  | | k rb  St | d |  } xJ | | k  r t  |  d @d k r Pn  | d 7} qx W| | k s t   |       f d   } |   s t    S(   s  
    helper to truncate UTF8 byte string to nearest character boundary ON OR AFTER <index>.
    returned prefix will always have length of at least <index>, and will stop on the
    first byte that's not a UTF8 continuation byte (128 - 191 inclusive).
    since utf8 should never take more than 4 bytes to encode known unicode values,
    we can stop after ``index+3`` is reached.

    :param bytes source:
    :param int index:
    :rtype: bytes
    R   i    i   i   i   i   c             sJ   y  j  d  }  Wn t k
 r' t SX|  j   j  d   sF t  t S(   Ns   utf-8(   R   t   UnicodeDecodeErrorRn   t
   startswithR   (   t   text(   R   R   (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   sanity_check  s    (   R   R   R   R_   t   maxt   minR)   R   (   R   t   indexR   R   (    (   R   R   sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR   c  s"    
s	    
 aA:#!t   asciic         C   s   t  j |   t k S(   sR   Test if codec is compatible with 7-bit ascii (e.g. latin-1, utf-8; but not utf-16)(   t   _ASCII_TEST_UNICODER   t   _ASCII_TEST_BYTES(   t   codec(    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   is_ascii_codec  s    c         C   s<   |  | k r t  S|  o | s  t St |   j t |  j k S(   s3   Check if two codec names are aliases for same codec(   Rn   Rj   t   _lookup_codect   name(   R   R   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR7     s
    s   i    c            s5   t  |  t  r t n t   t   f d   |  D  S(   s<   Check if string (bytes or unicode) contains only 7-bit asciic         3   s   |  ] } |   k  Vq d  S(   N(    (   R|   R   (   R   (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pys	   <genexpr>  s    (   R   R   t   _B80t   _U80t   all(   R   (    (   R   sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR8     s    s   utf-8c         C   s}   | s t   t |  t  rN | rG t | |  rG |  j |  j |  S|  Sn+ t |  t  rj |  j |  St |  |   d S(   s  Helper to normalize input to bytes.

    :arg source:
        Source bytes/unicode to process.

    :arg encoding:
        Target encoding (defaults to ``"utf-8"``).

    :param param:
        Optional name of variable/noun to reference when raising errors

    :param source_encoding:
        If this is specified, and the source is bytes,
        the source will be transcoded from *source_encoding* to *encoding*
        (via unicode).

    :raises TypeError: if source is not unicode or bytes.

    :returns:
        * unicode strings will be encoded using *encoding*, and returned.
        * if *source_encoding* is not specified, byte strings will be
          returned unchanged.
        * if *source_encoding* is specified, byte strings will be transcoded
          to *encoding*.
    N(   R   R   R   R7   R   R   R(   R   (   R   t   encodingR   t   source_encoding(    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR9     s    c         C   sN   | s t   t |  t  r |  St |  t  r; |  j |  St |  |   d S(   s  Helper to normalize input to unicode.

    :arg source:
        source bytes/unicode to process.

    :arg encoding:
        encoding to use when decoding bytes instances.

    :param param:
        optional name of variable/noun to reference when raising errors.

    :raises TypeError: if source is not unicode or bytes.

    :returns:
        * returns unicode strings unchanged.
        * returns bytes strings decoded using *encoding*
    N(   R   R   R(   R   R   R   (   R   R   R   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR:     s    c         C   sB   t  |  t  r |  j |  St  |  t  r/ |  St |  |   d  S(   N(   R   R   R   R(   R   (   R   R   R   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR;     s
    c         C   sB   t  |  t  r |  St  |  t  r/ |  j |  St |  |   d  S(   N(   R   R   R(   R   R   (   R   R   R   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR;     s
    s>  Take in unicode or bytes, return native string.

    Python 2: encodes unicode using specified encoding, leaves bytes alone.
    Python 3: leaves unicode alone, decodes bytes using specified encoding.

    :raises TypeError: if source is not unicode or bytes.

    :arg source:
        source unicode or bytes string.

    :arg encoding:
        encoding to use when encoding unicode or decoding bytes.
        this defaults to ``"utf-8"``.

    :param param:
        optional name of variable/noun to reference when raising errors.

    :returns: :class:`str` instance
    t
   deprecateds   1.6t   removeds   1.7c         C   s   t  |  | d d S(   s'   deprecated, use to_native_str() insteadR   t   hash(   R;   (   R   R   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   to_hash_str$  s    s    true t yes y on 1 enable enableds#   false f no n off 0 disable disabledt   nonet   booleanc         C   s   | t  t d g k s t  t |  t  r |  j   j   } | t k rL t  S| t	 k r\ t S| t
 k rl | St d | |  f   n- t |  t  r |  S|  d k r | St |   Sd S(   s\   
    helper to convert value to boolean.
    recognizes strings such as "true", "false"
    s   unrecognized %s value: %rN(   Rn   Rj   Ry   R   R   R,   t   lowerR   t	   _true_sett
   _false_sett	   _none_setR   t   bool(   R   R   R   t   clean(    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   as_bool-  s    c         C   sH   t  s t |  t  r t Sy |  j d  t SWn t k
 rC t SXd S(   s   
    UT helper --
    test if value is safe to pass to crypt.crypt();
    under PY3, can't pass non-UTF8 bytes to crypt.crypt.
    s   utf-8N(   t   crypt_accepts_bytesR   R   Rn   R   R   Rj   (   R   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   is_safe_crypt_inputG  s    (   t   cryptc         C   s   d  S(   N(   Ry   (   t   secretR   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR>   ]  s    i   i   (   t   nullcontexts   *:!s   t   xxc         C   sx  t  rf t |  t  r' |  j d  }  n  t |  k rB t d   n  t | t  r| j d  } qn t |  t  r |  } y |  j d  }  Wn t k
 r d  SX|  j d  | k s t
 d   n  t |  k r t d   n  t | t  r| j d  } n  y  t  t |  |  } Wd  QXWn t k
 r7d  SXt | t  rY| j d  } n  | sp| d t k rtd  S| S(   Ns   utf-8s   null character in secretR   s"   utf-8 spec says this can't happen!i    (   R  R   R(   R   R   R   R   R   R   Ry   R   t   _NULLt   _safe_crypt_lockt   _cryptt   OSErrort   _invalid_prefixes(   R  R   t   origR   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR>     s:    c         C   s   t  |  t  r! |  j d  }  n  t |  k r< t d   n  t  | t  r] | j d  } n  t  t |  |  } Wd  QX| s d  S| j d  } | d t	 k r d  S| S(   Ns   utf-8s   null character in secretR   i    (
   R   R(   R   R  R   R	  R
  Ry   R   R  (   R  R   R   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR>     s    s  Wrapper around stdlib's crypt.

    This is a wrapper around stdlib's :func:`!crypt.crypt`, which attempts
    to provide uniform behavior across Python 2 and 3.

    :arg secret:
        password, as bytes or unicode (unicode will be encoded as ``utf-8``).

    :arg hash:
        hash or config string, as ascii bytes or unicode.

    :returns:
        resulting hash as ascii unicode; or ``None`` if the password
        couldn't be hashed due to one of the issues:

        * :func:`crypt()` not available on platform.

        * Under Python 3, if *secret* is specified as bytes,
          it must be use ``utf-8`` or it can't be passed
          to :func:`crypt()`.

        * Some OSes will return ``None`` if they don't recognize
          the algorithm being used (though most will simply fall
          back to des-crypt).

        * Some OSes will return an error string if the input config
          is recognized but malformed; current code converts these to ``None``
          as well.
    c         C   sJ   t  | t  s% t d t |    | s7 t d   t |  |  | k S(   s   check if :func:`crypt.crypt` supports specific hash
    :arg secret: password to test
    :arg hash: known hash of password to use as reference
    :returns: True or False
    s#   hash must be unicode_or_str, got %ss   hash must be non-empty(   R   R+   R   R   R>   (   R  R   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR=     s    
c         C   sB   t  j d |   } | r> t d   | j d  j d  D  Sd S(   s   helper to parse version strings   (\d+(?:\.\d+)+)c         s   s   |  ] } t  |  Vq d  S(   N(   R   (   R|   R   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pys	   <genexpr>  s    i   t   .N(   t   ret   searchR   t   groupR   Ry   (   R   t   m(    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   parse_version  s    &i   c         C   s   d d l  m } t |  d  rd t |  d  rd y |  j   }  Wqd t k
 r` |  j d  }  qd Xn  t d  |  t t d  r t j   n d t
 t    t j   t   t r t j d	  j d
  n d f } t | | j d   j   d  S(   s.   generate prng seed value from system resourcesi(   t   sha512t   getstatet   getrandbitsi   i   s   %s %s %s %.15f %.15f %st   getpidi    s   latin-1i    s   utf-8i   i   N(   t   hashlibR  t   hasattrR  RV   R  R&   t   osR  Ry   t   idt   objectt   timeR?   t   has_urandomt   urandomR   R   R   t	   hexdigest(   R   R  R   (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   genseed  s    		(c            s)     s
 t  S   f d   } t |    S(   s]   return byte-string containing *count* number of randomly generated bytes, using specified rngc          3   sM    j    d > }  d } x- |   k  rH |  d @V|  d L}  | d 7} q Wd  S(   Ni   i    i   i   (   R  (   R   R   (   R   R@   (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   helperM  s    	
(   t   _BEMPTYR!   (   R@   R   R"  (    (   R   R@   sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyRA   B  s    	c            s    d k  r t  d   n  t      d k rB t  d   n   d k rV    S     f d   } t   t  r t |    St |    Sd S(   s|   return string containing *count* number of chars/bytes, whose elements are drawn from specified charset, using specified rngi    s   count must be >= 0s   alphabet must not be emptyi   c          3   sT    j  d    }  d } x1 |  k  rO   |   V|   }  | d 7} q Wd  S(   Ni    i   (   t	   randrange(   R   R   (   t   charsetR   t   lettersR@   (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyR"  f  s    
N(   R   R_   R   R(   R'   R"   (   R@   R%  R   R"  (    (   R%  R   R&  R@   sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyRB   W  s    	t4   2346789ABCDEFGHJKMNPQRTUVWXYZabcdefghjkmnpqrstuvwxyzs   2.0t   replacements/   passlib.pwd.genword() / passlib.pwd.genphrase()i
   c         C   s   t  t | |   S(   sw  generate random password using given length & charset

    :param size:
        size of password.

    :param charset:
        optional string specified set of characters to draw from.

        the default charset contains all normal alphanumeric characters,
        except for the characters ``1IiLl0OoS5``, which were omitted
        due to their visual similarity.

    :returns: :class:`!str` containing randomly generated password.

    .. note::

        Using the default character set, on a OS with :class:`!SystemRandom` support,
        this function should generate passwords with 5.7 bits of entropy per character.
    (   RB   R@   (   R   R%  (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyRC   v  s    R   t   setting_kwdst   context_kwdst   verifyR   t   identifyc            s   t    f d   t D  S(   s4   check if object follows the :ref:`password-hash-api`c         3   s   |  ] } t    |  Vq d  S(   N(   R  (   R|   R   (   t   obj(    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pys	   <genexpr>  s    (   R   t   _handler_attrs(   R-  (    (   R-  sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyRD     s    t   needs_updatet	   genconfigt   genhasht   encryptc            s   t    f d   t D  S(   sO   check if object appears to be a :class:`~passlib.context.CryptContext` instancec         3   s   |  ] } t    |  Vq d  S(   N(   R  (   R|   R   (   R-  (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pys	   <genexpr>  s    (   R   t   _context_attrs(   R-  (    (   R-  sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyRE     s    c         C   s%   d |  j  k o$ t |  d d  d k	 S(   s_   check if handler provides the optional :ref:`rounds information <rounds-attributes>` attributest   roundst
   min_roundsN(   R)  t   getattrRy   (   t   handler(    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyRF     s    c         C   s%   d |  j  k o$ t |  d d  d k	 S(   s[   check if handler provides the optional :ref:`salt information <salt-attributes>` attributest   saltt   min_salt_sizeN(   R)  R6  Ry   (   R7  (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyRG     s    t   (   i   i   i    (   i   i   i   (   R   R)  R*  R+  R   R,  (   R/  R0  R1  R+  R2  R,  (   Rf   t   passlib.utils.compatR    t   binasciiR   R   R   t   _BinAsciiErrort   base64R   R   t   collections.abcR   R   t   ImportErrort   collectionst   codecsR   R   t	   functoolsR	   R   Rg   t   loggingt	   getLoggerRd   t   logt   mathR  t   syst   randomR  R   Ry   R   R  R   t	   threadingt   timeitt   typest   warningsR
   t   passlib.utils.binaryR   R   R   R   R   R   R   R   R   R   R   R   R   t   passlib.utils.decorR   R   R   R   R   t   passlib.excR   R   R   R    R!   R"   R#   R$   R%   R&   R'   R(   R)   R*   R+   R,   R-   R.   R/   t   __all__R   t   maxsizet   maxintR0   R1   R2   RQ   R#  R   R   t   environRk   t   MAX_PASSWORD_SIZER  RU   t	   Parametert   VAR_KEYWORDRp   t   sett   VAR_POSITIONALRm   Ru   Rj   R   R   R3   t   str_consteqt   hmacR   R   R4   R6   R   R   R   R   R5   R   R   R   R   R   R   R   R   R   R   R7   R   R   R8   R9   R:   R;   R   R   R   R   R   R  R  R  R
  R<   R  t   crypt_needs_lockR	  R>   Rn   R  t   pypy_version_infot   LockR  R  R   R=   t   default_timert   timerR?   R  R  R  RV   R!  t   SystemRandomR@   t   RandomRA   RB   t
   _52charsetRC   R.  RD   R3  RE   RF   RG   (    (    (    sQ   /var/www/html/packages/venv/lib/python3.8/site-packages/passlib/utils/__init__.pyt   <module>   s   
X(p	.		V		>								F			%	+			/				

!		  	  	
	