관리-도구
편집 파일: filewrapper.cpython-38.pyc
U &?�f� � @ sV d dl mZ d dlZd dlmZ d dlmZmZmZ erDd dl m Z G dd� d�ZdS )� )�annotationsN)�NamedTemporaryFile)� TYPE_CHECKING�Any�Callable)�HTTPResponsec @ sp e Zd ZdZdddd�dd�Zdd d �dd�Zd d�dd�Zdd�dd�Zdddd�dd�Zddd�dd�Z dS )�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 zCallable[[bytes], None] | None�None)�fp�callback�returnc C s t ddd�| _|| _|| _d S )Nzrb+T)�delete)r �_CallbackFileWrapper__buf�_CallbackFileWrapper__fp�_CallbackFileWrapper__callback)�selfr r � r �R/opt/hc_python/lib/python3.8/site-packages/pip/_vendor/cachecontrol/filewrapper.py�__init__! s zCallbackFileWrapper.__init__�strr )�namer c C s | � d�}t||�S )Nr )�__getattribute__�getattr)r r r r r r �__getattr__( s zCallbackFileWrapper.__getattr__�bool)r c C sL z| j jd kW S tk r" Y nX z| j j}|W S tk rF Y nX dS )NF)r r �AttributeError�closed)r r r r r �__is_fp_closed4 s z"CallbackFileWrapper.__is_fp_closedc C sb | j rN| j�� dkrd}n*| j�dd� ttj| j�� dtjd��}| � |� d | _ | j�� d S )Nr � )�access) r r �tell�seek� memoryview�mmap�fileno�ACCESS_READ�close)r �resultr r r �_closeF s � zCallbackFileWrapper._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 zCallbackFileWrapper.read�intc C s@ | j �|�}|dkr |dkr |S | j�|� | �� r<| �� |S )N� s )r � _safe_readr r, r- r( r. r r r r2 l s zCallbackFileWrapper._safe_read)N) �__name__� __module__�__qualname__�__doc__r r r- r( r+ r2 r r r r r s r )� __future__r r# �tempfiler �typingr r r �http.clientr r r r r r �<module> s