
    3 d                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
mZmZmZ ddlmZ  G d d	          Z G d
 d          Z G d d          Z G d de          ZdS )zB
Extension for processing data before they are exported to feeds.
    )BZ2File)GzipFile)IOBase)LZMAFile)AnyBinaryIODictListload_objectc                   N    e Zd ZdZdedeeef         ddfdZde	de
fdZd
d	ZdS )
GzipPlugina	  
    Compresses received data using `gzip <https://en.wikipedia.org/wiki/Gzip>`_.

    Accepted ``feed_options`` parameters:

    - `gzip_compresslevel`
    - `gzip_mtime`
    - `gzip_filename`

    See :py:class:`gzip.GzipFile` for more info about parameters.
    filefeed_optionsreturnNc                     || _         || _        | j                            dd          }| j                            d          }| j                            d          }t          | j         d|||          | _        d S )Ngzip_compresslevel	   
gzip_mtimegzip_filenamewb)fileobjmodecompresslevelmtimefilename)r   r   getr   gzipfile)selfr   r   compress_levelr   r   s         @lib/python3.11/site-packages/scrapy/extensions/postprocessing.py__init__zGzipPlugin.__init__   s    	(*../CQGG!%%l33$((99 I(
 
 
    datac                 6    | j                             |          S N)r   writer   r$   s     r!   r'   zGzipPlugin.write(       }""4(((r#   c                 j    | j                                          | j                                         d S r&   )r   closer   r   s    r!   r+   zGzipPlugin.close+   .    	r#   r   N__name__
__module____qualname____doc__r   r	   strr   r"   bytesintr'   r+    r#   r!   r   r      s        
 

X 
T#s(^ 
 
 
 
 
)% )C ) ) ) )     r#   r   c                   N    e Zd ZdZdedeeef         ddfdZde	de
fdZd
d	ZdS )	Bz2Pluginz
    Compresses received data using `bz2 <https://en.wikipedia.org/wiki/Bzip2>`_.

    Accepted ``feed_options`` parameters:

    - `bz2_compresslevel`

    See :py:class:`bz2.BZ2File` for more info about parameters.
    r   r   r   Nc                     || _         || _        | j                            dd          }t          | j         d|          | _        d S )Nbz2_compresslevelr   r   )r   r   r   )r   r   r   r   bz2file)r   r   r   r    s       r!   r"   zBz2Plugin.__init__;   sM    	(*../BAFFYT
 
 
r#   r$   c                 6    | j                             |          S r&   )r<   r'   r(   s     r!   r'   zBz2Plugin.writeC   s    |!!$'''r#   c                 j    | j                                          | j                                         d S r&   )r<   r+   r   r,   s    r!   r+   zBz2Plugin.closeF   s.    	r#   r.   r/   r7   r#   r!   r9   r9   0   s         
X 
T#s(^ 
 
 
 
 
(% (C ( ( ( (     r#   r9   c                   N    e Zd ZdZdedeeef         ddfdZde	de
fdZd
d	ZdS )
LZMAPluginu  
    Compresses received data using `lzma <https://en.wikipedia.org/wiki/Lempel–Ziv–Markov_chain_algorithm>`_.

    Accepted ``feed_options`` parameters:

    - `lzma_format`
    - `lzma_check`
    - `lzma_preset`
    - `lzma_filters`

    .. note::
        ``lzma_filters`` cannot be used in pypy version 7.3.1 and older.

    See :py:class:`lzma.LZMAFile` for more info about parameters.
    r   r   r   Nc                 2   || _         || _        | j                            d          }| j                            dd          }| j                            d          }| j                            d          }t          | j         d||||          | _        d S )Nlzma_format
lzma_checklzma_presetlzma_filtersr   )r   r   formatcheckpresetfilters)r   r   r   r   lzmafile)r   r   r   rG   rH   rI   rJ   s          r!   r"   zLZMAPlugin.__init__\   s    	("&&}55!%%lB77"&&}55#''77 Y
 
 
r#   r$   c                 6    | j                             |          S r&   )rK   r'   r(   s     r!   r'   zLZMAPlugin.writem   r)   r#   c                 j    | j                                          | j                                         d S r&   )rK   r+   r   r,   s    r!   r+   zLZMAPlugin.closep   r-   r#   r.   r/   r7   r#   r!   r@   r@   K   s          
X 
T#s(^ 
 
 
 
 
")% )C ) ) ) )     r#   r@   c                       e Zd ZdZdee         dedeeef         ddfdZ	de
defd	Zdefd
ZddZdefdZdee         dee         fdZdefdZdS )PostProcessingManagera  
    This will manage and use declared plugins to process data in a
    pipeline-ish way.
    :param plugins: all the declared plugins for the feed
    :type plugins: list
    :param file: final target file where the processed data will be written
    :type file: file like object
    pluginsr   r   r   Nc                     |                      |          | _        || _        || _        |                                 | _        d S r&   )_load_pluginsrP   r   r   _get_head_pluginhead_plugin)r   rP   r   r   s       r!   r"   zPostProcessingManager.__init__   sB     ))'22	(0022r#   r$   c                 6    | j                             |          S )a  
        Uses all the declared plugins to process data first, then writes
        the processed data to target file.
        :param data: data passed to be written to target file
        :type data: bytes
        :return: returns number of bytes written
        :rtype: int
        )rT   r'   r(   s     r!   r'   zPostProcessingManager.write   s     %%d+++r#   c                 4    | j                                         S r&   )r   tellr,   s    r!   rW   zPostProcessingManager.tell   s    y~~r#   c                 8    | j                                          dS )zC
        Close the target file along with all the plugins.
        N)rT   r+   r,   s    r!   r+   zPostProcessingManager.close   s     	     r#   c                     dS )NTr7   r,   s    r!   writablezPostProcessingManager.writable   s    tr#   c                     d |D             }|S )Nc                 ,    g | ]}t          |          S r7   r   ).0plugins     r!   
<listcomp>z7PostProcessingManager._load_plugins.<locals>.<listcomp>   s     ===6;v&&===r#   r7   )r   rP   s     r!   rR   z#PostProcessingManager._load_plugins   s    ==W===r#   c                 \    | j         }| j        d d d         D ]} ||| j                  }|S )NrD   )r   rP   r   )r   prevr^   s      r!   rS   z&PostProcessingManager._get_head_plugin   s@    yl44R4( 	3 	3F6$ 122DDr#   r.   )r0   r1   r2   r3   r
   r   r   r	   r4   r"   r5   r6   r'   rW   r+   boolrZ   rR   rS   r7   r#   r!   rO   rO   x   s        3Cy3(03@DS#X3	3 3 3 3	,% 	,C 	, 	, 	, 	, c        ! ! ! !$    T#Y 49    #      r#   rO   N)r3   bz2r   gzipr   ior   lzmar   typingr   r   r	   r
   scrapy.utils.miscr   r   r9   r@   rO   r7   r#   r!   <module>ri      s=                            , , , , , , , , , , , , ) ) ) ) ) )               F       6' ' ' ' ' ' ' 'Z1 1 1 1 1F 1 1 1 1 1r#   