Viewing File: /usr/lib64/python3.6/logging/__pycache__/config.cpython-36.opt-1.pyc

3


 \Ќ
@stdZddlZddlZddlZddlZddlZddlZddlZddlZyddl	Z
ddlZWnek
rpdZ
YnXddl
mZmZdZejZdad+ddZdd	Zd
dZdd
ZddZddZddZddZejdejZddZGddde Z!Gddde"e!Z#Gddde$e!Z%Gdd d e&e!Z'Gd!d"d"e Z(Gd#d$d$e(Z)e)Z*d%d&Z+edfd'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)ThreadingTCPServerStreamRequestHandleriF#Tc
Csddl}t||jr|}n*|j|}t|dr:|j|n
|j|t|}tj	z t
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).
    rNreadline)configparser
isinstanceZRawConfigParserZConfigParserhasattrZ	read_fileread_create_formatterslogging_acquireLock_clearExistingHandlers_install_handlers_install_loggers_releaseLock)ZfnameZdefaultsdisable_existing_loggersrcp
formattershandlersr/usr/lib64/python3.6/config.py
fileConfig8s	



rcCsp|jd}|jd}t|}xN|D]F}|d|}yt||}Wq"tk
rft|t||}Yq"Xq"W|S)z)Resolve a dotted name to a global object..r)splitpop
__import__getattrAttributeError)nameusedfoundnrrr_resolveZs


r!cCstdd|S)NcSs|jS)N)strip)xrrr<lambda>isz_strip_spaces.<locals>.<lambda>)map)Zalistrrr
_strip_spaceshsr&cCs|dd}t|siS|jd}t|}i}x~|D]v}d|}|j|dddd}|j|d	ddd}|j|d
ddd}tj}||jd}	|	rt|	}||||}
|
||<q4W|S)
zCreate and return formattersrkeys,zformatter_%sformatTN)rawfallbackdatefmtstyle%class)lenrr&getr
	Formatterr!)rflistrZformZsectnameZfsZdfsZstlc
class_namefrrrr	ks$

r	c
CsD|dd}t|siS|jd}t|}i}g}x|D]}|d|}|d}|jdd}yt|tt}Wn ttfk
rt	|}YnX|d}	t|	tt}	||	}
d	|kr|d	}|
j
|t|r|
j||t|tj
jr|jd
d}t|r|j|
|f|
||<q8Wx |D]\}
}
|
j||
q$W|S)zInstall and return handlersrr'r(z
handler_%sr/	formatterargsleveltarget)r0rr&r1evalvarsr
r	NameErrorr!setLevelsetFormatter
issubclassr
MemoryHandlerappendZ	setTarget)rrhlistrZfixupshandsectionklassfmtr9hr:r;trrrr
s>



r
cCsHtj}x<|D]4}|jj|}||kr:tj|_g|_d|_q||_qWdS)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
rootmanager
loggerDictZNOTSETr:r	propagatedisabled)existing
child_loggersdisable_existingrKlogloggerrrr_handle_existing_loggerss
rUcCs,|dd}|jd}ttdd|}|jd|d}tj}|}d|kr^|d}|j|x |jd	d	D]}|j|qnW|d
}	t	|	r|	jd}	t
|	}	x|	D]}
|j||
qWt|jj
j}|jg}x>|D]4}|d|}|d}
|jd
dd}tj|
}|
|kr|j|
d}|
d}t	|}t	|}x<||kr||d	||krt|j|||d7}qFW|j|
d|kr|d}|j|x"|jd	d	D]}|j|qW||_d|_|d
}	t	|	r|	jd}	t
|	}	x|	D]}
|j||
qWqWt|||d	S)zCreate and install loggersloggersr'r(cSs|jS)N)r")r#rrrr$sz"_install_loggers.<locals>.<lambda>rKZlogger_rootr:Nrz	logger_%squalnamerN)r+rr)rlistr%remover
rKr?r
removeHandlerr0r&
addHandlerrLrMr'sortZgetint	getLoggerindexrCrNrOrU)rrrRZllistrFrKrSr:rIrDrErPrQZqnrNrTiprefixedpflennum_existingrrrrsd











rcCs.tjjtjtjddtjdd=dS)z!Clear and close existing handlersN)r
	_handlersclearZshutdownZ_handlerListrrrrrs
