
    h!	                         S r SSKJrJrJrJr  SSKJr  SSKJ	r	  SSK
JrJrJr  SSKJrJr  \" \5       " S S	5      5       r\4S
\\   S\\   S\4S jjrg)z
File log observer.
    )IOAnyCallableOptional)implementer)ioType   )formatEventAsClassicLogText
formatTimetimeFormatRFC3339)ILogObserverLogEventc                   X    \ rS rSrSrS\\   S\\/\	\
   4   SS4S jrS\SS4S	 jrS
rg)FileLogObserver   z1
Log observer that writes to a file-like object.
outFileformatEventreturnNc                 ^    [        U5      [        La  SU l        OSU l        Xl        X l        g)z
@param outFile: A file-like object.  Ideally one should be passed which
    accepts text data.  Otherwise, UTF-8 L{bytes} will be used.
@param formatEvent: A callable that formats an event.
zutf-8N)r   str	_encoding_outFiler   )selfr   r   s      [/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/logger/_file.py__init__FileLogObserver.__init__   s)     '?#%,3DN!DN&    eventc                 $   U R                  U5      nU(       ax  U R                  c  U R                  R                  U5        O4U R                  R                  UR	                  U R                  5      5        U R                  R                  5         gg)z/
Write event to file.

@param event: An event.
N)r   r   r   writeencodeflush)r   r   texts      r   __call__FileLogObserver.__call__(   sg     &~~%##D)##DKK$?@MM! r   )r   r   r   )__name__
__module____qualname____firstlineno____doc__r   r   r   r   r   r   r   r$   __static_attributes__ r   r   r   r      sK    '#w'-5xj(3-6O-P'	' "h "4 "r   r   r   
timeFormatr   c                 P   ^ S[         S[        [           4U4S jjn[        X5      $ )a  
Create a L{FileLogObserver} that emits text to a specified (writable)
file-like object.

@param outFile: A file-like object.  Ideally one should be passed which
    accepts text data.  Otherwise, UTF-8 L{bytes} will be used.
@param timeFormat: The format to use when adding timestamp prefixes to
    logged events.  If L{None}, or for events with no C{"log_timestamp"}
    key, the default timestamp prefix of C{"-"} is used.

@return: A file log observer.
r   r   c                     > [        U U4S jS9$ )Nc                    > [        U T5      $ )Nr   )er-   s    r   <lambda>:textFileLogObserver.<locals>.formatEvent.<locals>.<lambda>J   s    
1j(Ar   r1   )r
   )r   r-   s    r   r   (textFileLogObserver.<locals>.formatEventH   s    *A
 	
r   )r   r   r   r   )r   r-   r   s    ` r   textFileLogObserverr6   8   s'     
8 
 

 700r   N)r*   typingr   r   r   r   zope.interfacer   twisted.python.compatr   _formatr
   r   r   _interfacesr   r   r   r   r6   r,   r   r   <module>r<      sk   
 / . & ( O O / \"" "" ""L 3D1W1"*3-11r   