
    !h$                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
JrJrJr  SSKJr   " S S	5      r " S
 S5      r " S S5      r " S S\5      rg)zB
Extension for processing data before they are exported to feeds.
    )BZ2File)GzipFile)IOBase)LZMAFile)IOAnyBinaryIOcastload_objectc                   T    \ rS rSrSrS\S\\\4   SS4S jr	S\
S\4S	 jrSS
 jrSrg)
GzipPlugin   z
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                     Xl         X l        U R                  R                  SS5      nU R                  R                  S5      nU R                  R                  S5      n[        U R                   SUUUS9U l        g )Ngzip_compresslevel	   
gzip_mtimegzip_filenamewb)fileobjmodecompresslevelmtimefilename)r   r   getr   gzipfile)selfr   r   compress_levelr   r   s         g/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/scrapy/extensions/postprocessing.py__init__GzipPlugin.__init__   sq    	(**../CQG!!%%l3$$((9 II(
    datac                 8    U R                   R                  U5      $ N)r   writer    r&   s     r"   r)   GzipPlugin.write)       }}""4((r%   c                 8    U R                   R                  5         g r(   )r   closer    s    r"   r.   GzipPlugin.close,       r%   )r   r   r   r   N__name__
__module____qualname____firstlineno____doc__r	   dictstrr   r#   bytesintr)   r.   __static_attributes__ r%   r"   r   r      sA    

X 
T#s(^ 
 
)% )C )r%   r   c                   T    \ rS rSrSrS\S\\\4   SS4S jr	S\
S\4S	 jrSS
 jrSrg)	Bz2Plugin0   z
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                     Xl         X l        U R                  R                  SS5      n[        U R                   SUS9U l        g )Nbz2_compresslevelr   r   )r   r   r   )r   r   r   r   bz2file)r    r   r   r!   s       r"   r#   Bz2Plugin.__init__;   s=    	(**../BAFYYT
r%   r&   c                 8    U R                   R                  U5      $ r(   )rD   r)   r*   s     r"   r)   Bz2Plugin.writeC   s    ||!!$''r%   c                 8    U R                   R                  5         g r(   )rD   r.   r/   s    r"   r.   Bz2Plugin.closeF   s    r%   )rD   r   r   r2   r3   r>   r%   r"   r@   r@   0   sA    
X 
T#s(^ 
 
(% (C (r%   r@   c                   T    \ rS rSrSrS\S\\\4   SS4S jr	S\
S\4S	 jrSS
 jrSrg)
LZMAPluginJ   uf  
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           	      0   Xl         X l        U R                  R                  S5      nU R                  R                  SS5      nU R                  R                  S5      nU R                  R                  S5      n[        U R                   SUUUUS9U l        g )Nlzma_format
lzma_checklzma_presetlzma_filtersr   )r   r   formatcheckpresetfilters)r   r   r   r   lzmafile)r    r   r   rS   rT   rU   rV   s          r"   r#   LZMAPlugin.__init__[   s    	(""&&}5!!%%lB7""&&}5##''7 YY
r%   r&   c                 8    U R                   R                  U5      $ r(   )rW   r)   r*   s     r"   r)   LZMAPlugin.writel   r,   r%   c                 8    U R                   R                  5         g r(   )rW   r.   r/   s    r"   r.   LZMAPlugin.closeo   r1   r%   )r   r   rW   r2   r3   r>   r%   r"   rK   rK   J   sA     
X 
T#s(^ 
 
")% )C )r%   rK   c                       \ rS rSrSrS\\   S\\   S\	\
\4   SS4S jrS	\S\4S
 jrS\4S jrSS jrS\4S jrS\\   S\\   4S jrS\4S jrSrg)PostProcessingManagerv   a  
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                 r    U R                  U5      U l        X l        X0l        U R	                  5       U l        g r(   )_load_pluginsr`   r   r   _get_head_pluginhead_plugin)r    r`   r   r   s       r"   r#   PostProcessingManager.__init__   s2     ))'2	(002r%   r&   c                 T    [        [        U R                  R                  U5      5      $ )z
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
)r
   r<   rd   r)   r*   s     r"   r)   PostProcessingManager.write   s"     C))//566r%   c                 6    U R                   R                  5       $ r(   )r   tellr/   s    r"   ri   PostProcessingManager.tell   s    yy~~r%   c                 8    U R                   R                  5         g)z3
Close the target file along with all the plugins.
N)rd   r.   r/   s    r"   r.   PostProcessingManager.close   s     	 r%   c                     g)NTr>   r/   s    r"   writablePostProcessingManager.writable   s    r%   c                 D    U Vs/ s H  n[        U5      PM     sn$ s  snf r(   r   )r    r`   plugins      r"   rb   #PostProcessingManager._load_plugins   s    29:'F#':::s   c                 t    U R                   nU R                  S S S2    H  nU" XR                  5      nM     U$ )NrP   )r   r`   r   )r    prevrq   s      r"   rc   &PostProcessingManager._get_head_plugin   s7    yyll4R4(F$ 1 12D )r%   )r   r   rd   r`   r2   )r4   r5   r6   r7   r8   listr   r   r;   r9   r:   r#   r<   r)   ri   r.   boolrn   rb   rc   r=   r>   r%   r"   r^   r^   v   s    3Cy3(*5	3AEc3h3	3	7% 	7C 	7 c  !$ ;T#Y ;49 ;# r%   r^   N)r8   bz2r   gzipr   ior   lzmar   typingr   r   r	   r
   scrapy.utils.miscr   r   r@   rK   r^   r>   r%   r"   <module>r~      sM        * * ) D 4& &X0F 0r%   