
    3 do                     X    d Z ddlZddlmZ  ej        e          Z G d d          ZdS )zQ
Depth Spider Middleware

See documentation in docs/topics/spider-middleware.rst
    N)Requestc                   D    e Zd Zd
dZed             Zd Zd Zd Zd Z	d	S )DepthMiddlewareF   c                 >    || _         || _        || _        || _        d S N)maxdepthstatsverbose_statsprio)selfr	   r
   r   r   s        >lib/python3.11/site-packages/scrapy/spidermiddlewares/depth.py__init__zDepthMiddleware.__init__   s#     
*			    c                     |j         }|                    d          }|                    d          }|                    d          } | ||j        ||          S )NDEPTH_LIMITDEPTH_STATS_VERBOSEDEPTH_PRIORITY)settingsgetintgetboolr
   )clscrawlerr   r	   verboser   s         r   from_crawlerzDepthMiddleware.from_crawler   sY    #??=11""#899/00s8W]GT:::r   c                 X                                       fd|pdD             S )Nc              3   J   K   | ]}                     |          |V  d S r   )_filter).0rresponser   spiders     r   	<genexpr>z8DepthMiddleware.process_spider_output.<locals>.<genexpr>   s8      MMa4<<8V+L+LMMMMMMMr    )_init_depth)r   r!   resultr"   s   `` `r   process_spider_outputz%DepthMiddleware.process_spider_output   s?    6***MMMMMM6<RMMMMr   c                   K   |                      ||           |pd2 3 d {V }|                     |||          r|W V  $6 d S )Nr$   )r%   r   )r   r!   r&   r"   r    s        r   process_spider_output_asyncz+DepthMiddleware.process_spider_output_async!   su      6***| 	 	 	 	 	 	 	!||Ax00  $||s   Ac                 z    d|j         vr/d|j         d<   | j        r | j                            d|           d S d S d S )Ndepthr   zrequest_depth_count/0r"   )metar   r
   	inc_value)r   r!   r"   s      r   r%   zDepthMiddleware._init_depth'   sd    (-' 	M%&HM'"! M
$$%<V$LLLLL	M 	MM Mr   c                    t          |t                    sdS |j        d         dz   }||j        d<   | j        r|xj        || j        z  z  c_        | j        r9|| j        k    r.t                              d| j        |j        dd|i           dS | j	        r| j
                            d	| |
           | j
                            d||
           dS )NTr+   r   z1Ignoring link (depth > %(maxdepth)d): %(requrl)s )r	   requrlr"   )extraFzrequest_depth_count/r,   request_depth_max)
isinstancer   r-   r   priorityr	   loggerdebugurlr   r
   r.   	max_value)r   requestr!   r"   r+   s        r   r   zDepthMiddleware._filter.   s   '7++ 	4g&* %W9 	2	 11= 	UT]2 	LLC!]gkBB(    
 5 	PJ  !?!?!? OOO
0%GGGtr   N)Fr   )
__name__
__module____qualname__r   classmethodr   r'   r)   r%   r   r$   r   r   r   r      s            ; ; [;N N N  M M M    r   r   )__doc__loggingscrapy.httpr   	getLoggerr:   r5   r   r$   r   r   <module>rB      sp           		8	$	$1 1 1 1 1 1 1 1 1 1r   