3 Pf8Z @sddlmZddlZddlZddlZddlZddlmZej dej Z ddZ yddlm Z Wnek rzdd Z YnXGd d d eZGd d d eZGdddeZGdddeZGdddeZeZddZdS))absolute_importN)sixz^[a-z_][a-z0-9_]*$cCstj|}|std|dS)Nz!Not a valid Python identifier: %rT) IDENTIFIERmatch ValueError)smr /usr/lib/python3.6/dictconfig.py valid_ident"s  r ) _checkLevelcCsNt|tr|}n:t||kr>|tjkr2td|tj|}n td||S)NzUnknown level: %rz*Level not an integer or a valid string: %r) isinstanceintstrloggingZ _levelNamesr TypeError)levelrvr r r r .s     r c@s,eZdZdZddZd ddZd ddZdS) ConvertingDictz A converting dictionary wrapper.cCsJtj||}|jj|}||k rF|||<t|tttfkrF||_||_ |S)N) dict __getitem__ configuratorconverttyperConvertingListConvertingTupleparentkey)selfrvalueresultr r r rGs   zConvertingDict.__getitem__NcCsLtj|||}|jj|}||k rH|||<t|tttfkrH||_||_ |S)N) rgetrrrrrrrr)rrdefaultrr r r r r!Ss  zConvertingDict.getcCsDtj|||}|jj|}||k r@t|tttfkr@||_||_ |S)N) rpoprrrrrrrr)rrr"rr r r r r#_s  zConvertingDict.pop)N)N)__name__ __module__ __qualname____doc__rr!r#r r r r rDs rc@s"eZdZdZddZd ddZdS) 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)ridxrr r r r r#xs   zConvertingList.popN)r+)r$r%r&r'rr#r r r r rjs rc@seZdZdZddZdS)rzA converting tuple wrapper.cCsBtj||}|jj|}||k r>t|tttfkr>||_||_ |S)N) tuplerrrrrrrrr)rrrr r r r rs   zConvertingTuple.__getitem__N)r$r%r&r'rr r r r rsrc@seZdZdZejdZejdZejdZejdZ ejdZ ddd Z e Z d d Zd d ZddZddZddZddZddZdS)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_dS)N)rconfigr)rr0r 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 rtjdd\}}td||f}|||_ |_ |YnXdS)z` Resolve strings to objects using standard import and attribute syntax. .rr)NzCannot resolve %r: %s) splitr#importergetattrAttributeError ImportErrorsysexc_infor __cause__ __traceback__) rrnameZusedfoundZfragetbvr r r resolves"      zBaseConfigurator.resolvecCs |j|S)z*Default converter for the ext:// protocol.)rA)rrr r r r.szBaseConfigurator.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_PATTERNrrendr0groups DOT_PATTERN INDEX_PATTERN DIGIT_PATTERNrr)rrrestrdr*nr r r r/s2       zBaseConfigurator.cfg_convertcCst|t r&t|tr&t|}||_nt|t rLt|trLt|}||_n~t|t rrt|trrt|}||_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. prefixNsuffix)r rrrrr(rr,rZ string_typesCONVERT_PATTERNr groupdictvalue_convertersr!r5)rrrrIrKZ converterrLr r r rs*     zBaseConfigurator.convertcsjd}t|d r8ttdr8t|tjkr8|j|}jdd}tfddD}|f|}|rx |jD]\}}t|||qrW|S)z1Configure an object with a user-supplied factory.z()__call__ ClassTyper2Nc3s"|]}t|r||fVqdS)N)r ).0k)r0r r sz4BaseConfigurator.configure_custom..) r#hasattrtypesrrQrAritemssetattr)rr0cZpropskwargsr r<rr )r0r configure_customs $   z!BaseConfigurator.configure_customcCst|trt|}|S)z0Utility function which converts lists to tuples.)r r(r,)rrr r r as_tuples zBaseConfigurator.as_tupleN)r$r%r&r'recompilerMrBrErFrGrO __import__r4r1rAr.r/rr[r\r r r r r-s      "r-c@s^eZdZdZddZddZddZdd Zd d Zd d Z dddZ dddZ dddZ dS)DictConfiguratorz] Configure logging using a dictionary-like object to describe the configuration. cCs|j}d|krtd|ddkr2td|d|jdd}i}tjz||r|jd|}tjdd dkrx|D]}|tjkrtd |qzy4tj|}||}|jd d}|r|j t |Wqzt k r} ztd || fWYdd} ~ XqzXqzW|jd|} xZ| D]R}y|j || |dWn4t k rd} ztd|| fWYdd} ~ XnXqW|jdd} | ry|j | dWn0t k r} ztd| WYdd} ~ XnXn|jdd} tjjtjdd=|jd|} xZ| D]R}y|j| || |<Wn4t k rF} ztd|| fWYdd} ~ XnXqW|jd|}xZ|D]R}y|j||||<Wn4t k r} ztd|| fWYdd} ~ XnXq`W|jd|}xht|D]\}y |j||}||_|||<Wn4t k r$} ztd || fWYdd} ~ XnXqWtj} t| jj}|jg}|jd|} x| D]}||kr|j|}|d}t|}t|}|d}x<||kr||d||kr|j|||d}qW|j|y|j || |Wn4t k r$} ztd|| fWYdd} ~ XnXq\WxF|D]>}| jj|}||krbtj|_g|_ d|_!n | r2d|_"q2W|jdd} | ry|j | Wn0t k r} ztd| WYdd} ~ XnXWdtj#XdS)zDo the configuration.versionz$dictionary doesn't specify a versionr)zUnsupported version: %s incrementalFhandlersNzNo handler found with name %rrz"Unable to configure handler %r: %sloggersTz!Unable to configure logger %r: %srootz#Unable to configure root logger: %sZdisable_existing_loggers formattersz$Unable to configure formatter %r: %sfiltersz!Unable to configure filter %r: %sr2)rdre)$r0rr#rZ _acquireLockr!r8 version_infoZ _handlerssetLevelr StandardErrorconfigure_loggerconfigure_rootclearZ _handlerListconfigure_formatterconfigure_filtersortedconfigure_handlerr<rgr(ZmanagerZ loggerDictsortindexlenappendremoveZNOTSETrrc propagateZdisabledZ _releaseLock)rr0rbZ EMPTY_DICTrcr<ZhandlerZhandler_configrr>rfrgZdisable_existingrhriZexistingZ child_loggersiZprefixedZpflenZ num_existinglogloggerr r r configures        "  $      $  $  $        $     zDictConfigurator.configurecCsd|krr|d}y|j|}Wqtk rn}z4dt|kr>|jd|d<||d<|j|}WYdd}~XqXn$|jdd}|jdd}tj||}|S)z(Configure a formatter from a dictionary.z()z'format'formatfmtNZdatefmt)r[rrr#r!rZ Formatter)rr0factoryr terZdfmtr r r rps    z$DictConfigurator.configure_formattercCs.d|kr|j|}n|jdd}tj|}|S)z%Configure a filter from a dictionary.z()r<)r[r!rFilter)rr0r r<r r r rqs    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.rizUnable to add filter %r: %sN)Z addFilterr0rlr)rZfiltererrifr>r r r add_filterss  zDictConfigurator.add_filtersc -s@jdd}|rVy|jd|}Wn2tk rT}ztd||fWYdd}~XnXjdd}jdd}dkrjd}t|d rttd rt|tjkr|j|}|}n|jjd }t |t j j od kr2y|jd d d <Wn8tk r.}ztd d |fWYdd}~XnXnZt |t j j r`dkr`|jdd<n,t |t j jrdkr|jdd<|}tfddD} y|f| } WnLtk r} z.dt| kr؂| jd| d<|f| } WYdd} ~ XnX|r| j||dk r*| jt||r<|j| || S)z&Configure a handler from a dictionary. formatterNrhzUnable to set formatter %r: %srriz()rPrQclasstargetrcz#Unable to set target handler %r: %sZmailhostZaddressc3s"|]}t|r||fVqdS)N)r )rRrS)r0r r rTsz5DictConfigurator.configure_handler..z'stream'streamZstrm)r#r0rlrrUrVrrQrA issubclassrrcZ MemoryHandlerZ SMTPHandlerr\Z SysLogHandlerrrrZ setFormatterrkr r) rr0rr>rrirYrklassrZr rr )r0r rssX    $  $     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.rczUnable to add handler %r: %sN)Z addHandlerr0rlr)rr|rchr>r r r add_handlers s  zDictConfigurator.add_handlersFcCs|jdd}|dk r"|jt||sx |jddD]}|j|q6W|jdd}|rd|j|||jdd}|r|j||dS)zU Perform configuration which is common to root and non-root loggers. rNrcri)r!rkr rcZ removeHandlerrr)rr|r0rbrrrcrir r r common_logger_configs    z%DictConfigurator.common_logger_configcCs6tj|}|j||||jdd}|dk r2||_dS)z.Configure a non-root logger from a dictionary.ryN)r getLoggerrr!ry)rr<r0rbr|ryr r r rm#s   z!DictConfigurator.configure_loggercCstj}|j|||dS)z*Configure a root logger from a dictionary.N)rrr)rr0rbrgr r r rn+szDictConfigurator.configure_rootN)F)F)F) r$r%r&r'r}rprqrrsrrrmrnr r r r r`s 5  r`cCst|jdS)z%Configure logging using a dictionary.N)dictConfigClassr})r0r r r dictConfig3sr)Z __future__rZlogging.handlersrr]r8rVZ pip._vendorrr^Irr r r7rrr(rr,robjectr-r`rrr r r r s*   &