o
    ž<[a1  ã                   @   sB   d Z ddlZddlZejZG dd„ dejƒZG dd„ dejƒZdS )z7Internal classes used by the gzip, lzma and bz2 modulesé    Nc                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )Ú
BaseStreamzMode-checking helper functions.c                 C   s   | j rtdƒ‚d S )NzI/O operation on closed file)ÚclosedÚ
ValueError©Úself© r   ú*/var/www/Python-3.10.0/Lib/_compression.pyÚ_check_not_closed   s   ÿzBaseStream._check_not_closedc                 C   ó   |   ¡ s	t d¡‚d S )NzFile not open for reading)ÚreadableÚioÚUnsupportedOperationr   r   r   r   Ú_check_can_read   ó   
ÿzBaseStream._check_can_readc                 C   r
   )NzFile not open for writing)Úwritabler   r   r   r   r   r   Ú_check_can_write   r   zBaseStream._check_can_writec                 C   s(   |   ¡ s	t d¡‚|  ¡ st d¡‚d S )Nz3Seeking is only supported on files open for readingz3The underlying file object does not support seeking)r   r   r   Úseekabler   r   r   r   Ú_check_can_seek   s
   

ÿzBaseStream._check_can_seekN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r   r   r   r   r   r   	   s    r   c                       sr   e Zd ZdZdd„ Zddd„Z‡ fdd„Zd	d
„ Zdd„ Zddd„Z	dd„ Z
dd„ Zejfdd„Zdd„ Z‡  ZS )ÚDecompressReaderz5Adapts the decompressor API to a RawIOBase reader APIc                 C   s   dS )NTr   r   r   r   r   r   $   s   zDecompressReader.readabler   c                 K   sB   || _ d| _d| _d| _|| _|| _| jdi | j¤Ž| _|| _d S )NFr   éÿÿÿÿr   )Ú_fpÚ_eofÚ_posÚ_sizeÚ_decomp_factoryÚ_decomp_argsÚ_decompressorÚ_trailing_error)r   ÚfpZdecomp_factoryÚtrailing_errorZdecomp_argsr   r   r   Ú__init__'   s   
zDecompressReader.__init__c                    s   d | _ tƒ  ¡ S ©N)r    ÚsuperÚcloser   ©Ú	__class__r   r   r'   ;   s   
zDecompressReader.closec                 C   s
   | j  ¡ S r%   )r   r   r   r   r   r   r   ?   s   
zDecompressReader.seekablec              	   C   s’   t |ƒ9}| d¡}|  t|ƒ¡}||d t|ƒ…< W d   ƒ n1 s$w   Y  W d   ƒ t|ƒS W d   ƒ t|ƒS 1 s@w   Y  t|ƒS )NÚB)Ú
memoryviewÚcastÚreadÚlen)r   ÚbZviewZ	byte_viewÚdatar   r   r   ÚreadintoB   s   (þýýzDecompressReader.readintor   c                 C   sê   |dk r|   ¡ S |r| jrdS d }	 | jjrA| jjp| j t¡}|s#q_| jdi | j	¤Ž| _z	| j 
||¡}W n$ | jy@   Y q_w | jjrR| j t¡}|sQtdƒ‚nd}| j 
||¡}|r^q_q|sjd| _| j| _dS |  jt|ƒ7  _|S )Nr   ó    TzACompressed file ended before the end-of-stream marker was reachedr   )Úreadallr   r    ÚeofÚunused_datar   r-   ÚBUFFER_SIZEr   r   Ú
decompressr!   Zneeds_inputÚEOFErrorr   r   r.   )r   Úsizer0   Zrawblockr   r   r   r-   H   sH   

ÿÿþÿèzDecompressReader.readc                 C   s8   g }|   tj¡ }r| |¡ |   tj¡ }s
d |¡S )Nr2   )r-   ÚsysÚmaxsizeÚappendÚjoin)r   Úchunksr0   r   r   r   r3   q   s
   
ÿ
zDecompressReader.readallc                 C   s0   | j  d¡ d| _d| _| jdi | j¤Ž| _d S )Nr   Fr   )r   Úseekr   r   r   r   r    r   r   r   r   Ú_rewind|   s   zDecompressReader._rewindc                 C   sÈ   |t jkrn/|t jkr| j| }n$|t jkr.| jdk r(|  t j¡r(	 |  t j¡s!| j| }ntd 	|¡ƒ‚|| jk r?|  
¡  n|| j8 }|dkra|  tt j|ƒ¡}|sW	 | jS |t|ƒ8 }|dksH| jS )Nr   zInvalid value for whence: {})r   ÚSEEK_SETÚSEEK_CURr   ÚSEEK_ENDr   r-   ÚDEFAULT_BUFFER_SIZEr   Úformatr@   Úminr.   )r   ÚoffsetÚwhencer0   r   r   r   r?   ‚   s,   



ÿ


þüzDecompressReader.seekc                 C   s   | j S )z!Return the current file position.N)r   r   r   r   r   Útell    s   zDecompressReader.tell)r   )r   )r   r   r   r   r   r$   r'   r   r1   r-   r3   r@   r   rA   r?   rI   Ú__classcell__r   r   r(   r   r   !   s    

)r   )	r   r   r:   rD   r6   ÚBufferedIOBaser   Ú	RawIOBaser   r   r   r   r   Ú<module>   s    