
bc           @   s"  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 m
 Z
 m Z m Z y d d l Z Wn e k
 r d Z n Xy e e Z Wn e k
 r e Z n Xd Z d Z d Z d Z d Z d Z d$ Z d e j f d     YZ d e f d     YZ d e f d     YZ d e j f d     YZ  d e j! f d     YZ" d e" f d     YZ# d e j! f d     YZ$ d e j! f d     YZ% d e j! f d     YZ& d e j! f d     YZ' d e j! f d      YZ( d! e( f d"     YZ) d S(%   s   
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(   t   ST_DEVt   ST_INOt   ST_MTIMEi<#  i=#  i>#  i?#  i  i   i<   t   BaseRotatingHandlerc           B   s&   e  Z d  Z d d d  Z d   Z RS(   s   
    Base class for handlers that rotate log files at a certain point.
    Not meant to be instantiated directly.  Instead, use RotatingFileHandler
    or TimedRotatingFileHandler.
    i    c         C   sG   t  d k r d } n  t j j |  | | | |  | |  _ | |  _ d S(   sA   
        Use the specified filename for streamed logging
        N(   t   codecst   Nonet   loggingt   FileHandlert   __init__t   modet   encoding(   t   selft   filenameR	   R
   t   delay(    (    s&   /usr/lib/python2.7/logging/handlers.pyR   :   s
    		c         C   sg   y3 |  j  |  r |  j   n  t j j |  |  Wn- t t f k
 rO   n |  j |  n Xd S(   s   
        Emit a record.

        Output the record to the file, catering for rollover as described
        in doRollover().
        N(   t   shouldRollovert
   doRolloverR   R   t   emitt   KeyboardInterruptt
   SystemExitt   handleError(   R   t   record(    (    s&   /usr/lib/python2.7/logging/handlers.pyR   D   s    N(   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   4   s   
t   RotatingFileHandlerc           B   s8   e  Z d  Z d d d d d d  Z d   Z d   Z RS(   s   
    Handler for logging to a set of files, which switches from one file
    to the next when the current file reaches a certain size.
    t   ai    c         C   sD   | d k r d } n  t  j |  | | | |  | |  _ | |  _ d S(   s  
        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.
        i    R   N(   R   R   t   maxBytest   backupCount(   R   R   R	   R   R   R
   R   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   Y   s
    		c         C   sB  |  j  r" |  j  j   d |  _  n  |  j d k r#x t |  j d d d  D]w } d |  j | f } d |  j | d f } t j j |  rK t j j |  r t j	 |  n  t j
 | |  qK qK W|  j d } t j j |  r t j	 |  n  t j j |  j  r#t j
 |  j |  q#n  |  j s>|  j   |  _  n  d S(   s<   
        Do a rollover, as described in __init__().
        i    i   is   %s.%ds   .1N(   t   streamt   closeR   R   t   ranget   baseFilenamet   ost   patht   existst   removet   renameR   t   _open(   R   t   it   sfnt   dfn(    (    s&   /usr/lib/python2.7/logging/handlers.pyR   y   s$    	 	c         C   s   |  j  d k r! |  j   |  _  n  |  j d k r d |  j |  } |  j  j d d  |  j  j   t |  |  j k r d Sn  d S(   s   
        Determine if rollover should occur.

        Basically, see if the supplied record would cause the file to exceed
        the size limit we have.
        i    s   %s
i   i   N(   R   R   R%   R   t   formatt   seekt   tellt   len(   R   R   t   msg(    (    s&   /usr/lib/python2.7/logging/handlers.pyR      s    "N(   R   R   R   R   R   R   R   (    (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   T   s    	t   TimedRotatingFileHandlerc           B   sM   e  Z d  Z d d d d	 e e d  Z d   Z d   Z d   Z d   Z	 RS(
   s   
    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.
    t   hi   i    c   	      C   s2  t  j |  | d | |  | j   |  _ | |  _ | |  _ |  j d k rg d |  _ d |  _ d |  _ nV|  j d k r d |  _ d |  _ d	 |  _ n)|  j d
 k r d |  _ d |  _ d |  _ n |  j d k s |  j d k r d |  _ d |  _ d |  _ n |  j j	 d  rd |  _ t
 |  j  d k rCt d |  j   n  |  j d d k  si|  j d d k rt d |  j   n  t |  j d  |  _ d |  _ d |  _ n t d |  j   t j |  j  |  _ |  j | |  _ t j j |  r
t j |  t } n t t j    } |  j |  |  _ d  S(    NR   t   Si   s   %Y-%m-%d_%H-%M-%Ss%   ^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}$t   Mi<   s   %Y-%m-%d_%H-%Ms   ^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}$t   Hs   %Y-%m-%d_%Hs   ^\d{4}-\d{2}-\d{2}_\d{2}$t   Dt   MIDNIGHTi   s   %Y-%m-%ds   ^\d{4}-\d{2}-\d{2}$t   Wi   i   sH   You must specify a day for weekly rollover from 0 to 6 (0 is Monday): %st   0t   6s-   Invalid day specified for weekly rollover: %ss'   Invalid rollover interval specified: %si  i  iQ i  iQ i:	 (   R   R   t   uppert   whenR   t   utct   intervalt   suffixt   extMatcht
   startswithR,   t
   ValueErrort   intt	   dayOfWeekt   ret   compileR    R!   R"   t   statR   t   timet   computeRollovert
   rolloverAt(	   R   R   R9   R;   R   R
   R   R:   t   t(    (    s&   /usr/lib/python2.7/logging/handlers.pyR      sH    											&	c         C   sq  | |  j  } |  j d k s. |  j j d  rm|  j rI t j |  } n t j |  } | d } | d } | d } t | d | d | } | | } |  j j d  rm| d } | |  j k rj| |  j k  r |  j | }	 n d | |  j d }	 | |	 d }
 |  j s^| d
 } t j |
  d
 } | | k r^| sHd } n d } |
 | 7}
 q^n  |
 } qjqmn  | S(   sI   
        Work out the rollover time based on the specified time.
        R4   R5   i   i   i   i<   i   i   i   iii  i  iQ (	   R;   R9   R>   R:   RE   t   gmtimet	   localtimet	   _MIDNIGHTRA   (   R   t   currentTimet   resultRH   t   currentHourt   currentMinutet   currentSecondt   rt   dayt
   daysToWaitt   newRolloverAtt   dstNowt   dstAtRollovert   addend(    (    s&   /usr/lib/python2.7/logging/handlers.pyRF      s8    !	




	
	c         C   s)   t  t j    } | |  j k r% d Sd S(   s   
        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
        i   i    (   R@   RE   RG   (   R   R   RH   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR     s    c   	      C   s   t  j j |  j  \ } } t  j |  } g  } | d } t |  } x\ | D]T } | |  | k rM | | } |  j j |  r | j t  j j	 | |   q qM qM W| j
   t |  |  j k  r g  } n | t |  |  j  } | S(   s   
        Determine the files to delete when rolling over.

        More specific than the earlier method, which just used glob.glob().
        t   .(   R    R!   t   splitR   t   listdirR,   R=   t   matcht   appendt   joint   sortR   (	   R   t   dirNamet   baseNamet	   fileNamesRM   t   prefixt   plent   fileNameR<   (    (    s&   /usr/lib/python2.7/logging/handlers.pyt   getFilesToDelete(  s    

&
	c         C   s+  |  j  r" |  j  j   d |  _  n  t t j    } t j |  d } |  j |  j } |  j rr t j	 |  } nP t j |  } | d } | | k r | r d } n d } t j | |  } n  |  j
 d t j |  j |  } t j j |  rt j |  n  t j j |  j
  r/t j |  j
 |  n  |  j d k rex$ |  j   D] } t j |  qKWn  |  j s|  j   |  _  n  |  j |  }	 x |	 | k r|	 |  j }	 qW|  j d k s|  j j d  r|  j rt j |	  d }
 | |
 k r| sd } n d } |	 | 7}	 qn  |	 |  _ d S(	   sx  
        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.
        ii  iRX   i    R4   R5   N(   R   R   R   R@   RE   RJ   RG   R;   R:   RI   R   t   strftimeR<   R    R!   R"   R#   R$   R   Re   R   R%   RF   R9   R>   (   R   RL   RU   RH   t	   timeTuplet   dstThenRW   R(   t   sRT   RV   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   ?  sH    		
	 	+	N(
   R   R   R   R   t   FalseR   RF   R   Re   R   (    (    (    s&   /usr/lib/python2.7/logging/handlers.pyR.      s   5	<		t   WatchedFileHandlerc           B   s2   e  Z d  Z d d d d  Z d   Z d   Z RS(   s  
    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.
    R   i    c         C   s<   t  j j |  | | | |  d \ |  _ |  _ |  j   d  S(   Ni(   ii(   R   R   R   t   devt   inot   _statstream(   R   R   R	   R
   R   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR     s    c         C   sC   |  j  r? t j |  j  j    } | t | t |  _ |  _ n  d  S(   N(   R   R    t   fstatt   filenoR    R   Rl   Rm   (   R   t   sres(    (    s&   /usr/lib/python2.7/logging/handlers.pyRn     s    	c         C   s   y t  j |  j  } Wn1 t k
 rI } | j t j k rC d } qJ   n X| sw | t |  j k sw | t	 |  j
 k r |  j d k	 r |  j j   |  j j   d |  _ |  j   |  _ |  j   q n  t j j |  |  d S(   s   
        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(   R    RD   R   t   OSErrort   errnot   ENOENTR   R    Rl   R   Rm   R   t   flushR   R%   Rn   R   R   R   (   R   R   Rq   t   err(    (    s&   /usr/lib/python2.7/logging/handlers.pyR     s    	-	N(   R   R   R   R   R   Rn   R   (    (    (    s&   /usr/lib/python2.7/logging/handlers.pyRk   r  s   	t   SocketHandlerc           B   sY   e  Z d  Z d   Z d d  Z d   Z d   Z d   Z d   Z d   Z	 d	   Z
 RS(
   s  
    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         C   s\   t  j j |   | |  _ | |  _ d |  _ d |  _ d |  _ d |  _	 d |  _
 d |  _ d S(   s	  
        Initializes the handler with a specific host address and port.

        The attribute 'closeOnError' is set to 1 - which means that if
        a socket error occurs, the socket is silently closed and then
        reopened on the next logging call.
        i    g      ?g      >@g       @N(   R   t   HandlerR   t   hostt   portR   t   sockt   closeOnErrort	   retryTimet
   retryStartt   retryMaxt   retryFactor(   R   Ry   Rz   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR     s    							i   c         C   sT   t  j  t  j t  j  } t | d  r7 | j |  n  | j |  j |  j f  | S(   sr   
        A factory method which allows subclasses to define the precise
        type of socket they want.
        t
   settimeout(   t   sockett   AF_INETt   SOCK_STREAMt   hasattrR   t   connectRy   Rz   (   R   t   timeoutRi   (    (    s&   /usr/lib/python2.7/logging/handlers.pyt
   makeSocket  s
    c         C   s   t  j    } |  j d k r$ d } n | |  j k } | r y |  j   |  _ d |  _ Wq t j k
 r |  j d k r |  j |  _ n4 |  j |  j	 |  _ |  j |  j
 k r |  j
 |  _ n  | |  j |  _ q Xn  d S(   s   
        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.
        i   N(   RE   R}   R   R   R{   R   t   errorR~   t   retryPeriodR   R   (   R   t   nowt   attempt(    (    s&   /usr/lib/python2.7/logging/handlers.pyt   createSocket  s    	c         C   s   |  j  d k r |  j   n  |  j  r yx t |  j  d  rM |  j  j |  nO d } t |  } x: | d k r |  j  j | |  } | | } | | } qb WWq t j k
 r |  j  j	   d |  _  q Xn  d S(   s   
        Send a pickled string to the socket.

        This function allows for partial sends which can happen when the
        network is busy.
        t   sendalli    N(
   R{   R   R   R   R   R,   t   sendR   R   R   (   R   Ri   t	   sentsofart   leftt   sent(    (    s&   /usr/lib/python2.7/logging/handlers.pyR     s    	
c         C   s   | j  } | r* |  j |  } d | _  n  t | j  } | j   | d <d | d <t j | d  } | rw | | _  n  t j	 d t
 |   } | | S(   s   
        Pickles the record in binary format with a length prefix, and
        returns it ready for transmission across the socket.
        R-   t   argsi   s   >LN(   t   exc_infoR)   R   t   dictt   __dict__t
   getMessaget   cPicklet   dumpst   structt   packR,   (   R   R   t   eit   dummyt   dRi   t   slen(    (    s&   /usr/lib/python2.7/logging/handlers.pyt
   makePickle  s    	
c         C   sB   |  j  r+ |  j r+ |  j j   d |  _ n t j j |  |  d S(   s   
        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(   R|   R{   R   R   R   Rx   R   (   R   R   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   *  s    c         C   sT   y  |  j  |  } |  j |  Wn- t t f k
 r<   n |  j |  n Xd S(   s  
        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(   R   R   R   R   R   (   R   R   Ri   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   8  s    	c         C   sU   |  j    z) |  j } | r2 d |  _ | j   n  Wd |  j   Xt j j |   d S(   s$   
        Closes the socket.
        N(   t   acquireR{   R   R   t   releaseR   Rx   (   R   R{   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   I  s    
		(   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s&   /usr/lib/python2.7/logging/handlers.pyRw     s   						t   DatagramHandlerc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s  
    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         C   s    t  j |  | |  d |  _ d S(   sP   
        Initializes the handler with a specific host address and port.
        i    N(   Rw   R   R|   (   R   Ry   Rz   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   b  s    c         C   s   t  j  t  j t  j  } | S(   su   
        The factory method of SocketHandler is here overridden to create
        a UDP socket (SOCK_DGRAM).
        (   R   R   t
   SOCK_DGRAM(   R   Ri   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   i  s    c         C   s?   |  j  d k r |  j   n  |  j  j | |  j |  j f  d S(   s   
        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(   R{   R   R   t   sendtoRy   Rz   (   R   Ri   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   q  s    (   R   R   R   R   R   R   (    (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   W  s   
		t   SysLogHandlerc           B   s  e  Z d  Z d Z d Z d Z d Z d Z d Z d Z	 d Z
 d Z d Z d Z d Z d Z d Z d Z d Z d	 Z d
 Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z i e d 6e d 6e d 6e
 d 6e d 6e d 6e d 6e	 d 6e d 6e d 6e d 6e d  6Z i e d! 6e d" 6e d# 6e d$ 6e d% 6e d& 6e d' 6e d( 6e d) 6e d* 6e d+ 6e d, 6e d- 6e d. 6e d/ 6e d0 6e d1 6e d2 6e d3 6e d4 6e d5 6Z  i d d6 6d d7 6d  d8 6d d9 6d d: 6Z! d; e" f e dC d<  Z$ d=   Z% d> Z& d?   Z' d@   Z( dA   Z) dB   Z* RS(D   s  
    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).
    i    i   i   i   i   i   i   i   i   i	   i
   i   i   i   i   i   i   i   i   i   t   alertt   critt   criticalt   debugt   emergRv   R   t   infot   noticet   panict   warnt   warningt   autht   authprivt   cront   daemont   ftpt   kernt   lprt   mailt   newst   securityt   syslogt   usert   uucpt   local0t   local1t   local2t   local3t   local4t   local5t   local6t   local7t   DEBUGt   INFOt   WARNINGt   ERRORt   CRITICALt	   localhostc         C   s|  t  j j |   | |  _ | |  _ | |  _ t | t  rS d |  _ |  j	 |  n%t
 |  _ | d k rt t j } n  | \ } } t j | | d |  } | s t j d   n  x | D] } | \ } } }	 }
 } d } } y9 t j | | |	  } | t j k r| j |  n  PWq t j k
 rL} | } | d k	 rM| j   qMq Xq W| d k	 rf|  n  | |  _ | |  _ d S(   s  
        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.
        i   i    s!   getaddrinfo returns an empty listN(   R   Rx   R   t   addresst   facilityt   socktypet
   isinstancet
   basestringt
   unixsockett   _connect_unixsocketRj   R   R   R   t   getaddrinfoR   R   R   R   (   R   R   R   R   Ry   Rz   t   resst   rest   aft   protot   _t   saRv   R{   t   exc(    (    s&   /usr/lib/python2.7/logging/handlers.pyR     s<    					
		c         C   s   |  j  } | d  k r! t j } n  t j t j |  |  _ y |  j j |  | |  _  Wn t j k
 r |  j j   |  j  d  k	 r   n  t j } t j t j |  |  _ y |  j j |  | |  _  Wq t j k
 r |  j j     q Xn Xd  S(   N(	   R   R   R   R   t   AF_UNIXR   R   R   R   (   R   R   t   use_socktype(    (    s&   /usr/lib/python2.7/logging/handlers.pyR     s&    		s   <%d>%s c         C   sJ   t  | t  r |  j | } n  t  | t  r> |  j | } n  | d >| BS(   s   
        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   (   R   R   t   facility_namest   priority_names(   R   R   t   priority(    (    s&   /usr/lib/python2.7/logging/handlers.pyt   encodePriority1  s
    c         C   sI   |  j    z |  j r& |  j j   n  Wd |  j   Xt j j |   d S(   s$   
        Closes the socket.
        N(   R   R   R   R   R   R   Rx   (   R   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   >  s    
	c         C   s   |  j  j | d  S(   sK  
        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).
        R   (   t   priority_mapt   get(   R   t	   levelName(    (    s&   /usr/lib/python2.7/logging/handlers.pyt   mapPriorityJ  s    c         C   s=  y	|  j  |  d } d |  j |  j |  j | j   } t |  t k r_ | j d  } n  | | } |  j r y |  j	 j
 |  Wqt	 j k
 r |  j	 j   |  j |  j  |  j	 j
 |  qXn; |  j t	 j k r |  j	 j | |  j  n |  j	 j |  Wn- t t f k
 r%  n |  j |  n Xd S(   s   
        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.
        s    s   <%d>s   utf-8N(   R)   R   R   R   t	   levelnamet   typet   unicodet   encodeR   R   R   R   R   R   R   R   R   R   R   R   R   R   (   R   R   R-   t   prio(    (    s&   /usr/lib/python2.7/logging/handlers.pyR   T  s*    
	N(+   R   R   R   t	   LOG_EMERGt	   LOG_ALERTt   LOG_CRITt   LOG_ERRt   LOG_WARNINGt
   LOG_NOTICEt   LOG_INFOt	   LOG_DEBUGt   LOG_KERNt   LOG_USERt   LOG_MAILt
   LOG_DAEMONt   LOG_AUTHt
   LOG_SYSLOGt   LOG_LPRt   LOG_NEWSt   LOG_UUCPt   LOG_CRONt   LOG_AUTHPRIVt   LOG_FTPt
   LOG_LOCAL0t
   LOG_LOCAL1t
   LOG_LOCAL2t
   LOG_LOCAL3t
   LOG_LOCAL4t
   LOG_LOCAL5t
   LOG_LOCAL6t
   LOG_LOCAL7R   R   R   t   SYSLOG_UDP_PORTR   R   R   t   log_format_stringR   R   R   R   (    (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   }  s   


	.				
t   SMTPHandlerc           B   s/   e  Z d  Z d d d  Z d   Z d   Z RS(   sK   
    A handler class which sends an SMTP email for each logging event.
    c         C   s   t  j j |   t | t t f  r: | \ |  _ |  _ n | d |  _ |  _ t | t t f  rw | \ |  _	 |  _
 n	 d |  _	 | |  _ t | t  r | g } n  | |  _ | |  _ | |  _ d |  _ d S(   s  
        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).
        g      @N(   R   Rx   R   R   t   listt   tuplet   mailhostt   mailportR   t   usernamet   passwordt   fromaddrR   t   toaddrst   subjectt   securet   _timeout(   R   R  R  R  R  t   credentialsR  (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   {  s    					c         C   s   |  j  S(   s   
        Determine the subject for the email.

        If you want to specify a subject line which is record-dependent,
        override this method.
        (   R  (   R   R   (    (    s&   /usr/lib/python2.7/logging/handlers.pyt
   getSubject  s    c         C   sK  yd d l  } d d l m } |  j } | s: | j } n  | j |  j | d |  j } |  j |  } d |  j	 d j
 |  j  |  j |  |   | f } |  j r |  j d k	 r | j   | j |  j   | j   n  | j |  j |  j  n  | j |  j	 |  j |  | j   Wn- t t f k
 r3  n |  j |  n Xd S(   sd   
        Emit a record.

        Format the record and send it to the specified addressees.
        iN(   t
   formatdateR   s-   From: %s
To: %s
Subject: %s
Date: %s

%st   ,(   t   smtplibt   email.utilsR  R  t	   SMTP_PORTt   SMTPR  R  R)   R  R]   R  R  R  R  R   t   ehlot   starttlst   loginR  t   sendmailt   quitR   R   R   (   R   R   R  R  Rz   t   smtpR-   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR     s2    		
N(   R   R   R   R   R   R  R   (    (    (    s&   /usr/lib/python2.7/logging/handlers.pyR  w  s    		t   NTEventLogHandlerc           B   sJ   e  Z d  Z d d d  Z d   Z d   Z d   Z d   Z d   Z	 RS(	   s  
    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.
    t   Applicationc         C   s2  t  j j |   y d d  l } d d  l } | |  _ | |  _ | s t j j	 |  j j
  } t j j	 | d  } t j j | d d  } n  | |  _ | |  _ |  j j | | |  | j |  _ i | j t  j 6| j t  j 6| j t  j 6| j t  j 6| j t  j 6|  _ Wn t k
 r-d GHd  |  _ n Xd  S(   Nii    s   win32service.pydsW   The Python Win32 extensions for NT (service, event logging) appear not to be available.(   R   Rx   R   t   win32evtlogutilt   win32evtlogt   appnamet   _weluR    R!   RY   t   __file__R]   t   dllnamet   logtypet   AddSourceToRegistryt   EVENTLOG_ERROR_TYPEt   deftypet   EVENTLOG_INFORMATION_TYPER   R   t   EVENTLOG_WARNING_TYPER   R   R   t   typemapt   ImportErrorR   (   R   R&  R)  R*  R$  R%  (    (    s&   /usr/lib/python2.7/logging/handlers.pyR     s,    				c         C   s   d S(   sy  
        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   (    (   R   R   (    (    s&   /usr/lib/python2.7/logging/handlers.pyt   getMessageID  s    c         C   s   d S(   s   
        Return the event category for the record.

        Override this if you want to specify your own categories. This version
        returns 0.
        i    (    (   R   R   (    (    s&   /usr/lib/python2.7/logging/handlers.pyt   getEventCategory  s    c         C   s   |  j  j | j |  j  S(   s  
        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.
        (   R0  R   t   levelnoR-  (   R   R   (    (    s&   /usr/lib/python2.7/logging/handlers.pyt   getEventType  s    c         C   s   |  j  r yb |  j |  } |  j |  } |  j |  } |  j |  } |  j  j |  j | | | | g  Wq t t f k
 r   q |  j	 |  q Xn  d S(   s   
        Emit a record.

        Determine the message ID, event category and event type. Then
        log the message in the NT event log.
        N(
   R'  R2  R3  R5  R)   t   ReportEventR&  R   R   R   (   R   R   t   idt   catR   R-   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   	  s    	&c         C   s   t  j j |   d S(   sS  
        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   Rx   R   (   R   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR     s    N(
   R   R   R   R   R   R2  R3  R5  R   R   (    (    (    s&   /usr/lib/python2.7/logging/handlers.pyR"    s   		
				t   HTTPHandlerc           B   s,   e  Z d  Z d d  Z d   Z d   Z RS(   s^   
    A class which sends records to a Web server, using either GET or
    POST semantics.
    t   GETc         C   sV   t  j j |   | j   } | d k r7 t d   n  | |  _ | |  _ | |  _ d S(   sr   
        Initialize the instance with the host, the request URL, and the method
        ("GET" or "POST")
        R:  t   POSTs   method must be GET or POSTN(   R:  R;  (   R   Rx   R   R8   R?   Ry   t   urlt   method(   R   Ry   R<  R=  (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   .  s    		c         C   s   | j  S(   s   
        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.
        (   R   (   R   R   (    (    s&   /usr/lib/python2.7/logging/handlers.pyt   mapLogRecord;  s    c   
      C   s  yTd d l  } d d l } |  j } | j |  } |  j } | j |  j |   } |  j d k r | j d  d k r d } n d } | d | | f } n  | j	 |  j |  | j d  }	 |	 d k r | |	  } n  | j
 d	 |  |  j d
 k r'| j
 d d  | j
 d t t |    n  | j |  j d
 k rB| n d  | j   Wn- t t f k
 rp  n |  j |  n Xd S(   sk   
        Emit a record.

        Send the record to the Web server as a percent-encoded dictionary
        iNR:  t   ?i    t   &s   %c%st   :t   HostR;  s   Content-types!   application/x-www-form-urlencodeds   Content-length(   t   httplibt   urllibRy   t   HTTPR<  t	   urlencodeR>  R=  t   findt
   putrequestt	   putheadert   strR,   t
   endheadersR   t   getreplyR   R   R   (
   R   R   RC  RD  Ry   R/   R<  t   datat   sepR&   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   C  s4    				"(   R   R   R   R   R>  R   (    (    (    s&   /usr/lib/python2.7/logging/handlers.pyR9  )  s   	t   BufferingHandlerc           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s   
  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         C   s&   t  j j |   | |  _ g  |  _ d S(   s>   
        Initialize the handler with the buffer size.
        N(   R   Rx   R   t   capacityt   buffer(   R   RP  (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   m  s    	c         C   s   t  |  j  |  j k S(   s   
        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.
        (   R,   RQ  RP  (   R   R   (    (    s&   /usr/lib/python2.7/logging/handlers.pyt   shouldFlushu  s    c         C   s0   |  j  j |  |  j |  r, |  j   n  d S(   s   
        Emit a record.

        Append the record. If shouldFlush() tells us to, call flush() to process
        the buffer.
        N(   RQ  R\   RR  Ru   (   R   R   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR   ~  s    c         C   s)   |  j    z g  |  _ Wd |  j   Xd S(   sw   
        Override to implement custom flushing behaviour.

        This version just zaps the buffer to empty.
        N(   R   RQ  R   (   R   (    (    s&   /usr/lib/python2.7/logging/handlers.pyRu     s    
c         C   s&   z |  j    Wd t j j |   Xd S(   sp   
        Close the handler.

        This version just flushes and chains to the parent class' close().
        N(   Ru   R   Rx   R   (   R   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR     s    (   R   R   R   R   RR  R   Ru   R   (    (    (    s&   /usr/lib/python2.7/logging/handlers.pyRO  g  s   					t   MemoryHandlerc           B   sD   e  Z d  Z e j d d  Z d   Z d   Z d   Z	 d   Z
 RS(   s   
    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.
    c         C   s&   t  j |  |  | |  _ | |  _ d S(   s  
        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(   RO  R   t
   flushLevelt   target(   R   RP  RT  RU  (    (    s&   /usr/lib/python2.7/logging/handlers.pyR     s    	c         C   s(   t  |  j  |  j k p' | j |  j k S(   sP   
        Check for buffer full or a record at the flushLevel or higher.
        (   R,   RQ  RP  R4  RT  (   R   R   (    (    s&   /usr/lib/python2.7/logging/handlers.pyRR    s    c         C   s   | |  _  d S(   s:   
        Set the target handler for this handler.
        N(   RU  (   R   RU  (    (    s&   /usr/lib/python2.7/logging/handlers.pyt	   setTarget  s    c         C   sY   |  j    z= |  j rF x! |  j D] } |  j j |  q  Wg  |  _ n  Wd |  j   Xd S(   s   
        For a MemoryHandler, flushing means just sending the buffered
        records to the target, if there is one. Override if you want
        different behaviour.
        N(   R   RU  RQ  t   handleR   (   R   R   (    (    s&   /usr/lib/python2.7/logging/handlers.pyRu     s    
	c         C   sH   z |  j    Wd |  j   z d |  _ t j |   Wd |  j   XXd S(   sD   
        Flush, set the target to None and lose the buffer.
        N(   Ru   R   R   RU  RO  R   R   (   R   (    (    s&   /usr/lib/python2.7/logging/handlers.pyR     s    
	N(   R   R   R   R   R   R   R   RR  RV  Ru   R   (    (    (    s&   /usr/lib/python2.7/logging/handlers.pyRS    s   			i  iQ (*   R   Rs   R   R   R    R   R   RE   RB   RD   R    R   R   R   R1  R   R   t   Truet   _unicodet	   NameErrorRj   t   DEFAULT_TCP_LOGGING_PORTt   DEFAULT_UDP_LOGGING_PORTt   DEFAULT_HTTP_LOGGING_PORTt   DEFAULT_SOAP_LOGGING_PORTR  t   SYSLOG_TCP_PORTRK   R   R   R   R.   Rk   Rx   Rw   R   R   R  R"  R9  RO  RS  (    (    (    s&   /usr/lib/python2.7/logging/handlers.pyt   <module>   s<   `


 N>&Nd>9