
    #HJj'                    `   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     `/Users/ahmed/devFolder/claude-voice/.venv/lib/python3.12/site-packages/smart_open/compression.pyget_supported_compression_typesr       s    
 0N3K3M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FcM: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{sd{""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,    SXX=xd=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   ,    TYY>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"$"YYIx5d5f5F--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    SYY^^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 HdA'9'?RAA! 	* 	NNdfn 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\ FK ( E< ( FL ) E: & FK (r   