Your IP : 18.116.19.29


Current Path : /opt/alt/python34/lib64/python3.4/logging/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/logging/__pycache__/config.cpython-34.pyc

�
j f���
@sdZddlZddlZddlZddlZddlZddlZddlZddlZyddl	Z
ddlZWnek
r�dZ
YnXddl
mZmZdZejZdadddd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zejdej�Zdd�ZGdd�de�Z Gdd�de!e �Z"Gdd�de#e �Z$Gdd�de%e �Z&Gdd �d e�Z'Gd!d"�d"e'�Z(e(Z)d#d$�Z*edd%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-2014 Vinay Sajip. All Rights Reserved.

To use, simply 'import logging' and log away!
�N)�ThreadingTCPServer�StreamRequestHandleriF#Tc
Cs�ddl}t||j�r'|}n;|j|�}t|d�rU|j|�n
|j|�t|�}tj	�z@tj
j�tjdd�=t
||�}t|||�Wdtj�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�
isinstanceZRawConfigParserZConfigParser�hasattrZ	read_file�read�_create_formatters�logging�_acquireLock�	_handlers�clear�_handlerList�_install_handlers�_install_loggers�_releaseLock)ZfnameZdefaults�disable_existing_loggersr�cp�
formatters�handlers�r�3/opt/alt/python34/lib64/python3.4/logging/config.py�
fileConfig8s		


rcCs�|jd�}|jd�}t|�}x]|D]U}|d|}yt||�}Wq1tk
r�t|�t||�}Yq1Xq1W|S)z)Resolve a dotted name to a global object.�.r)�split�pop�
__import__�getattr�AttributeError)�name�used�found�nrrr�_resolveZs


r#cCstdd�|�S)NcSs
|j�S)N)�strip)�xrrr�<lambda>isz_strip_spaces.<locals>.<lambda>)�map)Zalistrrr�
_strip_spaceshsr(c
Cs�|dd}t|�siS|jd�}t|�}i}x�|D]�}d|}|j|ddddd	�}|j|d
dddd	�}tj}||jd�}|r�t|�}n|||�}	|	||<qFW|S)zCreate and return formattersr�keys�,zformatter_%s�format�rawT�fallbackN�datefmt�class)�lenrr(�getr
�	Formatterr#)
rZflistrZformZsectnameZfsZdfs�cZ
class_name�frrrr	ks"

	r	c
Cs�|dd}t|�siS|jd�}t|�}i}g}x?|D]7}|d|}|d}|jdd�}yt|tt��}Wn$ttfk
r�t	|�}YnX|d}	t|	tt��}	||	�}
d	|kr
|d	}|
j
|�nt|�r-|
j||�nt|tj
j�ry|jd
d�}t|�ry|j|
|f�qyn|
||<qLWx%|D]\}
}
|
j||
�q�W|S)zInstall and return handlersrr)r*z
handler_%sr/�	formatter��args�level�target)r0rr(r1�eval�varsr
r�	NameErrorr#�setLevel�setFormatter�
issubclassr�
MemoryHandler�appendZ	setTarget)rr�hlistrZfixups�hand�section�klass�fmtr7�hr8r9�trrrr�s>



rcCsdtj}xT|D]L}|jj|}||krStj|_g|_d|_q||_qWdS)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�
loggerDictZNOTSETr8r�	propagate�disabled)�existing�
child_loggers�disable_existingrI�log�loggerrrr�_handle_existing_loggers�s	
	rScCs�|dd}|jd�}ttdd�|��}|jd�|d}tj}|}d|kr�|d}|j|�nx(|jd	d	�D]}|j|�q�W|d
}	t	|	�r|	jd�}	t
|	�}	x"|	D]}
|j||
�q�Wnt|jj
j��}|j�g}x�|D]�}|d|}|d}
|jd
dd�}tj|
�}|
|kr|j|
�d}|
d}t	|�}t	|�}xH||kr||d	|�|kr�|j||�n|d7}q�W|j|
�nd|kr8|d}|j|�nx(|jd	d	�D]}|j|�qLW||_d|_|d
}	t	|	�r4|	jd�}	t
|	�}	x"|	D]}
|j||
�q�Wq4q4Wt|||�d	S)zCreate and install loggers�loggersr)r*cSs
|j�S)N)r$)r%rrrr&�sz"_install_loggers.<locals>.<lambda>rIZlogger_rootr8Nrz	logger_%sZqualnamerLr-�rr)r�listr'�remover
rIr=r�
removeHandlerr0r(�
addHandlerrJrKr)�sortZgetint�	getLogger�indexrArLrMrS)rrrPZllistrDrIrQr8rGrBrCrNrOZqnrLrR�i�prefixed�pflen�num_existingrrrr�sd

	







		

