grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026î ¤ f¬Iã@s dZddddddgZdZdd lmZdd lZdd lZydd lm Z Wn"e k r„dd l m Z YnXdd l m Z mZdZd ZdZdZdZGdd„dejƒZddd d d dd„Zddd„Zdd„Zd S)z¬Interface to the libbzip2 compression library. This module provides a file interface, classes for incremental (de)compression, and functions for one-shot (de)compression. ÚBZ2FileÚ BZ2CompressorÚBZ2DecompressorÚopenÚcompressÚ decompressz%Nadeem Vawda é)rN)ÚRLock)rréééi c@sieZdZdZddddd„Zdd„Zed d „ƒZd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zddd„Zdd d!„Zd"d#d$„Zd:d&d'„Zd;d(d)„Zd*d+„Zd<d,d-„Zd=d.d/„Zd0d1„Zd2d3„Zd4d5„Zd"d6d7„Zd8d9„ZdS)>ra@A file object providing transparent bzip2 (de)compression. A BZ2File can act as a wrapper for an existing file object, or refer directly to a named file on disk. Note that BZ2File provides a *binary* file interface - data read is returned as bytes, and data to be written should be given as bytes. ÚrNé cCsÌtƒ|_d|_d|_t|_d|_d|_|dk rXtj dt ƒnd|koodknsƒt dƒ‚n|dkr¼d }t }t ƒ|_d |_d|_n‘|dkræd }t}t|ƒ|_ng|dkrd}t}t|ƒ|_n=|dkr:d}t}t|ƒ|_nt d|fƒ‚t|ttfƒr‰t||ƒ|_d|_||_n?t|dƒs§t|dƒr¼||_||_n tdƒ‚dS)a3Open a bzip2-compressed file. If filename is a str or bytes object, it gives the name of the file to be opened. Otherwise, it should be a file object, which will be used to read or write the compressed data. mode can be 'r' for reading (default), 'w' for (over)writing, 'x' for creating exclusively, or 'a' for appending. These can equivalently be given as 'rb', 'wb', 'xb', and 'ab'. buffering is ignored. Its use is deprecated. If mode is 'w', 'x' or 'a', compresslevel can be a number between 1 and 9 specifying the level of compression: 1 produces the least compression, and 9 (default) produces the most compression. If mode is 'r', the input file may be the concatenation of multiple compressed streams. NFrr z)Use of 'buffering' argument is deprecatedr z%compresslevel must be between 1 and 9Úr ÚrbóÚwÚwbÚxÚxbÚaÚabzInvalid mode: %rTÚreadÚwritez1filename must be a str or bytes object, or a fileéÿÿÿÿ)rr zrb)rzwb)rr)rr)rÚ_lockÚ_fpÚ_closefpÚ _MODE_CLOSEDÚ_modeÚ_posÚ_sizeÚwarningsÚwarnÚDeprecationWarningÚ ValueErrorÚ _MODE_READrÚ _decompressorÚ_bufferÚ_buffer_offsetÚ _MODE_WRITErÚ _compressorÚ isinstanceÚstrÚbytesÚ _builtin_openÚhasattrÚ TypeError)ÚselfÚfilenameÚmodeÚ bufferingÚ compresslevelZ mode_code©r6ú(/opt/alt/python34/lib64/python3.4/bz2.pyÚ__init__+sL                    zBZ2File.__init__cCsÒ|j�Ã|jtkrdSzY|jttfkrAd|_n4|jtkru|jj|j j ƒƒd|_ nWdz|j r•|jj ƒnWdd|_d|_ t|_d|_ d|_XXWdQXdS)z«Flush and close the file. May be called more than once without error. Once the file is closed, any other operation on it will raise a ValueError. NFrr)rrrr%Ú_MODE_READ_EOFr&r)rrr*ÚflushrÚcloser'r()r1r6r6r7r;ns"       z BZ2File.closecCs |jtkS)zTrue if this file is closed.)rr)r1r6r6r7ÚclosedˆszBZ2File.closedcCs|jƒ|jjƒS)z3Return the file descriptor for the underlying file.)Ú_check_not_closedrÚfileno)r1r6r6r7r>�s zBZ2File.filenocCs|jƒo|jjƒS)z)Return whether the file supports seeking.)ÚreadablerÚseekable)r1r6r6r7r@’szBZ2File.seekablecCs|jƒ|jttfkS)z/Return whether the file was opened for reading.)r=rr%r9)r1r6r6r7r?–s zBZ2File.readablecCs|jƒ|jtkS)z/Return whether the file was opened for writing.)r=rr))r1r6r6r7Úwritable›s zBZ2File.writablecCs|jrtdƒ‚ndS)NzI/O operation on closed file)r<r$)r1r6r6r7r=¢s zBZ2File._check_not_closedcCs5|jttfkr1|jƒtjdƒ‚ndS)NzFile not open for reading)rr%r9r=ÚioÚUnsupportedOperation)r1r6r6r7Ú_check_can_read¦s zBZ2File._check_can_readcCs/|jtkr+|jƒtjdƒ‚ndS)NzFile not open for writing)rr)r=rBrC)r1r6r6r7Ú_check_can_write«s zBZ2File._check_can_writecCsV|jttfkr1|jƒtjdƒ‚n|jjƒsRtjdƒ‚ndS)Nz3Seeking is only supported on files open for readingz3The underlying file object does not support seeking)rr%r9r=rBrCrr@)r1r6r6r7Ú_check_can_seek°s  zBZ2File._check_can_seekc Cs|jtkrdSxô|jt|jƒkr |jjpI|jjt ƒ}|s†|jj rwt|_|j |_ dSt dƒ‚n|jj rètƒ|_y|jj|ƒ|_Wqýtk rät|_|j |_ dSYqýXn|jj|ƒ|_d|_qWdS)NFzACompressed file ended before the end-of-stream marker was reachedrT)rr9r(Úlenr'r&Ú unused_datarrÚ _BUFFER_SIZEÚeofrr ÚEOFErrorrrÚOSError)r1Zrawblockr6r6r7Ú _fill_bufferºs,           zBZ2File._fill_bufferTcCsŒ|j|jd…|_d|_g}xJ|jƒrt|rP|j|jƒn|jt|jƒ7_d|_q+W|rˆdj|ƒSdS)Nrr)r'r(rMÚappendrrGÚjoin)r1Ú return_dataÚblocksr6r6r7Ú _read_allßs  zBZ2File._read_allcCsC|j|}|t|jƒkrd|j|j|…}||_|jt|ƒ7_|r`|SdS|j|jd…|_d|_g}x�|dkr+|jƒr+|t|jƒkrÛ|jd|…}||_n|j}d|_|r|j|ƒn|jt|ƒ7_|t|ƒ8}q�W|r?dj|ƒSdS)Nrr)r(rGr'rrMrNrO)r1ÚnrPÚendÚdatarQr6r6r7Ú _read_blockïs*      zBZ2File._read_blockrc CsB|j�3|jƒ|jƒs$dS|j|jd…SWdQXdS)z¿Return buffered data without advancing the file position. Always returns at least one byte of data, unless at EOF. The exact number of bytes returned is unspecified. rN)rrDrMr'r()r1rSr6r6r7Úpeek s    z BZ2File.peekr c CsQ|j�B|jƒ|dkr$dS|dkr:|jƒS|j|ƒSWdQXdS)z±Read up to size uncompressed bytes from the file. If size is negative or omitted, read until EOF is reached. Returns b'' if the file is already at EOF. rrN)rrDrRrV)r1Úsizer6r6r7rs     z BZ2File.readc CsÕ|j�Æ|jƒ|dksE|jt|jƒkrI|jƒ rIdS|dkrŠ|j|j|j|…}|jt|ƒ7_n(|j|jd…}d|_d|_|jt|ƒ7_|SWdQXdS)z¨Read up to size uncompressed bytes, while trying to avoid making multiple reads from the underlying stream. Returns b'' if the file is at EOF. rrN)rrDr(rGr'rMr)r1rXrUr6r6r7Úread1&s   %    z BZ2File.read1c Cs'|j�tjj||ƒSWdQXdS)z_Read up to len(b) bytes into b. Returns the number of bytes read (0 for EOF). N)rrBÚBufferedIOBaseÚreadinto)r1Úbr6r6r7r[As zBZ2File.readintoc CsÜt|tƒs<t|dƒs-tdƒ‚n|jƒ}n|j�‘|jƒ|dkr¿|jjd|j ƒd}|dkr¿|j|j |…}||_ |j t |ƒ7_ |Snt j j||ƒSWdQXdS)a Read a line of uncompressed bytes from the file. The terminating newline (if present) is retained. If size is non-negative, no more than size bytes will be read (in which case the line may be incomplete). Returns b'' if already at EOF. Ú __index__zInteger argument expectedrs r N)r+Úintr/r0r]rrDr'Úfindr(rrGrBrZÚreadline)r1rXrTÚliner6r6r7r`Is     zBZ2File.readlinec Csct|tƒs<t|dƒs-tdƒ‚n|jƒ}n|j�tjj||ƒSWdQXdS)zùRead a list of lines of uncompressed bytes from the file. size can be specified to control the number of lines read: no further lines will be read once the total size of the lines read so far equals or exceeds size. r]zInteger argument expectedN) r+r^r/r0r]rrBrZÚ readlines)r1rXr6r6r7rb`s  zBZ2File.readlinesc Cs_|j�P|jƒ|jj|ƒ}|jj|ƒ|jt|ƒ7_t|ƒSWdQXdS)zöWrite a byte string to the file. Returns the number of uncompressed bytes written, which is always len(data). Note that due to buffering, the file on disk may not reflect the data written until close() is called. N)rrEr*rrrrrG)r1rUZ compressedr6r6r7rns   z BZ2File.writec Cs'|j�tjj||ƒSWdQXdS)zñWrite a sequence of byte strings to the file. Returns the number of uncompressed bytes written. seq can be any iterable yielding byte strings. Line separators are not added between the written byte strings. N)rrBrZÚ writelines)r1Úseqr6r6r7rc|s zBZ2File.writelinescCsG|jjddƒt|_d|_tƒ|_d|_d|_dS)Nrr) rÚseekr%rrrr&r'r()r1r6r6r7Ú_rewindˆs     zBZ2File._rewindc CsÝ|j�Î|jƒ|dkr#nm|dkr?|j|}nQ|dkr}|jdkrm|jddƒn|j|}ntd|fƒ‚||jkr¬|jƒn ||j8}|j|ddƒ|jSWdQXdS)açChange the file position. The new position is specified by offset, relative to the position indicated by whence. Values for whence are: 0: start of stream (default); offset must not be negative 1: current stream position 2: end of stream; offset must not be positive Returns the new file position. Note that seeking is emulated, so depending on the parameters, this operation may be extremely slow. rr r rPFzInvalid value for whence: %sN)rrFrr rRr$rfrV)r1ÚoffsetÚwhencer6r6r7re�s        z BZ2File.seekcCs%|j�|jƒ|jSWdQXdS)z!Return the current file position.N)rr=r)r1r6r6r7Útellºs  z BZ2File.tellrrrr)Ú__name__Ú __module__Ú __qualname__Ú__doc__r8r;Úpropertyr<r>r@r?rAr=rDrErFrMrRrVrWrrYr[r`rbrrcrfrerir6r6r6r7r s4 C         %    *rr cCsÓd|kr1d|kr‚td|fƒ‚q‚nQ|dk rLtdƒ‚n|dk rgtdƒ‚n|dk r‚tdƒ‚n|jddƒ}t||d |ƒ}d|krËtj||||ƒS|SdS) a Open a bzip2-compressed file in binary or text mode. The filename argument can be an actual filename (a str or bytes object), or an existing file object to read from or write to. The mode argument can be "r", "rb", "w", "wb", "x", "xb", "a" or "ab" for binary mode, or "rt", "wt", "xt" or "at" for text mode. The default mode is "rb", and the default compresslevel is 9. For binary mode, this function is equivalent to the BZ2File constructor: BZ2File(filename, mode, compresslevel). In this case, the encoding, errors and newline arguments must not be provided. For text mode, a BZ2File object is created, and wrapped in an io.TextIOWrapper instance with the specified encoding, error handling behavior, and line ending(s). Útr\zInvalid mode: %rNz0Argument 'encoding' not supported in binary modez.Argument 'errors' not supported in binary modez/Argument 'newline' not supported in binary moderr5)r$ÚreplacerrBÚ TextIOWrapper)r2r3r5ÚencodingÚerrorsÚnewlineZbz_modeZ binary_filer6r6r7rÁs      cCs#t|ƒ}|j|ƒ|jƒS)z¤Compress a block of data. compresslevel, if given, must be a number between 1 and 9. For incremental compression, use a BZ2Compressor object instead. )rrr:)rUr5Úcompr6r6r7rés c CsŒg}xv|r~tƒ}y|j|ƒ}Wntk rL|rEPn‚YnX|j|ƒ|jsrtdƒ‚n|j}q Wdj|ƒS)zjDecompress a block of data. For incremental decompression, use a BZ2Decompressor object instead. zACompressed data ended before the end-of-stream marker was reachedr)rrrLrNrJr$rHrO)rUZresultsZdecompÚresr6r6r7rôs      )rmÚ__all__Ú __author__Úbuiltinsrr.rBr!Z threadingrÚ ImportErrorZdummy_threadingZ_bz2rrrr%r9r)rIrZrrrr6r6r6r7Ús,    ÿ¢'