
Ѯh7              "   @   s8  d  Z  d d l Z e j dk k  Z e j dl k Z e j dm k  s^ dn e j k oY do k  n rj e d   e j dp k  Z e j j d  Z	 e
 e d	  Z e r e j dq k  r e d
   d e j k Z d d l Z e j e  Z e r d d l Z n d d l Z d d   Z 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& d' d( d) d* d+ d, d- d. d g" Z e   Z e re Z d/ d   Z e e f Z e f Z n' e j Z d0 d   Z e f Z e f Z e Z  e Z! e d1  j" Z# d2 j" Z$ e rid3 d   Z% d4 d   Z& d5 d   Z' d6 d   Z( e Z) Z* d7 d$   Z+ d8 d%   Z, d9 d:   Z- n` d; d   Z% d< d   Z& d= d   Z' d> d   Z( d? d"   Z) e$ Z* e. Z+ d@ d%   Z, dA d:   Z- e e% dB  e e& dC  e e' dD  e e( dE  e e, dF  e e- dG  e r5e/ f Z0 e/ e1 f Z2 n e/ e3 f Z0 e/ e3 e1 f Z2 e re4 Z5 dH d(   Z6 e7 Z8 dI d)   Z9 dJ d*   Z: dK dL   Z; e< Z= nF e> Z5 e7 Z6 d dM l? m8 Z8 m= Z= dN d)   Z9 dO d*   Z: dP dL   Z; e e; dQ  e rdR Z@ n dS Z@ dT d.   ZA dU dV   ZB d dW dX  ZC eC ZD e rie d dY dZ d[ d d[ d d\  Z eE e d]  ZF n- e d d^ dZ d_ d d^ d d`  Z da d   ZF e rdb e d, <n
 dc e d, <y d dd lG mH ZH Wn( eI k
 rGde d-   d- eJ  ZH Yn Xd df lK mL ZL dg dh   ZM Gdi dj   dj eL  ZN eN jO e e  d S)rz7passlib.utils.compat - python 2/3 compatibility helpers    N         z?Passlib requires Python 2.6, 2.7, or >= 3.2 (as of passlib 1.7)   javapypy_version_infoz0passlib requires pypy >= 2.0 (as of passlib 1.7)ZPystonc             C   s   | |  _  d S)zadd docstring to an objectN)__doc__)objdoc r   &../../passlib/utils/compat/__init__.pyadd_doc*   s    r   PY2PY3PY26BytesIOStringIOZNativeStringIOZSafeConfigParserprint_	int_types	num_typesunicode_or_bytes_typesnative_string_typesuunicodeuascii_to_strbascii_to_strstr_to_uasciistr_to_basciijoin_unicode
