
    !h                        S SK Jr  S SKJrJr  S SKJrJr  \(       a  S SKJ	r	J
r
  S SKJr  S SKJr  S SKJr   " S S	5      rg
)    )annotations)TYPE_CHECKINGAny)RequestSpider)AsyncIteratorIterable)Self)Crawler)Responsec                      \ rS rSrSrSS jr\SS j5       r      SS jrSS jr	        SS jr
        SS jrSS	 jr      SS
 jrSS jrSrg)BaseSpiderMiddleware   a  Optional base class for spider middlewares.

.. versionadded:: 2.13

This class provides helper methods for asynchronous
``process_spider_output()`` and ``process_start()`` methods. Middlewares
that don't have either of these methods don't need to use this class.

You can override the
:meth:`~scrapy.spidermiddlewares.base.BaseSpiderMiddleware.get_processed_request`
method to add processing code for requests and the
:meth:`~scrapy.spidermiddlewares.base.BaseSpiderMiddleware.get_processed_item`
method to add processing code for items. These methods take a single
request or item from the spider output iterable and return a request or
item (the same or a new one), or ``None`` to remove this request or item
from the processing.
c                    Xl         g Ncrawler)selfr   s     d/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/scrapy/spidermiddlewares/base.py__init__BaseSpiderMiddleware.__init__$   s     '    c                    U " U5      $ r    )clsr   s     r   from_crawler!BaseSpiderMiddleware.from_crawler'   s    7|r   c              #  T   #    U H  nU R                  US 5      =nc  M  Uv   M      g 7fr   _get_processed)r   startspideros       r   process_start_requests+BaseSpiderMiddleware.process_start_requests+   s.      A((D11> s   (	(c               d   #    U  S h  vN nU R                  US 5      =nc  M   U7v   M'   N"
 g 7fr   r   )r   r!   r#   s      r   process_start"BaseSpiderMiddleware.process_start2   s3      	!((D11>	us    0.,.00.0c              #  R   #    U H  nU R                  XA5      =nc  M  Uv   M     g 7fr   r   r   responseresultr"   r#   s        r   process_spider_output*BaseSpiderMiddleware.process_spider_output7   s,      A((55B s   '	'c               b   #    U  S h  vN nU R                  XA5      =nc  M  U7v   M&   N!
 g 7fr   r   r*   s        r   process_spider_output_async0BaseSpiderMiddleware.process_spider_output_async>   s3       	!((55B	vs    /-+-//-/c                p    [        U[        5      (       a  U R                  X5      $ U R                  X5      $ r   )
isinstancer   get_processed_requestget_processed_item)r   r#   r+   s      r   r    #BaseSpiderMiddleware._get_processedE   s1    a!!--a::&&q33r   c                    U$ )a  Return a processed request from the spider output.

This method is called with a single request from the start seeds or the
spider output. It should return the same or a different request, or
``None`` to ignore it.

:param request: the input request
:type request: :class:`~scrapy.Request` object

:param response: the response being processed
:type response: :class:`~scrapy.http.Response` object or ``None`` for
    start seeds

:return: the processed request or ``None``
r   )r   requestr+   s      r   r4   *BaseSpiderMiddleware.get_processed_requestJ   s	    $ r   c                    U$ )a  Return a processed item from the spider output.

This method is called with a single item from the start seeds or the
spider output. It should return the same or a different item, or
``None`` to ignore it.

:param item: the input item
:type item: item object

:param response: the response being processed
:type response: :class:`~scrapy.http.Response` object or ``None`` for
    start seeds

:return: the processed item or ``None``
r   )r   itemr+   s      r   r5   'BaseSpiderMiddleware.get_processed_item^   s	      r   r   N)r   r   )r   r   returnr
   )r!   Iterable[Any]r"   r   r=   r>   )r!   AsyncIterator[Any]r=   r?   )r+   r   r,   r>   r"   r   r=   r>   )r+   r   r,   r?   r"   r   r=   r?   )r#   r   r+   Response | Noner=   r   )r8   r   r+   r@   r=   zRequest | None)r;   r   r+   r@   r=   r   )__name__
__module____qualname____firstlineno____doc__r   classmethodr   r$   r'   r-   r0   r    r4   r5   __static_attributes__r   r   r   r   r      s    $(  ",2	
 *7AG	 *<FL	4
*9	(r   r   N)
__future__r   typingr   r   scrapyr   r   collections.abcr   r	   typing_extensionsr
   scrapy.crawlerr   scrapy.httpr   r   r   r   r   <module>rO      s+    " % "7 '&$] ]r   