a cæ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Ú isinstanceZRawConfigParserÚ ConfigParserÚhasattrZ read_fileÚreadÚ_create_formattersÚloggingÚ _acquireLockÚ_clearExistingHandlersÚ_install_handlersÚ_install_loggersÚ _releaseLock)ZfnameÚdefaultsÚdisable_existing_loggersrÚcpÚ formattersÚhandlers©rú//opt/imh-python/lib/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#) rÚflistrZformZsectnameÚfsÚdfsZstlÚ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_%sr1Ú formatterÚÚargsú()Úkwargsz{}ÚlevelÚtarget)r2rr(r3ÚevalÚvarsr rÚ NameErrorr#rÚsetLevelÚ setFormatterÚ issubclassrÚ MemoryHandlerÚappendZ setTarget)rrÚhlistrZfixupsÚhandÚsectionÚklassÚfmtr=r?Úhr@rAÚtrrrr|sD             rcCsTtj}|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Ú loggerDictrÚ PlaceHolderrEÚNOTSETrÚ propagateÚdisabled)ÚexistingÚ child_loggersÚdisable_existingrQÚlogÚloggerrrrÚ_handle_existing_loggers¢s    r]cCs |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 | ¡}| | vrv|  | ¡d }| d}t |ƒ}t | ƒ}||krl| |d|…|kr`|  | |¡|d 7}q2|  | ¡d|vr’|d}| |¡|jdd…D]}| |¡q ||_d|_|d} t | ƒrÐ|  d¡} t| ƒ} | D]} |  || ¡qäqÐt| | |ƒdS)zCreate and install loggersÚloggersr)r*rQZ logger_rootr@Nrz logger_%sÚqualnamerVé)r-rr)rÚlistr(Úremover rQrErÚ removeHandlerr2Ú addHandlerrRrSr)ÚsortZgetintÚ getLoggerÚindexrIrVrWr])rrrZZllistrLrQr[r@rOrJrKrXrYZqnrVr\ÚiÚprefixedÚpflenÚ num_existingrrrr¸sd                  rcCs.tj ¡t tjdd…¡tjdd…=dS)z!Clear and close existing handlersN)r Ú _handlersÚclearÚshutdownÚ _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  ruc@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)Úselfr~ÚvalueÚreplaceÚresultrrrÚconvert_with_key#s  ÿz ConvertingMixin.convert_with_keycCs0|j |¡}||ur,t|ƒtttfvr,||_|Sr$)rwrxryrzr{r|r})rr€r‚rrrrx/s  ÿzConvertingMixin.convertN)T)Ú__name__Ú __module__Ú __qualname__Ú__doc__rƒrxrrrrrv s rvc@s,eZdZdZdd„Zd dd„Zd dd„ZdS) rzz A converting dictionary wrapper.cCst ||¡}| ||¡Sr$)ÚdictÚ __getitem__rƒ©rr~r€rrrr‰Ds zConvertingDict.__getitem__NcCst |||¡}| ||¡Sr$)rˆr3rƒ©rr~Údefaultr€rrrr3HszConvertingDict.getcCst |||¡}|j||ddS©NF)r)rˆrrƒr‹rrrrLszConvertingDict.pop)N)N)r„r…r†r‡r‰r3rrrrrrzAs rzc@s"eZdZdZdd„Zddd„ZdS) r{zA converting list wrapper.cCst ||¡}| ||¡Sr$)rar‰rƒrŠrrrr‰Rs zConvertingList.__getitem__éÿÿÿÿcCst ||¡}| |¡Sr$)rarrx)rÚidxr€rrrrVs zConvertingList.popN)rŽ)r„r…r†r‡r‰rrrrrr{Psr{c@seZdZdZdd„ZdS)r|zA converting tuple wrapper.cCst ||¡}|j||ddSr)Útupler‰rƒrŠrrrr‰\s zConvertingTuple.__getitem__N)r„r…r†r‡r‰rrrrr|Zsr|c@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)ÚextZcfgcCst|ƒ|_||j_dSr$)rzÚconfigrw)rr•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. rrr`NzCannot resolve %r: %s) rrÚimporterrrÚ ImportErrorÚsysÚexc_inforrÚ __cause__Ú __traceback__) rrsrr r!ÚfragÚeÚtbÚvrrrÚresolveys"       zBaseConfigurator.resolvecCs | |¡S)z*Default converter for the ext:// protocol.)r¡©rr€rrrr’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_PATTERNrqrrÚendr•ÚgroupsÚ DOT_PATTERNÚ INDEX_PATTERNÚ DIGIT_PATTERNÚintÚ TypeError)rr€ÚrestrtÚdrr"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)rrzrˆrwr{rar|rrr&ÚCONVERT_PATTERNrqÚ groupdictÚvalue_convertersr3r)rr€rtr¬r®Ú converterr¯rrrrx¶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©ru©Ú.0Úk©r•rrÚ Ùóz5BaseConfigurator.configure_custom..)rÚcallabler¡ÚitemsÚsetattr)rr•r8Úpropsr?r‚rr€rr¸rÚconfigure_customÒs   z!BaseConfigurator.configure_customcCst|tƒrt|ƒ}|S)z0Utility function which converts lists to tuples.)rrarr¢rrrÚas_tupleàs zBaseConfigurator.as_tupleN)r„r…r†r‡ÚreÚcompiler°r£r¦r§r¨r²Ú staticmethodrr—r–r¡r’r“rxr¿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 } ~ 00n$| dd ¡} t ƒ| d|¡} | D]R}z|  | |¡| |<Wn4t y} ztd|ƒ| ‚WYd } ~ n d } ~ 00qÈ| d|¡}|D]R}z| ||¡||<Wn4t yz} ztd|ƒ| ‚WYd } ~ n d } ~ 00q,| d|¡}g}t|ƒD]x}z | ||¡}||_|||<WnPt y } z6dt| jƒvrê| |¡ntd |ƒ| ‚WYd } ~ n d } ~ 00q˜|D]\}z | ||¡}||_|||<Wn4t yn} ztd |ƒ| ‚WYd } ~ n d } ~ 00qtj} t| jj ¡ƒ}| ¡g}| d |¡} | D]Ä}||vr| |¡d}|d}t|ƒ}t|ƒ}||kr||d |…|kr| ||¡|d7}qÚ| |¡z|  || |¡Wn4t yf} ztd|ƒ| ‚WYd } ~ n d } ~ 00q¦t||| ƒ| dd ¡} | rÊz|  | ¡Wn0t yÈ} ztdƒ| ‚WYd } ~ n d } ~ 00Wt ¡n t ¡0d S)zDo the configuration.Úversionz$dictionary doesn't specify a versionr`zUnsupported version: %sÚ incrementalFrzNo handler found with name %rr@NzUnable to configure handler %rr^TzUnable to configure logger %rrQzUnable to configure root loggerrrz Unable to configure formatter %rÚfilterszUnable to configure filter %rútarget not configured yetr) r•rrrr r r3rlrEÚ _checkLevelÚ ExceptionÚconfigure_loggerÚconfigure_rootr Úconfigure_formatterÚconfigure_filterÚsortedÚconfigure_handlerrr&r›rIrQrarRrSr)rergr2rbr]r)rr•rÆÚ EMPTY_DICTrrÚhandlerZhandler_configr@ržr^rQrZrrÇZdeferredrXrYrhrirjrkrrrÚ 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+rNNr.r/r0r1Úvalidate)r¿rªr&rr3r r4r#) rr•Úfactoryr‚ÚterNZdfmtr/Úcnamer8rrrrÍŠs* "     z$DictConfigurator.configure_formattercCs.d|vr| |¡}n| dd¡}t |¡}|S)z%Configure a filter from a dictionary.r>rr<)r¿r3r ÚFilter)rr•r‚rrrrrή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)Ú addFilterr•rÊrr)rZfiltererrÇr:rž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 ˆvrJz>|jd ˆd } t | tj ƒsˆ  |¡td ƒ‚| ˆd <Wn8tyF}ztd ˆd ƒ|‚WYd}~n d}~00nZt| tj jƒrxd ˆvrx| ˆd ¡ˆd <n,t| tj jƒr¤dˆvr¤| ˆd¡ˆd<| }ˆ dd¡} ‡fdd„ˆDƒ} z|fi| ¤Ž}WnRty*}z8dt|ƒvrú‚|  d¡| d<|fi| ¤Ž}WYd}~n d}~00|r<| |¡|durV| t |¡¡|rh| ||¡| rŽ|  ¡D]\}}t|||ƒqv|S)z&Configure a handler from a dictionary.r;NrzUnable to set formatter %rr@rÇr>r1rArrÈzUnable to set target handler %rZmailhostÚaddressrcsi|]}t|ƒr|ˆ|“qSrr´rµr¸rrr¹çrºz6DictConfigurator.configure_handler..z'stream'ÚstreamZstrm)rˆrr•rÊrrr»r¡rGr rrHrÚHandlerÚupdaterªZ SMTPHandlerrÀZ SysLogHandlerr&rFrErÉrÚr¼r½)rr•Z config_copyr;ržr@rÇr8rÕr×rMÚthr¾r?r‚rÖrr€rr¸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)rdr•rÊrr)rr\rrOrž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Ç)r3rEr rÉrrcràrÚ)rr\r•rÆr@rOrrÇrrrÚcommon_logger_configs     z%DictConfigurator.common_logger_configcCs6t |¡}| |||¡| dd¡}|dur2||_dS)z.Configure a non-root logger from a dictionary.rVN)r rfrár3rV)rrr•rÆr\rVrrrrËs   z!DictConfigurator.configure_loggercCst ¡}| |||¡dS)z*Configure a root logger from a dictionary.N)r rfrá)rr•rÆrQrrrrÌ szDictConfigurator.configure_rootN)F)F)F) r„r…r†r‡rÓ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 SsPz|j}| d¡}t|ƒdkrt d|¡d}|j |¡}t|ƒ|krb|| |t|ƒ¡}q>|jjdurz|j |¡}|durþ| d¡}z,ddl}|  |¡}t |t ƒs®J‚t |ƒWnDt yüt |¡}z t|ƒWnt yöt ¡Yn0Yn0|jjr|jj ¡Wn4tyJ}z|jtkr6‚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)Ú connectionÚrecvr2ÚstructÚunpackÚserverÚverifyÚdecodeÚjsonÚloadsrrˆrãrÊÚioÚStringIOrÚ tracebackÚ print_excÚreadyÚsetÚOSErrorÚerrnoÚ RESET_ERROR)rÚconnÚchunkZslenrìr¬ÚfileržrrrÚhandleGs8              z*listen..ConfigStreamHandler.handleN)r„r…r†r‡rúrrrrÚConfigStreamHandler@srûc@s0eZdZdZdZdedddfdd„Zdd„ZdS) z$listen..ConfigSocketReceiverzD A simple TCP socket-based logging config receiver. r`Ú localhostNcSs>t |||f|¡t ¡d|_t ¡d|_||_||_dS)Nrr`) rr–r r ÚabortrÚtimeoutròrê)rÚhostÚportrÒròrêrrrr–usz-listen..ConfigSocketReceiver.__init__cSs`ddl}d}|sT| |j ¡ggg|j¡\}}}|r<| ¡t ¡|j}t ¡q |  ¡dS)Nr) ÚselectÚsocketÚfilenorþZhandle_requestr r rýrZ server_close)rrrýZrdÚwrÚexrrrÚserve_until_stoppedsþ  z8listen..ConfigSocketReceiver.serve_until_stopped)r„r…r†r‡Zallow_reuse_addressÚDEFAULT_LOGGING_CONFIG_PORTr–rrrrrÚConfigSocketReceiverns ÿ rcs&eZdZ‡‡fdd„Zdd„Z‡ZS)zlisten..Servercs4tˆ|ƒ ¡||_||_||_||_t ¡|_dSr$) Úsuperr–ÚrcvrÚhdlrrrêÚ threadingÚEventrò)rr r rrê)ÚServerÚ __class__rrr–s zlisten..Server.__init__cSsZ|j|j|j|j|jd}|jdkr0|jd|_|j ¡t ¡|a t  ¡|  ¡dS)N)rrÒròrêrr`) r rr ròrêZserver_addressrór r Ú _listenerrr)rrérrrÚrun—s þ   zlisten..Server.run)r„r…r†r–rÚ __classcell__r©r)rrrsr)rrr ÚThread)rrêrûrrrrÚlisten,s.rcCs2t ¡ztrdt_daWt ¡n t ¡0dS)zN Stop the listening server which was created with a call to listen(). r`N)r r rrýrrrrrÚ stopListening¦s r)NT)+r‡rõrîr Zlogging.handlersrÁrçr™r rðÚ socketserverrrrZ ECONNRESETrörrr#r(r rr]rr rÂÚIrpruÚobjectrvrˆrzrar{rr|r‘rÄrârãrrrrrrÚsH  "&W! Az