;
Οβ"Ic               @   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 y d d l Z	 d d l
 Z
 Wn e k
 o d Z	 Yn Xd d l m Z m Z d Z e j d k o
 d Z n d Z d a d d d	  Z d
   Z d   Z d   Z d   Z d   Z e d  Z d   Z d S(   u  
Configuration functions for the logging package for Python. The core package
is based on PEP 282 and comments thereto in comp.lang.python, and influenced
by Apache's log4j system.

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

To use, simply 'import logging' and log away!
i    N(   u   ThreadingTCPServeru   StreamRequestHandleriF#  u   win32iF'  ih   i   c             C   sΑ   d d l  } | j |  } t | d  o! t |  d  o | j |   n | j |   t |  } t j   z@ t j j	   t j
 d d  =t | |  } t | | |  Wd t j   Xd S(   u5  
    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    Nu   readfpu   readline(   u   configparseru   ConfigParseru   hasattru   readfpu   readu   _create_formattersu   loggingu   _acquireLocku	   _handlersu   clearu   _handlerListu   _install_handlersu   _install_loggersu   _releaseLock(   u   fnameu   defaultsu   disable_existing_loggersu   configparseru   cpu
   formattersu   handlers(    (    u+   /mit/python/lib/python3.0/logging/config.pyu
   fileConfig4   s     
c          
   C   s   |  j  d  }  |  j d  } t |  } x_ |  D]W } | d | } y t | |  } Wq1 t k
 o! t |  t | |  } Yq1 Xq1 W| S(   u)   Resolve a dotted name to a global object.u   .i    (   u   splitu   popu
   __import__u   getattru   AttributeError(   u   nameu   usedu   foundu   n(    (    u+   /mit/python/lib/python3.0/logging/config.pyu   _resolveW   s     
c             C   s   t  d   |   S(   Nc             S   s
   |  j    S(    (   u   strip(   u   x(    (    u+   /mit/python/lib/python3.0/logging/config.pyu   <lambda>f   s    (   u   map(   u   alist(    (    u+   /mit/python/lib/python3.0/logging/config.pyu   _strip_spacese   s    c             C   s'  |  j  d d  } t |  p i  S| j d  } t |  } i  } xΫ | D]Σ } d | } |  j |  } d | k o |  j  | d d  } n d	 } d | k o |  j  | d d  } n d	 } t j } d | k o- |  j  | d  }	 |	 o t |	  } qn | | |  }
 |
 | | <qL W| S(
   u   Create and return formattersu
   formattersu   keysu   ,u   formatter_%su   formati   u   datefmtu   classN(	   u   getu   lenu   splitu   _strip_spacesu   optionsu   Noneu   loggingu	   Formatteru   _resolve(   u   cpu   flistu
   formattersu   formu   sectnameu   optsu   fsu   dfsu   cu
   class_nameu   f(    (    u+   /mit/python/lib/python3.0/logging/config.pyu   _create_formattersh   s0     
	c             C   s  |  j  d d  } t |  p i  S| j d  } t |  } i  } g  } x‘| D]} d | } |  j  | d  } |  j |  } d | k o |  j  | d  }	 n d }	 y t | t t   } Wn& t t	 f k
 o t
 |  } Yn X|  j  | d  }
 t |
 t t   }
 | |
   } d	 | k o* |  j  | d	  } | j t j |  n t |	  o | j | |	  n t | t j j  oQ d
 | k o |  j  | d
  } n d } t |  o | j | | f  qαn | | | <qR Wx% | D] \ } } | j | |  qφW| S(   u   Install and return handlersu   handlersu   keysu   ,u
   handler_%su   classu	   formatteru    u   argsu   levelu   target(   u   getu   lenu   splitu   _strip_spacesu   optionsu   evalu   varsu   loggingu   AttributeErroru	   NameErroru   _resolveu   setLevelu   _levelNamesu   setFormatteru
   issubclassu   handlersu   MemoryHandleru   appendu	   setTarget(   u   cpu
   formattersu   hlistu   handlersu   fixupsu   handu   sectnameu   klassu   optsu   fmtu   argsu   hu   levelu   targetu   t(    (    u+   /mit/python/lib/python3.0/logging/config.pyu   _install_handlers   sL     
 c             C   s¨  |  j  d d  } | j d  } t t d   |   } | j d  d } t j } | } |  j |  } d | k o* |  j  | d  } | j t j	 |  n x( | j
 d d  D] }	 | j |	  q΅ W|  j  | d	  }
 t |
  oA |
 j d  }
 t |
  }
 x# |
 D] } | j | |  qWn t | j j j    } | j   g  } xι| D]α} d
 | } |  j  | d  } |  j |  } d | k o |  j | d  } n d } t j |  } | | k o | j |  } | d } t |  } t |  } | d } xH | | k  o: | | d |  | k o | j | |  | d } qW| j |  n d | k o* |  j  | d  } | j t j	 |  n x( | j
 d d  D] }	 | j |	  q³W| | _ d | _ |  j  | d	  }
 t |
  oA |
 j d  }
 t |
  }
 x# |
 D] } | j | |  qWq[q[Wxa | D]Y } | j j | } | | k o" t j | _ g  | _
 d | _ qG| o d | _ qGqGWd S(   u   Create and install loggersu   loggersu   keysu   ,c             S   s
   |  j    S(    (   u   strip(   u   x(    (    u+   /mit/python/lib/python3.0/logging/config.pyu   <lambda>Ά   s    u   rootu   logger_rootu   levelNu   handlersu	   logger_%su   qualnameu	   propagatei   u   .i    (   u   getu   splitu   listu   mapu   removeu   loggingu   rootu   optionsu   setLevelu   _levelNamesu   handlersu   removeHandleru   lenu   _strip_spacesu
   addHandleru   manageru
   loggerDictu   keysu   sortu   getintu	   getLoggeru   indexu   appendu	   propagateu   disabledu   NOTSETu   level(   u   cpu   handlersu   disable_existing_loggersu   llistu   sectnameu   rootu   logu   optsu   levelu   hu   hlistu   handu   existingu   child_loggersu   qnu	   propagateu   loggeru   iu   prefixedu   pflenu   num_existing(    (    u+   /mit/python/lib/python3.0/logging/config.pyu   _install_loggers°   s    	  
 


 ( 		  	c             C   se   t  p t d   n Gd   d t  } Gd   d t  } d   } t j d | d | | |  f  S(	   uW  
    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().
    u    listen() needs threading to workc             B   s   |  Ee  Z d  Z d   Z d S(   u€   
        Handler for a logging configuration request.

        It expects a completely new logging configuration and uses fileConfig
        to install it.
        c       	      S   s  d d l  } y|  j } | j d  } t |  d k oε t j d |  d } |  j j |  } x5 t |  | k  o! | | j | t |   } qe W| j d  } t | d  } | j |  | j	   y t
 |  Wn. t t f k
 o   Yn t j   Yn Xt j |  n Wne t j k
 oV } z@ t | j t  p   n" | j d } | t k o   n WYd d } ~ Xn Xd S(   uθ   
            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   u   >Lu   .iniu   w(   u   tempfileu
   connectionu   recvu   lenu   structu   unpacku   mktempu   openu   writeu   closeu
   fileConfigu   KeyboardInterruptu
   SystemExitu	   tracebacku	   print_excu   osu   removeu   socketu   erroru   isinstancetypeu   argsu   tupleu   RESET_ERROR(	   u   selfu   tempfileu   connu   chunku   slenu   fileu   fu   eu   errcode(    (    u+   /mit/python/lib/python3.0/logging/config.pyu   handle  s6    	 "
N(   u   __name__u
   __module__u   __doc__u   handle(   u
   __locals__(    (    u+   /mit/python/lib/python3.0/logging/config.pyu   ConfigStreamHandler  s   
u   ConfigStreamHandlerc             B   s5   |  Ee  Z d  Z d Z d e d d  Z d   Z d S(   uD   
        A simple TCP socket-based logging config receiver.
        i   u	   localhostc             S   sC   t  j |  | | f |  t j   d |  _ t j   d |  _ d  S(   Ni    i   (   u   ThreadingTCPServeru   __init__u   loggingu   _acquireLocku   abortu   _releaseLocku   timeout(   u   selfu   hostu   portu   handler(    (    u+   /mit/python/lib/python3.0/logging/config.pyu   __init__O  s
    
	
c             S   s   d d  l  } d } xn | pf | j  |  j j   g g  g  |  j  \ } } } | o |  j   n t j   |  j } t j   q Wd  S(   Ni    (	   u   selectu   socketu   filenou   timeoutu   handle_requestu   loggingu   _acquireLocku   abortu   _releaseLock(   u   selfu   selectu   abortu   rdu   wru   ex(    (    u+   /mit/python/lib/python3.0/logging/config.pyu   serve_until_stoppedW  s     
	N(   u   __name__u
   __module__u   __doc__u   allow_reuse_addressu   DEFAULT_LOGGING_CONFIG_PORTu   Noneu   __init__u   serve_until_stopped(   u
   __locals__(    (    u+   /mit/python/lib/python3.0/logging/config.pyu   ConfigSocketReceiverH  s
   
u   ConfigSocketReceiverc             S   s=   |  d | d |  } t  j   | a t  j   | j   d  S(   Nu   portu   handler(   u   loggingu   _acquireLocku	   _listeneru   _releaseLocku   serve_until_stopped(   u   rcvru   hdlru   portu   server(    (    u+   /mit/python/lib/python3.0/logging/config.pyu   served  s
    

u   targetu   args(   u   threadu   NotImplementedErroru   StreamRequestHandleru   ThreadingTCPServeru	   threadingu   Thread(   u   portu   ConfigStreamHandleru   ConfigSocketReceiveru   serve(    (    u+   /mit/python/lib/python3.0/logging/config.pyu   listen  s    
0	c               C   s2   t  o' t j   d t  _ d a  t j   n d S(   uN   
    Stop the listening server which was created with a call to listen().
    i   N(   u	   _listeneru   loggingu   _acquireLocku   abortu   Noneu   _releaseLock(    (    (    u+   /mit/python/lib/python3.0/logging/config.pyu   stopListeningp  s
    
	(   u   __doc__u   sysu   loggingu   logging.handlersu   socketu   structu   osu	   tracebacku   _threadu   threadu	   threadingu   ImportErroru   Noneu   socketserveru   ThreadingTCPServeru   StreamRequestHandleru   DEFAULT_LOGGING_CONFIG_PORTu   platformu   RESET_ERRORu	   _listeneru
   fileConfigu   _resolveu   _strip_spacesu   _create_formattersu   _install_handlersu   _install_loggersu   listenu   stopListening(    (    (    u+   /mit/python/lib/python3.0/logging/config.pyu   <module>   s(   T
#				+	[e