
    lc,                         d 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 ede            ede           dS )z?Implements the compression layer of the ``smart_open`` library.    Ndisableinfer_from_extensionc                  <    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     6lib/python3.11/site-packages/smart_open/compression.pyget_supported_compression_typesr      s    
 014L4N4NNNr
   c                  N    t          t                                                    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            | t          v rt                              d|            |t          | <   dS )a)  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, format=lzma.FORMAT_XZ)
    >>>
    >>> register_compressor('.xz', _handle_xz)

    r   .z,ext must be a string starting with ., not %rz.overriding existing compression handler for %rN)
ValueErrorr   loggerwarning)extcallbacks     r   register_compressorr   &   sf    2  OCFcM OG#MNNN
"" NGMMM (r
   c                 2    | j         fd}|| _         dS )aH  Ensure that closing the `outer` stream closes the `inner` stream as well.

    Use this when your compression library's `close` method does not
    automatically close the underlying filestream.  See
    https://github.com/RaRe-Technologies/smart_open/issues/630 for an
    explanation why that is a problem for smart_open.
    c                      	               rd c}|                                  d S d S # rd c}|                                  w w xY w)Nclose)argsfpinnerouter_closes     r   
close_bothztweak_close.<locals>.close_bothP   sk    	KMMM  %	r




 u  %	r



s	   
, A
Nr   )outerr   r!   r    s    ` @r   tweak_closer#   F   s8     +K      EKKKr
   c                 J    ddl m}  || |          }t          ||            |S )Nr   )BZ2File)bz2r%   r#   )file_objmoder%   results       r   _handle_bz2r*   \   s:    WXt$$F!!!Mr
   c                 \    dd l }|                    | |          }t          ||            |S )Nr   )fileobjr(   )gzipGzipFiler#   )r'   r(   r-   r)   s       r   _handle_gzipr/   c   s5    KKK]]8$]77F!!!Mr
   c                    |t           k    r| S |t          k    r_	 | j        }n4# t          t          f$ r  t
                              d|            | cY S w xY wt          j        	                    |          \  }}|t          v r'|                    d          rt          d|z            	 t          |         } || |          S # t          $ r | cY S w xY w)a[  
    This function will wrap the file_obj with an appropriate
    [de]compression mechanism based on the specified extension.

    file_obj must either be a filehandle object, or a class which behaves
    like one. It must have a .name attribute.

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

    zRunable to transparently decompress %r because it seems to lack a string-like .name+z3transparent (de)compression unsupported for mode %r)r   r   nameAttributeError	TypeErrorr   r   ospathsplitextr   endswithr   KeyError)r'   r(   compressionfilename_r   s         r   compression_wrapperr=   j   s    n$ 4	,	, 	4	}HH	* 	 	 	NN45=   OOO	 ))(33;** Wt}}S/A/A WNQUUVVV('4 x$'''    s!   " .AA)C CCz.bz2z.gz)__doc__loggingos.pathr5   	getLogger__name__r   r   r   r   r   r   r   r#   r*   r/   r=   r	   r
   r   <module>rC      s    F E  		8	$	$  4- O O O/ / /
) ) )@  ,    !( !( !(N  FK ( ( (  E< ( ( ( ( (r
   