rz^[a-z_][a-z0-9_]*$cCstj|}|std|dS)Nz!Not a valid Python identifier: %rT)
IDENTIFIERmatch
ValueError)smrrrvalid_idents
rkc@s"eZdZdZdddZddZdS)	ConvertingMixinz?For ConvertingXXX's, this mixin class provides common functionsTcCsB|jj|}||k	r>|r |||<t|tttfkr>||_||_|S)N)configuratorconverttypeConvertingDictConvertingListConvertingTupleparentkey)selfrtvaluereplaceresultrrrconvert_with_key$s
z ConvertingMixin.convert_with_keycCs0|jj|}||k	r,t|tttfkr,||_|S)N)rmrnrorprqrrrs)rurvrxrrrrn0s
zConvertingMixin.convertN)T)__name__
__module____qualname____doc__ryrnrrrrrl!s
rlc@s,eZdZdZddZd	ddZd
ddZdS)rpz A converting dictionary wrapper.cCstj||}|j||S)N)dict__getitem__ry)rurtrvrrrrEszConvertingDict.__getitem__NcCstj|||}|j||S)N)r~r1ry)rurtdefaultrvrrrr1IszConvertingDict.getcCstj|||}|j||ddS)NF)rw)r~rry)rurtrrvrrrrMszConvertingDict.pop)N)N)rzr{r|r}rr1rrrrrrpBs
rpc@s"eZdZdZddZd	ddZdS)
rqzA converting list wrapper.cCstj||}|j||S)N)rYrry)rurtrvrrrrSszConvertingList.__getitem__rXcCstj||}|j|S)N)rYrrn)ruidxrvrrrrWszConvertingList.popN)r)rzr{r|r}rrrrrrrqQsrqc@seZdZdZddZdS)rrzA converting tuple wrapper.cCstj||}|j||ddS)NF)rw)tuplerry)rurtrvrrrr]szConvertingTuple.__getitem__N)rzr{r|r}rrrrrrr[srrc@seZdZdZejdZejdZejdZejdZ	ejdZ
ddd	Zee
Zd
dZdd
ZddZddZddZddZddZdS)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_convertcfg_convert)ZextZcfgcCst||_||j_dS)N)rpconfigrm)rurrrr__init__vs
zBaseConfigurator.__init__c	Cs|jd}|jd}y`|j|}xP|D]H}|d|7}yt||}Wq&tk
rl|j|t||}Yq&Xq&W|Stk
rtjdd\}}td||f}|||_	|_
|YnXdS)z`
        Resolve strings to objects using standard import and attribute
        syntax.
        rrrXNzCannot resolve %r: %s)rrimporterrrImportErrorsysexc_inforh	__cause__
__traceback__)	rurirrrZfragetbvrrrresolvezs"




zBaseConfigurator.resolvecCs
|j|S)z*Default converter for the ext:// protocol.)r)rurvrrrrszBaseConfigurator.ext_convertcCs|}|jj|}|dkr&td|n||jd}|j|jd}x|r|jj|}|rp||jd}nd|jj|}|r|jd}|jj|s||}n2yt	|}||}Wnt
k
r||}YnX|r||jd}qJtd||fqJW|S)z*Default converter for the cfg:// protocol.NzUnable to convert %rrzUnable to convert %r at %r)WORD_PATTERNrgrhendrgroupsDOT_PATTERN
INDEX_PATTERN
DIGIT_PATTERNint	TypeError)rurvrestrjdrr rrrrs2
zBaseConfigurator.cfg_convertcCst|tr&t|tr&t|}||_nt|trLt|trLt|}||_n|t|trrt|trrt|}||_nVt|tr|j	j
|}|r|j}|d}|j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.
        prefixNsuffix)rrpr~rmrqrYrrrstrCONVERT_PATTERNrg	groupdictvalue_convertersr1r)rurvrjrrZ	converterrrrrrns*


zBaseConfigurator.convertcsrjd}t|s|j|}jdd}tfddD}|f|}|rnx |jD]\}}t|||qVW|S)z1Configure an object with a user-supplied factory.z()rNcs g|]}t|r||fqSr)rk).0k)rrr
<listcomp>sz5BaseConfigurator.configure_custom.<locals>.<listcomp>)rcallablerr~itemssetattr)rurr4propskwargsrxrrvr)rrconfigure_customs


z!BaseConfigurator.configure_customcCst|trt|}|S)z0Utility function which converts lists to tuples.)rrYr)rurvrrras_tuples
zBaseConfigurator.as_tupleN)rzr{r|r}recompilerrrrrrstaticmethodrrrrrrrnrrrrrrrbs 




