
    3 d                         d dl Z d dlZd dlmZ d dlmZ dej        z   dz   Zdej        z   dz   ZdZ	dZ
d	Zd
ZdZ G d d          ZdS )    N)Failure)referer_strz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                   N    e Zd ZdZd Zd Zd Zd Zd Zd
dZ	e
d	             ZdS )LogFormattera%  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           	          |j         rdt          |j                    nd}|j         rdt          |j                    nd}t          j        t          |j        ||t          |          ||ddS )z0Logs a message when the crawler finds a webpage.  )statusrequestrequest_flagsrefererresponse_flagsflagslevelmsgargs)r   strloggingDEBUG
CRAWLEDMSGr
   r   )selfr   responsespiderr   r   s         3lib/python3.11/site-packages/scrapy/logformatter.pycrawledzLogFormatter.crawled7   s    4;MI0C..000r6>nL2S00222"]"/"!.&w//"0' 
 
 	
    c                     t          |t                    r|                                }n|}t          j        t
          ||ddS )z3Logs a message when an item is scraped by a spider.)srcitemr   )
isinstancer   getErrorMessager   r   
SCRAPEDMSG)r   r    r   r   r   s        r   scrapedzLogFormatter.scrapedI   sS    h(( 	**,,CCC] 
 
 	
r   c                 2    t           j        t          ||ddS )zULogs a message when an item is dropped while it is passing through the item pipeline.)	exceptionr    r   )r   WARNING
DROPPEDMSGr   r    r&   r   r   s        r   droppedzLogFormatter.droppedX   s+     _& 
 
 	
r   c                 0    t           j        t          d|idS )zLogs a message when an item causes an error while it is passing
        through the item pipeline.

        .. versionadded:: 2.0
        r    r   )r   ERRORITEMERRORMSGr)   s        r   
item_errorzLogFormatter.item_errorc   s%     ]
 
 	
r   c                 L    t           j        t          |t          |          ddS )zLLogs an error message from a spider.

        .. versionadded:: 2.0
        )r   r   r   )r   r,   SPIDERERRORMSGr   )r   failurer   r   r   s        r   spider_errorzLogFormatter.spider_errorq   s3     ]!"&w// 
 
 	
r   Nc                 V    d|i}|rt           }||d<   nt          }t          j        ||dS )zLogs a download error message from a spider (typically coming from
        the engine).

        .. versionadded:: 2.0
        r   errmsgr   )DOWNLOADERRORMSG_LONGDOWNLOADERRORMSG_SHORTr   r,   )r   r1   r   r   r4   r   r   s          r   download_errorzLogFormatter.download_error   sE     7# 	)'C#DNN(C]
 
 	
r   c                      |             S N )clscrawlers     r   from_crawlerzLogFormatter.from_crawler   s    suur   r9   )__name__
__module____qualname____doc__r   r$   r*   r.   r2   r7   classmethodr=   r:   r   r   r   r      s        # #J
 
 
$
 
 
	
 	
 	

 
 

 
 

 
 
 
$   [  r   r   )r   ostwisted.python.failurer   scrapy.utils.requestr   linesepr#   r(   r   r-   r0   r6   r5   r   r:   r   r   <module>rG      s     				 * * * * * * , , , , , ,#bj0:=
%
2Z?
i
*M8 C B B B B B B B B B Br   