rz^[a-z_][a-z0-9_]*$cCs,tj|�}|s(td|��ndS)Nz!Not a valid Python identifier: %rT)�
IDENTIFIER�match�
ValueError)�s�mrrr�valid_identsrfc@s1eZdZdZddd�Zdd�ZdS)�ConvertingMixinz?For ConvertingXXX's, this mixin class provides common functionsTcCsh|jj|�}||k	rd|r1|||<nt|�tttfkrd||_||_qdn|S)N)�configurator�convert�type�ConvertingDict�ConvertingList�ConvertingTuple�parent�key)�selfro�value�replace�resultrrr�convert_with_keys
	z ConvertingMixin.convert_with_keycCsL|jj|�}||k	rHt|�tttfkrH||_qHn|S)N)rhrirjrkrlrmrn)rprqrsrrrri'szConvertingMixin.convertN)�__name__�
__module__�__qualname__�__doc__rtrirrrrrgsrgc@s@eZdZdZdd�Zddd�Zddd�ZdS)	rkz A converting dictionary wrapper.cCs"tj||�}|j||�S)N)�dict�__getitem__rt)rprorqrrrrz<szConvertingDict.__getitem__NcCs%tj|||�}|j||�S)N)ryr1rt)rpro�defaultrqrrrr1@szConvertingDict.getcCs+tj|||�}|j||dd�S)NrrF)ryrrt)rpror{rqrrrrDszConvertingDict.pop)rurvrwrxrzr1rrrrrrk9srkc@s1eZdZdZdd�Zddd�ZdS)	rlzA converting list wrapper.cCs"tj||�}|j||�S)N)rVrzrt)rprorqrrrrzJszConvertingList.__getitem__rUcCstj||�}|j|�S)N)rVrri)rp�idxrqrrrrNszConvertingList.popN���)rurvrwrxrzrrrrrrlHsrlc@s"eZdZdZdd�ZdS)rmzA converting tuple wrapper.cCs(tj||�}|j||dd�S)NrrF)�tuplerzrt)rprorqrrrrzTszConvertingTuple.__getitem__N)rurvrwrxrzrrrrrmRsrmc@s�eZdZdZejd�Zejd�Zejd�Zejd�Z	ejd�Z
idd6d	d
6Zee
�Zdd�Zd
d�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_convertZext�cfg_convertZcfgcCst|�|_||j_dS)N)rk�configrh)rpr�rrr�__init__mszBaseConfigurator.__init__c	Cs�|jd�}|jd�}yz|j|�}x`|D]X}|d|7}yt||�}Wq7tk
r�|j|�t||�}Yq7Xq7W|SWn]tk
r�tj�dd�\}}td||f�}|||_	|_
|�YnXdS)z`
        Resolve strings to objects using standard import and attribute
        syntax.
        rrrUNzCannot resolve %r: %s)rr�importerrr�ImportError�sys�exc_inforc�	__cause__�
__traceback__)	rprdrr r!Zfrag�e�tb�vrrr�resolveqs"



