
    \j                         d Z ddlZddlZddlZ ej
                  e      Zi ZdZ		 dZ
	 d Zd Zd Zd Zd	 Zd
 Zd Zd Zd Ze
dfdZ ede        ede        ede        ede       y)z=Implements the compression layer of the `smart_open` library.    Ndisableinfer_from_extensionc                  0    t         t        gt               z   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     @/root/env/lib/python3.12/site-packages/smart_open/compression.pyget_supported_compression_typesr      s    
 014L4NNNr
   c                  <    t        t        j                               S )zLReturn the list of file extensions for which we have registered compressors.)sorted_COMPRESSOR_REGISTRYkeysr	   r
   r   r   r   "   s    &++-..r
   c                     | r| d   dk(  st        d| z        | j                         } | t        v rt        j	                  d|        |t        | <   y)al  Register a callback for transparently decompressing files with a specific extension.

    Parameters
    ----------
    ext: str
        The extension.  Must include the leading period, e.g. `.gz`.
    callback: callable
        The callback.  It must accept two position arguments, file_obj and mode.
        This function will be called when `smart_open` is opening a file with
        the specified extension.

    Examples
    --------

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

    >>> def _handle_xz(file_obj, mode):
    ...     import lzma
    ...     return lzma.LZMAFile(filename=file_obj, mode=mode)
    >>>
    >>> 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 %rz.overriding existing compression handler for %rN)
ValueErrorlowerr   loggerwarning)extcallbacks     r   register_compressorr   '   sP    6 CFcMG#MNN
))+C
""GM (r
   c                 :    | j                   fd}|| _         y)a  Ensure that closing the `outer` stream closes the `inner` stream as well.

    Deprecated: `smart_open.open().__exit__` now always calls `__exit__` on the
    underlying filestream.

    Use this when your compression library's `close` method does not
    automatically close the underlying filestream.  See
    https://github.com/piskvorky/smart_open/issues/630 for an
    explanation why that is a problem for smart_open.
    c                      	          rd c}|j                          y y # rd c}|j                          w w xY w)Nclose)argsfpinnerouter_closes     r   
close_bothztweak_close.<locals>.close_bothW   sF    	M %	r
 u %	r
 s   # =Nr   )outerr    r"   r!   s    ` @r   tweak_closer$   J   s     ++K EKr
   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/   c   sO    F
d{sd{""6* M 
""6*Mr
   c                 H    dd l }|j                  | |      }t        ||      S Nr   )filenamer-   )bz2openr/   )r,   r-   r3   r.   s       r   _handle_bz2r5   m   s$    XXxdX3F--r
   c                 H    dd l }|j                  | |      }t        ||      S r1   )gzipr4   r/   )r,   r-   r7   r.   s       r   _handle_gzipr8   s   $    YYtY4F--r
   c                     dd l }|j                  dk\  rddlm} nddlm} |j                  | |      }t        ||      S )Nr   )      )zstd)r-   )sysversion_infocompressionr=   	backportsr4   r/   )r,   r-   r>   r=   r.   s        r   _handle_zstdrB   y   s8    
7"$"YYxdY+F--r
   c                 H    dd l }|j                  | |      }t        ||      S r1   )lzmar4   r/   )r,   r-   rD   r.   s       r   
_handle_xzrE      r9   r
   c                    |t         k(  r| S |t        k(  rA	 |xs | j                  j                         }t        j                  j                  |      \  }}|t        v r|j                  d      rt        d|z        	 t        |   } || |      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.

    zRunable to transparently decompress %r because it seems to lack a string-like .name+z3transparent (de)compression unsupported for mode %r)r   r   namer   AttributeError	TypeErrorr   r   ospathsplitextr   endswithr   KeyError)r,   r-   r@   r2   _r   s         r   compression_wrapperrQ      s     n$	,	,	 1HMM88:H ))(3;**t}}S/ANQUUVV('4 $''! 	* 	NN45= O	  s#   B >	B= 'B:9B:=C
Cz.bz2z.gzz.zstz.xz)__doc__r)   loggingos.pathrK   	getLogger__name__r   r   r   r   r   r   r   r$   r/   r5   r8   rB   rE   rQ   r	   r
   r   <module>rW      s    D 	  			8	$  4- O/
 )F2.... 5ISW !(N FK ( E< ( FL ) E: &r
   