
    h;                         S r SSKrSSKrSSKr\R
                  " \5      r0 rSr	 Sr
 S rS rS rS rS	 rS
 rS rS rS r\
S4S jr\" S\5        \" S\5        \" S\5        \" S\5        g)z=Implements the compression layer of the `smart_open` library.    Ndisableinfer_from_extensionc                  0    [         [        /[        5       -   $ )zuReturn the list of supported compression types available to open.

See compression paratemeter to smart_open.open().
)NO_COMPRESSIONINFER_FROM_EXTENSIONget_supported_extensions     P/home/james-whalen/.local/lib/python3.13/site-packages/smart_open/compression.pyget_supported_compression_typesr      s    
 014L4NNNr
   c                  <    [        [        R                  5       5      $ )zLReturn the list of file extensions for which we have registered compressors.)sorted_COMPRESSOR_REGISTRYkeysr	   r
   r   r   r   "   s    &++-..r
   c                     U (       a	  U S   S:X  d  [        SU -  5      eU R                  5       n U [        ;   a  [        R	                  SU 5        U[        U '   g)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)
>>>
>>> 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                 :   ^^ U R                   mUU4S jnX l         g)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                     >  T" 5         T(       a  S TsmnUR                  5         g g ! T(       a  S TsmnUR                  5         f f = f)Nclose)argsfpinnerouter_closes     r   
close_bothtweak_close.<locals>.close_bothW   sF    	M %	r
 u %	r
 s	   ( ANr   )outerr    r"   r!   s    ` @r   tweak_closer%   J   s     ++K Kr
   c                     U nSU;   a  SU;   a  [         R                  " U5      nU$ SU;   a  SU;   a  [         R                  " U5      nU$ )Nbwr)ioBufferedWriterBufferedReader)file_objmoderesults      r   _maybe_wrap_bufferedr0   c   sO    F
d{sd{""6* M 
""6*Mr
   c                 >    SS K nUR                  XS9n[        X15      $ Nr   )filenamer.   )bz2openr0   )r-   r.   r4   r/   s       r   _handle_bz2r6   m   s     XXxX3F--r
   c                 >    SS K nUR                  XS9n[        X15      $ r2   )gzipr5   r0   )r-   r.   r8   r/   s       r   _handle_gzipr9   s        YYY4F--r
   c                 >    SS K nUR                  XS9n[        X15      $ r2   )	zstandardr5   r0   )r-   r.   r<   r/   s       r   _handle_zstdr=   y   s     ^^X^9F--r
   c                 >    SS K nUR                  XS9n[        X15      $ r2   )lzmar5   r0   )r-   r.   r?   r/   s       r   
_handle_xzr@      r:   r
   c                    U[         :X  a  U $ U[        :X  aE   U=(       d    U R                  R                  5       n[        R                  R                  U5      u  pBU[        ;   a$  UR                  S5      (       a  [        SU-  5      e [        U   nU" X5      $ ! [        [
        4 a    [        R                  SU 5        U s $ f = f! [         a    U s $ f = f)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.   compressionr3   _r   s         r   compression_wrapperrM      s     n$	,	,	 1HMM88:H ))(3**t}}S/A/ANQUUVV('4 ''! 	* 	NN45= O	  s#   #B 	C
 (CC
CCz.bz2z.gzz.zstz.xz)__doc__r*   loggingos.pathrF   	getLogger__name__r   r   r   r   r   r   r   r%   r0   r6   r9   r=   r@   rM   r	   r
   r   <module>rS      s    D 	  			8	$  4- O/
 )F2.... 5ISW !(N FK ( E< ( FL ) E: &r
   