zBaseConfigurator.resolvecCs
|j|�S)z*Default converter for the ext:// protocol.)r�)rprqrrrr��szBaseConfigurator.ext_convertcCs\|}|jj|�}|dkr7td|��n!||j�d�}|j|j�d}x�|rW|jj|�}|r�||j�d}n�|jj|�}|r|j�d}|jj|�s�||}qyt	|�}||}Wqt
k
r||}YqXn|r>||j�d�}qgtd||f��qgW|S)z*Default converter for the cfg:// protocol.NzUnable to convert %rrzUnable to convert %r at %r)�WORD_PATTERNrbrc�endr��groups�DOT_PATTERN�
INDEX_PATTERN�
DIGIT_PATTERN�int�	TypeError)rprq�restre�dr|r"rrrr��s2	

zBaseConfigurator.cfg_convertcCs/t|t�r7t|t�r7t|�}||_n�t|t�rnt|t�rnt|�}||_n�t|t�r�t|t�r�t|�}||_n�t|t�r+|j	j
|�}|r+|j�}|d}|jj
|d�}|r(|d}t||�}||�}q(q+n|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.
        �prefixN�suffix)rrkryrhrlrVrmr~�str�CONVERT_PATTERNrb�	groupdict�value_convertersr1r)rprqrer�r�Z	converterr�rrrri�s*

zBaseConfigurator.convertcs��jd�}t|�s-|j|�}n�jdd�}t�fdd��D��}||�}|r�x-|j�D]\}}t|||�q}Wn|S)z1Configure an object with a user-supplied factory.z()rNcs,g|]"}t|�r|�|f�qSr)rf)�.0�k)r�rr�
<listcomp>�s	z5BaseConfigurator.configure_custom.<locals>.<listcomp>)r�callabler�ry�items�setattr)rpr�r3�props�kwargsrsrrqr)r�r�configure_custom�sz!BaseConfigurator.configure_customcCs"t|t�rt|�}n|S)z0Utility function which converts lists to tuples.)rrVr~)rprqrrr�as_tuple�szBaseConfigurator.as_tupleN)rurvrwrx�re�compiler�r�r�r�r�r��staticmethodrr�r�r�r�r�rir�r�rrrrrYs"
"rc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	ddd�Z
ddd�Zddd�ZdS)�DictConfiguratorz]
    Configure logging using a dictionary-like object to describe the
    configuration.
    cCsQ|j}d|kr$td��n|ddkrKtd|d��n|jdd�}i}tj�z�|r+|jd|�}x�|D]�}|tjkr�td|��q�yLtj|}||}|jd	d
�}|r|jtj|��nWq�t	k
r@}	ztd||	f��WYd
d
}	~	Xq�Xq�W|jd|�}
xg|
D]_}y|j
||
|d
�Wq^t	k
r�}	ztd||	f��WYd
d
}	~	Xq^Xq^W|jdd
�}|r>y|j|d
�Wq(t	k
r$}	ztd|	��WYd
d
}	~	Xq(Xq>n|jdd
�}tjj�tj
d
d
�=|jd|�}
xg|
D]_}y|j|
|�|
|<Wqst	k
r�}	ztd||	f��WYd
d
}	~	XqsXqsW|jd|�}xg|D]_}y|j||�||<Wq�t	k
rM}	ztd||	f��WYd
d
}	~	Xq�Xq�W|jd|�}g}x�t|�D]�}y*|j||�}||_|||<Wqwt	k
r}	z=dt|	�kr�|j|�ntd||	f��WYd
d
}	~	XqwXqwWxv|D]n}y*|j||�}||_|||<Wqt	k
r}	ztd||	f��WYd
d
}	~	XqXqWtj}t|jjj��}|j�g}|jd|�}
x|
D]�}||krp|j|�d}|d}t|�}t|�}xH||kr_||d
|�|krR|j||�n|d7}qW|j|�ny|j
||
|�Wq�t	k
r�}	ztd||	f��WYd
d
}	~	Xq�Xq�Wt|||�|jdd
�}|r>y|j|�Wq>t	k
r:}	ztd|	��WYd
d
}	~	Xq>XnWd
tj�Xd
S)zDo the configuration.�versionz$dictionary doesn't specify a versionrUzUnsupported version: %s�incrementalFrzNo handler found with name %rr8Nz"Unable to configure handler %r: %srTTz!Unable to configure logger %r: %srIz#Unable to configure root logger: %srrz$Unable to configure formatter %r: %s�filtersz!Unable to configure filter %r: %sztarget not configured yetr) r�rcrr
rr1rr=�_checkLevel�	Exception�configure_logger�configure_rootr
r�configure_formatter�configure_filter�sorted�configure_handlerrr�rArIrVrJrKr)rZr\r0rWrSr)rpr�r�Z
EMPTY_DICTrr�handlerZhandler_configr8r�rTrIrPrr�ZdeferredrNrOr]r^r_r`rrr�	configure�s�	




'
'#

'
'	'
	'	


'	$zDictConfigurator.configurecCs�d|kr�|d}y|j|�}Wq�tk
r�}zIdt|�krV�n|jd�|d<||d<|j|�}WYdd}~Xq�XnK|jdd�}|jdd�}|jdd�}tj|||�}|S)	z(Configure a formatter from a dictionary.z()z'format'r+rFNr.�style�%)r�r�r�rr1r
r2)rpr��factoryrs�terFZdfmtr�rrrr��s

%z$DictConfigurator.configure_formattercCsCd|kr|j|�}n!|jdd�}tj|�}|S)z%Configure a filter from a dictionary.z()rr6)r�r1r
ZFilter)rpr�rsrrrrr��s
z!DictConfigurator.configure_filtercCsoxh|D]`}y|j|jd|�Wqtk
rf}ztd||f��WYdd}~XqXqWdS)z/Add filters to a filterer from a list of names.r�zUnable to add filter %r: %sN)Z	addFilterr�r�rc)rpZfiltererr�r4r�rrr�add_filters�s

