<s> import re <EOL> func_type = { <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : <NUM_LIT:3> , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> } <EOL> short_names = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:None>' : '<STR_LIT>' , <EOL> '<STR_LIT:True>' : '<STR_LIT>' , <EOL> '<STR_LIT:False>' : '<STR_LIT>' , <EOL> '<STR_LIT:bool>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> class Replacement ( object ) : <EOL> re_p = re . compile ( '''<STR_LIT>''' ) <EOL> def substitute ( self , src , names ) : <EOL> def subs ( m ) : <EOL> indent_level = int ( m . group ( <NUM_LIT:1> ) ) <EOL> args = m . group ( <NUM_LIT:0> ) [ : - <NUM_LIT:1> ] . split ( '<STR_LIT:U+002C>' ) [ <NUM_LIT:1> : ] <EOL> args = [ i . strip ( ) for i in m . group ( <NUM_LIT:0> ) [ : - <NUM_LIT:2> ] . split ( '<STR_LIT:U+002C>' ) [ <NUM_LIT:1> : ] ] <EOL> name , args = args [ <NUM_LIT:0> ] , args [ <NUM_LIT:1> : ] <EOL> if name in short_names : <EOL> return short_names [ name ] <EOL> try : <EOL> repl = getattr ( self , '<STR_LIT>' % name , None ) ( * args ) <EOL> except : <EOL> print '<STR_LIT>' , name , args <EOL> raise <EOL> lines = [ '<STR_LIT>' % ( <EOL> '<STR_LIT:U+0020>' * indent_level , <EOL> line , <EOL> ) for line in repl . split ( '<STR_LIT:\n>' ) ] <EOL> return "<STR_LIT:\n>" . join ( lines ) <EOL> dst = self . re_p . sub ( subs , src ) <EOL> for name in names : <EOL> if isinstance ( names [ name ] , basestring ) : <EOL> dst = dst . replace ( '<STR_LIT>' % name , names [ name ] ) <EOL> return dst <EOL> def repl_g ( self ) : <EOL> return short_names [ '<STR_LIT>' ] <EOL> def repl_l ( self ) : <EOL> return short_names [ '<STR_LIT>' ] <EOL> return '<STR_LIT>' <EOL> def repl_new_bool ( self , value , true , false ) : <EOL> return self . substitute ( """<STR_LIT>""" , locals ( ) ) <EOL> def repl_jsmethod ( self ) : <EOL> return str ( func_type [ '<STR_LIT>' ] ) <EOL> def repl_function ( self ) : <EOL> return str ( func_type [ '<STR_LIT>' ] ) <EOL> def repl_classmethod ( self ) : <EOL> return str ( func_type [ '<STR_LIT>' ] ) <EOL> def repl_staticmethod ( self ) : <EOL> return str ( func_type [ '<STR_LIT>' ] ) <EOL> def repl_wrappermethod ( self ) : <EOL> return str ( func_type [ '<STR_LIT>' ] ) <EOL> def repl_call_head ( self , skip ) : <EOL> return self . substitute ( """<STR_LIT>""" , locals ( ) ) <EOL> def repl_call_method ( self ) : <EOL> return self . substitute ( """<STR_LIT>""" , locals ( ) ) <EOL> def repl_call_object ( self ) : <EOL> return self . substitute ( """<STR_LIT>""" , locals ( ) ) <EOL> def repl_call_star_dstar ( self ) : <EOL> return self . substitute ( """<STR_LIT>""" , locals ( ) ) <EOL> def repl_call_tail ( self ) : <EOL> return self . substitute ( """<STR_LIT>""" , locals ( ) ) <EOL> def repl___new__ ( self , instance , cls , add_dict = True ) : <EOL> if add_dict is not True : <EOL> if add_dict . lower ( ) . strip ( ) == '<STR_LIT:false>' : <EOL> add_dict = False <EOL> else : <EOL> add_dict = True <EOL> if add_dict : <EOL> add_dict = """<STR_LIT>""" <EOL> else : <EOL> add_dict = '<STR_LIT>' <EOL> return self . substitute ( """<STR_LIT>""" % locals ( ) , locals ( ) ) <EOL> def repl_create_instance ( self , args , cls , mcall , fcall ) : <EOL> return self . substitute ( """<STR_LIT>""" , locals ( ) ) <EOL> def repl_bind_method ( self , dst , src , obj , meth_src ) : <EOL> return self . substitute ( """<STR_LIT>""" , locals ( ) ) <EOL> def repl_attr_args_validate ( self , _self , name ) : <EOL> return self . substitute ( """<STR_LIT>""" , locals ( ) ) <EOL> def repl_getattribute ( self , mro , dst , src , name , break_after_instance = False ) : <EOL> if break_after_instance : <EOL> break_after_instance = '<STR_LIT>' <EOL> else : <EOL> break_after_instance = '<STR_LIT>' <EOL> return self . substitute ( """<STR_LIT>""" , locals ( ) ) <EOL> def repl_getattributes ( self , dst , src , name , value ) : <EOL> return self . substitute ( """<STR_LIT>""" , locals ( ) ) <EOL> def repl_type_class ( self , cls , module , clsname , bases , dict ) : <EOL> return self . substitute ( """<STR_LIT>""" , locals ( ) ) <EOL> def repl_hash ( self , obj , dst ) : <EOL> return self . substitute ( """<STR_LIT>""" % locals ( ) , locals ( ) ) <EOL> def repl_op_compare ( self , op , a , b , val1 , val2 ) : <EOL> if op in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . substitute ( """<STR_LIT>""" % locals ( ) , locals ( ) ) <EOL> if op in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return self . substitute ( """<STR_LIT>""" % locals ( ) , locals ( ) ) <EOL> valnull = '<STR_LIT>' <EOL> if not '<STR_LIT:=>' in op : <EOL> opis = '<STR_LIT>' <EOL> elif op == '<STR_LIT>' : <EOL> opis = '<STR_LIT>' <EOL> valnull = '<STR_LIT>' <EOL> else : <EOL> opis = '<STR_LIT>' <EOL> opis = '<STR_LIT>' <EOL> return self . substitute ( """<STR_LIT>""" % locals ( ) , locals ( ) ) <EOL> def repl_op_arithmetic ( self , op , opname , x , y , i , opfunc = None ) : <EOL> jsop = op <EOL> if opfunc is None : <EOL> opnumber = "<STR_LIT>" % op <EOL> elif opfunc == '<STR_LIT>' : <EOL> jsop = '<STR_LIT:/>' <EOL> opnumber = "<STR_LIT>" % ( opfunc , jsop ) <EOL> elif opfunc == '<STR_LIT>' : <EOL> opnumber = "<STR_LIT>" % op <EOL> opnumber = "<STR_LIT>" % op <EOL> else : <EOL> opnumber = "<STR_LIT>" % opfunc <EOL> if op in [ '<STR_LIT:/>' , '<STR_LIT>' , '<STR_LIT:%>' ] : <EOL> zerodiv = "<STR_LIT>" ; <EOL> else : <EOL> zerodiv = '<STR_LIT>' <EOL> return self . substitute ( """<STR_LIT>""" % locals ( ) , locals ( ) ) <EOL> def repl_op_bitexpr2 ( self , op , opname , x , y ) : <EOL> return self . substitute ( """<STR_LIT>""" % locals ( ) , locals ( ) ) <EOL> def repl_op_bitexpr ( self , op , opname , args ) : <EOL> return self . substitute ( """<STR_LIT>""" % locals ( ) , locals ( ) ) <EOL> def repl_op_iexpr ( self , op , opname , x , y ) : <EOL> return self . substitute ( """<STR_LIT>""" % locals ( ) , locals ( ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import sys <EOL> if not sys . argv [ <NUM_LIT:1> : ] : <EOL> src = open ( "<STR_LIT>" , '<STR_LIT:r>' ) . read ( ) <EOL> dst = Replacement ( ) . substitute ( src , { } ) <EOL> open ( "<STR_LIT>" , '<STR_LIT:w>' ) . write ( dst ) <EOL> else : <EOL> src = open ( sys . argv [ <NUM_LIT:1> ] , '<STR_LIT:r>' ) . read ( ) <EOL> dst = Replacement ( ) . substitute ( src , { } ) <EOL> print dst </s>
