o
    YqiC                     @   s  d Z ddlmZmZ ddlZddlZddlZddlZddlZej	dkr*ddl
mZ nddlmZ ejdd Zedkroe d	v rJd
dlT dZnhe dv rWd
dlT dZn[zd
dlT dZW nR eyn   d
dlT dZY nDw edkrzd
dlT dZW n6 ey   d
dlT dZY n(w edkrd
dlT dZnedkrd
dlT dZnedkrd
dlT dZnede dZdZd
ZdZ							d ddZd!dededefddZd"dededefddZ dS )#z=Python interface to the Zstandard (zstd) compression library.    )absolute_importunicode_literalsN)      )Buffer)
ByteStringZPYTHON_ZSTANDARD_IMPORT_POLICYdefault)CPython   )*Zcext)PyPyZcffiZcffi_fallbackrustzKunknown module import policy: %s; use default, cffi_fallback, cext, or cffiz0.25.0   rbc                 C   s   | dd}|dv r|pt }d}	d}
n|dv r+|pt }d}	|}
|
ds*|
d }
ntd	|ttd
r>tt	tj
f}ntt	f}t| |rPt| |
}d}nt| dsZt| dra| }t|}ntd|	dkrq|j||d}n|	dkr}|j||d}ntdd|vrtj||||dS |S )a  Create a file object with zstd (de)compression.

    The object returned from this function will be a
    :py:class:`ZstdDecompressionReader` if opened for reading in binary mode,
    a :py:class:`ZstdCompressionWriter` if opened for writing in binary mode,
    or an ``io.TextIOWrapper`` if opened for reading or writing in text mode.

    :param filename:
       ``bytes``, ``str``, or ``os.PathLike`` defining a file to open or a
       file object (with a ``read()`` or ``write()`` method).
    :param mode:
       ``str`` File open mode. Accepts any of the open modes recognized by
       ``open()``.
    :param cctx:
       ``ZstdCompressor`` to use for compression. If not specified and file
       is opened for writing, the default ``ZstdCompressor`` will be used.
    :param dctx:
       ``ZstdDecompressor`` to use for decompression. If not specified and file
       is opened for reading, the default ``ZstdDecompressor`` will be used.
    :param encoding:
        ``str`` that defines text encoding to use when file is opened in text
        mode.
    :param errors:
       ``str`` defining text encoding error handling mode.
    :param newline:
       ``str`` defining newline to use in text mode.
    :param closefd:
       ``bool`` whether to close the file when the returned object is closed.
        Only used if a file object is passed. If a filename is specified, the
        opened file is always closed when the returned object is closed.
    t )rr   r   r   )wwbaabxxbr   bzInvalid mode: {!r}PathLikeTreadwritez6filename must be a str, bytes, file or PathLike object)closefdz2logic error in zstandard.open() handling open mode)encodingerrorsnewline)replaceZstdDecompressorZstdCompressorendswith
ValueErrorformathasattrosstrbytesr   
isinstancebuiltinsopenbool	TypeErrorstream_readerZstream_writerRuntimeErrorioTextIOWrapper)filenamemodecctxdctxr   r   r    r   Znormalized_modeZ	open_modeZraw_open_modetypesZinner_fhfh r:   Y/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/zstandard/__init__.pyr-   a   sF   )





r-   r   datalevelreturnc                 C   s   t |d}|| S )a  Compress source data using the zstd compression format.

    This performs one-shot compression using basic/default compression
    settings.

    This method is provided for convenience and is equivalent to calling
    ``ZstdCompressor(level=level).compress(data)``.

    If you find yourself calling this function in a tight loop,
    performance will be greater if you construct a single ``ZstdCompressor``
    and repeatedly call ``compress()`` on it.
    )r=   )r#   compress)r<   r=   r6   r:   r:   r;   r?      s   

r?   max_output_sizec                 C   s   t  }|j| |dS )a  Decompress a zstd frame into its original data.

    This performs one-shot decompression using basic/default compression
    settings.

    This method is provided for convenience and is equivalent to calling
    ``ZstdDecompressor().decompress(data, max_output_size=max_output_size)``.

    If you find yourself calling this function in a tight loop, performance
    will be greater if you construct a single ``ZstdDecompressor`` and
    repeatedly call ``decompress()`` on it.
    )r@   )r"   
decompress)r<   r@   r7   r:   r:   r;   rA      s   rA   )r   NNNNNN)r   )r   )!__doc__
__future__r   r   r,   r2   r(   platformsysversion_infocollections.abcr   typingr   environgetstripZ_module_policypython_implementationZ	backend_cbackendZbackend_cffiImportErrorZbackend_rust__version___MODE_CLOSED
_MODE_READ_MODE_WRITEr-   intr*   r?   rA   r:   r:   r:   r;   <module>   s   

W