Ñò
$8Zc           @   sJ  d  Z  d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k	 Z	 y d d k
 Z
 d d k Z Wn e j
 o d Z
 n Xd d k l Z l Z d Z e i d j o
 d Z n d Z d a d d d	 „ Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „ Z d „  Z d S(   sž  
Configuration functions for the logging package for Python. The core package
is based on PEP 282 and comments thereto in comp.lang.python, and influenced
by Apache's log4j system.

Should work under Python versions >= 1.5.2, except that source line
information is not available unless 'sys._getframe()' is.

Copyright (C) 2001-2008 Vinay Sajip. All Rights Reserved.

To use, simply 'import logging' and log away!
iÿÿÿÿN(   t   ThreadingTCPServert   StreamRequestHandleriF#  t   win32iF'  ih   i   c         C   s¸   d d k  } | i  | ƒ } t | d ƒ o! t |  d ƒ o | i |  ƒ n | i |  ƒ t | ƒ } t i ƒ  z7 t i i ƒ  t i	 2t
 | | ƒ } t | | | ƒ Wd t i ƒ  Xd S(   s5  
    Read the logging configuration from a ConfigParser-format file.

    This can be called several times from an application, allowing an end user
    the ability to select from various pre-canned configurations (if the
    developer provides a mechanism to present the choices and load the chosen
    configuration).
    In versions of ConfigParser which have the readfp method [typically
    shipped in 2.x versions of Python], you can pass in a file-like object
    rather than a filename, in which case the file-like object will be read
    using readfp.
    iÿÿÿÿNt   readfpt   readline(   t   ConfigParsert   hasattrR   t   readt   _create_formatterst   loggingt   _acquireLockt	   _handlerst   cleart   _handlerListt   _install_handlerst   _install_loggerst   _releaseLock(   t   fnamet   defaultst   disable_existing_loggersR   t   cpt
   formatterst   handlers(    (    s$   /usr/lib/python2.6/logging/config.pyt
   fileConfig7   s     
c         C   s’   t  i |  d ƒ }  |  i d ƒ } t | ƒ } x^ |  D]V } | d | } y t | | ƒ } Wq4 t j
 o  t | ƒ t | | ƒ } q4 Xq4 W| S(   s)   Resolve a dotted name to a global object.t   .i    (   t   stringt   splitt   popt
   __import__t   getattrt   AttributeError(   t   namet   usedt   foundt   n(    (    s$   /usr/lib/python2.6/logging/config.pyt   _resolveZ   s     
c         C   s   t  d „  |  ƒ S(   Nc         S   s   t  i |  ƒ S(    (   R   t   strip(   t   x(    (    s$   /usr/lib/python2.6/logging/config.pyt   <lambda>i   s    (   t   map(   t   alist(    (    s$   /usr/lib/python2.6/logging/config.pyt   _strip_spacesh   s    c         C   s"   t  |  t ƒ o |  S|  i d ƒ S(   Ns   utf-8(   t
   isinstancet   strt   encode(   t   s(    (    s$   /usr/lib/python2.6/logging/config.pyt   _encodedk   s    c         C   s*  |  i  d d ƒ } t | ƒ p h  St i | d ƒ } t | ƒ } h  } xÛ | D]Ó } d | } |  i | ƒ } d | j o |  i  | d d ƒ } n d	 } d | j o |  i  | d d ƒ } n d	 } t i } d | j o- |  i  | d ƒ }	 |	 o t	 |	 ƒ } q	n | | | ƒ }
 |
 | | <qO W| S(
   s   Create and return formattersR   t   keyst   ,s   formatter_%st   formati   t   datefmtt   classN(
   t   gett   lenR   R   R)   t   optionst   NoneR	   t	   FormatterR#   (   R   t   flistR   t   formt   sectnamet   optst   fst   dfst   ct
   class_namet   f(    (    s$   /usr/lib/python2.6/logging/config.pyR   n   s0     
	c         C   s  |  i  d d ƒ } t | ƒ p h  St i | d ƒ } t | ƒ } h  } g  } x | D]˜} d | } |  i  | d ƒ } |  i | ƒ } d | j o |  i  | d ƒ }	 n d }	 y t | t t ƒ ƒ } Wn% t	 t
 f j
 o t | ƒ } n X|  i  | d ƒ }
 t |
 t t ƒ ƒ }
 | |
 Œ  } d	 | j o* |  i  | d	 ƒ } | i t i | ƒ n t |	 ƒ o | i | |	 ƒ n t | t i i ƒ oQ d
 | j o |  i  | d
 ƒ } n d } t | ƒ o | i | | f ƒ qãn | | | <qU Wx% | D] \ } } | i | | ƒ qøW| S(   s   Install and return handlersR   R/   R0   s
   handler_%sR3   t	   formattert    t   argst   levelt   target(   R4   R5   R   R   R)   R6   t   evalt   varsR	   R   t	   NameErrorR#   t   setLevelt   _levelNamest   setFormattert
   issubclassR   t   MemoryHandlert   appendt	   setTarget(   R   R   t   hlistR   t   fixupst   handR;   t   klassR<   t   fmtRD   t   hRE   RF   t   t(    (    s$   /usr/lib/python2.6/logging/config.pyR   ‹   sL     
 c         C   s“  |  i  d d ƒ } t i | d ƒ } t d „  | ƒ } | i d ƒ d } t i } | } |  i | ƒ } d | j o* |  i  | d ƒ } | i t i	 | ƒ n x | i
 D] }	 | i |	 ƒ q© W|  i  | d ƒ }
 t |
 ƒ oD t i |
 d ƒ }
 t |
 ƒ }
 x# |
 D] } | i | | ƒ qWn | i i i ƒ  } | i d	 t ƒ g  } xÝ| D]Õ} d
 | } |  i  | d ƒ } |  i | ƒ } d | j o |  i | d ƒ } n d } t i | ƒ } | | j o‘ | i | ƒ } | d } t | ƒ } t | ƒ } | d } xB | | j  o4 | | |  | j o | i | | ƒ | d } qW| i | ƒ n d | j o* |  i  | d ƒ } | i t i	 | ƒ n x | i
 D] }	 | i |	 ƒ q›W| | _ d | _ |  i  | d ƒ }
 t |
 ƒ oD t i |
 d ƒ }
 t |
 ƒ }
 x# |
 D] } | i | | ƒ qWqRqRWxa | D]Y } | i i | } | | j o" t i | _ g  | _
 d | _ q2| o d | _ q2q2Wd S(   s   Create and install loggerst   loggersR/   R0   c         S   s   t  i |  ƒ S(    (   R   R$   (   R%   (    (    s$   /usr/lib/python2.6/logging/config.pyR&   ¼   s    t   roott   logger_rootRE   R   t   keys	   logger_%st   qualnamet	   propagatei   R   i    N(   R4   R   R   R'   t   removeR	   RY   R6   RJ   RK   R   t   removeHandlerR5   R)   t
   addHandlert   managert
   loggerDictR/   t   sortR.   t   getintt	   getLoggert   indexRO   R]   t   disabledt   NOTSETRE   (   R   R   R   t   llistR;   RY   t   logR<   RE   RV   RQ   RS   t   existingt   child_loggerst   qnR]   t   loggert   it   prefixedt   pflent   num_existing(    (    s$   /usr/lib/python2.6/logging/config.pyR   ¶   sˆ    	   


 " 		  	c         C   sh   t  p t d ‚ n d t f d „  ƒ  Y} d t f d „  ƒ  Y} d „  } t i d | d | | |  f ƒ S(	   sW  
    Start up a socket server on the specified port, and listen for new
    configurations.

    These will be sent as a file suitable for processing by fileConfig().
    Returns a Thread object on which you can call start() to start the server,
    and which you can join() when appropriate. To stop the server, call
    stopListening().
    s    listen() needs threading to workt   ConfigStreamHandlerc           B   s   e  Z d  Z d „  Z RS(   s¤   
        Handler for a logging configuration request.

        It expects a completely new logging configuration and uses fileConfig
        to install it.
        c   	   
   S   s~  d d k  } y|  i } | i d ƒ } t | ƒ d j oã t i d | ƒ d } |  i i | ƒ } x5 t | ƒ | j  o! | | i | t | ƒ ƒ } qe W| i d ƒ } t | d ƒ } | i | ƒ | i	 ƒ  y t
 | ƒ Wn, t t f j
 o
 ‚  n t i ƒ  n Xt i | ƒ n WnY t i j
 oJ } t | i ƒ t i j o ‚  qz| i d } | t j o ‚  qzn Xd S(   sè   
            Handle a request.

            Each request is expected to be a 4-byte length, packed using
            struct.pack(">L", n), followed by the config file.
            Uses fileConfig() to do the grunt work.
            iÿÿÿÿNi   s   >Li    s   .init   w(   t   tempfilet
   connectiont   recvR5   t   structt   unpackt   mktempt   opent   writet   closeR   t   KeyboardInterruptt
   SystemExitt	   tracebackt	   print_exct   osR^   t   sockett   errort   typeRD   t   typest	   TupleTypet   RESET_ERROR(	   t   selfRu   t   connt   chunkt   slent   fileRA   t   et   errcode(    (    s$   /usr/lib/python2.6/logging/config.pyt   handle%  s6    	 "
(   t   __name__t
   __module__t   __doc__R   (    (    (    s$   /usr/lib/python2.6/logging/config.pyRs     s   t   ConfigSocketReceiverc           B   s/   e  Z d  Z d Z d e d d „ Z d „  Z RS(   sD   
        A simple TCP socket-based logging config receiver.
        i   t	   localhostc         S   sC   t  i |  | | f | ƒ t i ƒ  d |  _ t i ƒ  d |  _ d  S(   Ni    i   (   R    t   __init__R	   R
   t   abortR   t   timeout(   R‰   t   hostt   portt   handler(    (    s$   /usr/lib/python2.6/logging/config.pyR–   U  s
    
	
c         S   s‡   d d  k  } d } xn | pf | i  |  i i ƒ  g g  g  |  i ƒ \ } } } | o |  i ƒ  n t i ƒ  |  i } t i ƒ  q Wd  S(   Niÿÿÿÿi    (	   t   selectRƒ   t   filenoR˜   t   handle_requestR	   R
   R—   R   (   R‰   Rœ   R—   t   rdt   wrt   ex(    (    s$   /usr/lib/python2.6/logging/config.pyt   serve_until_stopped]  s     
	N(   R‘   R’   R“   t   allow_reuse_addresst   DEFAULT_LOGGING_CONFIG_PORTR7   R–   R¢   (    (    (    s$   /usr/lib/python2.6/logging/config.pyR”   N  s
   c         S   s=   |  d | d | ƒ } t  i ƒ  | a t  i ƒ  | i ƒ  d  S(   NRš   R›   (   R	   R
   t	   _listenerR   R¢   (   t   rcvrt   hdlrRš   t   server(    (    s$   /usr/lib/python2.6/logging/config.pyt   servej  s
    

RF   RD   (   t   threadt   NotImplementedErrorR   R    t	   threadingt   Thread(   Rš   Rs   R”   R©   (    (    s$   /usr/lib/python2.6/logging/config.pyt   listen  s    
0	c           C   s2   t  o' t i ƒ  d t  _ d a  t i ƒ  n d S(   sN   
    Stop the listening server which was created with a call to listen().
    i   N(   R¥   R	   R
   R—   R7   R   (    (    (    s$   /usr/lib/python2.6/logging/config.pyt   stopListeningv  s
    
	(   R“   t   sysR	   t   logging.handlersR   Rƒ   Rx   R‚   R€   R†   Rª   R¬   t   ImportErrorR7   t   SocketServerR    R   R¤   t   platformRˆ   R¥   R   R#   R)   R.   R   R   R   R®   R¯   (    (    (    s$   /usr/lib/python2.6/logging/config.pyt   <module>   s*   l
#					+	[e