3

Q'íc8Zã@sÜddlmZddlZddlZddlZddlZddlmZej	dej
ƒZdd„Zyddlm
Z
Wnek
rzdd	„Z
YnXGd
d„deƒZGdd
„d
eƒZGdd„deƒZGdd„deƒZGdd„deƒZeZdd„ZdS)é)Úabsolute_importN)Úsixz^[a-z_][a-z0-9_]*$cCstj|ƒ}|std|ƒ‚dS)Nz!Not a valid Python identifier: %rT)Ú
IDENTIFIERÚmatchÚ
ValueError)ÚsÚm©r	ú4/tmp/pip-build-l_bcah40/pip/pip/compat/dictconfig.pyÚvalid_ident"s
r)Ú_checkLevelcCsNt|tƒr|}n:t|ƒ|kr>|tjkr2td|ƒ‚tj|}ntd|ƒ‚|S)NzUnknown level: %rz*Level not an integer or a valid string: %r)Ú
isinstanceÚintÚstrÚloggingZ_levelNamesrÚ	TypeError)ÚlevelÚrvr	r	r
r.s

rc@s,eZdZdZdd„Zd	dd„Zd
dd„ZdS)ÚConvertingDictz A converting dictionary wrapper.cCsJtj||ƒ}|jj|ƒ}||k	rF|||<t|ƒtttfkrF||_||_	|S)N)
ÚdictÚ__getitem__ÚconfiguratorÚconvertÚtyperÚConvertingListÚConvertingTupleÚparentÚkey)ÚselfrÚvalueÚresultr	r	r
rGs
zConvertingDict.__getitem__NcCsLtj|||ƒ}|jj|ƒ}||k	rH|||<t|ƒtttfkrH||_||_	|S)N)
rÚgetrrrrrrrr)rrÚdefaultrr r	r	r
r!Ss
zConvertingDict.getcCsDtj|||ƒ}|jj|ƒ}||k	r@t|ƒtttfkr@||_||_	|S)N)
rÚpoprrrrrrrr)rrr"rr r	r	r
r#_s
zConvertingDict.pop)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rr!r#r	r	r	r
rDs
rc@s"eZdZdZdd„Zd	dd„ZdS)
rzA converting list wrapper.cCsJtj||ƒ}|jj|ƒ}||k	rF|||<t|ƒtttfkrF||_||_	|S)N)
Úlistrrrrrrrrr)rrrr r	r	r
rls
zConvertingList.__getitem__écCs<tj||ƒ}|jj|ƒ}||k	r8t|ƒtttfkr8||_|S)N)	r(r#rrrrrrr)rÚidxrr r	r	r
r#xs
zConvertingList.popNéÿÿÿÿ)r+)r$r%r&r'rr#r	r	r	r
rjsrc@seZdZdZdd„ZdS)rzA converting tuple wrapper.cCsBtj||ƒ}|jj|ƒ}||k	r>t|ƒtttfkr>||_||_	|S)N)
Útuplerrrrrrrrr)rrrr r	r	r
r„s
zConvertingTuple.__getitem__N)r$r%r&r'rr	r	r	r
r‚src@sˆeZdZdZejdƒZejdƒZejdƒZejdƒZ	ejdƒZ
ddd	œZeZ
d
d„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_convertÚcfg_convert)ÚextÚcfgcCst|ƒ|_||j_dS)N)rÚconfigr)rr2r	r	r
Ú__init__£s
zBaseConfigurator.__init__c	CsÄ|jdƒ}|jdƒ}y`|j|ƒ}xP|D]H}|d|7}yt||ƒ}Wq&tk
rl|j|ƒt||ƒ}Yq&Xq&W|Stk
r¾tjƒdd…\}}td||fƒ}|||_	|_
|‚YnXdS)z`
        Resolve strings to objects using standard import and attribute
        syntax.
        Ú.rr)NzCannot resolve %r: %s)Úsplitr#ÚimporterÚgetattrÚAttributeErrorÚImportErrorÚsysÚexc_inforÚ	__cause__Ú
__traceback__)	rrÚnameÚusedÚfoundÚfragÚeÚtbÚvr	r	r
Úresolve§s"




zBaseConfigurator.resolvecCs
|j|ƒS)z*Default converter for the ext:// protocol.)rE)rrr	r	r
r.¾szBaseConfigurator.ext_convertcCs|}|jj|ƒ}|dkr&td|ƒ‚nØ||jƒd…}|j|jƒd}x´|rü|jj|ƒ}|rp||jƒd}nd|jj|ƒ}|rÔ|jƒd}|jj|ƒs¢||}n2yt	|ƒ}||}Wnt
k
rÒ||}YnX|rê||jƒd…}qJtd||fƒ‚qJW|S)z*Default converter for the cfg:// protocol.NzUnable to convert %rrzUnable to convert %r at %r)ÚWORD_PATTERNrrÚendr2ÚgroupsÚDOT_PATTERNÚ
INDEX_PATTERNÚ
DIGIT_PATTERNrr)rrÚrestrÚdr*Únr	r	r
r/Âs2
zBaseConfigurator.cfg_convertcCsÎt|tƒr&t|tƒr&t|ƒ}||_n¤t|tƒrLt|tƒrLt|ƒ}||_n~t|tƒrrt|tƒrrt|ƒ}||_nXt|tj	ƒrÊ|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.
        ÚprefixNÚsuffix)r
