a ÕDOgŽã@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)ÚfnameÚdefaultsÚdisable_existing_loggersrÚcpÚ formattersÚhandlers©rú&/usr/lib64/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_%sr2Ú formatterÚÚargsú()Úkwargsz{}ÚlevelÚtarget)r3rr)r4ÚevalÚvarsr rÚ NameErrorr$r ÚsetLevelÚ setFormatterÚ issubclassrÚ MemoryHandlerÚappendZ setTarget)rrÚhlistrZfixupsÚhandÚsectionÚklassÚfmtr>r@ÚhrArBÚ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Ú PlaceHolderrFÚNOTSETrÚ propagateÚdisabled)ÚexistingÚ child_loggersÚdisable_existingrRÚ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+rRZ logger_rootrANrz logger_%sÚqualnamerWé)r.rr)rÚlistr)Úremover rRrFrÚ removeHandlerr3Ú addHandlerrSrTr*ÚsortZgetintÚ getLoggerÚindexrJrWrXr^)rrr[ZllistrMrRr\rArPrKrLrYrZZqnrWr]Ú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  rvc@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%)rxryrzr{r|r}r~)r€rrƒrrrry/s  ÿzConvertingMixin.convertN)T)Ú__name__Ú __module__Ú __qualname__Ú__doc__r„ryrrrrrw s rwc@s,eZdZdZdd„Zd dd„Zd dd„ZdS) r{z A converting dictionary wrapper.cCst ||¡}| ||¡Sr%)ÚdictÚ __getitem__r„©r€rrrrrrŠDs zConvertingDict.__getitem__NcCst |||¡}| ||¡Sr%)r‰r4r„©r€rÚdefaultrrrrr4HszConvertingDict.getcCst |||¡}|j||ddS©NF)r‚)r‰rr„rŒrrrrLszConvertingDict.pop)N)N)r…r†r‡rˆrŠr4rrrrrr{As r{c@s"eZdZdZdd„Zddd„ZdS) r|zA converting list wrapper.cCst ||¡}| ||¡Sr%)rbrŠr„r‹rrrrŠRs zConvertingList.__getitem__éÿÿÿÿcCst ||¡}| |¡Sr%)rbrry)r€ÚidxrrrrrVs 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%)r{Úconfigrx)r€r–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. rrraNzCannot resolve %r: %s) rrÚimporterrrÚ ImportErrorÚsysÚexc_inforsÚ __cause__Ú __traceback__) r€rtr r!r"ÚfragÚeÚtbÚvrrrÚresolveys"       zBaseConfigurator.resolvecCs | |¡S)z*Default converter for the ext:// protocol.)r¢©r€rrrrr“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_PATTERNrrrsÚendr–ÚgroupsÚ DOT_PATTERNÚ INDEX_PATTERNÚ DIGIT_PATTERNÚintÚ TypeError)r€rÚrestruÚ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)rr{r‰rxr|rbr}r‘rr'ÚCONVERT_PATTERNrrÚ groupdictÚvalue_convertersr4r)r€rrur­r¯Ú converterr°rrrry¶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©rv©Ú.0Úk©r–rrÚ Ùóz5BaseConfigurator.configure_custom..)rÚcallabler¢ÚitemsÚsetattr)r€r–r9Úpropsr@rƒr rrr¹rÚconfigure_customÒs   z!BaseConfigurator.configure_customcCst|tƒrt|ƒ}|S)z0Utility function which converts lists to tuples.)rrbr‘r£rrrÚas_tupleàs zBaseConfigurator.as_tupleN)r…r†r‡rˆÚreÚcompiler±r¤r§r¨r©r³Ú staticmethodrr˜r—r¢r“r”ryrÀ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 versionrazUnsupported version: %sÚ incrementalFrzNo handler found with name %rrANzUnable to configure handler %rr_TzUnable to configure logger %rrRzUnable to configure root loggerrrz Unable to configure formatter %rÚfilterszUnable to configure filter %rútarget not configured yetr) r–rsrr r r4rmrFÚ _checkLevelÚ ExceptionÚconfigure_loggerÚconfigure_rootr Úconfigure_formatterÚconfigure_filterÚsortedÚconfigure_handlerr r'rœrJrRrbrSrTr*rfrhr3rcr^r)r€r–rÇÚ EMPTY_DICTrr ÚhandlerZhandler_configrArŸr_rRr[rrÈZdeferredrYrZrirjrkrlrrrÚ 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,rONr/r0r1r2Úvalidate)rÀr«r'rr4r r5r$) r€r–ÚfactoryrƒÚterOZdfmtr0Úcnamer9rrrrΊs* "     z$DictConfigurator.configure_formattercCs.d|vr| |¡}n| dd¡}t |¡}|S)z%Configure a filter from a dictionary.r?r r=)rÀr4r ÚFilter)r€r–rƒr rrrrÏ®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Ërs)r€ZfiltererrÈ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 %rrArÈr?r2rBrrÉzUnable to set target handler %rZmailhostÚaddressrcsi|]}t|ƒr|ˆ|“qSrrµr¶r¹rrrºçr»z6DictConfigurator.configure_handler..z'stream'ÚstreamZstrm)r‰rr–rËrsr¼r¢rHr rrIrÚHandlerÚupdater«Z SMTPHandlerrÁZ SysLogHandlerr'rGrFrÊrÛr½r¾)r€r–Z config_copyr<rŸrArÈr9rÖrØrNÚthr¿r@rƒr×r rrr¹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)rer–rËrs)r€r]rrPrŸ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. rANrrÈ)r4rFr rÊrrdrárÛ)r€r]r–rÇrArPrrÈrrrÚcommon_logger_configs     z%DictConfigurator.common_logger_configcCs6t |¡}| |||¡| dd¡}|dur2||_dS)z.Configure a non-root logger from a dictionary.rWN)r rgrâr4rW)r€r r–rÇr]rWrrrrÌs   z!DictConfigurator.configure_loggercCst ¡}| |||¡dS)z*Configure a root logger from a dictionary.N)r rgrâ)r€r–rÇrRrrrrÍ 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Úrecvr3Ú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. raÚ localhostNcSs>t |||f|¡t ¡d|_t ¡d|_||_||_dS)Nrra) 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)r€rrþZrdÚwrÚexrrrÚserve_until_stoppedsþ  z8listen..ConfigSocketReceiver.serve_until_stopped)r…r†r‡rˆZallow_reuse_addressÚDEFAULT_LOGGING_CONFIG_PORTr—rrrrrÚConfigSocketReceiverns ÿ r cs&eZdZ‡‡fdd„Zdd„Z‡ZS)zlisten..Servercs4tˆ|ƒ ¡||_||_||_||_t ¡|_dSr%) Úsuperr—ÚrcvrÚhdlrrrëÚ threadingÚEventró)r€r 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ërra) r rr rórëZserver_addressrôr r Ú _listenerrr)r€rêrrrÚrun—s þ   zlisten..Server.run)r…r†r‡r—rÚ __classcell__r©r)rrrsr)rrr ÚThread)rrërür rrrÚlisten,s.rcCs2t ¡ztrdt_daWt ¡n t ¡0dS)zN Stop the listening server which was created with a call to listen(). raN)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ÃÚIrqrvÚobjectrwr‰r{rbr|r‘r}r’rÅrãrärrrrrrÚsH  "&W! Az