U
    be                     @   s   d Z ddlZddlZeeZi ZdZdZ	dd Z
dd Zd	d
 Zdd Zdd Zdd Ze	dfddZede ede dS )z?Implements the compression layer of the ``smart_open`` library.    NdisableZinfer_from_extensionc                   C   s   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 r   r   X/var/www/html/services/stratfitenv/lib/python3.8/site-packages/smart_open/compression.pyget_supported_compression_types   s    r   c                   C   s   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                 C   sD   | r| d dkst d|  |  } | tkr8t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)
ValueErrorlowerr
   loggerwarning)extcallbackr   r   r   register_compressor&   s    r   c                    s   | j  fd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                     s(   z
  W 5  r"d    }|   X d S )Nclose)argsfpinnerZouter_closer   r   
close_bothQ   s
    

ztweak_close.<locals>.close_bothNr   )outerr   r   r   r   r   tweak_closeG   s    	r   c                 C   s$   ddl m} || |}t||  |S )Nr   )BZ2File)bz2r   r   )file_objmoder   resultr   r   r   _handle_bz2]   s    

r"   c                 C   s$   dd l }|j| |d}t||  |S )Nr   )fileobjr    )gzipGzipFiler   )r   r    r$   r!   r   r   r   _handle_gzipd   s    
r&   c              	   C   s   |t kr| S |tkr`z|p| j }W n( ttfk
rN   td|  |  Y S X tj	
|\}}|tkr~|dr~td| zt| }W n tk
r   |  Y S X || |S dS )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 %rN)r   r   namer   AttributeError	TypeErrorr   r   ospathsplitextr
   endswithr   KeyError)r   r    compressionfilename_r   r   r   r   compression_wrapperk   s&    

r3   z.bz2z.gz)__doc__loggingos.pathr+   	getLogger__name__r   r
   r   r   r   r   r   r   r"   r&   r3   r   r   r   r   <module>   s   
!'