rrrrr(rr,rÚstring_typesÚCONVERT_PATTERNrÚ	groupdictÚvalue_convertersr!r7)rrrrMrOÚ	converterrPr	r	r
räs*

zBaseConfigurator.convertcsŽˆjdƒ}t|dƒr8ttdƒr8t|ƒtjkr8|j|ƒ}ˆjddƒ}t‡fdd„ˆDƒƒ}|f|Ž}|rŠx |jƒD]\}}t|||ƒqrW|S)z1Configure an object with a user-supplied factory.z()Ú__call__Ú	ClassTyper4Nc3s"|]}t|ƒr|ˆ|fVqdS)N)r)Ú.0Úk)r2r	r
ú	<genexpr>sz4BaseConfigurator.configure_custom.<locals>.<genexpr>)	r#ÚhasattrÚtypesrrWrErÚitemsÚsetattr)rr2ÚcÚpropsÚkwargsr r>rr	)r2r
Úconfigure_customs
$

z!BaseConfigurator.configure_customcCst|tƒrt|ƒ}|S)z0Utility function which converts lists to tuples.)r
r(r,)rrr	r	r
Úas_tuples
zBaseConfigurator.as_tupleN)r$r%r&r'ÚreÚcompilerRrFrIrJrKrTÚ
__import__r6r3rEr.r/rrbrcr	r	r	r
r-s 




"r-c@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.
    cCsØ|j}d|krtdƒ‚|ddkr2td|dƒ‚|jddƒ}i}tjƒz||rÄ|jd|ƒ}tjdd	…dkrxŽ|D]†}|tjkr–td|ƒ‚qzy4tj|}||}|jddƒ}|rÈ|j	t
