o
    f1                     @   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   #/usr/lib/python3.10/_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   fpdecomp_factorytrailing_error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   bview	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#n<| jdi | j	| _z	| j
||}W n$ | jy@   Y nw | jjrR| jt}|sQtdnd}| j
||}|r^n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!   needs_inputEOFErrorr   r   r0   )r   sizer4   rawblockr   r   r   r/   H   sH   

zDecompressReader.readc                 C   s8   g }|  tj }r|| |  tj }s
d|S )Nr6   )r/   sysmaxsizeappendjoin)r   chunksr4   r   r   r   r7   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   formatrF   minr0   )r   offsetwhencer4   r   r   r   rE      s,   






zDecompressReader.seekc                 C   s   | j S )z!Return the current file position.)r   r   r   r   r   tell   s   zDecompressReader.tell)r   )r   )r   r   r   r   r   r&   r)   r   r5   r/   r7   rF   r   rG   rE   rO   __classcell__r   r   r*   r   r   !   s    

)r   )	r   r   r@   rJ   r:   BufferedIOBaser   	RawIOBaser   r   r   r   r   <module>   s    