zDictConfigurator.add_filtersc/s_t��}�jdd�}|rzy|jd|}Wqztk
rv}ztd||f��WYdd}~XqzXn�jdd�}�jdd�}d�kr��jd�}t|�s�|j|�}n|}nQ�jd�}	|j|	�}
t|
tj	j
�r�d	�kr�yQ|jd
�d	}t|tj�se�j
|�td��n|�d	<Wq+tk
r�}ztd�d	|f��WYdd}~Xq+Xnvt|
tj	j�r�d
�kr�|j�d
��d
<n;t|
tj	j�r+d�kr+|j�d��d<n|
}�jdd�}t�fdd��D��}
y||
�}Wn\tk
r�}z<dt|�kr��n|
jd�|
d<||
�}WYdd}~XnX|r�|j|�n|dk	r|jtj|��n|r%|j||�n|r[x-|j�D]\}}t|||�q8Wn|S)z&Configure a handler from a dictionary.r5NrzUnable to set formatter %r: %sr8r�z()r/r9rztarget not configured yetz#Unable to set target handler %r: %sZmailhostZaddressrcs,g|]"}t|�r|�|f�qSr)rf)r�r�)r�rrr��s	z6DictConfigurator.configure_handler.<locals>.<listcomp>z'stream'�streamZstrm)ryrr�r�rcr�r�r?r
rr@rZHandler�updater�ZSMTPHandlerr�Z
SysLogHandlerr�r>r=r�r�r�r�)rpr�Zconfig_copyr5r�r8r�r3r�ZcnamerEZthr�r�rsr�rrqr)r�rr��sl&	
*z"DictConfigurator.configure_handlercCsoxh|D]`}y|j|jd|�Wqtk
rf}ztd||f��WYdd}~XqXqWdS)z.Add handlers to a logger from a list of names.rzUnable to add handler %r: %sN)rYr�r�rc)rprRrrGr�rrr�add_handlers�s

zDictConfigurator.add_handlersFcCs�|jdd�}|dk	r7|jtj|��n|s�x(|jdd�D]}|j|�qQW|jdd�}|r�|j||�n|jdd�}|r�|j||�q�ndS)zU
        Perform configuration which is common to root and non-root loggers.
        r8Nrr�)r1r=r
