WcG.csdZgdZdZddlmZddlZddlZddlZddl 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)rricseZdZdZddddZdZedZdZd 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  compresslevelcs^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. NFrr z%compresslevel must be between 1 and 9)rrbr )Zwwbr)Zxxbr)ZaabrInvalid mode: Treadwritez6filename must be a str, bytes, file or PathLike object)Ztrailing_errorr)_fp_closefp _MODE_CLOSED_mode ValueError _MODE_READ _MODE_WRITEr _compressor isinstanceZstrbytesosZPathLike _builtin_openhasattr TypeError _compressionZDecompressReaderrOSErrorioZBufferedReader_buffer_pos)selffilenamemoder Z mode_codeZraws /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,,S1DLLLDIIIcs|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) rrrr%closerrrrflushrr' r*r-z BZ2File.closeas` :: % % F $zzZ'' ""$$${**t//55788#'  $===HHNN$$ % ) #   % ) # #### $===HHNN$$ % ) #  $  % ) # #### $ $ $s0BD 'C&&#D  E='E5"E=#E::E=cs,|jtkS)zTrue if this file is closed.)rrr/r0r*closedzBZ2File.closedyszz\))r,csZ|j|jjS)z3Return the file descriptor for the underlying file.)_check_not_closedrfilenor/r0r*r3zBZ2File.fileno~s"   xx  r,csZ|jo|jjS)z)Return whether the file supports seeking.)readabler%seekabler/r0r*r5zBZ2File.seekables }}:4<<#8#8#::r,cN|j|jtkS)z/Return whether the file was opened for reading.)r2rrr/r0r*r4zBZ2File.readables    zzZ''r,cr6)z/Return whether the file was opened for writing.)r2rrr/r0r*writablezBZ2File.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_readr%peek)r'Zn r*r:z BZ2File.peeks* ||  ##r,cr8)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. )r9r%rr'Zsizer;r*rz BZ2File.reads( ||  &&r,cs|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)r9r$ZDEFAULT_BUFFER_SIZEr%read1r=r;r*r>z BZ2File.read1s<  !88))D||!!$''r,cr8)zRRead bytes into b. Returns the number of bytes read (0 for EOF). )r9r%readinto)r'br;r*r?zBZ2File.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)rintr r!rBr9r%readliner=r;r*rEzBZ2File.readlinesZ$$$4-- ;<<>>#D ||$$T**r,crA)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. rBrC)rrDr r!rBr9r% readlinesr=r;r*rFzBZ2File.readlinessZ$$$4-- ;<<>>#D ||%%d++r,csD|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. ) Z_check_can_writerrZ bytearrayZlenZ memoryviewZnbytesrrrrr&)r'dataZlengthZ compressed r*rz BZ2File.writes  dUI. / /YFFd#D[[F%%..t4  z"" V  r,csFtjj||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)r'Zseqr;r*rJzBZ2File.writeliness&&11$<r?rErFrrJr$ZSEEK_SETrKrMr,r*rrs`:A:::::x$$$0***!!! ;;;((( ))) $ $ $ $'''' ( ( ( (((( + + + + , , , ,*===#%++1111$r,rr r cs@d|vrd|vr=td|| td| td| td|jdd}t||| }d|vr1tj|}tj ||||S|S) aOpen a bzip2-compressed file in binary or text mode. The filename argument can be an actual filename (a str, bytes, or PathLike 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). Ztr@rNz0Argument 'encoding' not supported in binary modez.Argument 'errors' not supported in binary modez/Argument 'newline' not supported in binary moder r )rZreplacerr$Z text_encodingZ TextIOWrapper)r(r)r ZencodingZerrorsZnewlineZbz_modeZ binary_files r*rrs* d{{ $;;*449: :  OP P  MN N  NO Oll3#G(G=IIK d{{##H- XvwGGr,csdt|}|j||jzS)zCompress a block of data. compresslevel, if given, must be a number between 1 and 9. For incremental compression, use a BZ2Compressor object instead. )rrr.)rGr ZcomprLr*rr9s(  'D ==  --r,csg}|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#ZappendZeofrZ unused_dataZjoin)rGZresultsZdecompZresrHr*rrDs G $ " ##D)C szzz@A A!! $ 88G    w  sA00 B>B)r r NNN)r )rNZ__all__Z __author__Zbuiltinsrrr$rr"Z_bz2rrrrrrIrrrrOr,r*rPs  - - -5 ****** ////////   rrrrrl%%rrj-.-1''''T....r,