
ÛÔ,Y  ã               @   sŽ  d  d l  m Z m Z m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z e	 Z
 e Z d d „  Z d d „  Z d d „  Z e e d	 ƒ r£ e j Z n d
 d d „ Z e e d ƒ rÓ d d d „ Z n d d d „ Z Gd d „  d e ƒ Z e e d ƒ re j Z n	 e j Z d d „  Z e j d! k rFd d „  Z n d d „  Z Gd d „  d e ƒ Z Gd d „  d e ƒ Z d d  „  Z d S)"é    )Úabsolute_importÚdivisionÚprint_functionNc                s   t  ‡  f d d †  ƒ S)Nc                s   t  |  ˆ  ƒ S)N)Úgetattr)Úself)Úname© ú4/usr/lib/python3/dist-packages/cryptography/utils.pyÚ<lambda>   s    z$read_only_property.<locals>.<lambda>)Úproperty)r   r   )r   r	   Úread_only_property   s    r   c                s   ‡  f d d †  } | S)Nc                s   t  ˆ  |  ƒ ˆ  j |  ƒ |  S)N)Úverify_interfaceÚregister)Úklass)Úifacer   r	   Úregister_decorator   s    z.register_interface.<locals>.register_decoratorr   )r   r   r   )r   r	   Úregister_interface   s    r   c                s   ‡  ‡ f d d †  } | S)Nc                s$   ˆ r  t  ˆ  |  ƒ ˆ  j |  ƒ |  S)N)r   r   )r   )r   Ú	predicater   r	   r   "   s    z1register_interface_if.<locals>.register_decoratorr   )r   r   r   r   )r   r   r	   Úregister_interface_if!   s    r   Ú
from_bytesFc             C   s;   | d k s t  ‚ | s t  ‚ t t |  ƒ j d ƒ d ƒ S)NÚbigÚhexé   )ÚAssertionErrorÚintÚbytesÚencode)ÚdataÚ	byteorderZsignedr   r   r	   Úint_from_bytes-   s    r   Úto_bytesc             C   s*   |  j  | p# |  j ƒ  d d p# d d ƒ S)Né   é   é   r   )r    Ú
bit_length)ÚintegerÚlengthr   r   r	   Úint_to_bytes6   s    r'   c             C   sM   d |  } | d  k r% t  | ƒ } n
 | d } t j | j | | d @ƒ ƒ S)Nz%xé   r#   )ÚlenÚbinasciiZ	unhexlifyÚzfill)r%   r&   Z
hex_stringÚnr   r   r	   r'   ;   s
    

c               @   s   e  Z d  Z d S)ÚInterfaceNotImplementedN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r	   r-   D   s   r-   Ú	signaturec             C   s±   xª |  j  D]Ÿ } t | | ƒ s7 t d j | | ƒ ƒ ‚ t t |  | ƒ t j ƒ rU q
 t t |  | ƒ ƒ } t t | | ƒ ƒ } | | k r
 t d j | | | | ƒ ƒ ‚ q
 Wd  S)Nz{0} is missing a {1!r} methodzO{0}.{1}'s signature differs from the expected. Expected: {2!r}. Received: {3!r})	Ú__abstractmethods__Úhasattrr-   ÚformatÚ
isinstancer   ÚabcÚabstractpropertyr1   )r   r   ÚmethodZsigZactualr   r   r	   r   N   s    r   r(   r!   c             C   s
   |  j  ƒ  S)N)r$   )Úxr   r   r	   r$   c   s    r$   c             C   s   t  t |  ƒ ƒ d |  d k S)Nr(   r   )r)   Úbin)r9   r   r   r	   r$   f   s    c               @   s   e  Z d  Z d d „  Z d S)Ú_DeprecatedValuec             C   s   | |  _  | |  _ | |  _ d  S)N)ÚvalueÚmessageÚwarning_class)r   r<   r=   r>   r   r   r	   Ú__init__k   s    		z_DeprecatedValue.__init__N)r.   r/   r0   r?   r   r   r   r	   r;   j   s   r;   c               @   sL   e  Z d  Z d d „  Z d d „  Z d d „  Z d d „  Z d	 d
 „  Z d S)Ú_ModuleWithDeprecationsc             C   s   | |  j  d <d  S)NÚ_module)Ú__dict__)r   Úmoduler   r   r	   r?   r   s    z _ModuleWithDeprecations.__init__c             C   sJ   t  |  j | ƒ } t | t ƒ rF t j | j | j d d ƒ| j } | S)NÚ
stacklevelr(   )	r   rA   r5   r;   ÚwarningsÚwarnr=   r>   r<   )r   ÚattrÚobjr   r   r	   Ú__getattr__u   s
    	z#_ModuleWithDeprecations.__getattr__c             C   s   t  |  j | | ƒ d  S)N)ÚsetattrrA   )r   rG   r<   r   r   r	   Ú__setattr__|   s    z#_ModuleWithDeprecations.__setattr__c             C   sQ   t  |  j | ƒ } t | t ƒ r= t j | j | j d d ƒt |  j | ƒ d  S)NrD   r(   )	r   rA   r5   r;   rE   rF   r=   r>   Údelattr)r   rG   rH   r   r   r	   Ú__delattr__   s    z#_ModuleWithDeprecations.__delattr__c             C   s   d g t  |  j ƒ S)NrA   )ÚdirrA   )r   r   r   r	   Ú__dir__†   s    z_ModuleWithDeprecations.__dir__N)r.   r/   r0   r?   rI   rK   rM   rO   r   r   r   r	   r@   q   s
   r@   c             C   s?   t  j | } t | t ƒ s/ t | ƒ t  j | <t |  | | ƒ S)N)ÚsysÚmodulesr5   r@   r;   )r<   Zmodule_namer=   r>   rC   r   r   r	   Ú
deprecatedŠ   s    rR   )r(   r!   ) Z
__future__r   r   r   r6   r*   ÚinspectrP   rE   ÚDeprecationWarningZPersistentlyDeprecatedÚPendingDeprecationWarningZDeprecatedIn19r   r   r   r3   r   r   r   r'   Ú	Exceptionr-   r1   Z
getargspecr   Úversion_infor$   Úobjectr;   r@   rR   r   r   r   r	   Ú<module>   s6   			