r�rrXr�r�)rprRr�r�r8rGrr�rrr�common_logger_config�sz%DictConfigurator.common_logger_configcCsPtj|�}|j|||�|jdd�}|dk	rL||_ndS)z.Configure a non-root logger from a dictionary.rLN)r
r[r�r1rL)rprr�r�rRrLrrrr�s
z!DictConfigurator.configure_loggercCs#tj�}|j|||�dS)z*Configure a root logger from a dictionary.N)r
r[r�)rpr�r�rIrrrr�szDictConfigurator.configure_rootN)
rurvrwrxr�r�r�r�r�r�r�r�r�rrrrr��s�	?r�cCst|�j�dS)z%Configure logging using a dictionary.N)�dictConfigClassr�)r�rrr�
dictConfigsr�csststd��nGdd�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.
    z listen() needs threading to workc@s"eZdZdZdd�ZdS)z#listen.<locals>.ConfigStreamHandlerz�
        Handler for a logging configuration request.

        It expects a completely new logging configuration and uses fileConfig
        to install it.
        cSs�y�|j}|jd�}t|�dkr�tjd|�d}|jj|�}x3t|�|kr�||j|t|��}qXW|jjdk	r�|jj|�}n|dk	r_|jd�}y>ddl}|j	|�}t
|t�st�t
|�Wq_tk
r[tj|�}yt|�Wntk
rVtj�YnXYq_Xn|jjr�|jjj�q�nWn:tk
r�}z|jtkr��nWYdd}~XnXdS)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
connectionZrecvr0�structZunpack�server�verify�decode�json�loadsrry�AssertionErrorr�r��io�StringIOr�	traceback�	print_exc�ready�set�OSError�errno�RESET_ERROR)rpZconn�chunkZslenr�r��filer�rrr�handle5s8	!

z*listen.<locals>.ConfigStreamHandler.handleN)rurvrwrxr�rrrr�ConfigStreamHandler.sr�c@sCeZdZdZdZdeddddd�Zdd�ZdS)	z$listen.<locals>.ConfigSocketReceiverzD
        A simple TCP socket-based logging config receiver.
        rUZ	localhostNcSsUtj|||f|�tj�d|_tj�d|_||_||_dS)NrrU)	rr�r
r�abortr�timeoutr�r�)rp�host�portr�r�r�rrrr�cs
	
		z-listen.<locals>.ConfigSocketReceiver.__init__cSs�ddl}d}xj|s~|j|jj�ggg|j�\}}}|r^|j�ntj�|j}tj�qW|jj	�dS)Nr)
�selectZsocket�filenor�Zhandle_requestr
rr�r�close)rpr�r�Zrd�wrZexrrr�serve_until_stoppedms	

	z8listen.<locals>.ConfigSocketReceiver.serve_until_stopped)rurvrwrxZallow_reuse_address�DEFAULT_LOGGING_CONFIG_PORTr�r�rrrr�ConfigSocketReceiver\s
	r�cs1eZdZ��fdd�Zdd�Z�S)zlisten.<locals>.ServercsJt�|�j�||_||_||_||_tj�|_dS)N)	�superr��rcvr�hdlrr�r��	threadingZEventr�)rpr�r�r�r�)�Server�	__class__rrr�}s				zlisten.<locals>.Server.__init__c	Ss�|jd|jd|jd|jd|j�}|jdkrR|jd|_n|jj�tj�|a	tj
�|j�dS)Nr�r�r�r�rrU)r�r�r�r�r�Zserver_addressr�r
r�	_listenerrr�)rpr�rrr�run�s	


zlisten.<locals>.Server.run)rurvrwr�r�r)r�)r�rr�{sr�)�thread�NotImplementedErrorrrr�ZThread)r�r�r�r�r)r�r�listens.r�c
Cs8tj�ztr%dt_danWdtj�XdS)zN
    Stop the listening server which was created with a call to listen().
    rUN)r
rr�r�rrrrr�
stopListening�s
	
r�)-rxr�r�r
Zlogging.handlersr�r�r�r��_threadr�r�r�Zsocketserverrrr�Z
ECONNRESETr�r�rr#r(r	rrSrr��Irarf�objectrgryrkrVrlr~rmrr�r�r�r�r�rrrr�<module>sJ
	"#V!
��4|

?>