join_bytesjoin_byte_valuesjoin_byte_elemsbyte_elem_valueiter_byte_valuesirangeimaplmap	iteritems
itervaluesnextOrderedDictnullcontextget_method_functionc             C   s   t  |  t  s t  |  S)N)
isinstancestrAssertionError)sr   r   r   r   e   s    c             C   s"   t  |  t  s t  |  j d  S)NZunicode_escape)r-   r.   r/   decode)r0   r   r   r   r   o   s         c             C   s   t  |  t  s t  |  S)N)r-   r   r/   )r0   r   r   r   r      s    c             C   s"   t  |  t  s t  |  j d  S)Nascii)r-   bytesr/   r1   )r0   r   r   r   r      s    c             C   s   t  |  t  s t  |  S)N)r-   r.   r/   )r0   r   r   r   r      s    c             C   s"   t  |  t  s t  |  j d  S)Nr4   )r-   r.   r/   encode)r0   r   r   r   r      s    c             C   s   t  |  t  s t  |  S)N)r-   intr/   )elemr   r   r   r"      s    c             C   s   t  |  t  s t  |  S)N)r-   r5   r/   )r0   r   r   r   r#      s    c             C   s&   t  |  t  s t  d d   |  D S)Nc             s   s   |  ] } t  | g  Vq d  S)N)r5   ).0cr   r   r   	<genexpr>   s    z"iter_byte_chars.<locals>.<genexpr>)r-   r5   r/   )r0   r   r   r   iter_byte_chars   s    r<   c             C   s"   t  |  t  s t  |  j d  S)Nr4   )r-   r   r/   r6   )r0   r   r   r   r      s    c             C   s   t  |  t  s t  |  S)N)r-   r5   r/   )r0   r   r   r   r      s    c             C   s"   t  |  t  s t  |  j d  S)Nr4   )r-   r.   r/   r1   )r0   r   r   r   r      s    c             C   s   t  |  t  s t  |  S)N)r-   r.   r/   )r0   r   r   r   r      s    c             C   s   t  d d   |  D  S)Nc             s   s   |  ] } t  |  Vq d  S)N)chr)r9   vr   r   r   r;      s    z#join_byte_values.<locals>.<genexpr>)r   )valuesr   r   r   r       s    c             C   s&   t  |  t  s t  d d   |  D S)Nc             s   s   |  ] } t  |  Vq d  S)N)ord)r9   r:   r   r   r   r;      s    z#iter_byte_values.<locals>.<genexpr>)r-   r5   r/   )r0   r   r   r   r#      s    c             C   s   t  |  t  s t  |  S)N)r-   r5   r/   )r0   r   r   r   r<      s    z-helper to convert ascii unicode -> native strz+helper to convert ascii bytes -> native strz-helper to convert ascii native str -> unicodez+helper to convert ascii native str -> bytesz2iterate over byte string as sequence of ints 0-255z6iterate over byte string as sequence of 1-byte stringsc              O   s   t  t |  |    S)N)listmap)akr   r   r   r&      s    c             C   s
   |  j    S)N)items)dr   r   r   r'      s    c             C   s
   |  j    S)N)r?   )rF   r   r   r   r(      s    c             C   s   |  j  S)N)__next__)r	   r   r   r   
nextgetter   s    rH   )r%   izipc             C   s
   |  j    S)N)r'   )rF   r   r   r   r'     s    c             C   s
   |  j    S)N)r(   )rF   r   r   r   r(     s    c             C   s   |  j  S)N)r)   )r	   r   r   r   rH   
  s    z;return function that yields successive values from iterable__func__Zim_funcc             C   s   t  |  t |   S)z4given (potential) method, return underlying function)getattrmethod_function_attr)funcr   r   r   r,     s    c             C   s   t  r
 |  S|  j S)z0given unbound method, return underlying function)r   rJ   )rM   r   r   r   get_unbound_method_function"  s    rN   c             C   s   | |  _  d |  _ |  S)z
    backward compat hack to suppress exception cause in python3.3+

    one python < 3.3 support is dropped, can replace all uses with "raise exc from None"
    T)	__cause____suppress_context__)exccauser   r   r   
error_from&  s    		rS   z
io.BytesIOZ	UnicodeIOzio.StringIOzconfigparser.ConfigParserprintzcStringIO.StringIOzStringIO.StringIOzConfigParser.SafeConfigParserc        	      O   s  | j  d t j  } | j  d d  } | j  d d  } | rK t d   | d k r[ d St | t  p t | t  p t d d   |  D  } | d k r | r t d  n d } n t | t  s t d	   | d k r | r t d
  n d
 } n t | t  st d   d } | j	 } xL |  D]D } | rAd } n
 | |  t | t
  sft |  } | |  q,W| |  d S)zThe new-style print function.filesepNendzinvalid keyword argumentsc             s   s   |  ] } t  | t  Vq d  S)N)r-   r   )r9   argr   r   r   r;   X  s    zprint_.<locals>.<genexpr>
