Your IP : 18.117.168.40


Current Path : /opt/alt/python310/lib64/python3.10/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/__pycache__/bz2.cpython-310.pyc

o

6��fG.�@s�dZgd�ZdZddlmZddlZddlZddlZddl	m
Z
mZdZdZ
dZGd	d
�d
ej�Z		dd
d�Zddd�Zdd�ZdS)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 <nadeem.vawda@gmail.com>�)rN)rr��c@s�eZdZdZd*dd�dd�Zdd�Zed	d
��Zdd�Zd
d�Z	dd�Z
dd�Zd+dd�Zd,dd�Z
d,dd�Zdd�Zd,dd�Zd,dd �Zd!d"�Zd#d$�Zejfd%d&�Zd'd(�Zd)S)-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�	��
compresslevelcCs6d|_d|_t|_d|krdkstd��td��|dvr$d}t}n1|dvr2d	}t}t|�|_n#|d
vr@d}t}t|�|_n|dvrNd
}t}t|�|_ntd|f��t	|t
ttj
f�rkt||�|_d|_||_nt|d�sut|d�r|||_||_ntd��|jtkr�tj|jttd�}t�|�|_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.
        NFrrz%compresslevel must be between 1 and 9)�r
�rbr)�w�wbr)�x�xbr)�a�abr�Invalid mode: %rT�read�writez6filename must be a str, bytes, file or PathLike object)Ztrailing_errorr)�_fp�_closefp�_MODE_CLOSED�_mode�
ValueError�
_MODE_READ�_MODE_WRITEr�_compressor�
isinstance�str�bytes�os�PathLike�
_builtin_open�hasattr�	TypeError�_compressionZDecompressReaderr�OSError�io�BufferedReader�_buffer�_pos)�self�filename�moder
Z	mode_code�raw�r3�*/opt/alt/python310/lib64/python3.10/bz2.py�__init__%sJ�
�
zBZ2File.__init__cCs|jtkrdSzQ|jtkr|j��n|jtkr$|j�|j�	��d|_Wz&|j
r=|j��Wd|_d|_
t|_d|_dSWd|_d|_
t|_d|_dSd|_d|_
t|_d|_wz$|j
rp|j��Wd|_d|_
t|_d|_wWd|_d|_
t|_d|_wd|_d|_
t|_d|_w)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.
        NF)rrrr-�closerrrr �flushr�r/r3r3r4r6asR


�
�
����z
BZ2File.closecCs
|jtkS)zTrue if this file is closed.)rrr8r3r3r4�closedys
zBZ2File.closedcCs|��|j��S)z3Return the file descriptor for the underlying file.)�_check_not_closedr�filenor8r3r3r4r;~�
zBZ2File.filenocCs|��o|j��S)z)Return whether the file supports seeking.)�readabler-�seekabler8r3r3r4r>�szBZ2File.seekablecC�|��|jtkS)z/Return whether the file was opened for reading.)r:rrr8r3r3r4r=�r<zBZ2File.readablecCr?)z/Return whether the file was opened for writing.)r:rrr8r3r3r4�writable�r<zBZ2File.writablercC�|��|j�|�S)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.
        )�_check_can_readr-�peek)r/�nr3r3r4rC�szBZ2File.peek���cCrA)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.
        )rBr-r�r/�sizer3r3r4r�szBZ2File.readcCs"|��|dkrtj}|j�|�S)z�Read 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)rBr+�DEFAULT_BUFFER_SIZEr-�read1rFr3r3r4rI�sz
BZ2File.read1cCrA)zRRead bytes into b.

        Returns the number of bytes read (0 for EOF).
        )rBr-�readinto)r/�br3r3r4rJ�szBZ2File.readintocC�8t|t�st|d�std��|��}|��|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(rMrBr-�readlinerFr3r3r4rP��

zBZ2File.readlinecCrL)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.
        rMrN)r!rOr'r(rMrBr-�	readlinesrFr3r3r4rR�rQzBZ2File.readlinescCsX|��t|ttf�rt|�}nt|�}|j}|j�|�}|j	�
|�|j|7_|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_writer!r#�	bytearray�len�
memoryview�nbytesr rrrr.)r/�dataZlengthZ
compressedr3r3r4r�s
z
BZ2File.writecCstj�||�S)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.
        )r)�
BaseStream�
writelines)r/�seqr3r3r4rY�szBZ2File.writelinescCs|��|j�||�S)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.
        )Z_check_can_seekr-�seek)r/�offset�whencer3r3r4r[�szBZ2File.seekcCs"|��|jtkr|j��S|jS)z!Return the current file position.)r:rrr-�tellr.r8r3r3r4r^s

zBZ2File.tellN)r
)r)rE)�__name__�
__module__�__qualname__�__doc__r5r6�propertyr9r;r>r=r@rCrrIrJrPrRrrYr+�SEEK_SETr[r^r3r3r3r4rs(	<



	


rrrcCs�d|vrd|vrtd|f��n|durtd��|dur td��|dur(td��|�dd�}t|||d	�}d|vrFt�|�}t�||||�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).

    �trKrNz0Argument 'encoding' not supported in binary modez.Argument 'errors' not supported in binary modez/Argument 'newline' not supported in binary moderr)r�replacerr+�
text_encoding�
TextIOWrapper)r0r1r
�encoding�errors�newlineZbz_modeZbinary_filer3r3r4rs �
rcCst|�}|�|�|��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.
    )rrr7)rWr
�compr3r3r4r9srcCsbg}|r,t�}z|�|�}Wnty|rYn�w|�|�|js'td��|j}|sd�|�S)zjDecompress a block of data.

    For incremental decompression, use a BZ2Decompressor object instead.
    zACompressed data ended before the end-of-stream marker was reached�)rrr*�append�eofrZunused_data�join)rWZresultsZdecomp�resr3r3r4rDs �
�
r)rrNNN)r)rb�__all__�
__author__�builtinsrr&r+r$r)Z_bz2rrrrrrXrrrr3r3r3r4�<module>s$v
�
*

?>