WcG.dZgdZdZddlmZddlZddlZddlZddl m Z m Z dZ dZ dZGd d ejZ dd ZddZdZdS)zInterface to the libbzip2 compression library. This module provides a file interface, classes for incremental (de)compression, and functions for one-shot (de)compression. )BZ2File BZ2CompressorBZ2Decompressoropencompress decompressz%Nadeem Vawda )rN)rrceZdZdZddddZdZedZdZd Z d Z d Z dd Z ddZ ddZdZddZddZdZdZej*fdZdZdS)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. r  compresslevelc^d|_d|_t|_d|cxkrdkst dt d|dvr d}t }np|dvrd }t }t||_nP|d vrd }t }t||_n0|d vrd }t }t||_nt d|t|tttjfr"t|||_d|_||_n8t|dst|dr||_||_n t!d|jt krLt#j$|jt&t(}t+j,||_dSd|_dS)aOpen a bzip2-compressed file. If filename is a str, bytes, or PathLike 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'. 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. NFr r z%compresslevel must be between 1 and 9)r rbr)wwbr)xxbr)aabrInvalid mode: Treadwritez6filename must be a str, bytes, file or PathLike object)trailing_errorr)_fp_closefp _MODE_CLOSED_mode ValueError _MODE_READ _MODE_WRITEr _compressor isinstancestrbytesosPathLike _builtin_openhasattr TypeError _compressionDecompressReaderrOSErrorioBufferedReader_buffer_pos)selffilenamemoder mode_coderaws /usr/lib64/python3.12/bz2.py__init__zBZ2File.__init__%s$ ! ]''''a''DE E(DE E ? " "D"II [ D#I,];D   [ D#I,];D   [ D#I,];D  *449: : heR[[ 9 : :$Xt4DH DM"DJJ Xv & &'(G*D*DDH"DJJTU U :: # #//99C,,S1DLLLDIIIc|jtkrdS |jtkr|jj nQ|jt kr<|j j|jjd|_ |jr|j j d|_d|_ t|_d|_dS#d|_d|_ t|_d|_wxYw# |jr|j j d|_d|_ t|_d|_w#d|_d|_ t|_d|_wxYwxYw)zFlush 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. NF) r rr"r2closer#rrr$flushrr4s r9r=z BZ2File.closeas` :: % % F $zzZ'' ""$$${**t//55788#'  $===HHNN$$ % ) #   % ) # #### $===HHNN$$ % ) #  $  % ) # #### $ $ $s0BD 'C&&#D  E='E5"E=#E::E=c,|jtkS)zTrue if this file is closed.)r rr?s r9closedzBZ2File.closedyszz\))r;cZ|j|jjS)z3Return the file descriptor for the underlying file.)_check_not_closedrfilenor?s r9rDzBZ2File.fileno~s"   xx  r;cZ|jo|jjS)z)Return whether the file supports seeking.)readabler2seekabler?s r9rGzBZ2File.seekables }}:4<<#8#8#::r;cN|j|jtkS)z/Return whether the file was opened for reading.)rCr r"r?s r9rFzBZ2File.readables    zzZ''r;cN|j|jtkS)z/Return whether the file was opened for writing.)rCr r#r?s r9writablezBZ2File.writables    zz[((r;rc\|j|jj|S)zReturn 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. )_check_can_readr2peek)r4ns r9rMz BZ2File.peeks* ||  ##r;c\|j|jj|S)zRead 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. )rLr2rr4sizes r9rz BZ2File.reads( ||  &&r;c|j|dkrtj}|jj |S)zRead up to size uncompressed bytes, while trying to avoid making multiple reads from the underlying stream. Reads up to a buffer's worth of data if size is negative. Returns b'' if the file is at EOF. r)rLr0DEFAULT_BUFFER_SIZEr2read1rQs r9rUz BZ2File.read1s<  !88))D||!!$''r;c\|j|jj|S)zRRead bytes into b. Returns the number of bytes read (0 for EOF). )rLr2readinto)r4bs r9rWzBZ2File.readintos( ||$$Q''r;ct|ts,t|ds td|j }|j |j j|S)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__Integer argument expected)r%intr+r,rZrLr2readlinerQs r9r]zBZ2File.readlinesZ$$$4-- ;<<>>#D ||$$T**r;ct|ts,t|ds td|j }|j |j j|S)zRead 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. rZr[)r%r\r+r,rZrLr2 readlinesrQs r9r_zBZ2File.readlinessZ$$$4-- ;<<>>#D ||%%d++r;cD|jt|ttfrt |}nt |}|j }|jj|}|jj||xj|z c_ |S)aWrite a byte string to the file. Returns the number of uncompressed bytes written, which is always the length of data in bytes. Note that due to buffering, the file on disk may not reflect the data written until close() is called. ) _check_can_writer%r' bytearraylen memoryviewnbytesr$rrrr3)r4datalength compresseds r9rz BZ2File.writes  dUI. / /YFFd#D[[F%%..t4  z"" V  r;cFtjj||S)zWrite 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. )r- BaseStream writelines)r4seqs r9rkzBZ2File.writeliness&&11$<)rfrcomps r9rr9s(  'D ==  --r;cg}|rYt} |j|}|j||js t d|j }|rYdj|S#t$r|rY wxYw)zjDecompress a block of data. For incremental decompression, use a BZ2Decompressor object instead. zACompressed data ended before the end-of-stream marker was reachedr;)rrr/appendeofr! unused_datajoin)rfresultsdecompress r9rrDs G $ " ##D)C szzz@A A!! $ 88G    w  sA00 B>B)rr NNN)r )rw__all__ __author__builtinsrr*r0r(r-_bz2rrrr"r#rjrrrrzr;r9rs  - - -5 ****** ////////   rrrrrl%%rrj-.-1''''T....r;