<s> """<STR_LIT>""" <EOL> import sys , os , time , io , traceback , warnings , weakref <EOL> from string import Template <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:error>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:info>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> try : <EOL> import threading <EOL> except ImportError : <EOL> threading = None <EOL> __author__ = "<STR_LIT>" <EOL> __status__ = "<STR_LIT>" <EOL> __version__ = "<STR_LIT>" <EOL> __date__ = "<STR_LIT>" <EOL> if hasattr ( sys , '<STR_LIT>' ) : <EOL> _srcfile = "<STR_LIT>" % ( os . sep , __file__ [ - <NUM_LIT:4> : ] ) <EOL> else : <EOL> _srcfile = __file__ <EOL> _srcfile = os . path . normcase ( _srcfile ) <EOL> if hasattr ( sys , '<STR_LIT>' ) : <EOL> currentframe = lambda : sys . _getframe ( <NUM_LIT:3> ) <EOL> else : <EOL> def currentframe ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> raise Exception <EOL> except : <EOL> return sys . exc_info ( ) [ <NUM_LIT:2> ] . tb_frame . f_back <EOL> _startTime = time . time ( ) <EOL> raiseExceptions = True <EOL> logThreads = True <EOL> logMultiprocessing = True <EOL> logProcesses = True <EOL> CRITICAL = <NUM_LIT:50> <EOL> FATAL = CRITICAL <EOL> ERROR = <NUM_LIT> <EOL> WARNING = <NUM_LIT:30> <EOL> WARN = WARNING <EOL> INFO = <NUM_LIT:20> <EOL> DEBUG = <NUM_LIT:10> <EOL> NOTSET = <NUM_LIT:0> <EOL> _levelNames = { <EOL> CRITICAL : '<STR_LIT>' , <EOL> ERROR : '<STR_LIT>' , <EOL> WARNING : '<STR_LIT>' , <EOL> INFO : '<STR_LIT>' , <EOL> DEBUG : '<STR_LIT>' , <EOL> NOTSET : '<STR_LIT>' , <EOL> '<STR_LIT>' : CRITICAL , <EOL> '<STR_LIT>' : ERROR , <EOL> '<STR_LIT>' : WARNING , <EOL> '<STR_LIT>' : WARNING , <EOL> '<STR_LIT>' : INFO , <EOL> '<STR_LIT>' : DEBUG , <EOL> '<STR_LIT>' : NOTSET , <EOL> } <EOL> def getLevelName ( level ) : <EOL> """<STR_LIT>""" <EOL> return _levelNames . get ( level , ( "<STR_LIT>" % level ) ) <EOL> def addLevelName ( level , levelName ) : <EOL> """<STR_LIT>""" <EOL> _acquireLock ( ) <EOL> try : <EOL> _levelNames [ level ] = levelName <EOL> _levelNames [ levelName ] = level <EOL> finally : <EOL> _releaseLock ( ) <EOL> def _checkLevel ( level ) : <EOL> if isinstance ( level , int ) : <EOL> rv = level <EOL> elif str ( level ) == level : <EOL> if level not in _levelNames : <EOL> raise ValueError ( "<STR_LIT>" % level ) <EOL> rv = _levelNames [ level ] <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" % level ) <EOL> return rv <EOL> if threading : <EOL> _lock = threading . RLock ( ) <EOL> else : <EOL> _lock = None <EOL> def _acquireLock ( ) : <EOL> """<STR_LIT>""" <EOL> if _lock : <EOL> _lock . acquire ( ) <EOL> def _releaseLock ( ) : <EOL> """<STR_LIT>""" <EOL> if _lock : <EOL> _lock . release ( ) <EOL> class LogRecord ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , level , pathname , lineno , <EOL> msg , args , exc_info , func = None , sinfo = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> ct = time . time ( ) <EOL> self . name = name <EOL> self . msg = msg <EOL> if args and len ( args ) == <NUM_LIT:1> and isinstance ( args [ <NUM_LIT:0> ] , dict ) and args [ <NUM_LIT:0> ] : <EOL> args = args [ <NUM_LIT:0> ] <EOL> self . args = args <EOL> self . levelname = getLevelName ( level ) <EOL> self . levelno = level <EOL> self . pathname = pathname <EOL> try : <EOL> self . filename = os . path . basename ( pathname ) <EOL> self . module = os . path . splitext ( self . filename ) [ <NUM_LIT:0> ] <EOL> except ( TypeError , ValueError , AttributeError ) : <EOL> self . filename = pathname <EOL> self . module = "<STR_LIT>" <EOL> self . exc_info = exc_info <EOL> self . exc_text = None <EOL> self . stack_info = sinfo <EOL> self . lineno = lineno <EOL> self . funcName = func <EOL> self . created = ct <EOL> self . msecs = ( ct - int ( ct ) ) * <NUM_LIT:1000> <EOL> self . relativeCreated = ( self . created - _startTime ) * <NUM_LIT:1000> <EOL> if logThreads and threading : <EOL> self . thread = threading . get_ident ( ) <EOL> self . threadName = threading . current_thread ( ) . name <EOL> else : <EOL> self . thread = None <EOL> self . threadName = None <EOL> if not logMultiprocessing : <EOL> self . processName = None <EOL> else : <EOL> self . processName = '<STR_LIT>' <EOL> mp = sys . modules . get ( '<STR_LIT>' ) <EOL> if mp is not None : <EOL> try : <EOL> self . processName = mp . current_process ( ) . name <EOL> except Exception : <EOL> pass <EOL> if logProcesses and hasattr ( os , '<STR_LIT>' ) : <EOL> self . process = os . getpid ( ) <EOL> else : <EOL> self . process = None <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % ( self . name , self . levelno , <EOL> self . pathname , self . lineno , self . msg ) <EOL> def getMessage ( self ) : <EOL> """<STR_LIT>""" <EOL> msg = str ( self . msg ) <EOL> if self . args : <EOL> msg = msg % self . args <EOL> return msg <EOL> _logRecordFactory = LogRecord <EOL> def setLogRecordFactory ( factory ) : <EOL> """<STR_LIT>""" <EOL> global _logRecordFactory <EOL> _logRecordFactory = factory <EOL> def getLogRecordFactory ( ) : <EOL> """<STR_LIT>""" <EOL> return _logRecordFactory <EOL> def makeLogRecord ( dict ) : <EOL> """<STR_LIT>""" <EOL> rv = _logRecordFactory ( None , None , "<STR_LIT>" , <NUM_LIT:0> , "<STR_LIT>" , ( ) , None , None ) <EOL> rv . __dict__ . update ( dict ) <EOL> return rv <EOL> class PercentStyle ( object ) : <EOL> default_format = '<STR_LIT>' <EOL> asctime_format = '<STR_LIT>' <EOL> asctime_search = '<STR_LIT>' <EOL> def __init__ ( self , fmt ) : <EOL> self . _fmt = fmt or self . default_format <EOL> def usesTime ( self ) : <EOL> return self . _fmt . find ( self . asctime_search ) >= <NUM_LIT:0> <EOL> def format ( self , record ) : <EOL> return self . _fmt % record . __dict__ <EOL> class StrFormatStyle ( PercentStyle ) : <EOL> default_format = '<STR_LIT>' <EOL> asctime_format = '<STR_LIT>' <EOL> asctime_search = '<STR_LIT>' <EOL> def format ( self , record ) : <EOL> return self . _fmt . format ( ** record . __dict__ ) <EOL> class StringTemplateStyle ( PercentStyle ) : <EOL> default_format = '<STR_LIT>' <EOL> asctime_format = '<STR_LIT>' <EOL> asctime_search = '<STR_LIT>' <EOL> def __init__ ( self , fmt ) : <EOL> self . _fmt = fmt or self . default_format <EOL> self . _tpl = Template ( self . _fmt ) <EOL> def usesTime ( self ) : <EOL> fmt = self . _fmt <EOL> return fmt . find ( '<STR_LIT>' ) >= <NUM_LIT:0> or fmt . find ( self . asctime_format ) >= <NUM_LIT:0> <EOL> def format ( self , record ) : <EOL> return self . _tpl . substitute ( ** record . __dict__ ) <EOL> _STYLES = { <EOL> '<STR_LIT:%>' : PercentStyle , <EOL> '<STR_LIT:{>' : StrFormatStyle , <EOL> '<STR_LIT:$>' : StringTemplateStyle <EOL> } <EOL> class Formatter ( object ) : <EOL> """<STR_LIT>""" <EOL> converter = time . localtime <EOL> def __init__ ( self , fmt = None , datefmt = None , style = '<STR_LIT:%>' ) : <EOL> """<STR_LIT>""" <EOL> if style not in _STYLES : <EOL> raise ValueError ( '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( <EOL> _STYLES . keys ( ) ) ) <EOL> self . _style = _STYLES [ style ] ( fmt ) <EOL> self . _fmt = self . _style . _fmt <EOL> self . datefmt = datefmt <EOL> default_time_format = '<STR_LIT>' <EOL> default_msec_format = '<STR_LIT>' <EOL> def formatTime ( self , record , datefmt = None ) : <EOL> """<STR_LIT>""" <EOL> ct = self . converter ( record . created ) <EOL> if datefmt : <EOL> s = time . strftime ( datefmt , ct ) <EOL> else : <EOL> t = time . strftime ( self . default_time_format , ct ) <EOL> s = self . default_msec_format % ( t , record . msecs ) <EOL> return s <EOL> def formatException ( self , ei ) : <EOL> """<STR_LIT>""" <EOL> sio = io . StringIO ( ) <EOL> tb = ei [ <NUM_LIT:2> ] <EOL> traceback . print_exception ( ei [ <NUM_LIT:0> ] , ei [ <NUM_LIT:1> ] , tb , None , sio ) <EOL> s = sio . getvalue ( ) <EOL> sio . close ( ) <EOL> if s [ - <NUM_LIT:1> : ] == "<STR_LIT:\n>" : <EOL> s = s [ : - <NUM_LIT:1> ] <EOL> return s <EOL> def usesTime ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _style . usesTime ( ) <EOL> def formatMessage ( self , record ) : <EOL> return self . _style . format ( record ) <EOL> def formatStack ( self , stack_info ) : <EOL> """<STR_LIT>""" <EOL> return stack_info <EOL> def format ( self , record ) : <EOL> """<STR_LIT>""" <EOL> record . message = record . getMessage ( ) <EOL> if self . usesTime ( ) : <EOL> record . asctime = self . formatTime ( record , self . datefmt ) <EOL> s = self . formatMessage ( record ) <EOL> if record . exc_info : <EOL> if not record . exc_text : <EOL> record . exc_text = self . formatException ( record . exc_info ) <EOL> if record . exc_text : <EOL> if s [ - <NUM_LIT:1> : ] != "<STR_LIT:\n>" : <EOL> s = s + "<STR_LIT:\n>" <EOL> s = s + record . exc_text <EOL> if record . stack_info : <EOL> if s [ - <NUM_LIT:1> : ] != "<STR_LIT:\n>" : <EOL> s = s + "<STR_LIT:\n>" <EOL> s = s + self . formatStack ( record . stack_info ) <EOL> return s <EOL> _defaultFormatter = Formatter ( ) <EOL> class BufferingFormatter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , linefmt = None ) : <EOL> """<STR_LIT>""" <EOL> if linefmt : <EOL> self . linefmt = linefmt <EOL> else : <EOL> self . linefmt = _defaultFormatter <EOL> def formatHeader ( self , records ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" <EOL> def formatFooter ( self , records ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" <EOL> def format ( self , records ) : <EOL> """<STR_LIT>""" <EOL> rv = "<STR_LIT>" <EOL> if len ( records ) > <NUM_LIT:0> : <EOL> rv = rv + self . formatHeader ( records ) <EOL> for record in records : <EOL> rv = rv + self . linefmt . format ( record ) <EOL> rv = rv + self . formatFooter ( records ) <EOL> return rv <EOL> class Filter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> self . name = name <EOL> self . nlen = len ( name ) <EOL> def filter ( self , record ) : <EOL> """<STR_LIT>""" <EOL> if self . nlen == <NUM_LIT:0> : <EOL> return True <EOL> elif self . name == record . name : <EOL> return True <EOL> elif record . name . find ( self . name , <NUM_LIT:0> , self . nlen ) != <NUM_LIT:0> : <EOL> return False <EOL> return ( record . name [ self . nlen ] == "<STR_LIT:.>" ) <EOL> class Filterer ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> self . filters = [ ] <EOL> def addFilter ( self , filter ) : <EOL> """<STR_LIT>""" <EOL> if not ( filter in self . filters ) : <EOL> self . filters . append ( filter ) <EOL> def removeFilter ( self , filter ) : <EOL> """<STR_LIT>""" <EOL> if filter in self . filters : <EOL> self . filters . remove ( filter ) <EOL> def filter ( self , record ) : <EOL> """<STR_LIT>""" <EOL> rv = True <EOL> for f in self . filters : <EOL> if hasattr ( f , '<STR_LIT>' ) : <EOL> result = f . filter ( record ) <EOL> else : <EOL> result = f ( record ) <EOL> if not result : <EOL> rv = False <EOL> break <EOL> return rv <EOL> _handlers = weakref . WeakValueDictionary ( ) <EOL> _handlerList = [ ] <EOL> def _removeHandlerRef ( wr ) : <EOL> """<STR_LIT>""" <EOL> if ( _acquireLock is not None and _handlerList is not None and <EOL> _releaseLock is not None ) : <EOL> _acquireLock ( ) <EOL> try : <EOL> if wr in _handlerList : <EOL> _handlerList . remove ( wr ) <EOL> finally : <EOL> _releaseLock ( ) <EOL> def _addHandlerRef ( handler ) : <EOL> """<STR_LIT>""" <EOL> _acquireLock ( ) <EOL> try : <EOL> _handlerList . append ( weakref . ref ( handler , _removeHandlerRef ) ) <EOL> finally : <EOL> _releaseLock ( ) <EOL> class Handler ( Filterer ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , level = NOTSET ) : <EOL> """<STR_LIT>""" <EOL> Filterer . __init__ ( self ) <EOL> self . _name = None <EOL> self . level = _checkLevel ( level ) <EOL> self . formatter = None <EOL> _addHandlerRef ( self ) <EOL> self . createLock ( ) <EOL> def get_name ( self ) : <EOL> return self . _name <EOL> def set_name ( self , name ) : <EOL> _acquireLock ( ) <EOL> try : <EOL> if self . _name in _handlers : <EOL> del _handlers [ self . _name ] <EOL> self . _name = name <EOL> if name : <EOL> _handlers [ name ] = self <EOL> finally : <EOL> _releaseLock ( ) <EOL> name = property ( get_name , set_name ) <EOL> def createLock ( self ) : <EOL> """<STR_LIT>""" <EOL> if threading : <EOL> self . lock = threading . RLock ( ) <EOL> else : <EOL> self . lock = None <EOL> def acquire ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . lock : <EOL> self . lock . acquire ( ) <EOL> def release ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . lock : <EOL> self . lock . release ( ) <EOL> def setLevel ( self , level ) : <EOL> """<STR_LIT>""" <EOL> self . level = _checkLevel ( level ) <EOL> def format ( self , record ) : <EOL> """<STR_LIT>""" <EOL> if self . formatter : <EOL> fmt = self . formatter <EOL> else : <EOL> fmt = _defaultFormatter <EOL> return fmt . format ( record ) <EOL> def emit ( self , record ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def handle ( self , record ) : <EOL> """<STR_LIT>""" <EOL> rv = self . filter ( record ) <EOL> if rv : <EOL> self . acquire ( ) <EOL> try : <EOL> self . emit ( record ) <EOL> finally : <EOL> self . release ( ) <EOL> return rv <EOL> def setFormatter ( self , fmt ) : <EOL> """<STR_LIT>""" <EOL> self . formatter = fmt <EOL> def flush ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> _acquireLock ( ) <EOL> try : <EOL> if self . _name and self . _name in _handlers : <EOL> del _handlers [ self . _name ] <EOL> finally : <EOL> _releaseLock ( ) <EOL> def handleError ( self , record ) : <EOL> """<STR_LIT>""" <EOL> if raiseExceptions and sys . stderr : <EOL> ei = sys . exc_info ( ) <EOL> try : <EOL> traceback . print_exception ( ei [ <NUM_LIT:0> ] , ei [ <NUM_LIT:1> ] , ei [ <NUM_LIT:2> ] , <EOL> None , sys . stderr ) <EOL> sys . stderr . write ( '<STR_LIT>' % ( <EOL> record . filename , record . lineno ) ) <EOL> except IOError : <EOL> pass <EOL> finally : <EOL> del ei <EOL> class StreamHandler ( Handler ) : <EOL> """<STR_LIT>""" <EOL> terminator = '<STR_LIT:\n>' <EOL> def __init__ ( self , stream = None ) : <EOL> """<STR_LIT>""" <EOL> Handler . __init__ ( self ) <EOL> if stream is None : <EOL> stream = sys . stderr <EOL> self . stream = stream <EOL> def flush ( self ) : <EOL> """<STR_LIT>""" <EOL> self . acquire ( ) <EOL> try : <EOL> if self . stream and hasattr ( self . stream , "<STR_LIT>" ) : <EOL> self . stream . flush ( ) <EOL> finally : <EOL> self . release ( ) <EOL> def emit ( self , record ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> msg = self . format ( record ) <EOL> stream = self . stream <EOL> stream . write ( msg ) <EOL> stream . write ( self . terminator ) <EOL> self . flush ( ) <EOL> except ( KeyboardInterrupt , SystemExit ) : <EOL> raise <EOL> except : <EOL> self . handleError ( record ) <EOL> class FileHandler ( StreamHandler ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , filename , mode = '<STR_LIT:a>' , encoding = None , delay = False ) : <EOL> """<STR_LIT>""" <EOL> self . baseFilename = os . path . abspath ( filename ) <EOL> self . mode = mode <EOL> self . encoding = encoding <EOL> self . delay = delay <EOL> if delay : <EOL> Handler . __init__ ( self ) <EOL> self . stream = None <EOL> else : <EOL> StreamHandler . __init__ ( self , self . _open ( ) ) <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> self . acquire ( ) <EOL> try : <EOL> if self . stream : <EOL> self . flush ( ) <EOL> if hasattr ( self . stream , "<STR_LIT>" ) : <EOL> self . stream . close ( ) <EOL> StreamHandler . close ( self ) <EOL> self . stream = None <EOL> finally : <EOL> self . release ( ) <EOL> def _open ( self ) : <EOL> """<STR_LIT>""" <EOL> return open ( self . baseFilename , self . mode , encoding = self . encoding ) <EOL> def emit ( self , record ) : <EOL> """<STR_LIT>""" <EOL> if self . stream is None : <EOL> self . stream = self . _open ( ) <EOL> StreamHandler . emit ( self , record ) <EOL> class _StderrHandler ( StreamHandler ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , level = NOTSET ) : <EOL> """<STR_LIT>""" <EOL> Handler . __init__ ( self , level ) <EOL> @ property <EOL> def stream ( self ) : <EOL> return sys . stderr <EOL> _defaultLastResort = _StderrHandler ( WARNING ) <EOL> lastResort = _defaultLastResort <EOL> class PlaceHolder ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , alogger ) : <EOL> """<STR_LIT>""" <EOL> self . loggerMap = { alogger : None } <EOL> def append ( self , alogger ) : <EOL> """<STR_LIT>""" <EOL> if alogger not in self . loggerMap : <EOL> self . loggerMap [ alogger ] = None <EOL> _loggerClass = None <EOL> def setLoggerClass ( klass ) : <EOL> """<STR_LIT>""" <EOL> if klass != Logger : <EOL> if not issubclass ( klass , Logger ) : <EOL> raise TypeError ( "<STR_LIT>" <EOL> + klass . __name__ ) <EOL> global _loggerClass <EOL> _loggerClass = klass <EOL> def getLoggerClass ( ) : <EOL> """<STR_LIT>""" <EOL> return _loggerClass <EOL> class Manager ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , rootnode ) : <EOL> """<STR_LIT>""" <EOL> self . root = rootnode <EOL> self . disable = <NUM_LIT:0> <EOL> self . emittedNoHandlerWarning = False <EOL> self . loggerDict = { } <EOL> self . loggerClass = None <EOL> self . logRecordFactory = None <EOL> def getLogger ( self , name ) : <EOL> """<STR_LIT>""" <EOL> rv = None <EOL> if not isinstance ( name , str ) : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> _acquireLock ( ) <EOL> try : <EOL> if name in self . loggerDict : <EOL> rv = self . loggerDict [ name ] <EOL> if isinstance ( rv , PlaceHolder ) : <EOL> ph = rv <EOL> rv = ( self . loggerClass or _loggerClass ) ( name ) <EOL> rv . manager = self <EOL> self . loggerDict [ name ] = rv <EOL> self . _fixupChildren ( ph , rv ) <EOL> self . _fixupParents ( rv ) <EOL> else : <EOL> rv = ( self . loggerClass or _loggerClass ) ( name ) <EOL> rv . manager = self <EOL> self . loggerDict [ name ] = rv <EOL> self . _fixupParents ( rv ) <EOL> finally : <EOL> _releaseLock ( ) <EOL> return rv <EOL> def setLoggerClass ( self , klass ) : <EOL> """<STR_LIT>""" <EOL> if klass != Logger : <EOL> if not issubclass ( klass , Logger ) : <EOL> raise TypeError ( "<STR_LIT>" <EOL> + klass . __name__ ) <EOL> self . loggerClass = klass <EOL> def setLogRecordFactory ( self , factory ) : <EOL> """<STR_LIT>""" <EOL> self . logRecordFactory = factory <EOL> def _fixupParents ( self , alogger ) : <EOL> """<STR_LIT>""" <EOL> name = alogger . name <EOL> i = name . rfind ( "<STR_LIT:.>" ) <EOL> rv = None <EOL> while ( i > <NUM_LIT:0> ) and not rv : <EOL> substr = name [ : i ] <EOL> if substr not in self . loggerDict : <EOL> self . loggerDict [ substr ] = PlaceHolder ( alogger ) <EOL> else : <EOL> obj = self . loggerDict [ substr ] <EOL> if isinstance ( obj , Logger ) : <EOL> rv = obj <EOL> else : <EOL> assert isinstance ( obj , PlaceHolder ) <EOL> obj . append ( alogger ) <EOL> i = name . rfind ( "<STR_LIT:.>" , <NUM_LIT:0> , i - <NUM_LIT:1> ) <EOL> if not rv : <EOL> rv = self . root <EOL> alogger . parent = rv <EOL> def _fixupChildren ( self , ph , alogger ) : <EOL> """<STR_LIT>""" <EOL> name = alogger . name <EOL> namelen = len ( name ) <EOL> for c in ph . loggerMap . keys ( ) : <EOL> if c . parent . name [ : namelen ] != name : <EOL> alogger . parent = c . parent <EOL> c . parent = alogger <EOL> class Logger ( Filterer ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , level = NOTSET ) : <EOL> """<STR_LIT>""" <EOL> Filterer . __init__ ( self ) <EOL> self . name = name <EOL> self . level = _checkLevel ( level ) <EOL> self . parent = None <EOL> self . propagate = True <EOL> self . handlers = [ ] <EOL> self . disabled = False <EOL> def setLevel ( self , level ) : <EOL> """<STR_LIT>""" <EOL> self . level = _checkLevel ( level ) <EOL> def debug ( self , msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if self . isEnabledFor ( DEBUG ) : <EOL> self . _log ( DEBUG , msg , args , ** kwargs ) <EOL> def info ( self , msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if self . isEnabledFor ( INFO ) : <EOL> self . _log ( INFO , msg , args , ** kwargs ) <EOL> def warning ( self , msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if self . isEnabledFor ( WARNING ) : <EOL> self . _log ( WARNING , msg , args , ** kwargs ) <EOL> def warn ( self , msg , * args , ** kwargs ) : <EOL> warnings . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" , DeprecationWarning , <NUM_LIT:2> ) <EOL> self . warning ( msg , * args , ** kwargs ) <EOL> def error ( self , msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if self . isEnabledFor ( ERROR ) : <EOL> self . _log ( ERROR , msg , args , ** kwargs ) <EOL> def exception ( self , msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> self . error ( msg , * args , ** kwargs ) <EOL> def critical ( self , msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if self . isEnabledFor ( CRITICAL ) : <EOL> self . _log ( CRITICAL , msg , args , ** kwargs ) <EOL> fatal = critical <EOL> def log ( self , level , msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( level , int ) : <EOL> if raiseExceptions : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> else : <EOL> return <EOL> if self . isEnabledFor ( level ) : <EOL> self . _log ( level , msg , args , ** kwargs ) <EOL> def findCaller ( self , stack_info = False ) : <EOL> """<STR_LIT>""" <EOL> f = currentframe ( ) <EOL> if f is not None : <EOL> f = f . f_back <EOL> rv = "<STR_LIT>" , <NUM_LIT:0> , "<STR_LIT>" , None <EOL> while hasattr ( f , "<STR_LIT>" ) : <EOL> co = f . f_code <EOL> filename = os . path . normcase ( co . co_filename ) <EOL> if filename == _srcfile : <EOL> f = f . f_back <EOL> continue <EOL> sinfo = None <EOL> if stack_info : <EOL> sio = io . StringIO ( ) <EOL> sio . write ( '<STR_LIT>' ) <EOL> traceback . print_stack ( f , file = sio ) <EOL> sinfo = sio . getvalue ( ) <EOL> if sinfo [ - <NUM_LIT:1> ] == '<STR_LIT:\n>' : <EOL> sinfo = sinfo [ : - <NUM_LIT:1> ] <EOL> sio . close ( ) <EOL> rv = ( co . co_filename , f . f_lineno , co . co_name , sinfo ) <EOL> break <EOL> return rv <EOL> def makeRecord ( self , name , level , fn , lno , msg , args , exc_info , <EOL> func = None , extra = None , sinfo = None ) : <EOL> """<STR_LIT>""" <EOL> rv = _logRecordFactory ( name , level , fn , lno , msg , args , exc_info , func , <EOL> sinfo ) <EOL> if extra is not None : <EOL> for key in extra : <EOL> if ( key in [ "<STR_LIT:message>" , "<STR_LIT>" ] ) or ( key in rv . __dict__ ) : <EOL> raise KeyError ( "<STR_LIT>" % key ) <EOL> rv . __dict__ [ key ] = extra [ key ] <EOL> return rv <EOL> def _log ( self , level , msg , args , exc_info = None , extra = None , stack_info = False ) : <EOL> """<STR_LIT>""" <EOL> sinfo = None <EOL> if _srcfile : <EOL> try : <EOL> fn , lno , func , sinfo = self . findCaller ( stack_info ) <EOL> except ValueError : <EOL> fn , lno , func = "<STR_LIT>" , <NUM_LIT:0> , "<STR_LIT>" <EOL> else : <EOL> fn , lno , func = "<STR_LIT>" , <NUM_LIT:0> , "<STR_LIT>" <EOL> if exc_info : <EOL> if not isinstance ( exc_info , tuple ) : <EOL> exc_info = sys . exc_info ( ) <EOL> record = self . makeRecord ( self . name , level , fn , lno , msg , args , <EOL> exc_info , func , extra , sinfo ) <EOL> self . handle ( record ) <EOL> def handle ( self , record ) : <EOL> """<STR_LIT>""" <EOL> if ( not self . disabled ) and self . filter ( record ) : <EOL> self . callHandlers ( record ) <EOL> def addHandler ( self , hdlr ) : <EOL> """<STR_LIT>""" <EOL> _acquireLock ( ) <EOL> try : <EOL> if not ( hdlr in self . handlers ) : <EOL> self . handlers . append ( hdlr ) <EOL> finally : <EOL> _releaseLock ( ) <EOL> def removeHandler ( self , hdlr ) : <EOL> """<STR_LIT>""" <EOL> _acquireLock ( ) <EOL> try : <EOL> if hdlr in self . handlers : <EOL> self . handlers . remove ( hdlr ) <EOL> finally : <EOL> _releaseLock ( ) <EOL> def hasHandlers ( self ) : <EOL> """<STR_LIT>""" <EOL> c = self <EOL> rv = False <EOL> while c : <EOL> if c . handlers : <EOL> rv = True <EOL> break <EOL> if not c . propagate : <EOL> break <EOL> else : <EOL> c = c . parent <EOL> return rv <EOL> def callHandlers ( self , record ) : <EOL> """<STR_LIT>""" <EOL> c = self <EOL> found = <NUM_LIT:0> <EOL> while c : <EOL> for hdlr in c . handlers : <EOL> found = found + <NUM_LIT:1> <EOL> if record . levelno >= hdlr . level : <EOL> hdlr . handle ( record ) <EOL> if not c . propagate : <EOL> c = None <EOL> else : <EOL> c = c . parent <EOL> if ( found == <NUM_LIT:0> ) : <EOL> if lastResort : <EOL> if record . levelno >= lastResort . level : <EOL> lastResort . handle ( record ) <EOL> elif raiseExceptions and not self . manager . emittedNoHandlerWarning : <EOL> sys . stderr . write ( "<STR_LIT>" <EOL> "<STR_LIT>" % self . name ) <EOL> self . manager . emittedNoHandlerWarning = True <EOL> def getEffectiveLevel ( self ) : <EOL> """<STR_LIT>""" <EOL> logger = self <EOL> while logger : <EOL> if logger . level : <EOL> return logger . level <EOL> logger = logger . parent <EOL> return NOTSET <EOL> def isEnabledFor ( self , level ) : <EOL> """<STR_LIT>""" <EOL> if self . manager . disable >= level : <EOL> return False <EOL> return level >= self . getEffectiveLevel ( ) <EOL> def getChild ( self , suffix ) : <EOL> """<STR_LIT>""" <EOL> if self . root is not self : <EOL> suffix = '<STR_LIT:.>' . join ( ( self . name , suffix ) ) <EOL> return self . manager . getLogger ( suffix ) <EOL> class RootLogger ( Logger ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , level ) : <EOL> """<STR_LIT>""" <EOL> Logger . __init__ ( self , "<STR_LIT:root>" , level ) <EOL> _loggerClass = Logger <EOL> class LoggerAdapter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , logger , extra ) : <EOL> """<STR_LIT>""" <EOL> self . logger = logger <EOL> self . extra = extra <EOL> def process ( self , msg , kwargs ) : <EOL> """<STR_LIT>""" <EOL> kwargs [ "<STR_LIT>" ] = self . extra <EOL> return msg , kwargs <EOL> def debug ( self , msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . log ( DEBUG , msg , * args , ** kwargs ) <EOL> def info ( self , msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . log ( INFO , msg , * args , ** kwargs ) <EOL> def warning ( self , msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . log ( WARNING , msg , * args , ** kwargs ) <EOL> def warn ( self , msg , * args , ** kwargs ) : <EOL> warnings . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" , DeprecationWarning , <NUM_LIT:2> ) <EOL> self . warning ( msg , * args , ** kwargs ) <EOL> def error ( self , msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . log ( ERROR , msg , * args , ** kwargs ) <EOL> def exception ( self , msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> kwargs [ "<STR_LIT>" ] = True <EOL> self . log ( ERROR , msg , * args , ** kwargs ) <EOL> def critical ( self , msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . log ( CRITICAL , msg , * args , ** kwargs ) <EOL> def log ( self , level , msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if self . isEnabledFor ( level ) : <EOL> msg , kwargs = self . process ( msg , kwargs ) <EOL> self . logger . _log ( level , msg , args , ** kwargs ) <EOL> def isEnabledFor ( self , level ) : <EOL> """<STR_LIT>""" <EOL> if self . logger . manager . disable >= level : <EOL> return False <EOL> return level >= self . getEffectiveLevel ( ) <EOL> def setLevel ( self , level ) : <EOL> """<STR_LIT>""" <EOL> self . logger . setLevel ( level ) <EOL> def getEffectiveLevel ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . logger . getEffectiveLevel ( ) <EOL> def hasHandlers ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . logger . hasHandlers ( ) <EOL> root = RootLogger ( WARNING ) <EOL> Logger . root = root <EOL> Logger . manager = Manager ( Logger . root ) <EOL> BASIC_FORMAT = "<STR_LIT>" <EOL> def basicConfig ( ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> _acquireLock ( ) <EOL> try : <EOL> if len ( root . handlers ) == <NUM_LIT:0> : <EOL> handlers = kwargs . get ( "<STR_LIT>" ) <EOL> if handlers is None : <EOL> if "<STR_LIT>" in kwargs and "<STR_LIT:filename>" in kwargs : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> if "<STR_LIT>" in kwargs or "<STR_LIT:filename>" in kwargs : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if handlers is None : <EOL> filename = kwargs . get ( "<STR_LIT:filename>" ) <EOL> if filename : <EOL> mode = kwargs . get ( "<STR_LIT>" , '<STR_LIT:a>' ) <EOL> h = FileHandler ( filename , mode ) <EOL> else : <EOL> stream = kwargs . get ( "<STR_LIT>" ) <EOL> h = StreamHandler ( stream ) <EOL> handlers = [ h ] <EOL> fs = kwargs . get ( "<STR_LIT>" , BASIC_FORMAT ) <EOL> dfs = kwargs . get ( "<STR_LIT>" , None ) <EOL> style = kwargs . get ( "<STR_LIT>" , '<STR_LIT:%>' ) <EOL> fmt = Formatter ( fs , dfs , style ) <EOL> for h in handlers : <EOL> if h . formatter is None : <EOL> h . setFormatter ( fmt ) <EOL> root . addHandler ( h ) <EOL> level = kwargs . get ( "<STR_LIT>" ) <EOL> if level is not None : <EOL> root . setLevel ( level ) <EOL> finally : <EOL> _releaseLock ( ) <EOL> def getLogger ( name = None ) : <EOL> """<STR_LIT>""" <EOL> if name : <EOL> return Logger . manager . getLogger ( name ) <EOL> else : <EOL> return root <EOL> def critical ( msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if len ( root . handlers ) == <NUM_LIT:0> : <EOL> basicConfig ( ) <EOL> root . critical ( msg , * args , ** kwargs ) <EOL> fatal = critical <EOL> def error ( msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if len ( root . handlers ) == <NUM_LIT:0> : <EOL> basicConfig ( ) <EOL> root . error ( msg , * args , ** kwargs ) <EOL> def exception ( msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> error ( msg , * args , ** kwargs ) <EOL> def warning ( msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if len ( root . handlers ) == <NUM_LIT:0> : <EOL> basicConfig ( ) <EOL> root . warning ( msg , * args , ** kwargs ) <EOL> def warn ( msg , * args , ** kwargs ) : <EOL> warnings . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" , DeprecationWarning , <NUM_LIT:2> ) <EOL> warning ( msg , * args , ** kwargs ) <EOL> def info ( msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if len ( root . handlers ) == <NUM_LIT:0> : <EOL> basicConfig ( ) <EOL> root . info ( msg , * args , ** kwargs ) <EOL> def debug ( msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if len ( root . handlers ) == <NUM_LIT:0> : <EOL> basicConfig ( ) <EOL> root . debug ( msg , * args , ** kwargs ) <EOL> def log ( level , msg , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if len ( root . handlers ) == <NUM_LIT:0> : <EOL> basicConfig ( ) <EOL> root . log ( level , msg , * args , ** kwargs ) <EOL> def disable ( level ) : <EOL> """<STR_LIT>""" <EOL> root . manager . disable = level <EOL> def shutdown ( handlerList = _handlerList ) : <EOL> """<STR_LIT>""" <EOL> for wr in reversed ( handlerList [ : ] ) : <EOL> try : <EOL> h = wr ( ) <EOL> if h : <EOL> try : <EOL> h . acquire ( ) <EOL> h . flush ( ) <EOL> h . close ( ) <EOL> except ( IOError , ValueError ) : <EOL> pass <EOL> finally : <EOL> h . release ( ) <EOL> except : <EOL> if raiseExceptions : <EOL> raise <EOL> import atexit <EOL> atexit . register ( shutdown ) <EOL> class NullHandler ( Handler ) : <EOL> """<STR_LIT>""" <EOL> def handle ( self , record ) : <EOL> """<STR_LIT>""" <EOL> def emit ( self , record ) : <EOL> """<STR_LIT>""" <EOL> def createLock ( self ) : <EOL> self . lock = None <EOL> _warnings_showwarning = None <EOL> def _showwarning ( message , category , filename , lineno , file = None , line = None ) : <EOL> """<STR_LIT>""" <EOL> if file is not None : <EOL> if _warnings_showwarning is not None : <EOL> _warnings_showwarning ( message , category , filename , lineno , file , line ) <EOL> else : <EOL> s = warnings . formatwarning ( message , category , filename , lineno , line ) <EOL> logger = getLogger ( "<STR_LIT>" ) <EOL> if not logger . handlers : <EOL> logger . addHandler ( NullHandler ( ) ) <EOL> logger . warning ( "<STR_LIT:%s>" , s ) <EOL> def captureWarnings ( capture ) : <EOL> """<STR_LIT>""" <EOL> global _warnings_showwarning <EOL> if capture : <EOL> if _warnings_showwarning is None : <EOL> _warnings_showwarning = warnings . showwarning <EOL> warnings . showwarning = _showwarning <EOL> else : <EOL> if _warnings_showwarning is not None : <EOL> warnings . showwarning = _warnings_showwarning <EOL> _warnings_showwarning = None </s>
