<s> from . toplevel import * <EOL> def closure ( ) : <EOL> term_mode = True <EOL> import sys <EOL> if not hasattr ( sys , '<STR_LIT>' ) : <EOL> return <EOL> import string , collections <EOL> global args <EOL> args = collections . defaultdict ( str ) <EOL> def isident ( s ) : <EOL> first = string . uppercase + '<STR_LIT:_>' <EOL> body = string . digits + first <EOL> if not s : <EOL> return False <EOL> if s [ <NUM_LIT:0> ] not in first : <EOL> return False <EOL> if not all ( c in body for c in s [ <NUM_LIT:1> : ] ) : <EOL> return False <EOL> return True <EOL> def asbool ( s ) : <EOL> if s . lower ( ) == '<STR_LIT:true>' : <EOL> return True <EOL> elif s . lower ( ) == '<STR_LIT:false>' : <EOL> return False <EOL> elif s . isdigit ( ) : <EOL> return bool ( int ( s ) ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> for k , v in os . environ . items ( ) : <EOL> if not k . startswith ( '<STR_LIT>' ) : <EOL> continue <EOL> k = k [ <NUM_LIT:7> : ] <EOL> if k == '<STR_LIT>' : <EOL> if asbool ( v ) : <EOL> context . log_level = '<STR_LIT>' <EOL> elif k == '<STR_LIT>' : <EOL> if asbool ( v ) : <EOL> context . log_level = '<STR_LIT>' <EOL> elif k == '<STR_LIT>' : <EOL> if asbool ( v ) : <EOL> term_mode = False <EOL> elif isident ( k ) : <EOL> args [ k ] = v <EOL> argv = sys . argv [ : ] <EOL> for arg in argv : <EOL> if arg == '<STR_LIT>' : <EOL> sys . argv . remove ( arg ) <EOL> context . log_level = '<STR_LIT>' <EOL> elif arg == '<STR_LIT>' : <EOL> sys . argv . remove ( arg ) <EOL> context . log_level = '<STR_LIT>' <EOL> elif arg == '<STR_LIT>' : <EOL> term_mode = False <EOL> elif arg . find ( '<STR_LIT:=>' ) > <NUM_LIT:0> : <EOL> k , v = arg . split ( '<STR_LIT:=>' , <NUM_LIT:1> ) <EOL> if not isident ( k ) : <EOL> continue <EOL> sys . argv . remove ( arg ) <EOL> args [ k ] = v <EOL> if '<STR_LIT>' in args : <EOL> context . log_level = args [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in args : <EOL> import logging , time <EOL> modes = ( '<STR_LIT:w>' , '<STR_LIT:wb>' , '<STR_LIT:a>' , '<STR_LIT>' ) <EOL> filename = args [ '<STR_LIT>' ] <EOL> mode = '<STR_LIT:a>' <EOL> if '<STR_LIT:U+002C>' in filename : <EOL> filename_ , mode_ = filename . rsplit ( '<STR_LIT:U+002C>' , <NUM_LIT:1> ) <EOL> if mode in modes : <EOL> filename = filename_ <EOL> mode = mode_ <EOL> dfmt = '<STR_LIT>' <EOL> with open ( filename , mode ) as fd : <EOL> lines = [ <EOL> '<STR_LIT:=>' * <NUM_LIT> , <EOL> '<STR_LIT>' % time . strftime ( dfmt ) , <EOL> '<STR_LIT>' , <EOL> ] <EOL> for arg in argv : <EOL> lines . append ( '<STR_LIT>' % arg ) <EOL> lines . append ( '<STR_LIT>' ) <EOL> lines . append ( '<STR_LIT:=>' * <NUM_LIT> ) <EOL> for line in lines : <EOL> fd . write ( '<STR_LIT>' % line . ljust ( <NUM_LIT> ) ) <EOL> mode = mode . replace ( '<STR_LIT:w>' , '<STR_LIT:a>' ) <EOL> handler = logging . FileHandler ( filename , mode ) <EOL> fmt = '<STR_LIT>' <EOL> formatter = logging . Formatter ( fmt , dfmt ) <EOL> handler . setFormatter ( formatter ) <EOL> logging . root . addHandler ( handler ) <EOL> if term_mode : <EOL> term . init ( ) <EOL> import pwnlib . log as log <EOL> import logging <EOL> log . rootlogger . setLevel ( logging . DEBUG ) <EOL> log . install_default_handler ( ) <EOL> closure ( ) <EOL> del closure <EOL> log = getLogger ( '<STR_LIT>' ) </s>
