B
    Áì2aÜ  ã               @   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   ú8/var/www/html/prediksi/Python-3.7.12/Lib/_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ÚUnsupportedOperation)r   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   Úseekable)r   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   s>   || _ d| _d| _d| _|| _|| _| jf | 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Úclose)r   )Ú	__class__r   r   r#   ;   s    zDecompressReader.closec             C   s
   | j  ¡ S )N)r   r   )r   r   r   r   r   ?   s    zDecompressReader.seekablec          
   C   sP   t |ƒ�:}| d¡�$}|  t|ƒ¡}||d t|ƒ…< W d Q R X W d Q R X 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 }xž| jjr„| jjp>| j t¡}|sFP | jf | j	Ž| _y| j 
||¡}W q¸ | jk
r€   P Y q¸X n4| jjr¦| j t¡}|sªtdƒ‚nd}| j 
||¡}|r$P q$W |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   Úsizer+   Zrawblockr   r   r   r(   H   s>    



zDecompressReader.readc             C   s,   | j  d¡ d| _d| _| jf | 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nV|t jkr"| j| }n@|t jkrT| jdk rHx|  t j¡rFq8W | j| }ntd 	|¡ƒ‚|| jk rv|  
¡  n
|| j8 }x0|dkr°|  tt j|ƒ¡}|s¢P |t|ƒ8 }q‚W | jS )Nr   zInvalid value for whence: {})r
   ÚSEEK_SETÚSEEK_CURr   ÚSEEK_ENDr   r(   ÚDEFAULT_BUFFER_SIZEr   Úformatr6   Úminr)   )r   ÚoffsetÚwhencer+   r   r   r   r5   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   r,   r(   r6   r
   r7   r5   r?   Ú__classcell__r   r   )r$   r   r   !   s   

*r   )r   r
   r:   r1   ÚBufferedIOBaser   Ú	RawIOBaser   r   r   r   r   Ú<module>   s   