Your IP : 18.191.12.128
U
e5d��@sNdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
mZmZdZ
ejZdad+dd�Zdd �Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Ze�dej�Zdd�ZGdd�de�ZGdd�dee�Z Gdd�de!e�Z"Gdd �d e#e�Z$Gd!d"�d"e�Z%Gd#d$�d$e%�Z&e&Z'd%d&�Z(e
dfd'd(�Z)d)d*�Z*dS),a
Configuration functions for the logging package for Python. The core package
is based on PEP 282 and comments thereto in comp.lang.python, and influenced
by Apache's log4j system.
Copyright (C) 2001-2019 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging' and log away!
�N)�ThreadingTCPServer�StreamRequestHandleriF#TcCs�ddl}t||j�r|}n*|�|�}t|d�r:|�|�n
|�|�t|�}t� �z t�t||�}t
|||�W5t�
�XdS)aD
Read the logging configuration from a ConfigParser-format file.
This can be called several times from an application, allowing an end user
the ability to select from various pre-canned configurations (if the
developer provides a mechanism to present the choices and load the chosen
configuration).
rN�readline)�configparser�
isinstanceZRawConfigParserZConfigParser�hasattrZ read_file�read�_create_formatters�logging�_acquireLock�_releaseLock�_clearExistingHandlers�_install_handlers�_install_loggers)Zfname�defaults�disable_existing_loggersr�cp�
formatters�handlers�r�&/usr/lib64/python3.8/logging/config.py�
fileConfig3s
rc Csl|�d�}|�d�}t|�}|D]F}|d|}zt||�}Wq tk
rdt|�t||�}Yq Xq |S)z)Resolve a dotted name to a global object.�.r)�split�pop�
__import__�getattr�AttributeError)�name�used�found�nrrr�_resolveUs
r"cCsttj|�S�N)�map�str�strip)Zalistrrr�
_strip_spacescsr'cCs�|dd}t|�siS|�d�}t|�}i}|D]v}d|}|j|dddd�}|j|d ddd�}|j|d
ddd�}tj}||�d�} | r�t| �}||||�}
|
||<q2|S)
zCreate and return formattersr�keys�,zformatter_%s�formatTN)�raw�fallback�datefmt�style�%�class)�lenrr'�getr
� Formatterr")rZflistrZformZsectnameZfsZdfsZstl�c�
class_name�frrrr fs$
r c
Cs^|dd}t|�siS|�d�}t|�}i}g}|D�]}|d|}|d}|�dd�}zt|tt��}Wn ttfk
r�t |�}YnX|�dd �} t| tt��} |�d
d�}
t|
tt��}
|| |
�}d|kr�|d}|�
|�t|�r�|�||�t|tj
j��r2|�d
d�}
t|
��r2|�||
f�|||<q6|D]\}}|�||��q@|S)zInstall and return handlersrr(r)z
handler_%sr0� formatter��args�()�kwargsz{}�level�target)r1rr'r2�eval�varsr
r� NameErrorr"�setLevel�setFormatter�
issubclassr�
MemoryHandler�appendZ setTarget)rr�hlistrZfixups�hand�section�klass�fmtr9r;�hr<r=�trrrr|sB
rcCsTtj}|D]D}|jj|}||krHt|tj�sN|�tj�g|_d|_ q
||_
q
dS)a�
When (re)configuring logging, handle loggers which were in the previous
configuration but are not in the new configuration. There's no point
deleting them as other threads may continue to hold references to them;
and by disabling them, you stop them doing any logging.
However, don't disable children of named loggers, as that's probably not
what was intended by the user. Also, allow existing loggers to NOT be
disabled if disable_existing is false.
TN)r
�root�manager�
loggerDictrZPlaceHolderrAZNOTSETr� propagate�disabled)�existing�
child_loggers�disable_existingrM�log�loggerrrr�_handle_existing_loggers�srWcCs|dd}|�d�}tt|��}|�d�|d}tj}|}d|krX|d}|�|�|jdd�D]}|�|�qf|d} t | �r�| �d�} t| �} | D]}
|�
||
�q�t|jj�
��}|��g}|D�](}|d |}|d
}
|jddd
�}t�|
�}|
|k�rv|�|
�d}|
d}t |�}t |�}||k�rl||d|�|k�r`|�||�|d7}�q2|�|
�d|k�r�|d}|�|�|jdd�D]}|�|��q�||_d|_|d} t | �r�| �d�} t| �} | D]}
|�
||
��q�q�t|||�dS)zCreate and install loggers�loggersr(r)rMZlogger_rootr<Nrz logger_%s�qualnamerP�)r,rr)r�listr'�remover
rMrAr�
removeHandlerr1�
addHandlerrNrOr(�sortZgetint� getLogger�indexrErPrQrW)rrrTZllistrHrMrUr<rKrFrGrRrSZqnrPrV�i�prefixed�pflen�num_existingrrrr�sd
rcCs.tj��t�tjdd��tjdd�=dS)z!Clear and close existing handlersN)r
� _handlers�clearZshutdownZ_handlerListrrrrr
s
r
z^[a-z_][a-z0-9_]*$cCst�|�}|std|��dS)Nz!Not a valid Python identifier: %rT)�
IDENTIFIER�match�
ValueError)�s�mrrr�valid_idents
rmc@s"eZdZdZddd�Zdd�ZdS) �ConvertingMixinz?For ConvertingXXX's, this mixin class provides common functionsTcCsB|j�|�}||k r>|r |||<t|�tttfkr>||_||_|Sr#)�configurator�convert�type�ConvertingDict�ConvertingList�ConvertingTuple�parent�key)�selfrv�value�replace�resultrrr�convert_with_key"s
�z ConvertingMixin.convert_with_keycCs0|j�|�}||k r,t|�tttfkr,||_|Sr#)rorprqrrrsrtru)rwrxrzrrrrp.s
�zConvertingMixin.convertN)T)�__name__�
__module__�__qualname__�__doc__r{rprrrrrns
rnc@s,eZdZdZdd�Zd dd�Zd
dd�ZdS)rrz A converting dictionary wrapper.cCst�||�}|�||�Sr#)�dict�__getitem__r{�rwrvrxrrrr�CszConvertingDict.__getitem__NcCst�|||�}|�||�Sr#)r�r2r{�rwrv�defaultrxrrrr2GszConvertingDict.getcCst�|||�}|j||dd�S�NF)ry)r�rr{r�rrrrKszConvertingDict.pop)N)N)r|r}r~rr�r2rrrrrrr@s
rrc@s"eZdZdZdd�Zddd�ZdS) rszA converting list wrapper.cCst�||�}|�||�Sr#)r[r�r{r�rrrr�QszConvertingList.__getitem__���cCst�||�}|�|�Sr#)r[rrp)rw�idxrxrrrrUszConvertingList.popN)r�)r|r}r~rr�rrrrrrsOsrsc@seZdZdZdd�ZdS)rtzA converting tuple wrapper.cCst�||�}|j||dd�Sr�)�tupler�r{r�rrrr�[szConvertingTuple.__getitem__N)r|r}r~rr�rrrrrtYsrtc@s�eZdZdZe�d�Ze�d�Ze�d�Ze�d�Z e�d�Z
ddd �Zee
�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�BaseConfiguratorzI
The configurator base class which defines some useful defaults.
z%^(?P<prefix>[a-z]+)://(?P<suffix>.*)$z^\s*(\w+)\s*z^\.\s*(\w+)\s*z^\[\s*(\w+)\s*\]\s*z^\d+$�ext_convert�cfg_convert)ZextZcfgcCst|�|_||j_dSr#)rr�configro)rwr�rrr�__init__ts
zBaseConfigurator.__init__c Cs�|�d�}|�d�}z^|�|�}|D]H}|d|7}zt||�}Wq$tk
rj|�|�t||�}Yq$Xq$|WStk
r�t��dd�\}}td||f�}|||_ |_
|�YnXdS)z`
Resolve strings to objects using standard import and attribute
syntax.
rrrZNzCannot resolve %r: %s)rr�importerrr�ImportError�sys�exc_inforj� __cause__�
__traceback__) rwrkrrr Zfrag�e�tb�vrrr�resolvexs"
zBaseConfigurator.resolvecCs
|�|�S)z*Default converter for the ext:// protocol.)r��rwrxrrrr��szBaseConfigurator.ext_convertcCs�|}|j�|�}|dkr&td|��n�||��d�}|j|��d}|r�|j�|�}|rn||��d}nd|j�|�}|r�|��d}|j�|�s�||}n2zt |�}||}Wnt
k
r�||}YnX|r�||��d�}qHtd||f��qH|S)z*Default converter for the cfg:// protocol.NzUnable to convert %rrzUnable to convert %r at %r)�WORD_PATTERNrirj�endr��groups�DOT_PATTERN�
INDEX_PATTERN�
DIGIT_PATTERN�int� TypeError)rwrx�restrl�dr�r!rrrr��s4
�zBaseConfigurator.cfg_convertcCs�t|t�s$t|t�r$t|�}||_n�t|t�sHt|t�rHt|�}||_n�t|t�svt|t�rvt|d�svt|�}||_nVt|t �r�|j
�|�}|r�|��}|d}|j
�|d�}|r�|d}t||�}||�}|S)z�
Convert values to an appropriate type. dicts, lists and tuples are
replaced by their converting alternatives. Strings are checked to
see if they have a conversion format and are converted if they do.
�_fields�prefixN�suffix)rrrr�rorsr[rtr�rr%�CONVERT_PATTERNri� groupdict�value_convertersr2r)rwrxrlr�r�Z converterr�rrrrp�s0
��
zBaseConfigurator.convertcsj��d�}t|�s|�|�}��dd�}�fdd��D�}|f|�}|rf|��D]\}}t|||�qP|S)z1Configure an object with a user-supplied factory.r:rNcsi|]}t|�r|�|�qSr�rm��.0�k�r�rr�
<dictcomp>�sz5BaseConfigurator.configure_custom.<locals>.<dictcomp>)r�callabler��items�setattr)rwr�r4�propsr;rzrrxrr�r�configure_custom�s
z!BaseConfigurator.configure_customcCst|t�rt|�}|S)z0Utility function which converts lists to tuples.)rr[r�r�rrr�as_tuple�s
zBaseConfigurator.as_tupleN)r|r}r~r�re�compiler�r�r�r�r�r��staticmethodrr�r�r�r�r�rpr�r�rrrrr�`s"
�"r�c@s^eZdZdZdd�Zdd�Zdd�Zdd �Zd
d�Zdd
�Z ddd�Z
ddd�Zddd�ZdS)�DictConfiguratorz]
Configure logging using a dictionary-like object to describe the
configuration.
cCs�|j}d|krtd��|ddkr2td|d��|�dd�}i}t���zn|�r�|�d|�}|D]�}|tjkr�td|��qdz6tj|}||}|�d d
�}|r�|�t� |��Wqdt
k
r�} ztd|�| �W5d
} ~ XYqdXqd|�d|�}
|
D]N}z|�||
|d
�Wq�t
k
�rF} ztd|�| �W5d
} ~ XYq�Xq�|�dd
�}|�r�z|�|d
�Wn.t
k
�r�} ztd�| �W5d
} ~ XYnX�n|�dd
�}t
�|�d|�}
|
D]P}z|�|
|�|
|<Wn2t
k
�r} ztd|�| �W5d
} ~ XYnX�q�|�d|�}|D]P}z|�||�||<Wn2t
k
�rp} ztd|�| �W5d
} ~ XYnX�q$|�d|�}g}t|�D]v}z |�||�}||_|||<WnNt
k
�r} z.dt| j�k�r�|�|�ntd|�| �W5d
} ~ XYnX�q�|D]Z}z |�||�}||_|||<Wn2t
k
�r`} ztd|�| �W5d
} ~ XYnX�q
tj}t|jj���}|��g}|�d|�}
|
D]�}||k�r|�|�d}|d}t|�}t|�}||k�r||d
|�|k�r�|�||�|d7}�q�|�|�z|�||
|�Wn2t
k
�rV} ztd|�| �W5d
} ~ XYnX�q�t|||�|�dd
�}|�r�z|�|�Wn.t
k
�r�} ztd�| �W5d
} ~ XYnXW5t��Xd
S)zDo the configuration.�versionz$dictionary doesn't specify a versionrZzUnsupported version: %s�incrementalFrzNo handler found with name %rr<NzUnable to configure handler %rrXTzUnable to configure logger %rrMzUnable to configure root loggerrrz Unable to configure formatter %r�filterszUnable to configure filter %r�target not configured yetr) r�rjrr
rrr2rfrA�_checkLevel� Exception�configure_logger�configure_rootr
�configure_formatter�configure_filter�sorted�configure_handlerrr%r�rErMr[rNrOr(r_rar1r\rW)rwr�r�Z
EMPTY_DICTrr�handlerZhandler_configr<r�rXrMrTrr�ZdeferredrRrSrbrcrdrerrr� configure�s
�
��������������
����zDictConfigurator.configurec
Cs�d|krr|d}z|�|�}Wq�tk
rn}z2dt|�kr>�|�d�|d<||d<|�|�}W5d}~XYq�Xnl|�dd�}|�dd�}|�dd�}|�d d�}|s�tj} nt|�} d
|kr�| ||||d
�}n| |||�}|S)z(Configure a formatter from a dictionary.r:z'format'r*rJNr-r.r/r0Zvalidate)r�r�r%rr2r
r3r")
rwr��factoryrz�terJZdfmtr.�cnamer4rrrr��s*z$DictConfigurator.configure_formattercCs.d|kr|�|�}n|�dd�}t�|�}|S)z%Configure a filter from a dictionary.r:rr8)r�r2r
ZFilter)rwr�rzrrrrr��s
z!DictConfigurator.configure_filtercCsX|D]N}z|�|jd|�Wqtk
rP}ztd|�|�W5d}~XYqXqdS)z/Add filters to a filterer from a list of names.r�zUnable to add filter %rN)Z addFilterr�r�rj)rwZfiltererr�r6r�rrr�add_filters�s
zDictConfigurator.add_filtersc
s�t��}��dd�}|r\z|jd|}Wn0tk
rZ}ztd|�|�W5d}~XYnX��dd�}��dd�}d�kr���d�}t|�s�|�|�}|}�n��d�} |�| �}
t|
tj j
��rFd �k�rFz>|jd
�d }t|tj��s��
|�td��|�d <Wn6tk
�rB}ztd�d �|�W5d}~XYnXnZt|
tj j��rtd
�k�rt|��d
��d
<n,t|
tj j��r�d�k�r�|��d��d<|
}��dd�}�fdd��D�}
z|f|
�}WnLtk
�r}z,dt|�k�r�|
�d�|
d<|f|
�}W5d}~XYnX|�r.|�|�|dk �rH|�t�|��|�rZ|�||�|�r�|��D]\}}t|||��qh|S)z&Configure a handler from a dictionary.r7NrzUnable to set formatter %rr<r�r:r0r=rr�zUnable to set target handler %rZmailhostZaddressrcsi|]}t|�r|�|�qSrr�r�r�rrr��sz6DictConfigurator.configure_handler.<locals>.<dictcomp>z'stream'�streamZstrm)r�rr�r�rjr�r�rCr
rrDrZHandler�updater�ZSMTPHandlerr�Z
SysLogHandlerr%rBrAr�r�r�r�)rwr�Zconfig_copyr7r�r<r�r4r�r�rIZthr�r;rzr�rrxrr�rr��s~��
�
����
z"DictConfigurator.configure_handlercCsX|D]N}z|�|jd|�Wqtk
rP}ztd|�|�W5d}~XYqXqdS)z.Add handlers to a logger from a list of names.rzUnable to add handler %rN)r^r�r�rj)rwrVrrKr�rrr�add_handlers�s
zDictConfigurator.add_handlersFcCs�|�dd�}|dk r$|�t�|��|s~|jdd�D]}|�|�q6|�dd�}|rb|�||�|�dd�}|r~|�||�dS)zU
Perform configuration which is common to root and non-root loggers.
r<Nrr�)r2rAr
r�rr]r�r�)rwrVr�r�r<rKrr�rrr�common_logger_configsz%DictConfigurator.common_logger_configcCs6t�|�}|�|||�|�dd�}|dk r2||_dS)z.Configure a non-root logger from a dictionary.rPN)r
r`r�r2rP)rwrr�r�rVrPrrrr�s
z!DictConfigurator.configure_loggercCst��}|�|||�dS)z*Configure a root logger from a dictionary.N)r
r`r�)rwr�r�rMrrrr�szDictConfigurator.configure_rootN)F)F)F)
r|r}r~rr�r�r�r�r�r�r�r�r�rrrrr��s$ ?
r�cCst|���dS)z%Configure logging using a dictionary.N)�dictConfigClassr�r�rrr�
dictConfig&sr�csDGdd�dt�}Gdd�dt�}G�fdd�dtj���||||�S)au
Start up a socket server on the specified port, and listen for new
configurations.
These will be sent as a file suitable for processing by fileConfig().
Returns a Thread object on which you can call start() to start the server,
and which you can join() when appropriate. To stop the server, call
stopListening().
Use the ``verify`` argument to verify any bytes received across the wire
from a client. If specified, it should be a callable which receives a
single argument - the bytes of configuration data received across the
network - and it should return either ``None``, to indicate that the
passed in bytes could not be verified and should be discarded, or a
byte string which is then passed to the configuration machinery as
normal. Note that you can return transformed bytes, e.g. by decrypting
the bytes passed in.
c@seZdZdZdd�ZdS)z#listen.<locals>.ConfigStreamHandlerz�
Handler for a logging configuration request.
It expects a completely new logging configuration and uses fileConfig
to install it.
cSsD�z
|j}|�d�}t|�dk�r
t�d|�d}|j�|�}t|�|krb||�|t|��}q>|jjdk rz|j�|�}|dk r�|�d�}zddl}|� |�}t
|�WnHtk
r�t�
|�}zt|�Wntk
r�t��YnXYnX|jj�r
|jj��Wn2tk
�r>}z|jtk�r.�W5d}~XYnXdS)z�
Handle a request.
Each request is expected to be a 4-byte length, packed using
struct.pack(">L", n), followed by the config file.
Uses fileConfig() to do the grunt work.
�z>LrNzutf-8)Z
connectionZrecvr1�structZunpack�server�verify�decode�json�loadsr�r��io�StringIOr� traceback� print_exc�ready�set�OSError�errno�RESET_ERROR)rwZconn�chunkZslenr�r��filer�rrr�handleFs6
z*listen.<locals>.ConfigStreamHandler.handleN)r|r}r~rr�rrrr�ConfigStreamHandler?sr�c@s0eZdZdZdZdedddfdd�Zdd�ZdS) z$listen.<locals>.ConfigSocketReceiverzD
A simple TCP socket-based logging config receiver.
rZZ localhostNcSs>t�|||f|�t��d|_t��d|_||_||_dS)NrrZ) rr�r
r�abortr�timeoutr�r�)rwZhost�portr�r�r�rrrr�tsz-listen.<locals>.ConfigSocketReceiver.__init__cSs`ddl}d}|sT|�|j��ggg|j�\}}}|r<|��t��|j}t��q|� �dS)Nr)
�selectZsocket�filenor�Zhandle_requestr
rr�rZserver_close)rwr�r�ZrdZwrZexrrr�serve_until_stopped~s�
z8listen.<locals>.ConfigSocketReceiver.serve_until_stopped)r|r}r~rZallow_reuse_address�DEFAULT_LOGGING_CONFIG_PORTr�r�rrrr�ConfigSocketReceiverms�
r�cs&eZdZ��fdd�Zdd�Z�ZS)zlisten.<locals>.Servercs4t�|���||_||_||_||_t��|_dSr#) �superr��rcvr�hdlrr�r�� threadingZEventr�)rwr�r�r�r�)�Server� __class__rrr��szlisten.<locals>.Server.__init__cSsZ|j|j|j|j|jd�}|jdkr0|jd|_|j��t��|a t�
�|��dS)N)r�r�r�r�rrZ)r�r�r�r�r�Zserver_addressr�r
r� _listenerrr�)rwr�rrr�run�s�
zlisten.<locals>.Server.run)r|r}r~r�r��
__classcell__r�r�)r�rr��sr�)rrr�ZThread)r�r�r�r�rr�r�listen+s.r�cCs*t��ztrdt_daW5t��XdS)zN
Stop the listening server which was created with a call to listen().
rZN)r
rrr�r�rrrr�
stopListening�sr�)NT)+rr�r�r
Zlogging.handlersr�r�r�r�r�Zsocketserverrrr�Z
ECONNRESETr�r�rr"r'r rrWrr
r��Irhrm�objectrnr�rrr[rsr�rtr�r�r�r�r�r�rrrr�<module>sH
"%W!
Az
?>