� c��jG.���dZgd�ZdZddlmZddlZddlZddlZddl m Z m Z dZ dZ dZGd �d ej�Z dd �Zdd �Zd �Zy)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)rr��c��eZdZdZddd�d�Zd�Zed��Zd�Zd�Z d �Z d �Z dd �Z dd �Z dd �Zd�Zdd�Zdd�Zd�Zd�Zej*fd�Zd�Zy)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 d��t d��|dvr d}t }ne|dvrd }t }t|�|_nH|d vrd }t }t|�|_n+|d vrd }t }t|�|_nt d|����t|tttjf�r t||�|_d|_||_n2t|d�s t|d�r||_||_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)��r�rbr)�w�wbr)�x�xbr)�a�abr�Invalid mode: T�read�writez6filename must be a str, bytes, file or PathLike object)�trailing_errorr)�_fp�_closefp� _MODE_CLOSED�_mode� ValueError� _MODE_READ� _MODE_WRITEr� _compressor� isinstance�str�bytes�os�PathLike� _builtin_open�hasattr� TypeError� _compression�DecompressReaderr�OSError�io�BufferedReader�_buffer�_pos)�self�filename�moder� mode_code�raws �/usr/lib64/python3.12/bz2.py�__init__zBZ2File.__init__%s^��$����� �!�� ��]�'�a�'��D�E� E�(��D�E� E� �?� "��D�"�I� �[� ��D�#�I�,�]�;�D� � �[� ��D�#�I�,�]�;�D� � �[� ��D�#�I�,�]�;�D� ��4�9�:� :� �h��e�R�[�[� 9� :�$�X�t�4�D�H� �D�M�"�D�J� �X�v� &�'�(�G�*D��D�H�"�D�J��T�U� U� �:�:�� #��/�/������9�C��,�,�S�1�D�L��D�I�c���|jtk(ry |jtk(r|jj �nM|jt k(r:|j j|jj��d|_ |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)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) r rr"r2�closer#rrr$�flushr�r4s r9r=z BZ2File.closeas�� �:�:�� %� � $��z�z�Z�'�� � �"�"�$����{�*������t�/�/�5�5�7�8�#'�� � $��=�=��H�H�N�N�$���� %�� �)�� �#�� �� ��� %�� �)�� �#�� �� $��=�=��H�H�N�N�$���� %�� �)�� �#�� �� ��� %�� �)�� �#�� �s0�A;C>�&C�"C;�>E,�&E�&!E,�"E)�)E,c�(�|jtk(S)zTrue if this file is closed.)r rr?s r9�closedzBZ2File.closedys���z�z�\�)�)r;c�V�|j�|jj�S)z3Return the file descriptor for the underlying file.)�_check_not_closedr�filenor?s r9rDzBZ2File.fileno~s�� ��� ��x�x��� � r;c�Z�|j�xr|jj�S)z)Return whether the file supports seeking.)�readabler2�seekabler?s r9rGzBZ2File.seekable�s ���}�}��:�4�<�<�#8�#8�#:�:r;c�H�|j�|jtk(S)z/Return whether the file was opened for reading.)rCr r"r?s r9rFzBZ2File.readable�s�� ��� ��z�z�Z�'�'r;c�H�|j�|jtk(S)z/Return whether the file was opened for writing.)rCr r#r?s r9�writablezBZ2File.writable�s�� ��� ��z�z�[�(�(r;c�X�|j�|jj|�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_readr2�peek)r4�ns r9rMz BZ2File.peek�s'�� �����|�|� � ��#�#r;c�X�|j�|jj|�S)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. )rLr2r�r4�sizes r9rz BZ2File.read�s%�� �����|�|� � ��&�&r;c��|j�|dkrtj}|jj |�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)rLr0�DEFAULT_BUFFER_SIZEr2�read1rPs r9rTz BZ2File.read1�s7�� ���� �!�8��)�)�D��|�|�!�!�$�'�'r;c�X�|j�|jj|�S)zRRead bytes into b. Returns the number of bytes read (0 for EOF). )rLr2�readinto)r4�bs r9rVzBZ2File.readinto�s%�� �����|�|�$�$�Q�'�'r;c���t|t�s't|d�s 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,rYrLr2�readlinerPs r9r\zBZ2File.readline�sQ���$��$��4��-�� ;�<�<��>�>�#�D� �����|�|�$�$�T�*�*r;c���t|t�s't|d�s td��|j �}|j �|j j|�S)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. rYrZ)r%r[r+r,rYrLr2� readlinesrPs r9r^zBZ2File.readlines�sQ���$��$��4��-�� ;�<�<��>�>�#�D� �����|�|�%�%�d�+�+r;c�.�|j�t|ttf�r 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'� bytearray�len� memoryview�nbytesr$rrrr3)r4�data�length� compresseds r9rz BZ2File.write�sv�� ���� �d�U�I�.� /���Y�F��d�#�D��[�[�F��%�%�.�.�t�4� � �����z�"� � � �V�� �� r;c�B�tjj||�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)r4�seqs r9rjzBZ2File.writelines�s���&�&�1�1�$��<�)rer�comps r9rr9s(�� �� '�D� �=�=�� ����� -�-r;c���g}|rSt�} |j|�}|j|�|js t d��|j }|r�Sdj|�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/�append�eofr!� unused_data�join)re�results�decomp�ress r9rrDs��� �G� � �"�� ��#�#�D�)�C� ���s���z�z��@�A� A��!�!�� � �8�8�G� ���� ����  �s�A)�) A8�6A8)rr NNN)r )rw�__all__� __author__�builtinsrr*r0r(r-�_bz2rrrr"r#rirrrrzr;r9�r�se���  -��5� �*� � ��/�� �� �� �r�l�%�%�r�j-.�-1�'�T.�r;