U
    
Haå	  ã                   @   s    d dl mZ G dd„ deƒZdS )é    )ÚBytesIOc                   @   sB   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zddd„Zdd„ Z	d
S )ÚCallbackFileWrapperav  
    Small wrapper around a fp object which will tee everything read into a
    buffer, and when that file is closed it will execute a callback with the
    contents of that buffer.

    All attributes are proxied to the underlying file object.

    This class uses members with a double underscore (__) leading prefix so as
    not to accidentally shadow an attribute.
    c                 C   s   t ƒ | _|| _|| _d S ©N)r   Ú_CallbackFileWrapper__bufÚ_CallbackFileWrapper__fpÚ_CallbackFileWrapper__callback)ÚselfÚfpÚcallback© r   úH/tmp/pip-unpacked-wheel-tx790h60/pip/_vendor/cachecontrol/filewrapper.pyÚ__init__   s    zCallbackFileWrapper.__init__c                 C   s   |   d¡}t||ƒS )Nr   )Ú__getattribute__Úgetattr)r   Únamer	   r   r   r   Ú__getattr__   s    	
zCallbackFileWrapper.__getattr__c                 C   sH   z| j jd kW S  tk
r"   Y nX z
| j jW S  tk
rB   Y nX dS )NF)r   r	   ÚAttributeErrorÚclosed©r   r   r   r   Ú__is_fp_closed!   s    
z"CallbackFileWrapper.__is_fp_closedc                 C   s    | j r|   | j ¡ ¡ d | _ d S r   )r   r   Úgetvaluer   r   r   r   Ú_close2   s    zCallbackFileWrapper._closeNc                 C   s,   | j  |¡}| j |¡ |  ¡ r(|  ¡  |S r   )r   Úreadr   ÚwriteÚ"_CallbackFileWrapper__is_fp_closedr   ©r   ÚamtÚdatar   r   r   r   =   s
    zCallbackFileWrapper.readc                 C   s@   | j  |¡}|dkr |dkr |S | j |¡ |  ¡ r<|  ¡  |S )Né   s   
)r   Ú
_safe_readr   r   r   r   r   r   r   r   r   E   s    zCallbackFileWrapper._safe_read)N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r   r      s   
r   N)Úior   Úobjectr   r   r   r   r   Ú<module>   s   