
    !h                        S SK Jr  S SKrS SKrS SKJrJrJr  S SKJ	r	  S SK
JrJr  S SKJr  S SKJr  S SKJr  \(       a  S S	KJr  S S
KJr  S\R.                  -   S-   rS\R.                  -   S-   rSrSrSrSrSr " S S\5      r " S S5      r g)    )annotationsN)TYPE_CHECKINGAny	TypedDict)Failure)RequestSpider)Response)global_object_name)referer_str)Self)CrawlerzScraped from %(src)sz%(item)szDropped: %(exception)szZCrawled (%(status)s) %(request)s%(request_flags)s (referer: %(referer)s)%(response_flags)szError processing %(item)sz:Spider error processing %(request)s (referer: %(referer)s)zError downloading %(request)sz)Error downloading %(request)s: %(errmsg)sc                  4    \ rS rSr% S\S'   S\S'   S\S'   Srg	)
LogFormatterResult   intlevelstrmsgz dict[str, Any] | tuple[Any, ...]args N)__name__
__module____qualname____firstlineno____annotations____static_attributes__r       Z/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/scrapy/logformatter.pyr   r      s    J	H
**r   r   c                      \ rS rSrSr        SS jr        SS jr          SS jr          SS jr          SS jr	 S         SS	 jjr
\SS
 j5       rSrg)LogFormatter%   a  Class for generating log messages for different actions.

All methods must return a dictionary listing the parameters ``level``, ``msg``
and ``args`` which are going to be used for constructing the log message when
calling ``logging.log``.

Dictionary keys for the method outputs:

*   ``level`` is the log level for that action, you can use those from the
    `python logging library <https://docs.python.org/3/library/logging.html>`_ :
    ``logging.DEBUG``, ``logging.INFO``, ``logging.WARNING``, ``logging.ERROR``
    and ``logging.CRITICAL``.
*   ``msg`` should be a string that can contain different formatting placeholders.
    This string, formatted with the provided ``args``, is going to be the long message
    for that action.
*   ``args`` should be a tuple or dict with the formatting placeholders for ``msg``.
    The final log message is computed as ``msg % args``.

Users can define their own ``LogFormatter`` class if they want to customize how
each action is logged or if they want to omit it entirely. In order to omit
logging an action the method must return ``None``.

Here is an example on how to create a custom log formatter to lower the severity level of
the log message when an item is dropped from the pipeline::

        class PoliteLogFormatter(logformatter.LogFormatter):
            def dropped(self, item, exception, response, spider):
                return {
                    'level': logging.INFO, # lowering the level from logging.WARNING
                    'msg': "Dropped: %(exception)s" + os.linesep + "%(item)s",
                    'args': {
                        'exception': exception,
                        'item': item,
                    }
                }
c           	         UR                   (       a  SUR                   < 3OSnUR                   (       a  SUR                   < 3OSn[        R                  [        UR                  UU[        U5      UUS.S.$ )z0Logs a message when the crawler finds a webpage.  )statusrequestrequest_flagsrefererresponse_flagsflagsr   r   r   )r+   loggingDEBUG
CRAWLEDMSGr&   r   )selfr'   responsespiderr(   r*   s         r   crawledLogFormatter.crawledK   sj     29!GMM,-B3;>>1X^^./r]]"//"!.&w/"0'
 	
r   c                    Uc  [        UR                  5       S3nO([        U[        5      (       a  UR	                  5       nOUn[
        R                  [        UUS.S.$ )z3Logs a message when an item is scraped by a spider.z.start)srcitemr,   )r   	__class__
isinstancer   getErrorMessager-   r.   
SCRAPEDMSG)r0   r7   r1   r2   r6   s        r   scrapedLogFormatter.scraped_   sa    
 '(8(89:&AC'****,CC]]
 	
r   c                    [        USS5      =nc  UR                  R                  S   n[        U[        5      (       a  [        [
        U5      nU[        UUS.S.$ )zULogs a message when an item is dropped while it is passing through the item pipeline.	log_levelNDEFAULT_DROPITEM_LOG_LEVEL)	exceptionr7   r,   )getattrcrawlersettingsr9   r   r-   
DROPPEDMSG)r0   r7   rA   r1   r2   r   s         r   droppedLogFormatter.droppeds   sa     YT::ECNN++,HIEeS!!GU+E&
 	
r   c                6    [         R                  [        SU0S.$ )zrLogs a message when an item causes an error while it is passing
through the item pipeline.

.. versionadded:: 2.0
r7   r,   )r-   ERRORITEMERRORMSG)r0   r7   rA   r1   r2   s        r   
item_errorLogFormatter.item_error   s"     ]]
 	
r   c                J    [         R                  [        U[        U5      S.S.$ )z<Logs an error message from a spider.

.. versionadded:: 2.0
)r'   r)   r,   )r-   rI   SPIDERERRORMSGr   )r0   failurer'   r1   r2   s        r   spider_errorLogFormatter.spider_error   s(     ]]!"&w/
 	
r   Nc                b    SU0nU(       a  [         nXES'   O[        n[        R                  UUS.$ )zgLogs a download error message from a spider (typically coming from
the engine).

.. versionadded:: 2.0
r'   errmsgr,   )DOWNLOADERRORMSG_LONGDOWNLOADERRORMSG_SHORTr-   rI   )r0   rO   r'   r2   rS   r   r   s          r   download_errorLogFormatter.download_error   s9     !*73'C#N(C]]
 	
r   c                    U " 5       $ Nr   )clsrC   s     r   from_crawlerLogFormatter.from_crawler   s	    ur   r   )r'   r   r1   r
   r2   r	   returnr   )r7   r   r1   Response | Failure | Noner2   r	   r]   r   )
r7   r   rA   BaseExceptionr1   r^   r2   r	   r]   r   )
rO   r   r'   r   r1   zResponse | Failurer2   r	   r]   r   rY   )
rO   r   r'   r   r2   r	   rS   z
str | Noner]   r   )rC   r   r]   r   )r   r   r   r   __doc__r3   r<   rF   rK   rP   rV   classmethodr[   r   r   r   r   r!   r!   %   s?   #J

*2
<B
	
(

#<
FL
	
(

 !
 ,	

 
 

*

 !
 ,	

 
 

(

 
 %	

 
 

2 "

 
 	

 
 

0  r   r!   )!
__future__r   r-   ostypingr   r   r   twisted.python.failurer   scrapyr   r	   scrapy.httpr
   scrapy.utils.pythonr   scrapy.utils.requestr   typing_extensionsr   scrapy.crawlerr   linesepr;   rE   r/   rJ   rN   rU   rT   r   r!   r   r   r   <module>rm      s    "  	 0 0 * #   2 ,&& $bjj0:=
%

2Z?
i
*M8 C + +e er   