zend must be None or a string zsep must be None or a stringTF)popsysstdout	TypeErrorr-   r   anyr   r   write
basestringr.   )	argskwdsfprV   rW   Zwant_unicodefirstr`   rX   r   r   r   r   I  s6    		
z.passlib.utils.compat._ordered_dict.OrderedDictzcollections.OrderedDict)r+   c               @   s=   e  Z d  Z d Z d d d  Z d d   Z d d   Z d S)	r+   zE
        Context manager that does no additional processing.
        Nc             C   s   | |  _  d  S)N)enter_result)selfrf   r   r   r   __init__  s    znullcontext.__init__c             C   s   |  j  S)N)rf   )rg   r   r   r   	__enter__  s    znullcontext.__enter__c             G   s   d  S)Nr   )rg   exc_infor   r   r   __exit__  s    znullcontext.__exit__)__name__
__module____qualname__r   rh   ri   rk   r   r   r   r   r+     s   )
ModuleTypec             C   s@   |  j  d d  \ } } t | d | g d d } t | |  S)zChelper to import object from module; accept format `path.to.object`.   fromlistlevelr   )rsplit
__import__rK   )sourcemodnameZmodattrmodr   r   r   _import_object  s    ry   c               @   s[   e  Z d  Z d Z e d d    Z d d d  Z d d   Z d	 d
   Z d d   Z	 d S)_LazyOverlayModuleag  proxy module which overlays original module,
    and lazily imports specified attributes.

    this is mainly used to prevent importing of resources
    that are only needed by certain password hashes,
    yet allow them to be imported from a single location.

    used by :mod:`passlib.utils`, :mod:`passlib.crypto`,
    and :mod:`passlib.utils.compat`.
    c             C   s0   t  j | } |  | | |  } | t  j | <| S)N)r\   modules)clsnameattrmaporigrg   r   r   r   replace_module  s    z!_LazyOverlayModule.replace_moduleNc             C   s8   t  j |  |  | |  _ | |  _ t j |  |  _ d  S)N)ro   rh   _LazyOverlayModule__attrmap_LazyOverlayModule__proxylogging	getLogger_LazyOverlayModule__log)rg   r}   r~   proxyr   r   r   rh     s    		z_LazyOverlayModule.__init__c             C   s   |  j  } | r+ t | |  r+ t | |  S|  j } | | k r | | } t |  rb |   } n t |  } t |  | |  |  j j d | |  | St	 d | f   d  S)Nzloaded lazy attr %r: %rz%'module' object has no attribute '%s')
r   hasattrrK   r   callablery   setattrr   debugAttributeError)rg   attrr   r~   rv   valuer   r   r   __getattr__  s    		
z_LazyOverlayModule.__getattr__c             C   s*   |  j  } | r t |  St j |   Sd  S)N)r   reprro   __repr__)rg   r   r   r   r   r     s    	
z_LazyOverlayModule.__repr__c             C   sg   t  t |  j   } | j |  j  | j |  j  |  j } | d  k	 r] | j t |   t |  S)N)setdir	__class__update__dict__r   r   rA   )rg   attrsr   r   r   r   __dir__  s    	z_LazyOverlayModule.__dir__)
rl   rm   rn   r   classmethodr   rh   r   r   r   r   r   r   r   rz     s   
rz   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )Pr   r\   version_infor   r   RuntimeErrorr   platform
startswithJYTHONr   PYPYr   versionZPYSTONr   r   rl   logbuiltinsZ__builtin__r   __all__dictZ_lazy_attrsr.   r   r   r5   r   r   ra   Zunicode_or_bytesunicode_or_strjoinr   r   r   r   r   r   r    r!   r"   r#   r<   r@   r7   r   floatr   Zlongranger$   r&   rB   r%   r'   r(   rH   ziprI   Zxrange	itertoolsrL   r,   rN   rS   suppress_causerK   r   Z
contextlibr+   ImportErrorobjecttypesro   ry   rz   r   r   r   r   r   <module>   s   . 							

					-
: