
-ºAj›7  ã            "   @   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   . 							

					-
: