Ë
    æš¾j'  ã                  ó`  — U d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	m
Z
 e	rddlmZmZ  ej                  e«      Zi Zded<   d	Z	 d
Z	 dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zeddf	 	 	 	 	 	 	 	 	 	 	 dd„Z ede«        ede«        ede«        ede«        ede«       y)z=Implements the compression layer of the `smart_open` library.é    )ÚannotationsN)ÚPath)ÚIOÚTYPE_CHECKINGÚAny)ÚCompressionKwargsÚ
Compressorzdict[str, Compressor]Ú_COMPRESSOR_REGISTRYÚdisableÚinfer_from_extensionc                 ó.   — t         t        gt        «       ¢S )z}Return the list of supported compression types available to open.

    See compression paratemeter to smart_open.open().
    )ÚNO_COMPRESSIONÚINFER_FROM_EXTENSIONÚget_supported_extensions© ó    ú`/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/smart_open/compression.pyÚget_supported_compression_typesr       s   € ô
 Ô0ÐNÔ3KÓ3MÐNÐNr   c                 ó<   — t        t        j                  «       «      S )zLReturn the list of file extensions for which we have registered compressors.)Úsortedr
   Úkeysr   r   r   r   r   (   s   € äÔ&×+Ñ+Ó-Ó.Ð.r   c                ó¦   — | r| d   dk(  sd| ›�}t        |«      ‚| j                  «       } | t        v rt        j	                  d| «       |t        | <   y)aÙ  Register a callback for transparently decompressing files with a specific extension.

    Args:
        ext: The extension.  Must include the leading period, e.g. `.gz`.
        callback: The callback.  It must accept two positional arguments, file_obj and mode,
            and is recommended to also accept **kwargs so that whatever the caller passes
            via smart_open.open(..., compression_kwargs={...}) reaches the underlying
            library unchanged.  Callbacks with the legacy (file_obj, mode) signature still
            work, but will raise TypeError if the caller supplies compression_kwargs
            that the callback doesn't declare.

    Raises:
        ValueError: If `ext` does not start with a period.

    Example:
        Instruct smart_open to use the `lzma` module whenever opening a file
        with a .xz extension (see README.md for the complete example showing I/O):

        >>> def _handle_xz(file_obj, mode, **kwargs):
        ...     import lzma
        ...
        ...     return lzma.open(filename=file_obj, mode=mode, **kwargs)
        >>>
        >>> register_compressor(".xz", _handle_xz)

        This is just an example: `lzma` is in the standard library and is registered by default.
    r   ú.z*ext must be a string starting with ., not z.overriding existing compression handler for %rN)Ú
ValueErrorÚlowerr
   ÚloggerÚwarning)ÚextÚcallbackÚmsgs      r   Úregister_compressorr!   -   sU   € ñ8 �C˜‘F˜c’MØ:¸3¸'ÐBˆÜ˜‹oÐØ
�)‰)‹+€CØ
Ô"Ñ"Ü�‰ÐGÈÔMØ (Ô˜Òr   c                ó‚   — | }d|v rd|v rt        j                  |«      }|S d|v rd|v rt        j                  |«      }|S )NÚbÚwÚr)ÚioÚBufferedWriterÚBufferedReader)Úfile_objÚmodeÚresults      r   Ú_maybe_wrap_bufferedr,   R   sO   € à€FØ
ˆd�{�s˜d‘{Ü×"Ñ" 6Ó*ˆð €Mð 
�‰˜ ™Ü×"Ñ" 6Ó*ˆØ€Mr   c                óL   — dd l } |j                  d| |dœ|¤Ž}t        ||«      S ©Nr   )Úfilenamer*   r   )Úbz2Úopenr,   )r)   r*   Úkwargsr0   r+   s        r   Ú_handle_bz2r3   \   s,   € ÛàˆS�X‰XÐ=˜x¨dÑ=°fÑ=€FÜ ¨Ó-Ð-r   c                óL   — dd l } |j                  d| |dœ|¤Ž}t        ||«      S r.   )Úgzipr1   r,   )r)   r*   r2   r5   r+   s        r   Ú_handle_gzipr6   c   ó,   € ÛàˆT�Y‰YÐ> ¨tÑ>°vÑ>€FÜ ¨Ó-Ð-r   c                óˆ   — dd l }|j                  dk\  rddlm} nddlm} |j
                  } || fd|i|¤Ž}t        ||«      S )Nr   )é   é   )Úzstdr*   )ÚsysÚversion_infoÚcompressionr;   Ú	backportsr1   r,   )r)   r*   r2   r<   r;   Ú	zstd_openr+   s          r   Ú_handle_zstdrA   j   sC   € Ûà
×Ñ˜7Ò"Þ$å"à—Y‘Y€IÙ�xÑ5 dÐ5¨fÑ5€FÜ ¨Ó-Ð-r   c                óL   — dd l } |j                  d| |dœ|¤Ž}t        ||«      S r.   )Úlzmar1   r,   )r)   r*   r2   rC   r+   s        r   Ú
_handle_xzrD   w   r7   r   c                ó`   — dd l } |j                  j                  | fd|i|¤Ž}t        ||«      S )Nr   r*   )Ú	lz4.frameÚframer1   r,   )r)   r*   r2   Úlz4r+   s        r   Ú_handle_lz4rI   ~   s0   € ÛàˆS�Y‰Y�^‰^˜HÑ:¨4Ð:°6Ñ:€FÜ ¨Ó-Ð-r   c                ó�  — |t         k(  r| S |t        k(  r4	 |xs | j                  j                  «       }t        |«      j                  }|t        v r!|j                  d«      rd|›�}t        |«      ‚	 t        |   } || |fi |xs i ¤ŽS # t        t
        f$ r t        j                  d| «       | cY S w xY w# t        $ r | cY S w xY w)a,  Wrap `file_obj` with an appropriate [de]compression mechanism based on its file extension.

    If the filename extension isn't recognized, simply return the original `file_obj` unchanged.

    `file_obj` must either be a filehandle object, or a class which behaves like one.

    If `filename` is specified, it will be used to extract the extension.
    If not, the `file_obj.name` attribute is used as the filename.

    If `compression_kwargs` is specified, its contents are forwarded as keyword
    arguments to the registered compressor callback.
    zRunable to transparently decompress %r because it seems to lack a string-like .nameú+z1transparent (de)compression unsupported for mode )r   r   Únamer   ÚAttributeErrorÚ	TypeErrorr   r   r   Úsuffixr
   Úendswithr   ÚKeyError)r)   r*   r>   r/   Úcompression_kwargsÚinferred_namer    r   s           r   Úcompression_wrapperrT   …   sß   € ð& ”nÒ$ØˆØÔ*Ò*ð	Ø%Ò6¨¯©×=Ñ=Ó?ˆMô ˜=Ó)×0Ñ0ˆàÔ*Ñ*¨t¯}©}¸SÔ/AØAÀ$ÀÐJˆÜ˜‹oÐðÜ'¨Ñ4ˆñ �H˜dÑAÐ'9Ò'?¸RÑAÐAøô! ¤	Ð*ò 	Ü�N‰NØdÐfnôð ŠOð		ûô ò ØŠðús#   –B
 Á3	B7 Â
'B4Â3B4Â7CÃCz.bz2z.gzz.zstz.xzz.lz4)Úreturnz	list[str])r   Ústrr   r	   rU   ÚNone)r)   r   r*   rV   rU   ú	IO[bytes])r)   rX   r*   rV   r2   r   rU   úIO[Any])r)   rY   r*   rV   r>   rV   r/   z
str | NonerR   zCompressionKwargs | NonerU   rY   )Ú__doc__Ú
__future__r   r&   ÚloggingÚpathlibr   Útypingr   r   r   Úsmart_open._typingr   r	   Ú	getLoggerÚ__name__r   r
   Ú__annotations__r   r   r   r   r!   r,   r3   r6   rA   rD   rI   rT   r   r   r   ú<module>rc      s  ðò Då "ã 	Û Ý ß )Ñ )áß@à	ˆ×	Ñ	˜8Ó	$€à.0Ð Ð+Ó 0à€Ø 4Ø-Ð ðóOó/ó
")óJó.ó.ó
.ó.ó.ð ,ØØ37ð(BØð(Bà
ð(Bð ð(Bð ð	(Bð
 1ð(Bð ó(Bñ\ �F˜KÔ (Ù �E˜<Ô (Ù �F˜LÔ )Ù �E˜:Ô &Ù �F˜KÕ (r   