QfG.dZgdZdZddlmZddlZddlZddlZddl m Z m Z dZ dZ dZGd d ejZ dd Zdd Zd Zy)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)rrceZdZdZddddZdZedZdZdZ d Z d Z dd Z dd Z dd ZdZddZddZdZdZej*fdZdZy)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.  compresslevelc d|_d|_t|_d|cxkrdkst dt d|dvr d}t }ne|dvrd }t }t||_nH|d vrd }t }t||_n+|d vrd }t }t||_nt d|t|tttjfr t|||_d|_||_n2t|ds t|dr||_||_n t!d|jt k(rEt#j$|jt&t(}t+j,||_yd|_y)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)rrbr)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 */opt/alt/python312/lib64/python3.12/bz2.py__init__zBZ2File.__init__%s^$ ! ]'a'DE E(DE E ? "D"I [ D#I,];D  [ D#I,];D  [ D#I,];D 49: : heR[[ 9 :$Xt4DH DM"DJ Xv &'(G*DDH"DJTU U :: #//9C,,S1DLDIc|jtk(ry |jtk(r|jj nM|jt k(r:|j j|jjd|_ |jr|j j d|_d|_ t|_d|_y#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 :: %  $zzZ' ""${*t//5578#'  $==HHNN$ % ) #   % ) #  $==HHNN$ % ) #   % ) # s0A;C>&C"C;>E,&E&!E,"E))E,c(|jtk(S)zTrue if this file is closed.)r rr?s r9closedzBZ2File.closedyszz\))r;cV|j|jjS)z3Return the file descriptor for the underlying file.)_check_not_closedrfilenor?s r9rDzBZ2File.fileno~s  xx  r;cZ|jxr|jjS)z)Return whether the file supports seeking.)readabler2seekabler?s r9rGzBZ2File.seekables }}:4<<#8#8#::r;cH|j|jtk(S)z/Return whether the file was opened for reading.)rCr r"r?s r9rFzBZ2File.readables  zzZ''r;cH|j|jtk(S)z/Return whether the file was opened for writing.)rCr r#r?s r9writablezBZ2File.writables  zz[((r;cX|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;cX|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_SIZEr2read1rPs r9rTz BZ2File.read1s7  !8))D||!!$''r;cX|j|jj|S)zRRead bytes into b. Returns the number of bytes read (0 for EOF). )rLr2readinto)r4bs r9rVzBZ2File.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,rYrLr2readlinerPs r9r\zBZ2File.readlinesQ$$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. rYrZ)r%r[r+r,rYrLr2 readlinesrPs r9r^zBZ2File.readlinessQ$$4- ;<<>>#D ||%%d++r;c.|jt|ttfr t |}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.writesv  dUI. /YFd#D[[F%%..t4  z" V  r;cBtjj||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 r9rjzBZ2File.writeliness&&11$<)rercomps r9rr9s(  'D ==  --r;cg}|rSt} |j|}|j||js t d|j }|rSdj|S#t$r|rYwxYw)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)reresultsdecompress r9rrDs G  " ##D)C szz@A A!!  88G    sA)) A86A8)rr NNN)r )rw__all__ __author__builtinsrr*r0r(r-_bz2rrrr"r#rirrrrzr;r9rse  -5 * /   rl%%rj-.-1'T.r;