|ƒƒWqztk
rþ}	ztd
||	fƒ‚WYdd}	~	XqzXqzW|jd|ƒ}
xZ|
D]R}y|j||
|dƒWn4tk
rd}	ztd||	fƒ‚WYdd}	~	XnXqW|jddƒ}|rÆy|j
|dƒWn0tk
r¾}	ztd|	ƒ‚WYdd}	~	XnXn|jddƒ}tjjƒtjdd…=|jd|ƒ}
xZ|
D]R}y|j|
|ƒ|
|<Wn4tk
rF}	ztd||	fƒ‚WYdd}	~	XnXqøW|jd|ƒ}xZ|D]R}y|j||ƒ||<Wn4tk
r®}	ztd||	fƒ‚WYdd}	~	XnXq`W|jd|ƒ}xht|ƒD]\}y |j||ƒ}||_|||<Wn4tk
r$}	ztd
||	fƒ‚WYdd}	~	XnXqÌWtj}t|jjƒ}|jƒg}|jd|ƒ}
xÔ|
D]Ì}||krÜ|j|ƒ}|d}t|ƒ}t|ƒ}|d}x<||krÐ||d|…|krÐ|j||ƒ|d}q–W|j|ƒy|j||
|ƒWn4tk
r$}	ztd||	fƒ‚WYdd}	~	XnXq\WxF|D]>}|jj|}||krbtj|_g|_ d|_!n|r2d|_"q2W|jddƒ}|rÆy|j
|ƒWn0tk
rÄ}	ztd|	ƒ‚WYdd}	~	XnXWdtj#ƒXdS)zDo the configuration.Úversionz$dictionary doesn't specify a versionr)zUnsupported version: %sÚincrementalFÚhandlersNéézNo handler found with name %rrz"Unable to configure handler %r: %sÚloggersTz!Unable to configure logger %r: %sÚrootz#Unable to configure root logger: %sÚdisable_existing_loggersÚ
formattersz$Unable to configure formatter %r: %sÚfiltersz!Unable to configure filter %r: %sr4)rkrl)$r2rr#rÚ_acquireLockr!r:Úversion_infoÚ	_handlersÚsetLevelrÚ
StandardErrorÚconfigure_loggerÚconfigure_rootÚclearÚ_handlerListÚconfigure_formatterÚconfigure_filterÚsortedÚconfigure_handlerr>rnr(ÚmanagerÚ
loggerDictÚsortÚindexÚlenÚappendÚremoveÚNOTSETrrjÚ	propagateÚdisabledÚ_releaseLock)rr2riÚ
EMPTY_DICTrjr>ÚhandlerÚhandler_configrrBrmrnÚdisable_existingrprqÚexistingÚ
child_loggersÚiÚprefixedÚpflenÚnum_existingÚlogÚloggerr	r	r
Ú	configuresÐ



"
$

$
$$



$

zDictConfigurator.configurecCsšd|krr|d}y|j|ƒ}Wq–tk
rn}z4dt|ƒkr>‚|jdƒ|d<||d<|j|ƒ}WYdd}~Xq–Xn$|jddƒ}|jddƒ}tj||ƒ}|S)z(Configure a formatter from a dictionary.z()z'format'ÚformatÚfmtNÚdatefmt)rbrrr#r!rÚ	Formatter)rr2Úfactoryr Úter˜Údfmtr	r	r
r{­sz$DictConfigurator.configure_formattercCs.d|kr|j|ƒ}n|jddƒ}tj|ƒ}|S)z%Configure a filter from a dictionary.z()r>Ú)rbr!rÚFilter)rr2r r>r	r	r
r|Ãs

z!DictConfigurator.configure_filtercCs^xX|D]P}y|j|jd|ƒWqtk
rT}ztd||fƒ‚WYdd}~XqXqWdS)z/Add filters to a filterer from a list of names.rqzUnable to add filter %r: %sN)Ú	addFilterr2rvr)rÚfiltererrqÚfrBr	r	r
Úadd_filtersÌs

zDictConfigurator.add_filtersc-s@ˆjddƒ}|rVy|jd|}Wn2tk
rT}ztd||fƒ‚WYdd}~XnXˆjddƒ}ˆjddƒ}dˆkr´ˆjdƒ}t|dƒr®ttd	ƒr®t|ƒtjkr®|j|ƒ}|}nÜ|jˆjd
ƒƒ}t	|t
jjƒoØdˆkr2y|jdˆdˆd<Wn8tk
r.}ztd
ˆd|fƒ‚WYdd}~XnXnZt	|t
jj
ƒr`dˆkr`|jˆdƒˆd<n,t	|t
jjƒrŒdˆkrŒ|jˆdƒˆd<|}t‡fdd„ˆDƒƒ}	y|f|	Ž}
WnLtk
r}z.dt|ƒkr؂|	jdƒ|	d<|f|	Ž}
WYdd}~XnX|r|
j|ƒ|dk	r*|
jt|ƒƒ|r<|j|
|ƒ|
S)z&Configure a handler from a dictionary.Ú	formatterNrpzUnable to set formatter %r: %srrqz()rVrWÚclassÚtargetrjz#Unable to set target handler %r: %sÚmailhostÚaddressc3s"|]}t|ƒr|ˆ|fVqdS)N)r)rXrY)r2r	r
rZõsz5DictConfigurator.configure_handler.<locals>.<genexpr>z'stream'ÚstreamÚstrm)r#r2rvrr[r\rrWrEÚ
issubclassrrjÚ
MemoryHandlerÚSMTPHandlerrcÚ
SysLogHandlerrrrÚsetFormatterrurr£)rr2r¤rBrrqr_r›Úklassrar rœr	)r2r
r~ÔsX
$

$



z"DictConfigurator.configure_handlercCs^xX|D]P}y|j|jd|ƒWqtk
rT}ztd||fƒ‚WYdd}~XqXqWdS)z.Add handlers to a logger from a list of names.rjzUnable to add handler %r: %sN)Ú
addHandlerr2rvr)rr•rjÚhrBr	r	r
Úadd_handlers	s

zDictConfigurator.add_handlersFcCs„|jddƒ}|dk	r"|jt|ƒƒ|s€x |jdd…D]}|j|ƒq6W|jddƒ}|rd|j||ƒ|jddƒ}|r€|j||ƒdS)zU
        Perform configuration which is common to root and non-root loggers.
        rNrjrq)r!rurrjÚ
removeHandlerr³r£)rr•r2rirr²rjrqr	r	r
Úcommon_logger_configsz%DictConfigurator.common_logger_configcCs6tj|ƒ}|j|||ƒ|jddƒ}|dk	r2||_dS)z.Configure a non-root logger from a dictionary.r‡N)rÚ	getLoggerrµr!r‡)rr>r2rir•r‡r	r	r
rw#s

z!DictConfigurator.configure_loggercCstjƒ}|j|||ƒdS)z*Configure a root logger from a dictionary.N)rr¶rµ)rr2rirnr	r	r
rx+szDictConfigurator.configure_rootN)F)F)F)
r$r%r&r'r–r{r|r£r~r³rµrwrxr	r	r	r
rgs	5

rgcCst|ƒjƒdS)z%Configure logging using a dictionary.N)ÚdictConfigClassr–)r2r	r	r
Ú
dictConfig3sr¸)Ú
__future__rÚlogging.handlersrrdr:r\Úpip._vendorrreÚIrrrr9rrr(rr,rÚobjectr-rgr·r¸r	r	r	r
Ú<module>s*	&