<s> import re <EOL> import sys <EOL> import inspect <EOL> import traceback <EOL> from stewbot . interfaces . ILogger import ILogger <EOL> from stewbot . components . Interface import Interface <EOL> from stewbot . components . LogSilent import LogSilent <EOL> from stewbot . components . modules . Formatting import Formatting <EOL> class BaseClass ( object ) : <EOL> """<STR_LIT>""" <EOL> class Error ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class LoginTokenRequestedError ( Error ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , logger ) : <EOL> """<STR_LIT>""" <EOL> self . logger = logger <EOL> self . re_address = re . compile ( '<STR_LIT>' ) <EOL> self . re_ipv6_address = re . compile ( <EOL> '<STR_LIT>' + '<STR_LIT>' + '<STR_LIT>' + '<STR_LIT>' <EOL> ) <EOL> Interface . Assert ( self . logger , ILogger ) <EOL> def Decode ( self , input ) : <EOL> """<STR_LIT>""" <EOL> return Formatting . Decode ( input ) <EOL> def Encode ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> return Formatting . Encode ( obj ) <EOL> def UrlEncode ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> return Formatting . UrlEncode ( obj ) <EOL> def capitalizeFirstLetter ( self , text ) : <EOL> """<STR_LIT>""" <EOL> self . trace ( ) <EOL> if text [ <NUM_LIT:0> ] . isupper ( ) : <EOL> return text <EOL> else : <EOL> text = list ( text ) <EOL> text [ <NUM_LIT:0> ] = text [ <NUM_LIT:0> ] . upper ( ) <EOL> text = '<STR_LIT>' . join ( text ) <EOL> return text <EOL> def isAddress ( self , text ) : <EOL> """<STR_LIT>""" <EOL> self . trace ( ) <EOL> return self . re_address . match ( text ) or self . re_ipv6_address . match ( text ) <EOL> def isInt ( self , text ) : <EOL> """<STR_LIT>""" <EOL> self . trace ( ) <EOL> try : <EOL> int ( text ) <EOL> return True <EOL> except TypeError : <EOL> return False <EOL> except ValueError : <EOL> return False <EOL> def trace ( self , overrides = None ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( self . logger , LogSilent ) : <EOL> try : <EOL> frame = inspect . stack ( ) [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> module = inspect . getmodule ( frame . f_code ) <EOL> if module is not None : <EOL> module = module . __name__ <EOL> else : <EOL> module = "<STR_LIT>" <EOL> function = frame . f_code . co_name <EOL> args = inspect . getargvalues ( frame ) <EOL> if overrides : <EOL> for k in overrides . keys ( ) : <EOL> args [ <NUM_LIT:3> ] [ k ] = overrides [ k ] <EOL> if args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> args [ <NUM_LIT:0> ] . pop ( <NUM_LIT:0> ) <EOL> del args [ <NUM_LIT:3> ] [ '<STR_LIT>' ] <EOL> arg_string = inspect . formatargvalues ( <EOL> args = args [ <NUM_LIT:0> ] , <EOL> varargs = args [ <NUM_LIT:1> ] , <EOL> varkw = args [ <NUM_LIT:2> ] , <EOL> locals = args [ <NUM_LIT:3> ] , <EOL> formatvalue = lambda v : u'<STR_LIT>' % self . _FormatArg ( self . Decode ( v ) ) <EOL> ) <EOL> self . logger . Log ( '<STR_LIT>' % ( module , function , arg_string ) ) <EOL> finally : <EOL> del frame <EOL> def traceMessage ( self , msg ) : <EOL> """<STR_LIT>""" <EOL> self . logger . Log ( msg ) <EOL> def HandleException ( self ) : <EOL> """<STR_LIT>""" <EOL> self . trace ( ) <EOL> ( type , value , tb ) = sys . exc_info ( ) <EOL> tb = traceback . format_exc ( ) <EOL> logExc = '<STR_LIT:\n>' <EOL> logExc += '<STR_LIT>' <EOL> logExc += '<STR_LIT>' <EOL> logExc += '<STR_LIT>' <EOL> logExc += '<STR_LIT>' % '<STR_LIT>' . join ( tb . splitlines ( ) ) <EOL> logExc += '<STR_LIT>' <EOL> logExc += '<STR_LIT>' <EOL> self . logger . Log ( logExc ) <EOL> tb_last = traceback . format_exc ( ) . splitlines ( ) <EOL> tb_last = tb_last [ len ( tb_last ) - <NUM_LIT:3> ] <EOL> return ( <EOL> "<STR_LIT>" % ( type . __name__ , str ( value ) , str ( tb_last ) ) , <EOL> logExc <EOL> ) <EOL> def _FormatArg ( self , value ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( value , BaseClass ) : <EOL> return u'<STR_LIT>' % inspect . getmodule ( value ) . __name__ <EOL> elif inspect . ismethod ( value ) : <EOL> return u'<STR_LIT>' % ( inspect . getmodule ( value ) . __name__ , value . __name__ ) <EOL> elif inspect . isfunction ( value ) : <EOL> return u'<STR_LIT>' % value . __name__ <EOL> else : <EOL> return value </s>
