Plan 9 from Bell Labs’s /usr/web/sources/contrib/bichued/root/sys/lib/python/gzip.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�
��c
@s�dZddkZddkZddkZddkZddkZddgZddddd	f\ZZZ	Z
Zddf\ZZ
d
�Zd�Zd�Zd
�Zd�Zddd�Zdfd��YZd�Zedjoe�ndS(s�Functions that read and write gzipped files.

The user of the file doesn't have to worry about the compression,
but random access is not allowed.i�NtGzipFiletopeniiiiicCs|djo|d7}n|S(s�Return i as an unsigned integer, assuming it fits in 32 bits.

    If it's >= 2GB when viewed as a 32-bit unsigned int, return a long.
    ili l((ti((s/sys/lib/python/gzip.pytU32s
cCs|d@S(s>Return the low-order 32 bits of an int, as a non-negative int.l�((R((s/sys/lib/python/gzip.pytLOWU32scCs|itid|��dS(Ns<l(twritetstructtpack(toutputtvalue((s/sys/lib/python/gzip.pytwrite32scCs|itid|��dS(Ns<L(RRR(RR	((s/sys/lib/python/gzip.pytwrite32u"scCstid|id��dS(Ns<lii(Rtunpacktread(tinput((s/sys/lib/python/gzip.pytread32'strbi	cCst|||�S(s�Shorthand for GzipFile(filename, mode, compresslevel).

    The filename argument is required; mode defaults to 'rb'
    and compresslevel defaults to 9.

    (R(tfilenametmodet
compresslevel((s/sys/lib/python/gzip.pyR*scBseZdZdZd!Zddddd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zdd�Z
d
�Zdd�Zd�Zd�Zd�Zd�Zeid�Zd�Zd�Zd�Zd�Zd�Zdd�Zdd�Zd�Zd�Zd�Z RS("s�The GzipFile class simulates most of the methods of a file object with
    the exception of the readinto() and truncate() methods.

    i
ii	c	Cs�|od|jo|d7}n|djo$ti||pd�}|_n|djo't|d�o
|i}q�d}n|djo't|d�o
|i}q�d}n|dd!djo:t|_t|_	d|_
d|_||_d	|_
n||dd!d
jp|dd!djoBt|_|i|�ti|tititid�|_ntd|d
�||_d|_|itjo|i�ndS(sAConstructor for the GzipFile class.

        At least one of fileobj and filename must be given a
        non-trivial value.

        The new class instance is based on fileobj, which can be a regular
        file, a StringIO object, or any other object which simulates a file.
        It defaults to None, in which case filename is opened to provide
        a file object.

        When fileobj is not None, the filename argument is only used to be
        included in the gzip file header, which may includes the original
        filename of the uncompressed file.  It defaults to the filename of
        fileobj, if discernible; otherwise, it defaults to the empty string,
        and in this case the original filename is not included in the header.

        The mode argument can be any of 'r', 'rb', 'a', 'ab', 'w', or 'wb',
        depending on whether the file will be read or written.  The default
        is the mode of fileobj if discernible; otherwise, the default is 'rb'.
        Be aware that only the 'rb', 'ab', and 'wb' values should be used
        for cross-platform portability.

        The compresslevel argument is an integer from 1 to 9 controlling the
        level of compression; 1 is fastest and produces the least compression,
        and 9 is slowest and produces the most compression.  The default is 9.

        tbRtnametRiitridtwtasMode s not supportedN(tNonet__builtin__Rt	myfileobjthasattrRRtREADtTruet_new_membertextrabuft	extrasizeRtmin_readsizetWRITEt_init_writetzlibtcompressobjtDEFLATEDt	MAX_WBITSt
DEF_MEM_LEVELtcompresstIOErrortfileobjtoffsett_write_gzip_header(tselfRRRR-((s/sys/lib/python/gzip.pyt__init__<s< 
$



					
(	
			cCs6t|i�}d|dd!dtt|��dS(Ns<gzip ii�t t>(treprR-thextid(R0ts((s/sys/lib/python/gzip.pyt__repr__�scCsY|ddjo|d}n||_tid�|_d|_g|_d|_dS(Ni�s.gzRi(RR&tcrc32tcrctsizetwritebuftbufsize(R0R((s/sys/lib/python/gzip.pyR%�s			cCs�|iid�|iid�|id }d}|o
t}n|iit|��t|itti���|iid�|iid�|o|ii|d�ndS(Ns�i�iss�(R-RRtFNAMEtchrRtlongttime(R0tfnametflags((s/sys/lib/python/gzip.pyR/�s

cCstid�|_d|_dS(NRi(R&R9R:R;(R0((s/sys/lib/python/gzip.pyt
_init_read�scCs�|iid�}|djo
td�nt|iid��}|djo
td�nt|iid��}|iid�|t@oLt|iid��}|dt|iid��}|ii|�n|t@o?x<to0|iid�}|p
|d	joPq�q�Wn|t@o?x<to0|iid�}|p
|d	joPq5q5Wn|t@o|iid�ndS(
Nis�Not a gzipped fileiisUnknown compression methodiiR>(	R-R
R,tordtFEXTRAR?RtFCOMMENTtFHCRC(R0tmagictmethodtflagtxlenR7((s/sys/lib/python/gzip.pyt_read_gzip_header�s0



 

cCs�|itjo"ddk}t|id��n|idjo
td�nt|�djoc|i	t|�|_	t
i||i�|_|ii
|ii|��|it|�7_ndS(Ni�s$write() on read-only GzipFile objects!write() on closed GzipFile objecti(RR$terrnoR,tEBADFR-Rt
ValueErrortlenR;R&R9R:RR+R.(R0tdataRO((s/sys/lib/python/gzip.pyR�s
i�c	Csx|itjo"ddk}t|id��n|idjo|idjodSnd}|djoYy6x/to'|i	|�t
|i|d�}qsWWq8tj
o|i}q8Xnsy?x8||ijo'|i	|�t
|i|d�}q�WWn0tj
o$||ijo
|i}q8nX|i
| }|i
||_
|i||_|i|7_|S(Ni�s$read() on write-only GzipFile objectiRii(RRROR,RPR"R-RRt_readtmintmax_read_chunktEOFErrorR!R.(R0R;ROtreadsizetchunk((s/sys/lib/python/gzip.pyR
�s2 




cCs?||i|_t|�|i|_|it|�8_dS(N(R!RRR"R.(R0tbuf((s/sys/lib/python/gzip.pyt_unread�scCsv|idjo
td�n|io�|ii�}|iidd�||ii�jo
td�n|ii|�|i�|i�ti	ti
�|_t|_n|ii
|�}|djo3|ii�}|i�|i|�td�n|ii|�}|i|�|iidjo;|iit|ii�dd�|i�t|_ndS(NsReached EOFiiRii(R-RRWR ttelltseekRERNR&t
decompressobjR)t
decompresstFalseR
tflusht	_read_eoft_add_read_datatunused_dataRRR(R0R;tposRZt
uncompress((s/sys/lib/python/gzip.pyRT�s0










$
cCsXti||i�|_|i||_|it|�|_|it|�|_dS(N(R&R9R:R!R"RRR;(R0RS((s/sys/lib/python/gzip.pyRc'scCs�|iidd�t|i�}tt|i��}t|�t|i�jo
td�n$|t|i�jo
td�ndS(Ni�isCRC check faileds!Incorrect length of data produced(R-R]RRR:R,RR;(R0R9tisize((s/sys/lib/python/gzip.pyRb-s
cCs�|itjoX|ii|ii��t|it|i��t|it|i	��d|_n|itjo
d|_n|io|ii
�d|_ndS(N(RR$R-RR+RaRRR:R;RRRtclose(R0((s/sys/lib/python/gzip.pyRh;s



cCsTy,|idjo|idjodSnWntj
odSnX|i�dS(N(RRR-tAttributeErrorRh(R0((s/sys/lib/python/gzip.pyt__del__Ns	cCsA|itjo |ii|ii|��n|ii�dS(N(RR$R-RR+Ra(R0t	zlib_mode((s/sys/lib/python/gzip.pyRaWs cCs
|ii�S(s�Invoke the underlying file object's fileno() method.

        This will raise AttributeError if the underlying file object
        doesn't support fileno().
        (R-tfileno(R0((s/sys/lib/python/gzip.pyRl]scCstS(N(R`(R0((s/sys/lib/python/gzip.pytisattyescCs|iS(N(R.(R0((s/sys/lib/python/gzip.pyR\hscCsX|itjotd��n|iid�t|_d|_d|_d|_	dS(s[Return the uncompressed stream file position indicator to the
        beginning of the filesCan't rewind in write modeiRN(
RRR,R-R]RR R!R"R.(R0((s/sys/lib/python/gzip.pytrewindks			cCs�|itjor||ijotd��n||i}x)t|d�D]}|idd�qNW|i|dd�ny|itjoh||ijo|i�n||i}x%t|d�D]}|id�q�W|i|d�ndS(NsNegative seek in write modeiR>(	RR$R.R,trangeRRRnR
(R0R.tcountR((s/sys/lib/python/gzip.pyR]vs 

cCsS|djoti}|i}n|}g}x�djo�|i|�}|id�}||jp |djo!t|�|jo|d}n|djp
|djo/|i||d �|i||d�Pn|i|�|t|�}t||d�}q2W||ijo t||idd�|_ndi	|�S(Nis
i�iRii(
tsystmaxintR#R
tfindRRtappendR[RUtjoin(R0R;RXtbufstcR((s/sys/lib/python/gzip.pytreadline�s(
	
-
 icCst|djo
ti}ng}xM|djo?|i�}|djoPn|i|�|t|�}q#W|S(NiR(RqRrRxRtRR(R0tsizehinttLtline((s/sys/lib/python/gzip.pyt	readlines�s



cCs"x|D]}|i|�qWdS(N(R(R0RzR{((s/sys/lib/python/gzip.pyt
writelines�scCs|S(N((R0((s/sys/lib/python/gzip.pyt__iter__�scCs%|i�}|o|Snt�dS(N(Rxt
StopIteration(R0R{((s/sys/lib/python/gzip.pytnext�sNi(i�(!t__name__t
__module__t__doc__RRRVR1R8R%R/RERNRR
R[RTRcRbRhRjR&tZ_SYNC_FLUSHRaRlRmR\RnR]RxR|R}R~R�(((s/sys/lib/python/gzip.pyR3s:E						"	
 	2												c
Cs�tid}|o|ddj}|o|d}n|p
dg}nxm|D]e}|o�|djo+tddddd	ti�}ti}qF|d
djodGt|�GHqTnt|d�}ti|d
 d
�}n^|djo+ti}tdddd
d	ti�}n&ti|d�}t|dd
�}x4to,|i	d�}|pPn|i
|�qIW|tij	o|i�n|tij	o|i�qTqTWdS(Niis-dt-RRRRR-i�s.gzsfilename doesn't end in .gz:twbi(RqtargvRtstdintstdoutR4RRRR
RRh(targsR_targtftgRY((s/sys/lib/python/gzip.pyt_test�s>




	"
t__main__(R�RRqRBR&Rt__all__tFTEXTRIRGR?RHRR$RRR
RRRRR�R�(((s/sys/lib/python/gzip.pys<module>s"$$							�&


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].