U
    cUh                     @  sV   d dl mZ d dlZd dlmZ d dlmZmZmZ erDd dl	m
Z
 G dd dZdS )    )annotationsN)NamedTemporaryFile)TYPE_CHECKINGAnyCallable)HTTPResponsec                   @  sp   e Zd ZdZddddddZdd	d
ddZddddZddddZddddddZdddddZ	dS )CallbackFileWrappera  
    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.

    The data is stored in a temporary file until it is all available.  As long
    as the temporary files directory is disk-based (sometimes it's a
    memory-backed-``tmpfs`` on Linux), data will be unloaded to disk if memory
    pressure is high.  For small files the disk usually won't be used at all,
    it'll all be in the filesystem memory cache, so there should be no
    performance impact.
    r   zCallable[[bytes], None] | NoneNone)fpcallbackreturnc                 C  s   t ddd| _|| _|| _d S )Nzrb+T)delete)r   _CallbackFileWrapper__buf_CallbackFileWrapper__fp_CallbackFileWrapper__callback)selfr
   r    r   d/opt/bot/vods_filmes/script/venv/lib/python3.8/site-packages/pip/_vendor/cachecontrol/filewrapper.py__init__!   s    zCallbackFileWrapper.__init__strr   )namer   c                 C  s   |  d}t||S )Nr   )__getattribute__getattr)r   r   r
   r   r   r   __getattr__(   s    	
zCallbackFileWrapper.__getattr__bool)r   c                 C  sL   z| j jd kW S  tk
r"   Y nX z| j j}|W S  tk
rF   Y nX dS )NF)r   r
   AttributeErrorclosed)r   r   r   r   r   Z__is_fp_closed4   s    z"CallbackFileWrapper.__is_fp_closedc                 C  sb   | j rN| j dkrd}n*| jdd ttj| j dtjd}|  | d | _ | j  d S )Nr       )access)	r   r   tellseek
memoryviewmmapfilenoZACCESS_READclose)r   resultr   r   r   _closeF   s    
zCallbackFileWrapper._closeNz
int | Nonebytes)amtr   c                 C  s0   | j |}|r| j| |  r,|   |S )N)r   readr   write"_CallbackFileWrapper__is_fp_closedr&   r   r(   datar   r   r   r)   a   s    zCallbackFileWrapper.readintc                 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   r0   l   s    zCallbackFileWrapper._safe_read)N)
__name__
__module____qualname____doc__r   r   r+   r&   r)   r0   r   r   r   r   r      s   r   )
__future__r   r"   tempfiler   typingr   r   r   http.clientr   r   r   r   r   r   <module>   s   