a XC?h��@sNdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z m Z dZ ejZdad+dd�Zdd �Zd d �Zd d �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 |||�Wt� �n t� �0dS)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� isinstanceZRawConfigParserZ ConfigParser�hasattrZ read_file�read�_create_formatters�logging� _acquireLock�_clearExistingHandlers�_install_handlers�_install_loggers� _releaseLock)Zfname�defaults�disable_existing_loggersr�cp� formatters�handlers�r�3/opt/alt/python39/lib64/python3.9/logging/config.py� fileConfig3s       rc Csj|�d�}|�d�}t|�}|D]D}|d|}zt||�}Wq tybt|�t||�}Yq 0q |S)z)Resolve a dotted name to a global object.�.r)�split�pop� __import__�getattr�AttributeError)�name�used�found�nrrr�_resolveUs    r"cCs ttj|�S�N)�map�str�strip)Zalistrrr� _strip_spacescsr'c Cs�|dd}t|�siS|�d�}t|�}i}|D]v}d|}|j|dddd�}|j|d ddd�}|j|d dd d�}tj}||�d �} | r�t| �}||||�} | ||<q2|S) zCreate and return formattersr�keys�,z formatter_%s�formatTN)�raw�fallback�datefmt�style�%�class)�lenrr'�getr � Formatterr") rZflistrZformZsectnameZfsZdfsZstl�c� class_name�frrrr fs$    r c Csh|dd}t|�siS|�d�}t|�}i}g}|D�] }|d|}|d}|�dd�}zt|tt��}Wnttfy�t |�}Yn0|�dd �} t| tt��} |�d d �} t| tt��} || i| ��} || _ d |vr�|d } | � | �t|��r| � ||�t |tjj��r<|�d d�} t| ��r<|�| | f�| ||<q6|D]\} }| �||��qJ|S)zInstall and return handlersrr(r)z handler_%sr0� formatter��args�()�kwargsz{}�level�target)r1rr'r2�eval�varsr r� NameErrorr"r�setLevel� setFormatter� issubclassr� MemoryHandler�appendZ setTarget)rr�hlistrZfixups�hand�section�klass�fmtr9r;�hr<r=�trrrr |sD             r cCsTtj}|D]D}|jj|}||vrHt|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� loggerDictrZ PlaceHolderrAZNOTSETr� propagate�disabled)�existing� child_loggers�disable_existingrM�log�loggerrrr�_handle_existing_loggers�s    rWcCs |dd}|�d�}tt|��}|�d�|d}tj}|}d|vrX|d}|�|�|jdd�D]}|�|�qf|d} t | �r�| �d�} t| �} | D]} |� || �q�t|j j � ��} | ��g} |D�](}|d |}|d } |jd d d �}t�| �}| | v�rv| �| �d }| d}t |�}t | �}||k�rl| |d|�|k�r`| �| |�|d 7}�q2| �| �d|v�r�|d}|�|�|jdd�D]}|�|��q�||_d|_|d} t | �r�| �d�} t| �} | D]} |� || ��q�q�t| | |�dS)zCreate and install loggers�loggersr(r)rMZ logger_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�|�}||ur>|r |||<t|�tttfvr>||_||_|Sr#)� configurator�convert�type�ConvertingDict�ConvertingList�ConvertingTuple�parent�key)�selfrv�value�replace�resultrrr�convert_with_key#s  �z ConvertingMixin.convert_with_keycCs0|j�|�}||ur,t|�tttfvr,||_|Sr#)rorprqrrrsrtru)rwrxrzrrrrp/s  �zConvertingMixin.convertN)T)�__name__� __module__� __qualname__�__doc__r{rprrrrrn s rnc@s,eZdZdZdd�Zd dd�Zd dd�ZdS) rrz A converting dictionary wrapper.cCst�||�}|�||�Sr#)�dict� __getitem__r{�rwrvrxrrrr�Ds zConvertingDict.__getitem__NcCst�|||�}|�||�Sr#)r�r2r{�rwrv�defaultrxrrrr2HszConvertingDict.getcCst�|||�}|j||dd�S�NF)ry)r�rr{r�rrrrLszConvertingDict.pop)N)N)r|r}r~rr�r2rrrrrrrAs rrc@s"eZdZdZdd�Zddd�ZdS) rszA converting list wrapper.cCst�||�}|�||�Sr#)r[r�r{r�rrrr�Rs zConvertingList.__getitem__�����cCst�||�}|�|�Sr#)r[rrp)rw�idxrxrrrrVs zConvertingList.popN)r�)r|r}r~rr�rrrrrrsPsrsc@seZdZdZdd�ZdS)rtzA converting tuple wrapper.cCst�||�}|j||dd�Sr�)�tupler�r{r�rrrr�\s zConvertingTuple.__getitem__N)r|r}r~rr�rrrrrtZsrtc@s�eZdZdZe�d�Ze�d�Ze�d�Ze�d�Z e�d�Z ddd �Z e e �Zd d �Zd d �Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�BaseConfiguratorzI The configurator base class which defines some useful defaults. z%^(?P[a-z]+)://(?P.*)$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__us zBaseConfigurator.__init__c Cs�|�d�}|�d�}z\|�|�}|D]F}|d|7}zt||�}Wq$tyh|�|�t||�}Yq$0q$|WSty�t��dd�\}}td||f�}|||_ |_ |�Yn0dS)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�resolveys"       zBaseConfigurator.resolvecCs |�|�S)z*Default converter for the ext:// protocol.)r��rwrxrrrr��szBaseConfigurator.ext_convertcCs�|}|j�|�}|dur&td|��n�||��d�}|j|��d}|r�|j�|�}|rn||��d}nb|j�|�}|r�|��d}|j�|�s�||}n0zt |�}||}Wnt y�||}Yn0|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.convertcsn��d�}t|�s|�|�}��dd�}�fdd��D�}|fi|��}|rj|��D]\}}t|||�qT|S)z1Configure an object with a user-supplied factory.r:rNcsi|]}t|�r|�|�qSr�rm��.0�k�r�rr� ��z5BaseConfigurator.configure_custom..)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�as"     �"r�c@s^eZdZdZdd�Zdd�Zdd�Zdd �Zd d �Zd d �Z ddd�Z ddd�Z ddd�Z dS)�DictConfiguratorz] Configure logging using a dictionary-like object to describe the configuration. c Cs�|j}d|vrtd��|ddkr2td|d��|�dd�}i}t���z�|�r�|�d|�}|D]�}|tjvr�td|��qdz6tj|}||}|�d d �}|r�|�t�|��Wqdt y�} ztd |�| �WYd } ~ qdd } ~ 00qd|�d |�} | D]P}z|� || |d �Wq�t �yJ} ztd|�| �WYd } ~ q�d } ~ 00q�|�dd �} | �r�z|� | d �Wn0t �y�} ztd�| �WYd } ~ n d } ~ 00�n$|�dd �} t �|�d|�} | D]R}z|� | |�| |<Wn4t �y} ztd|�| �WYd } ~ n d } ~ 00�q�|�d|�}|D]R}z|�||�||<Wn4t �yz} ztd|�| �WYd } ~ n d } ~ 00�q,|�d|�}g}t|�D]x}z |�||�}||_|||<WnPt �y } z6dt| j�v�r�|�|�ntd |�| �WYd } ~ n d } ~ 00�q�|D]\}z |�||�}||_|||<Wn4t �yn} ztd |�| �WYd } ~ n d } ~ 00�qtj} t| jj���}|��g}|�d |�} | D]�}||v�r|�|�d}|d}t|�}t|�}||k�r||d |�|k�r|�||�|d7}�q�|�|�z|� || |�Wn4t �yf} ztd|�| �WYd } ~ n d } ~ 00�q�t||| �|�dd �} | �r�z|� | �Wn0t �y�} ztd�| �WYd } ~ n d } ~ 00Wt��n t��0d 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 r r2rfrA� _checkLevel� Exception�configure_logger�configure_rootr �configure_formatter�configure_filter�sorted�configure_handlerrr%r�rErMr[rNrOr(r_rar1r\rWr)rwr�r�Z EMPTY_DICTrr�handlerZhandler_configr<r�rXrMrTrr�ZdeferredrRrSrbrcrdrerrr� configure�s    �  �� �� �  � �� ��    �� ��      ��� �zDictConfigurator.configurec Cs�d|vrt|d}z|�|�}Wq�typ}z:dt|�vr<�|�d�|d<||d<|�|�}WYd}~q�d}~00nl|�dd�}|�dd�}|�dd�}|�d d�}|s�tj} nt|�} d |vr�| ||||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|vr|�|�}n|�dd�}t�|�}|S)z%Configure a filter from a dictionary.r:rr8)r�r2r ZFilter)rwr�rzrrrrr��s    z!DictConfigurator.configure_filterc CsZ|D]P}z|�|jd|�WqtyR}ztd|�|�WYd}~qd}~00qdS)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|}Wn2ty\}ztd|�|�WYd}~n d}~00��dd�}��dd�}d�vr���d�}t|�s�|�|�}|}�n��d�} |�| �} t| tj j ��rJd �v�rJz>|jd �d } t | tj ��s�� |�td ��| �d <Wn8t�yF}ztd �d �|�WYd}~n d}~00nZt| tj j��rxd �v�rx|��d ��d <n,t| tj j��r�d�v�r�|��d��d<| }��dd�} �fdd��D�} z|fi| ��}WnRt�y*}z8dt|�v�r��| �d�| d<|fi| ��}WYd}~n d}~00|�r<|�|�|du�rV|�t�|��|�rh|�||�| �r�| ��D]\}}t|||��qv|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��r�z6DictConfigurator.configure_handler..z'stream'�streamZstrm)r�rr�r�rjr�r�rCr rrDrZHandler�updater�Z SMTPHandlerr�Z SysLogHandlerr%rBrAr�r�r�r�)rwr�Z config_copyr7r�r<r�r4r�r�rIZthr�r;rzr�rrxrr�rr��s~ ��      �  ���� $   z"DictConfigurator.configure_handlerc CsZ|D]P}z|�|jd|�WqtyR}ztd|�|�WYd}~qd}~00qdS)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�}|dur$|�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_configs     z%DictConfigurator.common_logger_configcCs6t�|�}|�|||�|�dd�}|dur2||_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..ConfigStreamHandlerz� Handler for a logging configuration request. It expects a completely new logging configuration and uses fileConfig to install it. c SsB�z|j}|�d�}t|�dk�rt�d|�d}|j�|�}t|�|krb||�|t|��}q>|jjdurz|j�|�}|dur�|�d�}zddl}|� |�}t |�WnDt y�t � |�}z t|�Wnt y�t��Yn0Yn0|jj�r|jj��Wn4t�y<}z|jtk�r(�WYd}~n d}~00dS)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�handleGs6              z*listen..ConfigStreamHandler.handleN)r|r}r~rr�rrrr�ConfigStreamHandler@sr�c@s0eZdZdZdZdedddfdd�Zdd�ZdS) z$listen..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�usz-listen..ConfigSocketReceiver.__init__cSs`ddl}d}|sT|�|j��ggg|j�\}}}|r<|��t��|j}t��q |� �dS)Nr) �selectZsocket�filenor�Zhandle_requestr r r�rZ server_close)rwr�r�ZrdZwrZexrrr�serve_until_stoppeds�  z8listen..ConfigSocketReceiver.serve_until_stopped)r|r}r~rZallow_reuse_address�DEFAULT_LOGGING_CONFIG_PORTr�r�rrrr�ConfigSocketReceiverns � r�cs&eZdZ��fdd�Zdd�Z�ZS)zlisten..Servercs4t�|���||_||_||_||_t��|_dSr#) �superr��rcvr�hdlrr�r�� threadingZEventr�)rwr�r�r�r�)�Server� __class__rrr��s zlisten..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..Server.run)r|r}r~r�r�� __classcell__r�r�)r�rr��sr�)rrr�ZThread)r�r�r�r�rr�r�listen,s.r�cCs2t��ztrdt_daWt��n t��0dS)zN Stop the listening server which was created with a call to listen(). rZN)r r r�r�rrrrr� stopListening�s r�)NT)+rr�r�r Zlogging.handlersr�r�r�r�r�Z socketserverrrr�Z ECONNRESETr�r�rr"r'r r rWrr r��Irhrm�objectrnr�rrr[rsr�rtr�r�r�r�r�r�rrrr�sH  "&W! Az