U
    c6{iÍ  ã                   @  s2  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZm	Z	 G dd„ de
ƒZeZeZeZeZeZejdkr„ejeeef ZnejZddd	d
œdd„Zddd	d
œdd„Zd(ddddœdd„ZG dd„ deƒZG dd„ dƒZG dd„ dejƒZd)dddddddœdd „Z d!d"d#œd$d%„Z!G d&d'„ d'ej"ƒZ"dS )*é    )ÚannotationsN)ÚCallableÚSequencec                   @  s   e Zd ZdS )ÚCryptographyDeprecationWarningN©Ú__name__Ú
__module__Ú__qualname__© r
   r
   ú6/tmp/pip-unpacked-wheel-6eg_dtv9/cryptography/utils.pyr      s   r   )é   é	   ÚstrÚbytesÚNone)ÚnameÚvalueÚreturnc                 C  s   t |tƒst| › d�ƒ‚d S )Nz must be bytes)Ú
isinstancer   Ú	TypeError©r   r   r
   r
   r   Ú_check_bytes)   s    
r   ÚBufferc                 C  s4   zt |ƒ W n" tk
r.   t| › d�ƒ‚Y nX d S )Nz must be bytes-like)Ú
memoryviewr   r   r
   r
   r   Ú_check_byteslike.   s    r   Úintz
int | None)ÚintegerÚlengthr   c                 C  s0   |dkrt dƒ‚|  |p*|  ¡ d d p*dd¡S )Nr   zlength argument can't be 0é   é   é   Úbig)Ú
ValueErrorÚto_bytesÚ
bit_length)r   r   r
   r
   r   Úint_to_bytes5   s     ÿr%   c                   @  s   e Zd ZdS )ÚInterfaceNotImplementedNr   r
   r
   r
   r   r&   =   s   r&   c                   @  s   e Zd Zdddœdd„ZdS )Ú_DeprecatedValueÚobjectr   )r   Úmessagec                 C  s   || _ || _|| _d S ©N)r   r)   Úwarning_class)Úselfr   r)   r+   r
   r
   r   Ú__init__B   s    z_DeprecatedValue.__init__N)r   r   r	   r-   r
   r
   r
   r   r'   A   s   r'   c                      sb   e Zd Zddœ‡ fdd„Zdddœdd	„Zddd
dœdd„Zdd
dœdd„Zddœdd„Z‡  ZS )Ú_ModuleWithDeprecationsztypes.ModuleType)Úmodulec                   s   t ƒ  |j¡ || jd< d S )NÚ_module)Úsuperr-   r   Ú__dict__)r,   r/   ©Ú	__class__r
   r   r-   I   s    z _ModuleWithDeprecations.__init__r   r(   )Úattrr   c                 C  s4   t | j|ƒ}t|tƒr0tj|j|jdd� |j}|S ©Né   )Ú
stacklevel)	Úgetattrr0   r   r'   ÚwarningsÚwarnr)   r+   r   ©r,   r5   Úobjr
   r
   r   Ú__getattr__M   s
    
z#_ModuleWithDeprecations.__getattr__r   )r5   r   r   c                 C  s   t | j||ƒ d S r*   )Úsetattrr0   )r,   r5   r   r
   r
   r   Ú__setattr__T   s    z#_ModuleWithDeprecations.__setattr__c                 C  s:   t | j|ƒ}t|tƒr*tj|j|jdd� t| j|ƒ d S r6   )	r9   r0   r   r'   r:   r;   r)   r+   Údelattrr<   r
   r
   r   Ú__delattr__W   s    
z#_ModuleWithDeprecations.__delattr__zSequence[str]©r   c                 C  s   dt | jƒ•S )Nr0   )r0   )Údirr0   ©r,   r
   r
   r   Ú__dir__^   s    z_ModuleWithDeprecations.__dir__)	r   r   r	   r-   r>   r@   rB   rF   Ú__classcell__r
   r
   r3   r   r.   H   s
   r.   r(   ztype[Warning]z
str | None)r   Úmodule_namer)   r+   r   r   c                 C  sJ   t j| }t|tƒs&t|ƒ t j|< }t| ||ƒ}|d k	rFt|||ƒ |S r*   )ÚsysÚmodulesr   r.   r'   r?   )r   rH   r)   r+   r   r/   Zdvr
   r
   r   Ú
deprecatedb   s    

rK   r   Úproperty)Úfuncr   c                   s.   dˆ› �‰ t ƒ ‰ddœ‡ ‡‡fdd„}t|ƒS )NZ_cached_r(   )Úinstancec                   s0   t | ˆ ˆƒ}|ˆk	r|S ˆ| ƒ}t| ˆ |ƒ |S r*   )r9   r?   )rN   ÚcacheÚresult©Zcached_namerM   Úsentinelr
   r   Úinnerw   s    zcached_property.<locals>.inner)r(   rL   )rM   rS   r
   rQ   r   Úcached_propertys   s    
rT   c                   @  s(   e Zd Zddœdd„Zddœdd„ZdS )ÚEnumr   rC   c                 C  s    d| j j› d| j› d| j›d�S )Nú<Ú.z: ú>)r4   r   Ú_name_Ú_value_rE   r
   r
   r   Ú__repr__…   s    zEnum.__repr__c                 C  s   | j j› d| j› �S )NrW   )r4   r   rY   rE   r
   r
   r   Ú__str__ˆ   s    zEnum.__str__N)r   r   r	   r[   r\   r
   r
   r
   r   rU   „   s   rU   )N)N)#Ú
__future__r   ÚenumrI   ÚtypesÚtypingr:   Úcollections.abcr   r   ÚUserWarningr   ZDeprecatedIn36ZDeprecatedIn40ZDeprecatedIn41ZDeprecatedIn42ZDeprecatedIn43Úversion_infoÚUnionr   Ú	bytearrayr   r   Ú
ByteStringr   r   r%   Ú	Exceptionr&   r'   Ú
ModuleTyper.   rK   rT   rU   r
   r
   r
   r   Ú<module>   s2   
 û