"rc@s^eZdZdZddZddZddZdd	Zd
dZdd
Z	dddZ
dddZdddZdS)DictConfiguratorz]
    Configure logging using a dictionary-like object to describe the
    configuration.
    cCs|j}d|krtd|ddkr2td|d|jdd}i}tjz|r|jd|}x|D]}|tjkrtd|qfy6tj|}||}|jd	d
}|r|jtj|Wqft	k
r}	ztd||	fWYd
d
}	~	XqfXqfW|jd|}
xZ|
D]R}y|j
||
|d
Wn4t	k
rP}	ztd||	fWYd
d
}	~	XnXqW|jdd
}|ry|j|d
Wn0t	k
r}	ztd|	WYd
d
}	~	XnXn:|jdd
}t|jd|}
xZ|
D]R}y|j
|
||
|<Wn4t	k
r"}	ztd||	fWYd
d
}	~	XnXqW|jd|}xZ|D]R}y|j||||<Wn4t	k
r}	ztd||	fWYd
d
}	~	XnXq<W|jd|}g}xt|D]v}y |j||}||_|||<WnNt	k
r}	z0dt|	kr|j|ntd||	fWYd
d
}	~	XnXqWxd|D]\}y |j||}||_|||<Wn4t	k
r}	ztd||	fWYd
d
}	~	XnXq,Wtj}t|jjj}|jg}|jd|}
x|
D]}||kr<|j|d}|d}t|}t|}x<||kr0||d
||kr$|j|||d7}qW|j|y|j
||
|Wn4t	k
r}	ztd||	fWYd
d
}	~	XnXqWt||||jdd
}|ry|j|Wn0t	k
r}	ztd|	WYd
d
}	~	XnXWd
tjXd
S)zDo the configuration.versionz$dictionary doesn't specify a versionrXzUnsupported version: %sincrementalFrzNo handler found with name %rr:Nz"Unable to configure handler %r: %srVTz!Unable to configure logger %r: %srKz#Unable to configure root logger: %srrz$Unable to configure formatter %r: %sfiltersz!Unable to configure filter %r: %sztarget not configured yetr)rrhrr
rr1rdr?_checkLevel	Exceptionconfigure_loggerconfigure_rootrconfigure_formatterconfigure_filtersortedconfigure_handlerrrrCrKrYrLrMr'r]r_r0rZrUr)rurrZ
EMPTY_DICTrrhandlerZhandler_configr:rrVrKrRrrZdeferredrPrQr`rarbrcrrr	configures



"
$
$
$$
$


$zDictConfigurator.configurec
Csd|krr|d}y|j|}Wqtk
rn}z4dt|kr>|jd|d<||d<|j|}WYdd}~XqXnP|jdd}|jdd}|jdd}|jd	d}|stj}	nt|}	|	|||}|S)
z(Configure a formatter from a dictionary.z()z'format'r)rHNr,r-r.r/)rrrrr1r
r2r!)
rurfactoryrxterHZdfmtr-cnamer4rrrrs&z$DictConfigurator.configure_formattercCs.d|kr|j|}n|jdd}tj|}|S)z%Configure a filter from a dictionary.z()rr8)rr1r
ZFilter)rurrxrrrrrs

z!DictConfigurator.configure_filtercCs^xX|D]P}y|j|jd|Wqtk
rT}ztd||fWYdd}~XqXqWdS)z/Add filters to a filterer from a list of names.rzUnable to add filter %r: %sN)Z	addFilterrrrh)ruZfiltererrr6rrrradd_filterss

zDictConfigurator.add_filtersc/st}jdd}|r^y|jd|}Wn2tk
r\}ztd||fWYdd}~XnXjdd}jdd}dkrjd}t|s|j|}|}njd}	|j|	}
t|
tj	j
od	krHy>|jd
d	}t|tjsj
|td|d	<Wn8tk
rD}ztdd	|fWYdd}~XnXnZt|
tj	jrvd
krv|jd
d
<n,t|
tj	jrdkr|jdd<|
}jdd}tfddD}
y|f|
}WnLtk
r"}z.dt|kr|
jd|
d<|f|
}WYdd}~XnX|r4|j||dk	rN|jtj||r`|j|||rx"|jD]\}}t|||qpW|S)z&Configure a handler from a dictionary.r7NrzUnable to set formatter %r: %sr:rz()r/r;rztarget not configured yetz#Unable to set target handler %r: %sZmailhostZaddressrcs g|]}t|r||fqSr)rk)rr)rrrrsz6DictConfigurator.configure_handler.<locals>.<listcomp>z'stream'streamZstrm)r~rrrrhrrrAr
rrBrZHandlerupdaterZSMTPHandlerrZ
SysLogHandlerrr@r?rrrr)rurZconfig_copyr7rr:rr4rrrGZthrrrxrrrvr)rrrsl





