QfdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z mZdZej ZdaddZdZdZdZd Zd Zd Zd Zej6d ej8ZdZGddeZ Gdde!e Z"Gdde#e Z$Gdde%e Z&GddeZ'dZ(Gdde'Z)e)Z*dZ+edfdZ,dZ-y) 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-2022 Vinay Sajip. All Rights Reserved. To use, simply 'import logging' and log away! N)ThreadingTCPServerStreamRequestHandleriF#cddl}t|trZtjj |st |dtjj|st|dt||jr|}nX |j|}t|dr|j|n(tj|}|j||t#|}t%j& t)t+||}t-|||t%j.y#|j $r}t|d|d}~wwxYw#t%j.wxYw)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). rNz doesn't existz is an empty filereadline)encodingz is invalid: ) configparser isinstancestrospathexistsFileNotFoundErrorgetsize RuntimeErrorRawConfigParser ConfigParserhasattr read_fileio text_encodingread ParsingError_create_formatterslogging _acquireLock_clearExistingHandlers_install_handlers_install_loggers _releaseLock) fnamedefaultsdisable_existing_loggersrrcpe formattershandlerss 5/opt/alt/python312/lib64/python3.12/logging/config.py fileConfigr(5s?%ww~~e$#ug^$<= ='%(9:; ;%556  ;**84Buj) U#++H51$B'J  %R4X'?@(( ;% aS9: : ; s% AD8#E8EEEE5c|jd}|jd}t|}|D]}|dz|z} t||}|S#t$rt|t||}Y>wxYw)z)Resolve a dotted name to a global object..r)splitpop __import__getattrAttributeError)nameusedfoundns r'_resolver4asz ::c?D 88A;D t E czA~ &E1%E L & t E1%E &s A  A/.A/c6ttj|SN)mapr strip)alists r' _strip_spacesr:os syy%  c|dd}t|siS|jd}t|}i}|D]}d|z}|j|ddd}|j|d dd}|j|d dd }|j|d dd}tj } ||jd } | r t | } |&t|tt}| ||||} n | |||} | ||<|S)zCreate and return formattersr%keys,z formatter_%sformatTN)rawfallbackdatefmtstyle%r!class)r!) lenr+r:getr Formatterr4evalvars) r#flistr%formsectnamefsdfsstlr!c class_namefs r'rrrs | V $E u: KK E % EJ!D( VVHhD4V @ffXydTfBffXwD3f?66(JD46H   \%%g. $A  Hd7m4H"c32A"c3A 4#$ r;c`|dd}t|siS|jd}t|}i}g}|D]3}|d|z}|d}|jdd} t |t t }|jdd } t | t t } |jd d } t | t t } || i| } || _ d |vr|d } | j| t|r| j||t|t jjr0|jd d} t| r|j!| | f| ||<6|D]\} }| j#|||S#ttf$rt|}Y7wxYw)zInstall and return handlersr&r=r>z handler_%srE formatterargs()kwargsz{}leveltarget)rFr+r:rGrIrJrr/ NameErrorr4r0setLevel setFormatter issubclassr& MemoryHandlerappend setTarget)r#r%hlistr&fixupshandsectionklassfmtrWrYhrZr[ts r'rrs zN6 "E u: KK E % EH F\D() kk+r* $W .E{{64(D$w-(Xt,fd7m, 4 "6 " g G$E JJu  s8 NN:c? + eW--;; <[[2.F6{ q&k*/21 HQK  O+ * $UOE $sFF-,F-c tj}|D]o}|jj|}||vrIt |tj r;|j tjg|_d|_ i||_ qy)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) rrootmanager loggerDictr PlaceHolderr]NOTSETr& propagatedisabled)existing child_loggersdisable_existingrllogloggers r'_handle_existing_loggersrxsi <rl logger_rootrZNr&z logger_%squalnamerq)rAr*r)r+listr:removerrlr]r& removeHandlerrF addHandlerrmrnr=sortgetint getLoggerindexrarqrrrx)r#r&rullistrfrlrvrZrircrersrtqnrqrwiprefixedpflen num_existings r'rrsq yM& !E KK E u% &E LLG < *DLL++0023H  MMOM[3&' Z NN;N; ""2& >r"Q&ACxHMEx=Ll"A;v&(2!((!5Ql" OOB  g G$E OOE "#A   #$$ # u:KK$E!%(E!!(4.15TX}6FGr;ctjjtjtjddtjdd=y)z!Clear and close existing handlersN)r _handlersclearshutdown _handlerListr;r'rr"s;  W))!,-Qr;z^[a-z_][a-z0-9_]*$cNtj|}|std|zy)Nz!Not a valid Python identifier: %rT) IDENTIFIERmatch ValueError)sms r' valid_identr,s)A [a-z]+)://(?P.*)$z ^\s*(\w+)\s*z^\.\s*(\w+)\s*z^\[\s*(\w+)\s*\]\s*z^\d+$ ext_convert cfg_convert)extcfgcFt||_||j_yr6)rconfigr)rrs r'__init__zBaseConfigurator.__init__s$V, #'  r;cH|jd}|jd} |j|}|D]}|d|zz } t||}|S#t$r |j|t||}YDwxYw#t $r}t d|d|}||d}~wwxYw)z` Resolve strings to objects using standard import and attribute syntax. r*rzCannot resolve z: N)r+r,importerr.r/ ImportErrorr)rrr0r1r2fragr$vs r'resolvezBaseConfigurator.resolves wws|xx{ MM$'Ed "1#E40EL&1MM$'#E40E1 a;    # #D ) 93e;< <>D AHHJqM*A$$**40!((*Q-(A**006Ahhjm#1177< !#A+$'H$%aD>D$38$&@AA',$-+$%cF+s)D%%D65D6cHt|ts$t|trt|}||_|St|ts$t|t rt |}||_|St|t s0t|tr t|dst |}||_|St|tri|jj|}|rL|j}|d}|jj|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. _fieldsprefixNsuffix)r rrrrr~rrrr CONVERT_PATTERNr groupdictvalue_convertersrGr.)rrrrr converterrs r'rzBaseConfigurator.converts %0Zt5L"5)E!%E $ #E>2z%7N"5)E!%E  E?3E5)'%2K#E*E!%E  s #$$**51AKKM8 1155fdC x[F 'i 8I%f-E r;c6|jd}t|s|j|}|Dcic]}|dk7s t|s|||}}|di|}|jdd}|r%|j D]\}}t ||||Scc}w)z1Configure an object with a user-supplied factory.rXr*Nr)r,callablerritemssetattr) rrrQkrYrpropsr0rs r'configure_customz!BaseConfigurator.configure_customs JJt { QA(.P118 A!VAY,PV 3% ${{} ee, - Qs B B Bc<t|tr t|}|S)z0Utility function which converts lists to tuples.)r r~rrs r'as_tuplezBaseConfigurator.as_tuples eT "%LE r;N)rrrrrecompilerrrrrr staticmethodr-rrrrrrrrrr;r'rrts!bjj!IJO2::o.L"**./KBJJ56MBJJx(M J'H(*# D8 r;rcttjryddlm}t|rygd}t fd|DS)z*Check that *obj* implements the Queue API.Tr)Queue) emptyfullrG get_nowaitput put_nowaitjoinqsize task_donec3JK|]}tt|dywr6)rr.).0methodobjs r' z(_is_queue_like_object..s'.,6VT23,s #)r queuermultiprocessing.queuesall)rMPQueuequeue_interfaces` r'_is_queue_like_objectrsG#u{{#7#wO .,. ..r;cReZdZdZdZdZdZdZdZdZ dZ d d Z d d Z d d Z y )DictConfiguratorz] Configure logging using a dictionary-like object to describe the configuration. c |j}d|vr td|ddk7rtd|dz|jdd}i}tj |r|j d|}|D]s}|tj vrtd|z tj |}||}|j d d }|r$|jtj|u|j d |} | D]} |j|| |d |j dd } | r$ |j| d n|jdd } t|j d|} | D]} |j| || |<|j d|}|D]} |j||||<|j d|}g}t|D]#} |j!||}||_|||<%|D]#} |j!||}||_|||<%tj*} t-| j.j0j3}|j5g}|j d |} | D]}||vro|j7|dz}|dz}t9|}t9|}||kr*||d ||k(r|j)|||dz }||kr*|j;| |j|| |t=||| |j dd } | r |j| tj>y #t$r} td |z| d } ~ wwxYw#t$r} td|z| d } ~ wwxYw#t$r} td| d } ~ wwxYw#t$r} td|z| d } ~ wwxYw#t$r} td|z| d } ~ wwxYw#t$rC} dt%| j&vr|j)|ntd |z| Yd } ~ kd } ~ wwxYw#t$r} td |z| d } ~ wwxYw#t$r} td|z| d } ~ wwxYw#t$r} td| d } ~ wwxYw#tj>wxYw)zDo the configuration.versionz$dictionary doesn't specify a versionr}zUnsupported version: %s incrementalFr&zNo handler found with name %rrZNzUnable to configure handler %rrzTzUnable to configure logger %rrlzUnable to configure root loggerr"r%z Unable to configure formatter %rfilterszUnable to configure filter %rz not configured yetr*) rrr,rrrGrr] _checkLevel Exceptionconfigure_loggerconfigure_rootrconfigure_formatterconfigure_filtersortedconfigure_handlerr0r __cause__rarlr~rmrnr=rrrFrrxr)rrr  EMPTY_DICTr&r0handlerhandler_configrZr$rzrlrur%r deferredrsrtrrrrs r' configurezDictConfigurator.configures F "CD D )  !6 9JJK Kjj6  Q #!::j*=$D7#4#44(*36:*;<<A&-&7&7&=G-5d^N$2$6$6w$EE$ ' 0 01D1DU1K L%!**Y ;#D=--dGDM4H$ zz&$/:++D$7 $*::.H$#O &($ZZ jA &DG+/+C+C?  !#  **Y ;#Dx'$NN4014#'#: #H '*8} ,.'{6E2h> - 4 4Xa[ AFA ,.!-=--dGDMB$<)=)9;zz&$/:++D1  "G )A",.248.9#:?@AA%=(*.04*56;<==%:(*2389::%G(*8:>*?@EFGG%D(*57;*<=BCDD%A0C 4DD$OOD1",.248.9#:?@A2A%=(*.04*56;<==N%=(*.04*56;<==2%:(*2389::  "sX9R1AM((R1NR10N(5R18OR1)O%$R1% PR1 Q-C R17R1 Q4#R1R( N1NNR1 N%N  N%%R1( O1 N==OR1 O"OO""R1% P.O==PR1 Q8Q R1 QR1 Q1Q,,Q11R14 R=R  RR1 R. R))R..R11Sc d|vr|d} |j|}|S|j dd}|j dd}|j dd}|j d d}|j d d} |st j } n t|} i} | | | d <d |vr| ||||d fi| }|S| |||fi| }|S#t$rC}dt|vr|jd|d<||d<|j|}Yd}~|Sd}~wwxYw) z(Configure a formatter from a dictionary.rXz'format'r?rhNrBrCrDrEr!validate)rrr r,rGrrHr4) rrfactoryrterhdfmtrCcnamer!rQrYs r'rz$DictConfigurator.configure_formattersK 6>TlG 7..v6L 5**Xt,C::i.DJJw,EJJw-Ezz*d3H%%UOF #%-z"V#3eVJ-?J6J 3e6v6 K 7SW, !' 8 4u &t ..v68 K 7sC D  8DD cd|vr|j|}|S|jdd}tj|}|S)z%Configure a filter from a dictionary.rXr0rV)rrGrFilter)rrrr0s r'rz!DictConfigurator.configure_filtersE 6>**62F ::fb)D^^D)F r;c|D]J} t|stt|ddr|}n|jd|}|j|Ly#t$r}t d|z|d}~wwxYw)z/Add filters to a filterer from a list of names.filterNr zUnable to add filter %r)rr.r addFilterr r)rfiltererr rSfilter_r$s r' add_filterszDictConfigurator.add_filterssvA GA;(71h+E"FG"kk)4Q7G""7+  G !:Q!>?QF GsAA A.A))A.c .d|vr|jd}ntj}|jdd}|jdtjj }|jdg}||g|d|i}||fi|}||_|S)Nrrespect_handler_levelFlistenerr&)r,rrrr& QueueListenerr*) rrgrYqrhllklassr&r*rs r'_configure_queue_handlerz)DictConfigurator._configure_queue_handlers f  7#A Ajj0%8J(8(8(F(FG::j"-!BhBcB$V$#r;c t|}|jdd}|r |jd|}|jdd}|jdd}d|vr1|jd}t |s|j |}|}n|jd} t | r| } n|j | } t| tjjryd |vrtj|d |d <d |vr, |d } |jd | } t| tjs|j|td | |d <nt| tjj r3d|vr|d} t| t"r5|j | }t |std| z||d<nYt| tr0d| vrtd| z|j%t| |d<nt'| std| zd|vr|d}t|t(r2t|tjj*std|zt|t"rS|j |}t|t(r}t|tjj*sYtd|zt|tr-d|vrtd|z|j%t|}ntd|zt |std|z||d<d |vrg} |d D]^}|jd |}t|tjs|j|td|z|j-|` ||d <nt| tjj.rd|vr|j1|d|d<n?t| tjj2rd|vr|j1|d|d<t| tjj r!t5j6|j8| }n| }|Dcic]}|dk7s t;|s|||}} |di|}|r|j=||$|j?tj||r|jA|||jdd}|r%|jCD]\}}tE||||S#t$r}t d|z|d}~wwxYw#t$r}t d  z|d}~wwxYw#t$r}t dz|d}~wwxYwcc}w#t$r5}dt#|vr|jd|d<|di|}Yd}~&d}~wwxYw)z&Configure a handler from a dictionary.rUNr%zUnable to set formatter %rrZr rXrE flushLevelr[r&ztarget not configured yetzUnable to set target handler %rrzInvalid queue specifier %rr*zInvalid listener specifier %rz)Required handler %r is not configured yetz!Unable to set required handler %rmailhostaddressr*z'stream'streamstrmr)#rr,rr rrrr_rr&r`r r Handlerupdater QueueHandlerr rrrr+ra SMTPHandlerr SysLogHandler functoolspartialr/rr^r]r'rr)rr config_copyrUr$rZr rQrrrgtnthqspecr,lspecr*rchnrirrYrrrr0rs r'rz"DictConfigurator.configure_handlers6l JJ{D1  : KK 5i@  7D)**Y- 6> 4 AA;LLOGJJw'E U+%!1!1!?!?@6)+2+>+>vl?S+TF<(v%X#H-![[4R8)"goo>"MM+6"+,G"HH+-x(E7#3#3#@#@Af$"7OE!%- LL/'{"+,H5,P"QQ*+#w#E40u,"+,H5,P"QQ*.*?*?U *Lw259'(Du(LMM'":.E!%.)%1A1A1O1OP"+,Ke,S"TT%eS1'+||E':H)(D9$.x9I9I9W9W$X&/0ORW0W&X X't4#50&/0ORW0W&X X'+'<'!>?#++D,I,I5Q(.P118 A!VAY,P '&v&F     *   OOG//6 7    VW - 3% ${{} ee, - e : "&(1"2389: :8%X()JR)OPVWWXf%Z()Lr)QRXYYZQ 'R( $ZZ1F6N&v&F 'ssT-AU A&U-; V  V V V- U 6UU  U*U%%U*- V 6VV  W*W  Wc|D]$} |j|jd|&y#t$r}td|z|d}~wwxYw)z.Add handlers to a logger from a list of names.r&zUnable to add handler %rN)rrr r)rrwr&rir$s r' add_handlerszDictConfigurator.add_handlerssUA H!!$++j"9!"<= H !;a!?@aG Hs!+ AAAc^|jdd}|$|jtj||ss|jddD]}|j ||jdd}|r|j |||jdd}|r|j||yyy)zU Perform configuration which is common to root and non-root loggers. rZNr&r )rGr]rr r&rrDr')rrwrr rZrir&r s r'common_logger_configz%DictConfigurator.common_logger_configs 7D)   OOG//6 7__Q'$$Q'(zz*d3H!!&(3jjD1G  1r;ctj|}|j|||d|_|j dd}|||_yy)z.Configure a non-root logger from a dictionary.FrqN)rrrFrrrGrq)rr0rr rwrqs r'rz!DictConfigurator.configure_loggersN""4( !!&&+>JJ{D1  (F  !r;cRtj}|j|||y)z*Configure a root logger from a dictionary.N)rrrF)rrr rls r'rzDictConfigurator.configure_roots"  " !!$ .ConfigStreamHandlerz Handler for a logging configuration request. It expects a completely new logging configuration and uses fileConfig to install it. c~ |j}|jd}t|dk(rtjd|d}|jj|}t||kr/||j|t|z z}t||kr/|j j |j j |}|2|jd} ddl}|j|}t||j j"r%|j j"j%yyy#t$rHtj|} t|n##t$rtj YnwxYwYwxYw#t&$r}|j(t*k7rYd}~yd}~wwxYw)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) connectionrecvrFstructunpackserververifydecodejsonloadsrKr rStringIOr( traceback print_excreadysetOSErrorerrno RESET_ERROR)rconnchunkslenrXrfiler$s r'handlez*listen..ConfigStreamHandler.handlesy  ! u:?!==u5a8D OO006Ee*t+ % $U2C(D De*t+{{))5 $ 2 25 9( % W 5 6'#zz%0A&qM{{(( ))--/)-# )6$&;;u#5D6 *4 0#,6 ) 3 3 56 6 77k)* sgBFAF$ E:FF E,+F,F  F F  FFFF F<F77F<N)rrrrrfrr;r'ConfigStreamHandlerrNs  % r;rgc,eZdZdZdZdedddfdZdZy)$listen..ConfigSocketReceiverzD A simple TCP socket-based logging config receiver. r} localhostNctj|||f|tjd|_tj d|_||_||_y)Nrr}) rrrrabortrtimeoutr]rV)rhostportrr]rVs r'rz-listen..ConfigSocketReceiver.__init__sL  ' 'tTlG D  "DJ  "DLDJ DKr;c<ddl}d}|s|j|jjggg|j\}}}|r|j t j |j}t j|s|jy)Nr) selectsocketfilenormhandle_requestrrrlr server_close)rrqrlrdwrexs r'serve_until_stoppedz8listen..ConfigSocketReceiver.serve_until_stoppeds E#]]DKK,>,>,@+A+-r+/<<9 B'')$$& $$&    r;)rrrrallow_reuse_addressDEFAULT_LOGGING_CONFIG_PORTrryrr;r'ConfigSocketReceiverris&   +2M!d ! r;r|c(eZdZfdZdZxZS)listen..Serverct|||_||_||_||_t j|_yr6) superrrcvrhdlrrorV threadingEventr])rrrrorVServer __class__s r'rzlisten..Server.__init__s: &$ ( *DIDIDI DK"*DJr;cl|j|j|j|j|j}|jdk(r|j d|_|jj tj|a tj|jy)N)rorr]rVrr}) rrorr]rVserver_addressr^rr _listenerrry)rrUs r'runzlisten..Server.runsYYDIItyy%)ZZ&*kk3FyyA~"11!4 JJNN   "I  "  & & (r;)rrrrr __classcell__)rrs@r'rr~s  + )r;r)rrrThread)rorVrgr|rs @r'listenrsE(,2,\ 1 >)!!). &(;T6 JJr;ctj tr dt_datjy#tjwxYw)zN Stop the listening server which was created with a call to listen(). r}N)rrrrlrrr;r' stopListeningr+s=   IOIs >A)NTN).rr`r;rrlogging.handlersr rrrSrr[ socketserverrrr{ ECONNRESETrarr(r4r:rrrxrrrIrrobjectrrrr~rrrrrrrJrKrrrr;r'rs"   A#   )X !:$L/,THn RZZ,bdd 3 fB @T? @#T?#@e_@AvAF.6V='V=p #( ,DxKt r;