syMac @sOdZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z m Z mZddlZyddlZWnek rdZYnXdZdZdZdZd Zd Zd)ZGd d d ejZGdddeZGdddeZGdddejZGdddejZ Gddde Z!GdddejZ"GdddejZ#GdddejZ$GdddejZ%Gd d!d!ejZ&Gd"d#d#e&Z'Gd$d%d%ejZ(erKGd&d'd'e)Z*ndS(*u 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-2013 Vinay Sajip. All Rights Reserved. To use, simply 'import logging.handlers' and log away! iN(uBOM_UTF8(uST_DEVuST_INOuST_MTIMEi<#i=#i>#i?#iii<cBsP|EeZdZdZd d ddZddZddZdd Z d S( uBaseRotatingHandleru Base class for handlers that rotate log files at a certain point. Not meant to be instantiated directly. Instead, use RotatingFileHandler or TimedRotatingFileHandler. cCsDtjj|||||||_||_d|_d|_dS(uA Use the specified filename for streamed logging N(uloggingu FileHandleru__init__umodeuencodinguNoneunamerurotator(uselfufilenameumodeuencodingudelay((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu__init__6s    uBaseRotatingHandler.__init__c Csiy3|j|r|jntjj||Wn/ttfk rPYn|j|YnXdS(u Emit a record. Output the record to the file, catering for rollover as described in doRollover(). N(ushouldRolloveru doRolloveruloggingu FileHandleruemituKeyboardInterruptu SystemExitu handleError(uselfurecord((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuemit@s uBaseRotatingHandler.emitcCs+t|js|}n|j|}|S(u 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. (ucallableunamer(uselfu default_nameuresult((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyurotation_filenamePs  u%BaseRotatingHandler.rotation_filenamecCsKt|js7tjj|rGtj||qGn|j||dS(uL 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(ucallableurotatoruosupathuexistsurename(uselfusourceudest((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyurotatecsuBaseRotatingHandler.rotateNF( u__name__u __module__u __qualname__u__doc__uNoneuFalseu__init__uemiturotation_filenameurotate(u __locals__((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuBaseRotatingHandler0s   uBaseRotatingHandlercBsM|EeZdZdZdddd d ddZddZdd Zd S( uRotatingFileHandleru Handler for logging to a set of files, which switches from one file to the next when the current file reaches a certain size. uaicCsD|dkrd}ntj|||||||_||_dS(u 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. iuaN(uBaseRotatingHandleru__init__umaxBytesu backupCount(uselfufilenameumodeumaxBytesu backupCountuencodingudelay((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu__init__}s    uRotatingFileHandler.__init__cCsE|jr"|jjd|_n|jdkr&xt|jdddD]}|jd|j|f}|jd|j|df}tjj |rKtjj |rtj |ntj ||qKqKW|j|jd}tjj |rtj |n|j |j|n|j sA|j|_ndS(u< Do a rollover, as described in __init__(). iiu%s.%du.1Ni(ustreamucloseuNoneu backupCounturangeurotation_filenameu baseFilenameuosupathuexistsuremoveurenameurotateudelayu_open(uselfuiusfnudfn((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu doRollovers$     uRotatingFileHandler.doRollovercCs|jdkr!|j|_n|jdkrd|j|}|jjdd|jjt||jkrdSndS(u Determine if rollover should occur. Basically, see if the supplied record would cause the file to exceed the size limit we have. iu%s iiN(ustreamuNoneu_openumaxBytesuformatuseekutellulen(uselfurecordumsg((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyushouldRollovers"u"RotatingFileHandler.shouldRolloverNF( u__name__u __module__u __qualname__u__doc__uNoneuFalseu__init__u doRolloverushouldRollover(u __locals__((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuRotatingFileHandlerxs uRotatingFileHandlercBsh|EeZdZdZddddddddZddZd d Zd d Z d dZ dS(uTimedRotatingFileHandleru 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. uhiic Cs8tj||d|||j|_||_||_|jdkrgd|_d|_d|_nV|jdkrd|_d|_d |_n)|jd krd|_d |_d |_n|jd ks|jdkrd|_d|_d|_n|jj drd|_t |jdkrCt d|jn|jddksi|jddkrt d|jnt |jd|_ d|_d|_nt d|jtj|jtj|_|j||_tjj|rtj|t}nt tj}|j||_dS( NuauSiu%Y-%m-%d_%H-%M-%Su-^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}(\.\w+)?$uMi<u%Y-%m-%d_%H-%Mu'^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}(\.\w+)?$uHu %Y-%m-%d_%Hu!^\d{4}-\d{2}-\d{2}_\d{2}(\.\w+)?$uDuMIDNIGHTiu%Y-%m-%du^\d{4}-\d{2}-\d{2}(\.\w+)?$uWiiuHYou must specify a day for weekly rollover from 0 to 6 (0 is Monday): %su0u6u-Invalid day specified for weekly rollover: %su'Invalid rollover interval specified: %siiiQiiQi: (uBaseRotatingHandleru__init__uupperuwhenu backupCountuutcuintervalusuffixuextMatchu startswithulenu ValueErroruintu dayOfWeekureucompileuASCIIuosupathuexistsustatuST_MTIMEutimeucomputeRolloveru rolloverAt( uselfufilenameuwhenuintervalu backupCountuencodingudelayuutcut((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu__init__sH               &  u!TimedRotatingFileHandler.__init__cCsq||j}|jdks.|jjdrm|jrItj|}ntj|}|d}|d}|d}t|d|d|}||}|jjdrm|d}||jkrj||jkr|j|} nd||jd} || d } |js^|d } tj| d} | | kr^| sHd} nd } | | 7} q^n| }qjqmn|S(uI Work out the rollover time based on the specified time. uMIDNIGHTuWiiii<iiiiiiQiii( uintervaluwhenu startswithuutcutimeugmtimeu localtimeu _MIDNIGHTu dayOfWeek(uselfu currentTimeuresultutu currentHouru currentMinuteu currentSecondurudayu daysToWaitu newRolloverAtudstNowu dstAtRolloveruaddend((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyucomputeRollovers8 !          u(TimedRotatingFileHandler.computeRollovercCs)ttj}||jkr%dSdS(u 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 ii(uintutimeu rolloverAt(uselfurecordut((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyushouldRollover=su'TimedRotatingFileHandler.shouldRolloverc Cstjj|j\}}tj|}g}|d}t|}xh|D]`}|d||krM||d}|jj|r|jtjj ||qqMqMW|j t||j krg}n|dt||j }|S(u Determine the files to delete when rolling over. More specific than the earlier method, which just used glob.glob(). u.N( uosupathusplitu baseFilenameulistdirulenuextMatchumatchuappendujoinusortu backupCount( uselfudirNameubaseNameu fileNamesuresultuprefixuplenufileNameusuffix((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyugetFilesToDeleteIs   &  u)TimedRotatingFileHandler.getFilesToDeletec Cs|jr"|jjd|_nttj}tj|d}|j|j}|jrrtj |}nPtj|}|d }||kr|rd}nd }tj||}n|j |j dtj |j |}tjj|r tj|n|j|j ||jdkrVx$|jD]}tj|q<Wn|jsq|j|_n|j|} x| |kr| |j} qW|jdks|jjdr|j rtj| d } || kr|sd }nd}| |7} qn| |_dS( ux do a rollover; in this case, a date/time stamp is appended to the filename when the rollover happens. However, you want the file to be named for the start of the interval, not the current time. If there is a backup count, then we have to get a list of matching filenames, sort them and remove the one with the oldest suffix. iiu.iuMIDNIGHTuWNiiiii(ustreamucloseuNoneuintutimeu localtimeu rolloverAtuintervaluutcugmtimeurotation_filenameu baseFilenameustrftimeusuffixuosupathuexistsuremoveurotateu backupCountugetFilesToDeleteudelayu_openucomputeRolloveruwhenu startswith( uselfu currentTimeudstNowutu timeTupleudstThenuaddendudfnusu newRolloverAtu dstAtRollover((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu doRollover`sH        +  u#TimedRotatingFileHandler.doRolloverNF( u__name__u __module__u __qualname__u__doc__uNoneuFalseu__init__ucomputeRolloverushouldRolloverugetFilesToDeleteu doRollover(u __locals__((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuTimedRotatingFileHandlers 5 < uTimedRotatingFileHandlercBsG|EeZdZdZdd d ddZddZddZd S( uWatchedFileHandleru A handler for logging to a file, which watches the file to see if it has changed while in use. This can happen because of usage of programs such as newsyslog and logrotate which perform log file rotation. This handler, intended for use under Unix, watches the file to see if it has changed since the last emit. (A file has changed if its device or inode have changed.) If it has changed, the old file stream is closed, and the file opened to get a new stream. This handler is not appropriate for use under Windows, because under Windows open files cannot be moved or renamed - logging opens the files with exclusive locks - and so there is no need for such a handler. Furthermore, ST_INO is not supported under Windows; stat always returns zero for this value. This handler is based on a suggestion and patch by Chad J. Schroeder. uacCs<tjj|||||d\|_|_|jdS(Niii(ii(uloggingu FileHandleru__init__udevuinou _statstream(uselfufilenameumodeuencodingudelay((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu__init__suWatchedFileHandler.__init__cCsC|jr?tj|jj}|t|t|_|_ndS(N(ustreamuosufstatufilenouST_DEVuST_INOudevuino(uselfusres((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu _statstreams uWatchedFileHandler._statstreamcCsytj|j}WnCtk r[}z#|jtjkrFd}nWYdd}~XnX| s|t|jks|t |j kr|j dk r|j j |j j |j|_ |jqntjj||dS(u Emit a record. First check if the underlying file has changed, and if it has, close the old stream and reopen the file to get the current stream. N(uosustatu baseFilenameuOSErroruerrnouENOENTuNoneuST_DEVudevuST_INOuinoustreamuflushucloseu_openu _statstreamuloggingu FileHandleruemit(uselfurecordusresuerr((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuemits  -  uWatchedFileHandler.emitNF( u__name__u __module__u __qualname__u__doc__uNoneuFalseu__init__u _statstreamuemit(u __locals__((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuWatchedFileHandlers uWatchedFileHandlercBs}|EeZdZdZddZdddZddZd d Zd d Zd dZ ddZ ddZ dS(u SocketHandleru 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. cCs\tjj|||_||_d|_d|_d|_ d|_ d|_ d|_ dS(u 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. g?g>@g@NF( ulogginguHandleru__init__uhostuportuNoneusockuFalseu closeOnErroru retryTimeu retryStarturetryMaxu retryFactor(uselfuhostuport((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu__init__s       uSocketHandler.__init__ic Cstjtjtj}t|dr7|j|ny!|j|j|jf|SWn"tjk r||j YnXdS(ur A factory method which allows subclasses to define the precise type of socket they want. u settimeoutN( usocketuAF_INETu SOCK_STREAMuhasattru settimeoutuconnectuhostuportuerroruclose(uselfutimeoutus((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu makeSockets uSocketHandler.makeSocketc Cstj}|jdkr$d}n||jk}|ry|j|_d|_Wqtjk r|jdkr|j|_ n4|j |j |_ |j |j kr|j |_ n||j |_YqXndS(u 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( utimeu retryTimeuNoneuTrueu makeSocketusockusocketuerroru retryStartu retryPeriodu retryFactoruretryMax(uselfunowuattempt((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu createSockets   uSocketHandler.createSocketc Cs|jdkr|jn|jry~t|jdrM|jj|nUd}t|}x@|dkr|jj||d}||}||}qbWWqtjk r|jj d|_YqXndS(u Send a pickled string to the socket. This function allows for partial sends which can happen when the network is busy. usendalliN( usockuNoneu createSocketuhasattrusendallulenusendusocketuerroruclose(uselfusu sentsofaruleftusent((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyusends     uSocketHandler.sendcCs|j}|r!|j|}nt|j}|j|dLN( uexc_infouformatudictu__dict__u getMessageuNoneupickleudumpsustructupackulen(uselfurecordueiudummyudususlen((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu makePickle8s   uSocketHandler.makePicklecCsB|jr+|jr+|jjd|_ntjj||dS(u 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(u closeOnErrorusockucloseuNoneulogginguHandleru handleError(uselfurecord((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu handleErrorLs  uSocketHandler.handleErrorc CsVy |j|}|j|Wn/ttfk r=Yn|j|YnXdS(u 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(u makePickleusenduKeyboardInterruptu SystemExitu handleError(uselfurecordus((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuemitZs uSocketHandler.emitc CsR|jz6|jr/|jjd|_ntjj|Wd|jXdS(u$ Closes the socket. N(uacquireusockucloseuNoneulogginguHandlerurelease(uself((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyucloseks    uSocketHandler.closeN( u__name__u __module__u __qualname__u__doc__u__init__u makeSocketu createSocketusendu makePickleu handleErroruemituclose(u __locals__((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu SocketHandlers       u SocketHandlercBs>|EeZdZdZddZddZddZdS( uDatagramHandleru 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. cCs tj|||d|_dS(uP Initializes the handler with a specific host address and port. NF(u SocketHandleru__init__uFalseu closeOnError(uselfuhostuport((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu__init__suDatagramHandler.__init__cCstjtjtj}|S(uu The factory method of SocketHandler is here overridden to create a UDP socket (SOCK_DGRAM). (usocketuAF_INETu SOCK_DGRAM(uselfus((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu makeSocketsuDatagramHandler.makeSocketcCs?|jdkr|jn|jj||j|jfdS(u 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(usockuNoneu createSocketusendtouhostuport(uselfus((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyusends uDatagramHandler.sendN(u__name__u __module__u __qualname__u__doc__u__init__u makeSocketusend(u __locals__((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuDatagramHandlerxs   uDatagramHandlercBsA|EeZdZdZdZdZdZdZdZdZ dZ d Z dZ dZ dZdZdZdZdZd Zd Zd Zd Zd ZdZdZdZdZdZdZdZdZi ed6ed6ed6e d6ed6ed6ed6e d6e d6ed6ed 6ed!6Z ied"6ed#6ed$6ed%6ed&6e d'6ed(6ed)6ed*6ed+6ed,6e d-6ed.6ed/6ed06ed16ed26ed36ed46ed56ed66Z!idd76dd86d!d96dd:6dd;6Z"d<e#fe dJd=d>Z%d?d@Z&dAdBZ'dCdDZ(dEdFZ)dGZ*dKZ,dHdIZ-dJS(Lu SysLogHandleru 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). iiiiiiiiii i i iiiiiiiiualertucritucriticaludebuguemerguerruerroruinfounoticeupanicuwarnuwarninguauthuauthprivucronudaemonuftpukernulprumailunewsusecurityusysloguuseruuucpulocal0ulocal1ulocal2ulocal3ulocal4ulocal5ulocal6ulocal7uDEBUGuINFOuWARNINGuERRORuCRITICALu localhostcCstjj|||_||_||_t|trSd|_ |j |ndd|_ |dkrtt j}nt j t j||_ |t jkr|j j|n||_d|_dS(u 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. NTF(ulogginguHandleru__init__uaddressufacilityusocktypeu isinstanceustruTrueu unixsocketu_connect_unixsocketuFalseuNoneusocketu SOCK_DGRAMuAF_INETu SOCK_STREAMuconnectu formatter(uselfuaddressufacilityusocktype((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu__init__s         uSysLogHandler.__init__cCs|j}|dkr!tj}ntjtj||_y|jj|||_Wntjk r|jj|jdk rntj}tjtj||_y|jj|||_Wn%tjk r|jjYnXYnXdS(N( usocktypeuNoneusocketu SOCK_DGRAMuAF_UNIXuconnectuerrorucloseu SOCK_STREAM(uselfuaddressu use_socktype((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu_connect_unixsocket!s&        u!SysLogHandler._connect_unixsocketcCsJt|tr|j|}nt|tr>|j|}n|d>|BS(u 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. i(u isinstanceustrufacility_namesupriority_names(uselfufacilityupriority((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuencodePriority9s uSysLogHandler.encodePriorityc Cs=|jz!|jjtjj|Wd|jXdS(u$ Closes the socket. N(uacquireusocketucloseulogginguHandlerurelease(uself((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyucloseFs   uSysLogHandler.closecCs|jj|dS(uK 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). uwarning(u priority_mapuget(uselfu levelName((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu mapPriorityQsuSysLogHandler.mapPriorityucCse|j|}|jr(|j|}n|jr>|d7}nd|j|j|j|j}|jd}|jd}||}y|jry|j j |Wq.t j k r|j j |j |j|j j |Yq.Xn;|jt jkr|j j||jn|j j|Wn/ttfk rLYn|j|YnXdS(u 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. uu<%d>uutf-8N(uformatuidentu append_nuluencodePriorityufacilityu mapPriorityu levelnameuencodeu unixsocketusocketusenduerrorucloseu_connect_unixsocketuaddressusocktypeu SOCK_DGRAMusendtousendalluKeyboardInterruptu SystemExitu handleError(uselfurecordumsguprio((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuemit^s2      uSysLogHandler.emitNT(.u__name__u __module__u __qualname__u__doc__u LOG_EMERGu LOG_ALERTuLOG_CRITuLOG_ERRu LOG_WARNINGu LOG_NOTICEuLOG_INFOu LOG_DEBUGuLOG_KERNuLOG_USERuLOG_MAILu LOG_DAEMONuLOG_AUTHu LOG_SYSLOGuLOG_LPRuLOG_NEWSuLOG_UUCPuLOG_CRONu LOG_AUTHPRIVuLOG_FTPu LOG_LOCAL0u LOG_LOCAL1u LOG_LOCAL2u LOG_LOCAL3u LOG_LOCAL4u LOG_LOCAL5u LOG_LOCAL6u LOG_LOCAL7upriority_namesufacility_namesu priority_mapuSYSLOG_UDP_PORTuNoneu__init__u_connect_unixsocketuencodePriorityucloseu mapPriorityuidentuTrueu append_nuluemit(u __locals__((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu SysLogHandlers       u SysLogHandlercBsG|EeZdZdZd d dddZddZddZd S( u SMTPHandleruK A handler class which sends an SMTP email for each logging event. g@cCstjj|t|tr4|\|_|_n|d|_|_t|trk|\|_|_ n d|_||_ t|t r|g}n||_ ||_ ||_||_dS(ux 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 `starttls` method). A timeout in seconds can be specified for the SMTP connection (the default is one second). N(ulogginguHandleru__init__u isinstanceutupleumailhostumailportuNoneuusernameupasswordufromaddrustrutoaddrsusubjectusecureutimeout(uselfumailhostufromaddrutoaddrsusubjectu credentialsusecureutimeout((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu__init__s      uSMTPHandler.__init__cCs|jS(u Determine the subject for the email. If you want to specify a subject line which is record-dependent, override this method. (usubject(uselfurecord((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu getSubjectsuSMTPHandler.getSubjectc CsMyddl}ddlm}|j}|s:|j}n|j|j|d|j}|j|}d|j dj |j |j |||f}|j r|jdk r|j|j|j|jn|j|j |jn|j|j |j ||jWn/ttfk r4Yn|j|YnXdS(ud Emit a record. Format the record and send it to the specified addressees. iN(u formatdateutimeoutu-From: %s To: %s Subject: %s Date: %s %su,(usmtplibu email.utilsu formatdateumailportu SMTP_PORTuSMTPumailhostutimeoutuformatufromaddrujoinutoaddrsu getSubjectuusernameusecureuNoneuehloustarttlsuloginupasswordusendmailuquituKeyboardInterruptu SystemExitu handleError(uselfurecordusmtplibu formatdateuportusmtpumsg((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuemits2       uSMTPHandler.emitN(u__name__u __module__u __qualname__u__doc__uNoneu__init__u getSubjectuemit(u __locals__((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu SMTPHandlers" u SMTPHandlercBsh|EeZdZdZddddZddZddZd d Zd d Z d dZ dS(uNTEventLogHandleru 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. u Applicationc Cs8tjj|yddl}ddl}||_||_|stjj |jj }tjj |d}tjj |dd}n||_ ||_ |jj||||j|_i|jtj6|jtj6|jtj6|jtj6|jtj6|_Wn%tk r3tdd|_YnXdS(Niuwin32service.pyduWThe Python Win32 extensions for NT (service, event logging) appear not to be available.(ulogginguHandleru__init__uwin32evtlogutilu win32evtloguappnameu_weluuosupathusplitu__file__ujoinudllnameulogtypeuAddSourceToRegistryuEVENTLOG_ERROR_TYPEudeftypeuEVENTLOG_INFORMATION_TYPEuDEBUGuINFOuEVENTLOG_WARNING_TYPEuWARNINGuERRORuCRITICALutypemapu ImportErroruprintuNone(uselfuappnameudllnameulogtypeuwin32evtlogutilu win32evtlog((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu__init__s,           uNTEventLogHandler.__init__cCsdS(uy 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. i((uselfurecord((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu getMessageIDsuNTEventLogHandler.getMessageIDcCsdS(u Return the event category for the record. Override this if you want to specify your own categories. This version returns 0. i((uselfurecord((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyugetEventCategorysu"NTEventLogHandler.getEventCategorycCs|jj|j|jS(u 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. (utypemapugetulevelnoudeftype(uselfurecord((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu getEventType s uNTEventLogHandler.getEventTypec Cs|jryb|j|}|j|}|j|}|j|}|jj|j||||gWqttfk rYq|j |YqXndS(u Emit a record. Determine the message ID, event category and event type. Then log the message in the NT event log. N( u_weluu getMessageIDugetEventCategoryu getEventTypeuformatu ReportEventuappnameuKeyboardInterruptu SystemExitu handleError(uselfurecorduiducatutypeumsg((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuemits &uNTEventLogHandler.emitcCstjj|dS(uS 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(ulogginguHandleruclose(uself((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuclose,s uNTEventLogHandler.closeN( u__name__u __module__u __qualname__u__doc__uNoneu__init__u getMessageIDugetEventCategoryu getEventTypeuemituclose(u __locals__((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuNTEventLogHandlers  uNTEventLogHandlercBsG|EeZdZdZdd d ddZddZddZd S( u HTTPHandleru^ A class which sends records to a Web server, using either GET or POST semantics. uGETcCshtjj||j}|dkr7tdn||_||_||_||_||_ dS(ur Initialize the instance with the host, the request URL, and the method ("GET" or "POST") uGETuPOSTumethod must be GET or POSTN(uGETuPOST( ulogginguHandleru__init__uupperu ValueErroruhostuurlumethodusecureu credentials(uselfuhostuurlumethodusecureu credentials((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu__init__>s      uHTTPHandler.__init__cCs|jS(u 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. (u__dict__(uselfurecord((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu mapLogRecordMsuHTTPHandler.mapLogRecordc Csyddl}ddl}|j}|jrB|jj|}n|jj|}|j}|jj |j |}|j dkr|j ddkrd}nd}|d||f}n|j |j ||j d} | dkr|d| }n|jd||j d krQ|jd d |jd tt|n|jrddl} d |jjd} d| j| j} |jd| n|j|j d kr|j|jdn|jWn/ttfk rYn|j|YnXdS(uk Emit a record. Send the record to the Web server as a percent-encoded dictionary iNuGETu?u&u%c%su:uHostuPOSTu Content-typeu!application/x-www-form-urlencodeduContent-lengthuu%s:%suutf-8uBasic u Authorization(u http.clientu urllib.parseuhostusecureuclientuHTTPSConnectionuHTTPConnectionuurluparseu urlencodeu mapLogRecordumethodufindu putrequestu putheaderustrulenu credentialsubase64uencodeu b64encodeustripu endheadersusendu getresponseuKeyboardInterruptu SystemExitu handleError( uselfurecorduhttpuurllibuhostuhuurludatausepuiubase64us((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuemitUsF         uHTTPHandler.emitNF( u__name__u __module__u __qualname__u__doc__uFalseuNoneu__init__u mapLogRecorduemit(u __locals__((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu HTTPHandler9s u HTTPHandlercBsV|EeZdZdZddZddZddZdd Zd d Zd S( uBufferingHandleru 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. cCs&tjj|||_g|_dS(u> Initialize the handler with the buffer size. N(ulogginguHandleru__init__ucapacityubuffer(uselfucapacity((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu__init__s uBufferingHandler.__init__cCst|j|jkS(u 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. (ulenubufferucapacity(uselfurecord((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu shouldFlushsuBufferingHandler.shouldFlushcCs0|jj||j|r,|jndS(u Emit a record. Append the record. If shouldFlush() tells us to, call flush() to process the buffer. N(ubufferuappendu shouldFlushuflush(uselfurecord((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuemitsuBufferingHandler.emitc Cs)|jz g|_Wd|jXdS(uw Override to implement custom flushing behaviour. This version just zaps the buffer to empty. N(uacquireubufferurelease(uself((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuflushs  uBufferingHandler.flushcCs|jtjj|dS(up Close the handler. This version just flushes and chains to the parent class' close(). N(uflushulogginguHandleruclose(uself((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyucloses uBufferingHandler.closeN( u__name__u __module__u __qualname__u__doc__u__init__u shouldFlushuemituflushuclose(u __locals__((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuBufferingHandlers   uBufferingHandlercBs_|EeZdZdZejd ddZddZddZ dd Z d d Z d S( u MemoryHandleru 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. cCs&tj||||_||_dS(u 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! N(uBufferingHandleru__init__u flushLevelutarget(uselfucapacityu flushLevelutarget((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu__init__s uMemoryHandler.__init__cCs(t|j|jkp'|j|jkS(uP Check for buffer full or a record at the flushLevel or higher. (ulenubufferucapacityulevelnou flushLevel(uselfurecord((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu shouldFlushsuMemoryHandler.shouldFlushcCs ||_dS(u: Set the target handler for this handler. N(utarget(uselfutarget((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu setTargetsuMemoryHandler.setTargetc CsY|jz=|jrFx!|jD]}|jj|q Wg|_nWd|jXdS(u 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 also cleared by this operation. N(uacquireutargetubufferuhandleurelease(uselfurecord((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuflushs  uMemoryHandler.flushc Cs@|j|jzd|_tj|Wd|jXdS(uD Flush, set the target to None and lose the buffer. N(uflushuacquireuNoneutargetuBufferingHandlerucloseurelease(uself((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyucloses    uMemoryHandler.closeN( u__name__u __module__u __qualname__u__doc__ulogginguERRORuNoneu__init__u shouldFlushu setTargetuflushuclose(u __locals__((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu MemoryHandlers    u MemoryHandlercBsJ|EeZdZdZddZddZddZdd Zd S( u QueueHandleru 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. cCstjj|||_dS(uA Initialise an instance, using the passed queue. N(ulogginguHandleru__init__uqueue(uselfuqueue((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu__init__suQueueHandler.__init__cCs|jj|dS(u 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(uqueueu put_nowait(uselfurecord((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuenqueue suQueueHandler.enqueuecCs/|j||j|_d|_d|_|S(u Prepares 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. 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(uformatumessageumsguNoneuargsuexc_info(uselfurecord((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuprepares     uQueueHandler.preparec CsPy|j|j|Wn/ttfk r7Yn|j|YnXdS(um Emit a record. Writes the LogRecord to the queue, preparing it for pickling first. N(uenqueueuprepareuKeyboardInterruptu SystemExitu handleError(uselfurecord((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuemit,s uQueueHandler.emitN(u__name__u __module__u __qualname__u__doc__u__init__uenqueueuprepareuemit(u __locals__((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu QueueHandlers    u QueueHandlercBs|EeZdZdZdZddZddZddZdd Z d d Z d d Z ddZ ddZ dS(u QueueListeneru 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. cGs.||_||_tj|_d|_dS(uc Initialise an instance with the specified queue and handlers. N(uqueueuhandlersu threadinguEventu_stopuNoneu_thread(uselfuqueueuhandlers((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu__init__Bs  uQueueListener.__init__cCs|jj|S(u 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. (uqueueuget(uselfublock((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyudequeueLsuQueueListener.dequeuecCs7tjd|j|_}|jd|jdS(u Start the listener. This starts up a background thread to monitor the queue for LogRecords to process. utargetNT(u threadinguThreadu_monitoru_threadu setDaemonuTrueustart(uselfut((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyustartUs uQueueListener.startcCs|S(u 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. ((uselfurecord((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuprepare`suQueueListener.preparecCs4|j|}x|jD]}|j|qWdS(u Handle a record. This just loops through the handlers offering them the record to handle. N(uprepareuhandlersuhandle(uselfurecorduhandler((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuhandlejsuQueueListener.handlec Cs|j}t|d}xq|jjsyF|jd}||jkrOPn|j||ro|jnWqtj k rYqXqWxbyF|jd}||jkrPn|j||r|jnWqtj k rPYqXqdS(u 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. u task_doneNTF( uqueueuhasattru_stopuisSetudequeueuTrueu _sentineluhandleu task_doneuEmptyuFalse(uselfuqu has_task_doneurecord((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu_monitorus,    uQueueListener._monitorcCs|jj|jdS(u 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(uqueueu put_nowaitu _sentinel(uself((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyuenqueue_sentinelsuQueueListener.enqueue_sentinelcCs1|jj|j|jjd|_dS(u! 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(u_stopusetuenqueue_sentinelu_threadujoinuNone(uself((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyustops   uQueueListener.stopN(u__name__u __module__u __qualname__u__doc__uNoneu _sentinelu__init__udequeueustartuprepareuhandleu_monitoruenqueue_sentinelustop(u __locals__((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyu QueueListener:s u QueueListeneriiQ(+u__doc__uerrnouloggingusocketuosupickleustructutimeureucodecsuBOM_UTF8ustatuST_DEVuST_INOuST_MTIMEuqueueu threadingu ImportErroruNoneuDEFAULT_TCP_LOGGING_PORTuDEFAULT_UDP_LOGGING_PORTuDEFAULT_HTTP_LOGGING_PORTuDEFAULT_SOAP_LOGGING_PORTuSYSLOG_UDP_PORTuSYSLOG_TCP_PORTu _MIDNIGHTu FileHandleruBaseRotatingHandleruRotatingFileHandleruTimedRotatingFileHandleruWatchedFileHandleruHandleru SocketHandleruDatagramHandleru SysLogHandleru SMTPHandleruNTEventLogHandleru HTTPHandleruBufferingHandleru MemoryHandleru QueueHandleruobjectu QueueListener(((u5/opt/alt/python33/lib64/python3.3/logging/handlers.pyus<`   HL>&PdJ7=B