eCdSrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK r SSK r SSK r Sr Sr SrSrSrSrSr"S S \R&5r"S S \5r"S S\5r"SS\R&5r"SS\R05r"SS\5r"SS\R05r"SS\R05r"SS\R05r"SS\R05r"SS\R05r"SS \5r "S!S"\R05r!"S#S$\"5r#g)%z Additional handlers for the logging package for Python. The core package is based on PEP 282 and comments thereto in comp.lang.python. Copyright (C) 2001-2021 Vinay Sajip. All Rights Reserved. To use, simply 'import logging.handlers' and log away! Ni<#i=#i>#i?#iQc<\rSrSrSrSrSrS SjrSrSr Sr Sr g) BaseRotatingHandler3z Base class for handlers that rotate log files at a certain point. Not meant to be instantiated directly. Instead, use RotatingFileHandler or TimedRotatingFileHandler. Nc h[RRXUX4US9 X lX0lXPlg)z1 Use the specified filename for streamed logging modeencodingdelayerrorsN)logging FileHandler__init__r r r selffilenamer r r r s 6/opt/imh/python3.13/lib/python3.13/logging/handlers.pyrBaseRotatingHandler.__init__<s8 $$T$.6,2 % 4   cURU5(aUR5 [RR X5 g![ a UR U5 gf=f)zd Emit a record. Output the record to the file, catering for rollover as described in doRollover(). N)shouldRollover doRolloverr remit Exception handleErrorrrecords rrBaseRotatingHandler.emitGsS %""6**!    $ $T 2 %   V $ %sAAA&%A&cd[UR5(dUnU$URU5nU$)ay Modify the filename of a log file when rotating. This is provided so that a custom filename can be provided. The default implementation calls the 'namer' attribute of the handler, if it's callable, passing the default name to it. If the attribute isn't callable (the default is None), the name is returned unchanged. :param default_name: The default name for the log file. )callablenamer)r default_nameresults rrotation_filename%BaseRotatingHandler.rotation_filenameUs4 ##!F ZZ -F rc[UR5(d<[RR U5(a[R "X5 ggURX5 g)a When rotating, rotate the current log. The default implementation calls the 'rotator' attribute of the handler, if it's callable, passing the source and dest arguments to it. If the attribute isn't callable (the default is None), the source is simply renamed to the destination. :param source: The source filename. This is normally the base filename, e.g. 'test.log' :param dest: The destination filename. This is normally what the source is rotated to, e.g. 'test.log.1'. N)r rotatorospathexistsrename)rsourcedests rrotateBaseRotatingHandler.rotatehsE %%ww~~f%% &'& LL &r)r r r )NFN) __name__ __module__ __qualname____firstlineno____doc__r!r'rrr$r.__static_attributes__rrrr3s' EG  %&'rrc2\rSrSrSrSSjrSrSrSrg) RotatingFileHandler}z Handler for logging to a set of files, which switches from one file to the next when the current file reaches a certain size. Nc US:aSnSU;a[R"U5n[RXX%XgS9 X0lX@lg)az Open the specified file and use it as the stream for logging. By default, the file grows indefinitely. You can specify particular values of maxBytes and backupCount to allow the file to rollover at a predetermined size. Rollover occurs whenever the current log file is nearly maxBytes in length. If backupCount is >= 1, the system will successively create new files with the same pathname as the base file, but with extensions ".1", ".2" etc. appended to it. For example, with a backupCount of 5 and a base file name of "app.log", you would get "app.log", "app.log.1", "app.log.2", ... through to "app.log.5". The file being written to is always "app.log" - when it gets filled up, it is closed and renamed to "app.log.1", and if files "app.log.1", "app.log.2" etc. exist, then they are renamed to "app.log.2", "app.log.3" etc. respectively. If maxBytes is zero, rollover never occurs. rabr r r N)io text_encodingrrmaxBytes backupCount)rrr r@rAr r r s rrRotatingFileHandler.__init__sM6 a<D d?''1H$$TT+0 % A &rctUR(a!URR5 SUlURS:GaN[URS- SS5HnUR SUR U4-5nUR SUR US-4-5n[ RRU5(dMl[ RRU5(a[ R"U5 [ R"X#5 M UR UR S-5n[ RRU5(a[ R"U5 URUR U5 UR(dUR5Ulgg)z, Do a rollover, as described in __init__(). Nrz%s.%dz.1)streamcloserAranger$ baseFilenamer(r)r*remover+r.r _open)risfndfns rrRotatingFileHandler.doRollovers? ;; KK   DK   a 4++a/B7,,W8I8I17M-MN,,W8I8I89A8?.?@77>>#&&ww~~c** #IIc'8(():):T)ABCww~~c"" # KK))3 /zz**,DKrcURcUR5UlURS:aURR5nU(dgSUR U5-nU[ U5-UR:a^[ RRUR5(a/[ RRUR5(dggg)z Determine if rollover should occur. Basically, see if the supplied record would cause the file to exceed the size limit we have. rFz%s T) rFrKr@tellformatlenr(r)r*rIisfile)rrposmsgs rr"RotatingFileHandler.shouldRollovers ;; **,DK ==1 ++""$C4;;v..CSX~.77>>$"3"344RWW^^DL]L]=^=^ r)rAr@rF)r;rrNFN) r0r1r2r3r4rrrr5r6rrr8r8}s!DE48"'H'.rr8c@\rSrSrSrS SjrSrSrSrSr S r g) TimedRotatingFileHandlerz Handler for logging to a file, rotating the log file at certain timed intervals. If backupCount is > 0, when rollover is done, no more than backupCount files are kept - the oldest ones are deleted. Nc [R"U5n[RXSUXiS9 UR 5UlX@lXplXlUR S:XaSUl SUl Sn GOJUR S:XaSUl S Ul S n GO(UR S :XaS Ul S Ul Sn GOUR S:XdUR S:XaSUl SUl Sn OUR RS5(aSUl [UR 5S:wa[SUR -5eUR SS:dUR SS:a[SUR -5e[UR S5UlSUl Sn O[SUR -5e[ R""U [ R$5UlURU-Ul UR(n[*R,R/U5(a*[[*R0"U5R25n O[[4R4"55n UR7U 5Ulg)Nr;r=SrDz%Y-%m-%d_%H-%M-%Sz0(?r?rrupperwhenrAutcatTimeintervalsuffix startswithrS ValueErrorint dayOfWeekrecompileASCIIextMatchrIr(r)r*statst_mtimetimecomputeRollover rolloverAt) rrrhrkrAr r rirjr rtts rr!TimedRotatingFileHandler.__init__s ##H-$$TS8+0 % AJJL &  99 DM-DKJH YY# DM*DKDH YY# #DM'DK>H YY# j!8(DM$DK8H YY ! !# & &,DM499~" !knrnwnw!wxxyy|c!TYYq\C%7 !PSWS\S\!\]] 1.DN$DK8HFRS S 8RXX6  0 $$ 77>>( # #BGGH%../ADIIK A..q1rcDXR-nURS:Xd!URRS5(GaUR(a[R "U5nO[R "U5nUSnUSnUSnUSnURc[nOJURRS-URR-S-URR-nXS-U-S-U-- n U S::aU [- n US -S -nX-nURRS5(aiUn XR:wa?XR:aURU - n OSU - UR-S -n X+[-- nX R[S -- - nOX R[- - nUR(dVUS n [R "U5S n X:wa3U (d&S n[R "US - 5S (dSnOS nX.- nU$)z9 Work out the rollover time based on the specified time. rbrcr^rrDrEr`) rkrhrmrirwgmtime localtimerj _MIDNIGHThourminutesecondrp)r currentTimer#rz currentHour currentMinute currentSecond currentDay rotate_tsrday daysToWaitdstNow dstAtRolloveraddends rrx(TimedRotatingFileHandler.computeRollovers}}, 99 "dii&:&:3&?&?xxKK ,NN;/A$KaDMaDM1J{{"% "kk..3dkk6H6HH"LKK&&' B.>"DAAvY(1n1  _F yy##C(( ..(^^+%)^^c%9 %&Wt~~%=%A 944F--)a-77--)33882 $v 6r : *!!&#~~fTk:2>%&F!%$F rcF[[R"55nX R:at[RR UR 5(aE[RRUR 5(dURU5Ulggg)z Determine if rollover should occur. record is not used, as we are just comparing times, but it is needed so the method signatures are the same FT) rorwryr(r)r*rIrTrx)rrrzs rr'TimedRotatingFileHandler.shouldRolloverksl    ww~~d//00HYHY9Z9Z#'"6"6q"9rc[RRUR5up[R"U5n/nUR cyUS-n[ U5nUHbnUSUU:XdMXvSnURRU5(dM4UR[RRX55 Md OUHnURRU5n U (dM'UR URS-U S-5n [RRU 5U:Xa0UR[RRX55 MURRXyR5S-5n U (aMM [ U5UR:a/nU$UR5 US[ U5UR- nU$)zw Determine the files to delete when rolling over. More specific than the earlier method, which just used glob.glob(). N.rrD)r(r)splitrIlistdirr!rSrt fullmatchappendjoinsearchbasenamestartrAsort) rdirNamebaseName fileNamesr#prefixplenfileNamerlmrNs rgetFilesToDelete)TimedRotatingFileHandler.getFilesToDelete~s GGMM$*;*;<JJw'  :: ^Fv;D%ET?f,%e_F}}..v66 bggll7&EF & & MM((2a**T%6%6%>#    ;; KK   DK D%%s+   a **, ! -zz**,DK..{;r) rjrArprtrkryrFrlrirh)hrDrNFFNN) r0r1r2r3r4rrxrrrr5r6rrrYrYs2DE?CA2FKZ&$L&r?r rrdevino _statstreamrs rrWatchedFileHandler.__init__sX d?''1H$$T$.6,2 % 4$$( rcURcg[R"URR55nURUlUR UlgN)rFr(fstatfilenost_devrst_inor)rsress rrWatchedFileHandler._statstreams@ ;;  xx **,-;;;;rcURcg[R"UR5nURUR :g=(d UR UR:gnU(dgURR5 URR5 SUlUR5UlUR5 g![a SnNwf=f)z Reopen log file if needed. Checks if the underlying file has changed, and if it has, close the old stream and reopen the file to get the current stream. NT) rFr(rurIrrrrFileNotFoundErrorflushrGrKr)rrreopens rreopenIfNeeded!WatchedFileHandler.reopenIfNeededs ;;    774,,-DkkTXX-H1HF    jjl  ! F sAC C! C!cbUR5 [RRX5 g)zc Emit a record. If underlying file has changed, reopen the file before emitting the record to it. N)rr rrrs rrWatchedFileHandler.emits$   .r)rrrF)r;NFN) r0r1r2r3r4rrrrr5r6rrrrs&$AF"H/rrcL\rSrSrSrSrS SjrSrSrSr Sr S r S r S r g ) SocketHandleria A handler class which writes logging records, in pickle format, to a streaming socket. The socket is kept open across logging calls. If the peer resets it, an attempt is made to reconnect on the next call. The pickle which is sent is that of the LogRecord's attribute dictionary (__dict__), so that the receiver does not need to have the logging module installed in order to process the logging event. To unpickle the record at the receiving end into a LogRecord, use the makeLogRecord function. c[RRU5 XlX lUcXlOX4UlSUlSUlSUlSUl SUl SUl g)z Initializes the handler with a specific host address and port. When the attribute *closeOnError* is set to True - if a socket error occurs, the socket is silently closed and then reopened on the next logging call. NFg?g>@g@) r Handlerrhostportaddresssock closeOnError retryTime retryStartretryMax retryFactorrrrs rrSocketHandler.__init__,sa   &  <L >63E3EFF   g & t||,    s 4BB-c[R"5nURcSnOXR:nU(aUR5UlSUlgg![a~ URcUR UlOIUR UR-UlUR UR:aURUlXR -Ulgf=f)z Try to create a socket, using an exponential backoff with a max retry time. Thanks to Robert Olson for the original patch (SF #815911) which has been slightly refactored. NT) rwrrrrr retryPeriodrr)rnowattempts r createSocketSocketHandler.createSocketVs iik >> !Gnn,G  8 OO- !%  8>>)'+D$'+'7'7$:J:J'JD$''$--7+/==(!$'7'7!7 8sABC"!C"cURcUR5 UR(aURRU5 gg![a$ URR 5 SUlgf=f)zy Send a pickled string to the socket. This function allows for partial sends which can happen when the network is busy. N)rrsendallrrGrrs rsendSocketHandler.sendrse 99      99 ! !!!$  ! !   !sA +A;:A;cHURnU(aURU5n[UR5nUR 5US'SUS'SUS'UR SS5 [ R"US5n[R"S[U55nXe-$)zt Pickles the record in binary format with a length prefix, and returns it ready for transmission across the socket. rVNargsexc_infomessagerDz>L) rrRdict__dict__ getMessagepoppickledumpsstructpackrS)rreidummydrslens r makePickleSocketHandler.makePickles __ KK'E  !$$&%& *  i LLA {{4Q(xrcUR(a3UR(a"URR5 SUlg[RR X5 g)z Handle an error during logging. An error has occurred during logging. Most likely cause - connection lost. Close the socket so that we can retry on the next event. N)rrrGr rrrs rrSocketHandler.handleErrors:    IIOO DI OO ' ' 5rcURU5nURU5 g![a URU5 gf=f)z Emit a record. Pickles the record and writes it to the socket in binary format. If there is an error with the socket, silently drop the packet. If there was a problem with the socket, re-establishes the socket. N)rrrr)rrrs rrSocketHandler.emits= %'A IIaL %   V $ %s"%AAcUR URnU(aSUlUR5 [RRU5 SSS5 g!,(df  g=fz Closes the socket. N)lockrrGr rrrs rrGSocketHandler.closesCYY99D   OO ! !$ ' YY A A  A.) rrrrrrrrrrN)rD)r0r1r2r3r4rrrrrrrrGr5r6rrrrs/ 2"88!&, 6 % (rrc*\rSrSrSrSrSrSrSrg)DatagramHandleria| A handler class which writes logging records, in pickle format, to a datagram socket. The pickle which is sent is that of the LogRecord's attribute dictionary (__dict__), so that the receiver does not need to have the logging module installed in order to process the logging event. To unpickle the record at the receiving end into a LogRecord, use the makeLogRecord function. c>[RXU5 SUlg)z@ Initializes the handler with a specific host address and port. FN)rrrrs rrDatagramHandler.__init__s t40!rcURc[RnO[Rn[R"U[R5nU$)z] The factory method of SocketHandler is here overridden to create a UDP socket (SOCK_DGRAM). )rrrAF_INET SOCK_DGRAM)rfamilyrs rrDatagramHandler.makeSockets; 99 ^^F^^F MM&&"3"3 4rcURcUR5 URRXR5 g)z Send a pickled string to a socket. This function no longer allows for partial sends which can happen when the network is busy - UDP does not guarantee delivery and can deliver packets out of sequence. N)rrsendtorrs rrDatagramHandler.sends0 99      LL)r)rN) r0r1r2r3r4rrrr5r6rrr r s "  *rr c \rSrSrSrSrSrSrSrSr Sr S r S r Sr SrSrSrSrSrS rS rS rS rS rSrSrSrSrSrSrSrSrSr Sr!Sr"Sr#Sr$\\\\ \\\\ \ \\ \ S. r%0S\_S\_S\_S\_S \_S!\_S"\ _S#\_S$\_S%\_S&\_S'\_S(\_S)\_S*\_S+\_S,\_\\\ \!\"\#\$S-.Er&S.S/S0S1S2S3.r'S4\(4\S54S6jr)S7r*S8r+S9r,S:r-S;r.Sr1S?r2g5)@ SysLogHandleriz A handler class which sends formatted logging records to a syslog server. Based on Sam Rushing's syslog module: http://www.nightmare.com/squirl/python-ext/misc/syslog.py Contributed by Nicolas Untz (after which minor refactoring changes have been made). rrDrdr}r~rrr ) alertcritcriticaldebugemergerrerrorinfonoticepanicwarnwarningauthauthprivconsolecrondaemonftpkernlprmailnewsntpsecurityz solaris-cronsysloguseruucplocal0)local1local2local3local4local5local6local7r-r1r5r0r,)DEBUGINFOWARNINGERRORCRITICAL localhostNc[RRU5 XlX lX0lSUlUR5 g)a Initialize a handler. If address is specified as a string, a UNIX socket is used. To log to a local syslogd, "SysLogHandler(address="/dev/log")" can be used. If facility is not specified, LOG_USER is used. If socktype is specified as socket.SOCK_DGRAM or socket.SOCK_STREAM, that specific socket type will be used. For Unix sockets, you can also specify a socktype of None, in which case socket.SOCK_DGRAM will be used, falling back to socket.SOCK_STREAM. N)r rrrfacilitysocktyperr)rrrTrUs rrSysLogHandler.__init__Ys8   &     rcTURnUc[Rn[R"[RU5UlURR U5 X lg![ a URR 5 URbe[Rn[R"[RU5UlURR U5 X lg![ a URR 5 ef=ff=fr)rUrrrrrrGr)rr use_socktypes r_connect_unixsocket!SysLogHandler._connect_unixsocketns}}  !,,LmmFNNLA   KK   ((M  KK   }}(!--L -- EDK  ##G, ,   !!#  s !A--A,D'!C==&D##D'cjURnURn[U[5(aSUlUR U5 gSUlUc[RnUup4[R"X4SU5nU(d [ S5eUHInUuprpn S=p[R"XrU5n U[R:XaU RU 5 O W bU eW UlX lg![ a gf=f![ a&n U n U bU R5 Sn A MSn A MSn A ff=f)a6 Try to create a socket and, if it's not a datagram socket, connect it to the other end. This method is called during handler initialization, but it's not regarded as an error if the other end isn't listening yet --- the method will be called again when emitting an event, if there is no socket at that point. TFNrz!getaddrinfo returns an empty list) rrU isinstancestr unixsocketrYrrr getaddrinforrrG)rrrUrrressresafproto_sar/rexcs rrSysLogHandler.createSockets),,== gs # #"DO  ((1$DO!,, JD%%d!X>DABB-0*e!!%!==u=D6#5#55 R( DK$M3  $%C' (%s)C2C? D2 D--D2c[U[5(aURUn[U[5(aURUnUS-U-$)z Encode the facility and priority. You can pass in strings or integers - if strings are passed, the facility_names and priority_names mapping dictionaries are used to convert them to integers. r})r\r]facility_namespriority_names)rrTprioritys rencodePrioritySysLogHandler.encodePrioritysM h $ $**84H h $ $**84HA ))rcUR URnU(aSUlUR5 [RRU5 SSS5 g!,(df  g=fr)rrrGr rr s rrGSysLogHandler.closesCYY;;D"  OO ! !$ ' YYr c:URRUS5$)a Map a logging level name to a key in the priority_names map. This is useful in two scenarios: when custom levels are being used, and in the case where you can't do a straightforward mapping by lowercasing the logging level name because of locale- specific issues (see SF #1524081). r5) priority_mapget)r levelNames r mapPrioritySysLogHandler.mapPrioritys  $$Y ::rTcURU5nUR(aURU-nUR(aUS- nSURURUR UR 55-nURS5nURS5nX2-nUR(dUR5 UR(aURRU5 gUR [R":Xa&URR%X R5 gURR'U5 g![aS URR5 URUR5 URRU5 gf=f![(a UR+U5 gf=f)z Emit a record. The record is formatted, and then sent to the syslog server. If exception information is present, it is NOT sent to the server. z<%d>utf-8N)rRident append_nulrlrTrt levelnameencoderrr^rrrGrYrrUrrrrr)rrrVprios rrSysLogHandler.emitsb %++f%Czzjj3&v D// 040@0@AQAQ0RTTD;;w'D**W%C*C;;!!#*KK$$S) &"3"33 ""3 5 ##C(*KK%%',,T\\:KK$$S)* %   V $ %s>CF6E6AF6:F6AF30F62F33F66GG)rrTrrUr^)3r0r1r2r3r4 LOG_EMERG LOG_ALERTLOG_CRITLOG_ERR LOG_WARNING LOG_NOTICELOG_INFO LOG_DEBUGLOG_KERNLOG_USERLOG_MAIL LOG_DAEMONLOG_AUTH LOG_SYSLOGLOG_LPRLOG_NEWSLOG_UUCPLOG_CRON LOG_AUTHPRIVLOG_FTPLOG_NTP LOG_SECURITY LOG_CONSOLE LOG_SOLCRON LOG_LOCAL0 LOG_LOCAL1 LOG_LOCAL2 LOG_LOCAL3 LOG_LOCAL4 LOG_LOCAL5 LOG_LOCAL6 LOG_LOCAL7rjrirqSYSLOG_UDP_PORTrrYrrlrGrtrzr{rr5r6rrrrs$IIHGKJHIHHHJHJGHHHLGGLKKJJJJJJJJ  N                                   ! "  # $#""""""1 N< L!,_="T*0,%\ * (; EJ&%rrc0\rSrSrSrSSjrSrSrSrg) SMTPHandlerizC A handler class which sends an SMTP email for each logging event. Nc[RRU5 [U[[ 45(aUuUlUlOUSsUlUl[U[[ 45(aUuUlUl OSUlX l [U[5(aU/nX0l X@l X`lXplg)a Initialize the handler. Initialize the instance with the from and to addresses and subject line of the email. To specify a non-standard SMTP port, use the (host, port) tuple format for the mailhost argument. To specify authentication credentials, supply a (username, password) tuple for the credentials argument. To specify the use of a secure protocol (TLS), pass in a tuple for the secure argument. This will only be used when authentication credentials are supplied. The tuple will be either an empty tuple, or a single-value tuple with the name of a keyfile, or a 2-value tuple with the names of the keyfile and certificate file. (This tuple is passed to the `ssl.SSLContext.load_cert_chain` method). A timeout in seconds can be specified for the SMTP connection (the default is one second). N)r rrr\listtuplemailhostmailportusernamepasswordfromaddrr]toaddrssubjectsecurer)rrrrr credentialsrrs rrSMTPHandler.__init__s&   & hu . .+3 (DM4=+3T (DM4= kD%= 1 1+6 (DM4= DM gs # #iG    rcUR$)z~ Determine the subject for the email. If you want to specify a subject line which is record-dependent, override this method. )rrs r getSubjectSMTPHandler.getSubject)s||rcSSKnSSKJn SSKnURnU(d UR nUR URXPRS9nU"5nURUS'SRUR5US'URU5US'URR5US 'URUR!U55 UR"(aUR$bbSSKnUR$Sn UR$S n UR+XS 9n UR-5 UR/U S 9 UR-5 UR1UR"UR25 UR5U5 UR75 g![(a Sn Nf=f![(a Sn Nf=f![8a UR;U5 gf=f) zL Emit a record. Format the record and send it to the specified addressees. rN) EmailMessagerFrom,ToSubjectDaterD)certfilekeyfilecontext)smtplib email.messager email.utilsr SMTP_PORTSMTPrrrrrrutilsr set_contentrRrrssl IndexError_create_stdlib_contextehlostarttlsloginr send_messagequitrr) rrrremailrsmtprVrrrrs rrSMTPHandler.emit2s ' %  2 ==D((<< t\\<JD.C--CK.CI!__V4C N++//1CK OODKK/ 0}};;*'"&++a.(#';;q>"88!)9GIIKMM'M2IIK 4==$--8   c " IIK!&'"&' &(#'( %   V $ %sUC8G;F F2BG F/,G.F//G2 G>GGGG"!G") rrrrrrrrr)NNg@) r0r1r2r3r4rrrr5r6rrrrs9<"H-%rrc@\rSrSrSrS SjrSrSrSrSr S r S r g) NTEventLogHandleriaa A handler class which sends events to the NT Event Log. Adds a registry entry for the specified application name. If no dllname is provided, win32service.pyd (which contains some basic message placeholders) is used. Note that use of these placeholders will make your event logs big, as the entire message source is held in the log. If you want slimmer logs, you have to pass in the name of your own DLL which contains the message definitions you want to use in the event log. Nc [RRU5 SSKnSSKnXlX@lU(dx[RRUR R5n[RRUS5n[RRUSS5nX l X0l UR RXU5 UR"Ul[R&UR([R*UR([R,UR.[R0UR"[R2UR"0Ulg![an[!USS5S:waeSnANSnAff=f![6a [9S5 SUlgf=f)Nrzwin32service.pydwinerrorrzWThe Python Win32 extensions for NT (service, event logging) appear not to be available.)r rrwin32evtlogutil win32evtlogappname_welur(r)r__file__rdllnamelogtypeAddSourceToRegistryrgetattrEVENTLOG_ERROR_TYPEdeftyperMEVENTLOG_INFORMATION_TYPErNrOEVENTLOG_WARNING_TYPErPrQtypemap ImportErrorprint)rrrrrres rrNTEventLogHandler.__init__ksN  &  /"L(J''-- (;(;<''-- 3'',,wqz3FG"L"L  ..wI '::DL +"G"G +"G"G+"C"C +"A"A  +"A"A  DL  1j$/145   ? @DJ s=BF!E8BF!8 FFF!FF!!G?Gcg)aI Return the message ID for the event record. If you are using your own messages, you could do this by having the msg passed to the logger being an ID rather than a formatting string. Then, in here, you could use a dictionary lookup to get the message ID. This version returns 1, which is the base message ID in win32service.pyd. rDr6rs r getMessageIDNTEventLogHandler.getMessageIDsrcg)z~ Return the event category for the record. Override this if you want to specify your own categories. This version returns 0. rr6rs rgetEventCategory"NTEventLogHandler.getEventCategorysrcbURRURUR5$)a Return the event type for the record. Override this if you want to specify your own types. This version does a mapping using the handler's typemap attribute, which is set up in __init__() to a dictionary which contains mappings for DEBUG, INFO, WARNING, ERROR and CRITICAL. If you are using your own levels you will either need to override this method or place a suitable dictionary in the handler's typemap attribute. )rrrlevelnorrs r getEventTypeNTEventLogHandler.getEventTypes#|| ==rcDUR(anURU5nURU5nURU5nUR U5nURR UR X#XE/5 gg![a URU5 gf=f)zt Emit a record. Determine the message ID, event category and event type. Then log the message in the NT event log. N) rrrrrR ReportEventrrr)rridcattyperVs rrNTEventLogHandler.emits :: )&&v.++F3((0kk&) &&t||RdEJ  )  ( )sA,BBBcB[RRU5 g)a Clean up this handler. You can remove the application name from the registry as a source of event log entries. However, if you do this, you will not be able to see the events as you intended in the Event Log Viewer - it needs to be able to access the registry to get the DLL name. N)r rrGrs rrGNTEventLogHandler.closes d#r)rrrrrr)N Application) r0r1r2r3r4rrrrrrGr5r6rrrras&!F >)" $rrc8\rSrSrSrS SjrSrSrSrSr g) HTTPHandlerizR A class which sends records to a web server, using either GET or POST semantics. Nc[RRU5 UR5nUS;a [ S5eU(dUb [ S5eXlX lX0lX@lXPl X`l g)zZ Initialize the instance with the host, the request URL, and the method ("GET" or "POST") )GETPOSTzmethod must be GET or POSTNz3context parameter only makes sense with secure=True) r rrrgrnrurlmethodrrr)rrrrrrrs rrHTTPHandler.__init__sn   &  (9: :'-01 1   & rcUR$)z Default implementation of mapping the log record into a dict that is sent as the CGI data. Overwrite in your class. Contributed by Franz Glasner. )rrs r mapLogRecordHTTPHandler.mapLogRecords rcSSKnU(a%URRXRS9nU$URR U5nU$)zk get a HTTP[S]Connection. Override when a custom connection is required, for example if there is a proxy. rNr) http.clientclientHTTPSConnectionrHTTPConnection)rrrhttp connections r getConnectionHTTPHandler.getConnectionsI  44T<<4PJ33D9JrcSSKnURnURX0R5nURnUR R URU55nURS:Xa#URS5S:aSnOSnUSXv4--nURURU5 URS5nUS:aUSUnURS:Xa6URS S 5 URS [[U555 UR(aeSSKn S UR-R!S 5n SU R#U 5R%5R'S5-n URSU 5 UR)5 URS:Xa UR+UR!S 55 UR-5 g![.a UR1U5 gf=f)zS Emit a record. Send the record to the web server as a percent-encoded dictionary rNr?&z%c%s:rz Content-typez!application/x-www-form-urlencodedzContent-lengthz%s:%sryzBasic ascii Authorization) urllib.parserr rrparse urlencoderrfind putrequest putheaderr]rSrbase64r} b64encodestripdecode endheadersr getresponserr) rrurllibrrrdataseprLrrs rrHTTPHandler.emits # % 99D""45A((C<<))$*;*;F*CDD{{e#HHSMQ&CCFc[00 LLc * #AAvBQx{{f$ N?A ,c#d)n=t///77@v//288:AA'JJ OQ/ LLN{{f$t{{7+, MMO %   V $ %sGGG98G9)rrrrrr)rFNN) r0r1r2r3r4rrr rr5r6rrrrs%KO( )%rrc6\rSrSrSrSrSrSrSrSr Sr g ) BufferingHandleri&z A handler class which buffers logging records in memory. Whenever each record is added to the buffer, a check is made to see if the buffer should be flushed. If it should, then flush() is expected to do what's needed. c\[RRU5 Xl/Ulg)z. Initialize the handler with the buffer size. N)r rrcapacitybuffer)rr's rrBufferingHandler.__init__,s"   &  rcF[UR5UR:$)z Should the handler flush its buffer? Returns true if the buffer is up to capacity. This method can be overridden to implement custom flushing strategies. )rSr(r'rs r shouldFlushBufferingHandler.shouldFlush4sDKK DMM12rcURRU5 URU5(aUR5 gg)zf Emit a record. Append the record. If shouldFlush() tells us to, call flush() to process the buffer. N)r(rr+rrs rrBufferingHandler.emit=s5 6"   F # # JJL $rcUR URR5 SSS5 g!,(df  g=f)z_ Override to implement custom flushing behaviour. This version just zaps the buffer to empty. N)rr(clearrs rrBufferingHandler.flushHs% YY KK   YYs1 ?cUR5 [RRU5 g![RRU5 f=f)zX Close the handler. This version just flushes and chains to the parent class' close(). N)rr rrGrs rrGBufferingHandler.closeQs5  ( JJL OO ! !$ 'GOO ! !$ 's 2!A)r(r'N) r0r1r2r3r4rr+rrrGr5r6rrr%r%&s  3   (rr%cT\rSrSrSr\R SS4SjrSrSr Sr S r S r g) MemoryHandleri\z A handler class which buffers logging records in memory, periodically flushing them to a target handler. Flushing occurs whenever the buffer is full, or when an event of a certain severity or greater is seen. NTcR[RX5 X lX0lX@lg)a Initialize the handler with the buffer size, the level at which flushing should occur and an optional target. Note that without a target being set either here or via setTarget(), a MemoryHandler is no use to anyone! The ``flushOnClose`` argument is ``True`` for backward compatibility reasons - the old behaviour is that when the handler is closed, the buffer is flushed, even if the flush level hasn't been exceeded nor the capacity exceeded. To prevent this, set ``flushOnClose`` to ``False``. N)r%r flushLeveltarget flushOnClose)rr'r7r8r9s rrMemoryHandler.__init__bs" !!$1$ (rc[UR5UR:=(d URUR:$)z@ Check for buffer full or a record at the flushLevel or higher. )rSr(r'rr7rs rr+MemoryHandler.shouldFlushvs3DKK DMM144??2 4rc\UR XlSSS5 g!,(df  g=f)z* Set the target handler for this handler. N)rr8)rr8s r setTargetMemoryHandler.setTarget}sYY KYYs +cUR UR(aHURHnURRU5 M URR 5 SSS5 g!,(df  g=f)z For a MemoryHandler, flushing means just sending the buffered records to the target, if there is one. Override if you want different behaviour. The record buffer is only cleared if a target has been set. N)rr8r(handler0rs rrMemoryHandler.flushsLYY{{"kkFKK&&v.* !!# YYs AA00 A>cZUR(aUR5 UR SUl[R U5 SSS5 g!,(df  g=f!UR SUl[R U5 SSS5 f!,(df  f=f=f)zQ Flush, if appropriately configured, set the target to None and lose the buffer. N)r9rrr8r%rGrs rrGMemoryHandler.closesd  -   "  &&t,"  &&t,s.!A&A A#& B*3B B* B' #B*)r7r9r8) r0r1r2r3r4r rPrr+r>rrGr5r6rrr5r5\s. -4MM$")(4! $ -rr5c0\rSrSrSrSrSrSrSrSr g) QueueHandleriah This handler sends events to a queue. Typically, it would be used together with a multiprocessing Queue to centralise logging to file in one process (in a multi-process application), so as to avoid file write contention between processes. This code is new in Python 3.2, but this class can be copy pasted into user code for use with earlier Python versions. c\[RRU5 XlSUlg)z1 Initialise an instance, using the passed queue. N)r rrqueuelistener)rrHs rrQueueHandler.__init__s"   &  rc:URRU5 g)z Enqueue a record. The base implementation uses put_nowait. You may want to override this method if you want to use blocking, timeouts or custom queue implementations. N)rH put_nowaitrs renqueueQueueHandler.enqueues f%rcURU5n[R"U5nX!lX!lSUlSUlSUlSUlU$)a] Prepare a record for queuing. The object returned by this method is enqueued. The base implementation formats the record to merge the message and arguments, and removes unpickleable items from the record in-place. Specifically, it overwrites the record's `msg` and `message` attributes with the merged message (obtained by calling the handler's `format` method), and sets the `args`, `exc_info` and `exc_text` attributes to None. You might want to override this method if you want to convert the record to a dict or JSON string, or send a modified copy of the record while leaving the original intact. N)rRcopyrrVrrexc_text stack_info)rrrVs rprepareQueueHandler.preparesL,kk&!6"    rcURURU55 g![a URU5 gf=f)zU Emit a record. Writes the LogRecord to the queue, preparing it for pickling first. N)rMrSrrrs rrQueueHandler.emits9  % LLf- . %   V $ %s #AA)rIrHN) r0r1r2r3r4rrMrSrr5r6rrrFrFs&B %rrFcT\rSrSrSrSrSS.SjrSrSrS r S r S r S r S r Srg) QueueListeneriz This class implements an internal threaded listener which watches for LogRecords being added to a queue, removes them and passes them to a list of handlers for processing. NF)respect_handler_levelc6XlX0lSUlX lg)z? Initialise an instance with the specified queue and handlers. N)rHhandlers_threadrY)rrHrYr[s rrQueueListener.__init__s    %:"rc8URRU5$)z Dequeue a record and return it, optionally blocking. The base implementation uses get. You may want to override this method if you want to use timeouts or work with custom queue implementations. )rHrr)rblocks rdequeueQueueListener.dequeueszz~~e$$rc|[R"URS9=UlnSUlUR 5 g)zi Start the listener. This starts up a background thread to monitor the queue for LogRecords to process. )r8TN) threadingThread_monitorr\r:r)rrzs rrQueueListener.starts/%++4==AA q  rcU$)z Prepare a record for handling. This method just returns the passed-in record. You may want to override this method if you need to do any custom marshalling or manipulation of the record before passing it to the handlers. r6rs rrSQueueListener.prepares  rcURU5nURHJnUR(dSnOURUR:nU(dM9UR U5 ML g)z\ Handle a record. This just loops through the handlers offering them the record to handle. TN)rSr[rYrlevelrA)rrhandlerprocesss rrAQueueListener.handlesQf%}}G-- ..GMM9wv& %rc,URn[US5nURS5nX0RLaU(aUR 5 gUR U5 U(aUR 5 Mb![R a gf=f)z Monitor the queue for records, and ask the handler to deal with them. This method runs on a separate, internal thread. The thread will terminate if it sees a sentinel object in the queue. task_doneTN)rHhasattrr` _sentinelrorAEmpty)rq has_task_doners rreQueueListener._monitor*s} JJ;/  d+^^+$  F# KKM;;  s6A<(A<<BBcNURRUR5 g)z This is used to enqueue the sentinel record. The base implementation uses put_nowait. You may want to override this method if you want to use timeouts or work with custom queue implementations. N)rHrLrqrs renqueue_sentinelQueueListener.enqueue_sentinelAs dnn-rcUR(a2UR5 URR5 SUlgg)z Stop the listener. This asks the thread to terminate, and then waits for it to do so. Note that if you don't call this before your application exits, there may be some records still left on the queue, which won't be processed. N)r\rwrrs rstopQueueListener.stopKs3 <<  ! ! # LL   DL r)r\r[rHrY)r0r1r2r3r4rqrr`rrSrArerwrzr5r6rrrXrXs9 I?D;% ' ..  rrX)$r4rPr>r r(rrHrqrrrcrwDEFAULT_TCP_LOGGING_PORTDEFAULT_UDP_LOGGING_PORTDEFAULT_HTTP_LOGGING_PORTDEFAULT_SOAP_LOGGING_PORTrSYSLOG_TCP_PORTrrrr8rYrrrr rrrrr%r5rFobjectrXr6rrrsN"   #"""!!  H''--H'TT-Tlw<2w