$



z"DictConfigurator.configure_handlercCs^xX|D]P}y|j|jd|Wqtk
rT}ztd||fWYdd}~XqXqWdS)z.Add handlers to a logger from a list of names.rzUnable to add handler %r: %sN)r\rrrh)rurTrrIrrrradd_handlerss

zDictConfigurator.add_handlersFcCs|jdd}|dk	r$|jtj||sx |jddD]}|j|q8W|jdd}|rf|j|||jdd}|r|j||dS)zU
        Perform configuration which is common to root and non-root loggers.
        r:Nrr)r1r?r
rrr[rr)rurTrrr:rIrrrrrcommon_logger_configsz%DictConfigurator.common_logger_configcCs6tj|}|j||||jdd}|dk	r2||_dS)z.Configure a non-root logger from a dictionary.rNN)r
r^rr1rN)rurrrrTrNrrrrs

z!DictConfigurator.configure_loggercCstj}|j|||dS)z*Configure a root logger from a dictionary.N)r
r^r)rurrrKrrrrszDictConfigurator.configure_rootN)F)F)F)
rzr{r|r}rrrrrrrrrrrrrrs	?

rcCst|jdS)z%Configure logging using a dictionary.N)dictConfigClassr)rrrr
dictConfig srcsPtstdGdddt}Gdddt}Gfdddtj||||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@seZdZdZddZdS)z#listen.<locals>.ConfigStreamHandlerz
        Handler for a logging configuration request.

        It expects a completely new logging configuration and uses fileConfig
        to install it.
        cSsHy|j}|jd}t|dkrtjd|d}|jj|}x&t||krd||j|t|}q@W|jjdk	r~|jj|}|dk	r|jd}yddl}|j	|}t
|WnHtk
rtj
|}yt|Wntk
rtjYnXYnX|jjr|jjjWn2tk
rB}z|jtkr2WYdd}~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
connectionZrecvr0structunpackserververifydecodejsonloadsrrioStringIOr	traceback	print_excreadysetOSErrorerrnoRESET_ERROR)ruZconnchunkZslenrrfilerrrrhandleBs6




z*listen.<locals>.ConfigStreamHandler.handleN)rzr{r|r}rrrrrConfigStreamHandler;src@s0eZdZdZdZdedddfddZddZdS)	z$listen.<locals>.ConfigSocketReceiverzD
        A simple TCP socket-based logging config receiver.
        rXZ	localhostNcSs>tj|||f|tjd|_tjd|_||_||_dS)NrrX)	rrr
rabortrtimeoutrr)ruhostportrrrrrrrpsz-listen.<locals>.ConfigSocketReceiver.__init__cSsfddl}d}xJ|sV|j|jjggg|j\}}}|r>|jtj|j}tjqW|jj	dS)Nr)
selectZsocketfilenorZhandle_requestr
rrrclose)rurrZrdwrZexrrrserve_until_stoppedzsz8listen.<locals>.ConfigSocketReceiver.serve_until_stopped)rzr{r|r}Zallow_reuse_addressDEFAULT_LOGGING_CONFIG_PORTrrrrrrConfigSocketReceiveris
	rcs&eZdZfddZddZZS)zlisten.<locals>.Servercs4t|j||_||_||_||_tj|_dS)N)	superrrcvrhdlrrr	threadingZEventr)rurrrr)Server	__class__rrrszlisten.<locals>.Server.__init__cSsZ|j|j|j|j|jd}|jdkr0|jd|_|jjtj|a	tj
|jdS)N)rrrrrrX)rrrrrZserver_addressrr
r	_listenerrr)rurrrrruns


zlisten.<locals>.Server.run)rzr{r|rr
__classcell__r)r)rrrsr)threadNotImplementedErrorrrrZThread)rrrrr)rrlisten%s.rc
Cs*tjztrdt_daWdtjXdS)zN
    Stop the listening server which was created with a call to listen().
    rXN)r
rrrrrrrr
stopListeningsr)NT).r}rrr
Zlogging.handlersrrrr_threadrrrZsocketserverrrrZ
ECONNRESETrrrr!r&r	r
rUrrrIrfrkobjectrlr~rprYrqrrrrrrrrrrrrr<module>sP

"#W!
9|
Back to Directory File Manager