î
Ó^ÝVx  ã               @   s*   d  d l  m Z Gd d „  d e ƒ Z d S)é    )ÚBytesIOc               @   sI   e  Z d  Z d Z d d „  Z d d „  Z d d „  Z d 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
   úC/tmp/pip-build-9m6vxulb/pip/pip/_vendor/cachecontrol/filewrapper.pyÚ__init__   s    	zCallbackFileWrapper.__init__c             C   s   |  j  d ƒ } t | | ƒ S)Nr   )Ú__getattribute__Úgetattr)r   Únamer   r
   r
   r   Ú__getattr__   s    	zCallbackFileWrapper.__getattr__c             C   sP   y |  j  j d  k SWn t k
 r( Yn Xy |  j  j SWn t k
 rK Yn Xd S)NF)r   r   ÚAttributeErrorÚclosed)r   r
   r
   r   Ú__is_fp_closed!   s    z"CallbackFileWrapper.__is_fp_closedNc             C   s`   |  j  j | ƒ } |  j j | ƒ |  j ƒ  r\ |  j rP |  j |  j j ƒ  ƒ n  d  |  _ n  | S)N)r   Úreadr   ÚwriteÚ"_CallbackFileWrapper__is_fp_closedr   Úgetvalue)r   ÚamtÚdatar
   r
   r   r   0   s    	zCallbackFileWrapper.read)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r
   r
   r
   r   r      s
   
r   N)Úior   Úobjectr   r
   r
   r
   r   Ú<module>   s   