<s> from inspect import getcallargs <EOL> from functools import wraps <EOL> import logging <EOL> import inspect <EOL> import time <EOL> _TIME_FUNC_ID = <NUM_LIT:0> <EOL> def _log_debug_as_f ( f , msg , msg_args ) : <EOL> name = f . __module__ <EOL> logger = logging . getLogger ( name ) <EOL> if logger . isEnabledFor ( logging . DEBUG ) : <EOL> lineno = f . func_code . co_firstlineno <EOL> pathname = f . func_code . co_filename <EOL> record = logging . LogRecord ( <EOL> name = name , <EOL> level = logging . DEBUG , <EOL> pathname = pathname , <EOL> lineno = lineno , <EOL> msg = msg , <EOL> args = msg_args , <EOL> exc_info = None <EOL> ) <EOL> logger . handle ( record ) <EOL> def log_function ( f ) : <EOL> """<STR_LIT>""" <EOL> func_name = f . __name__ <EOL> @ wraps ( f ) <EOL> def wrapped ( * args , ** kwargs ) : <EOL> name = f . __module__ <EOL> logger = logging . getLogger ( name ) <EOL> level = logging . DEBUG <EOL> if logger . isEnabledFor ( level ) : <EOL> bound_args = getcallargs ( f , * args , ** kwargs ) <EOL> def format ( value ) : <EOL> r = str ( value ) <EOL> if len ( r ) > <NUM_LIT:50> : <EOL> r = r [ : <NUM_LIT:50> ] + "<STR_LIT>" <EOL> return r <EOL> func_args = [ <EOL> "<STR_LIT>" % ( k , format ( v ) ) for k , v in bound_args . items ( ) <EOL> ] <EOL> msg_args = { <EOL> "<STR_LIT>" : func_name , <EOL> "<STR_LIT:args>" : "<STR_LIT:U+002CU+0020>" . join ( func_args ) <EOL> } <EOL> _log_debug_as_f ( <EOL> f , <EOL> "<STR_LIT>" , <EOL> msg_args <EOL> ) <EOL> return f ( * args , ** kwargs ) <EOL> wrapped . __name__ = func_name <EOL> return wrapped <EOL> def time_function ( f ) : <EOL> func_name = f . __name__ <EOL> @ wraps ( f ) <EOL> def wrapped ( * args , ** kwargs ) : <EOL> global _TIME_FUNC_ID <EOL> id = _TIME_FUNC_ID <EOL> _TIME_FUNC_ID += <NUM_LIT:1> <EOL> start = time . clock ( ) * <NUM_LIT:1000> <EOL> try : <EOL> _log_debug_as_f ( <EOL> f , <EOL> "<STR_LIT>" , <EOL> ( func_name , id ) , <EOL> ) <EOL> r = f ( * args , ** kwargs ) <EOL> finally : <EOL> end = time . clock ( ) * <NUM_LIT:1000> <EOL> _log_debug_as_f ( <EOL> f , <EOL> "<STR_LIT>" , <EOL> ( func_name , id , end - start , ) , <EOL> ) <EOL> return r <EOL> return wrapped <EOL> def trace_function ( f ) : <EOL> func_name = f . __name__ <EOL> linenum = f . func_code . co_firstlineno <EOL> pathname = f . func_code . co_filename <EOL> @ wraps ( f ) <EOL> def wrapped ( * args , ** kwargs ) : <EOL> name = f . __module__ <EOL> logger = logging . getLogger ( name ) <EOL> level = logging . DEBUG <EOL> s = inspect . currentframe ( ) . f_back <EOL> to_print = [ <EOL> "<STR_LIT>" % ( <EOL> pathname , linenum , func_name , args , kwargs <EOL> ) <EOL> ] <EOL> while s : <EOL> if True or s . f_globals [ "<STR_LIT>" ] . startswith ( "<STR_LIT>" ) : <EOL> filename , lineno , function , _ , _ = inspect . getframeinfo ( s ) <EOL> args_string = inspect . formatargvalues ( * inspect . getargvalues ( s ) ) <EOL> to_print . append ( <EOL> "<STR_LIT>" % ( <EOL> filename , lineno , function , args_string <EOL> ) <EOL> ) <EOL> s = s . f_back <EOL> msg = "<STR_LIT>" % ( func_name , ) + "<STR_LIT:\n>" . join ( to_print ) <EOL> record = logging . LogRecord ( <EOL> name = name , <EOL> level = level , <EOL> pathname = pathname , <EOL> lineno = lineno , <EOL> msg = msg , <EOL> args = None , <EOL> exc_info = None <EOL> ) <EOL> logger . handle ( record ) <EOL> return f ( * args , ** kwargs ) <EOL> wrapped . __name__ = func_name <EOL> return wrapped <EOL> def get_previous_frames ( ) : <EOL> s = inspect . currentframe ( ) . f_back . f_back <EOL> to_return = [ ] <EOL> while s : <EOL> if s . f_globals [ "<STR_LIT>" ] . startswith ( "<STR_LIT>" ) : <EOL> filename , lineno , function , _ , _ = inspect . getframeinfo ( s ) <EOL> args_string = inspect . formatargvalues ( * inspect . getargvalues ( s ) ) <EOL> to_return . append ( "<STR_LIT>" % ( <EOL> filename , lineno , function , args_string <EOL> ) ) <EOL> s = s . f_back <EOL> return "<STR_LIT:U+002CU+0020>" . join ( to_return ) <EOL> def get_previous_frame ( ignore = [ ] ) : <EOL> s = inspect . currentframe ( ) . f_back . f_back <EOL> while s : <EOL> if s . f_globals [ "<STR_LIT>" ] . startswith ( "<STR_LIT>" ) : <EOL> if not any ( s . f_globals [ "<STR_LIT>" ] . startswith ( ig ) for ig in ignore ) : <EOL> filename , lineno , function , _ , _ = inspect . getframeinfo ( s ) <EOL> args_string = inspect . formatargvalues ( * inspect . getargvalues ( s ) ) <EOL> return "<STR_LIT>" % ( <EOL> filename , lineno , function , args_string <EOL> ) <EOL> s = s . f_back <EOL> return None </s>
