a
    jCiÜ  ã                   @   s:   d 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/local/lib/python3.9/_compression.pyÚ_check_not_closed   s    zBaseStream._check_not_closedc                 C   s   |   ¡ st d¡‚d S )NzFile not open for reading)ÚreadableÚioÚUnsupportedOperationr   r   r   r   Ú_check_can_read   s    zBaseStream._check_can_readc                 C   s   |   ¡ st d¡‚d S )NzFile not open for writing)Úwritabler   r   r   r   r   r   Ú_check_can_write   s    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                       sj   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
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f i | j¤Ž| _|| _d S )NFr   éÿÿÿÿ)Ú_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   sx   t |ƒ�X}| d¡�.}|  t|ƒ¡}||d t|ƒ…< W d   ƒ n1 sH0    Y  W d   ƒ n1 sf0    Y  t|ƒS )NÚB)Ú
memoryviewÚcastÚreadÚlen)r   ÚbÚviewÚ	byte_viewÚdatar   r   r   ÚreadintoB   s    LzDecompressReader.readintor   c                 C   sî   |dk r|   ¡ S |r| jrdS d }| jjr†| jjp<| j t¡}|sDqÂ| jf i | j	¤Ž| _z| j 
||¡}W qº | jy‚   Y qÂY qº0 n4| jjr¨| j t¡}|s¬tdƒ‚nd}| j 
||¡}|r"qÂq"|sØd| _| j| _dS |  jt|ƒ7  _|S )Nr   ó    zACompressed file ended before the end-of-stream marker was reachedT)Úreadallr   r   ÚeofÚunused_datar   r+   ÚBUFFER_SIZEr   r   Ú
decompressr   Zneeds_inputÚEOFErrorr   r   r,   )r   Úsizer0   Zrawblockr   r   r   r+   H   s@    

ÿÿ
zDecompressReader.readc                 C   s0   | j  d¡ d| _d| _| jf i | j¤Ž| _d S )Nr   F)r   Úseekr   r   r   r   r   r   r   r   r   Ú_rewindr   s    zDecompressReader._rewindc                 C   s°   |t jkrnR|t jkr"| j| }n<|t jkrP| jdk rD|  t j¡rDq6| j| }ntd 	|¡ƒ‚|| jk rr|  
¡  n
|| j8 }|dkrª|  tt j|ƒ¡}|sœqª|t|ƒ8 }q|| 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:   x   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   r1   r+   r;   r   r<   r:   rD   Ú__classcell__r   r   r&   r   r   !   s   

*r   )r   r   r?   r6   ÚBufferedIOBaser   Ú	RawIOBaser   r   r   r   r   Ú<module>   s   