<s> """<STR_LIT>""" <EOL> import sys <EOL> import string <EOL> def import_gwt_to_pyjamas ( txt ) : <EOL> """<STR_LIT>""" <EOL> if txt . startswith ( "<STR_LIT>" ) : <EOL> return '<STR_LIT>' <EOL> if not txt . startswith ( '<STR_LIT>' ) : <EOL> return txt <EOL> if txt == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> if txt . startswith ( '<STR_LIT>' ) : <EOL> module = txt [ <NUM_LIT> : - <NUM_LIT:1> ] <EOL> return "<STR_LIT>" % ( module , module ) <EOL> if txt . startswith ( '<STR_LIT>' ) : <EOL> module = txt [ <NUM_LIT> : - <NUM_LIT:1> ] <EOL> if module == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> return "<STR_LIT>" % module <EOL> if txt . startswith ( '<STR_LIT>' ) : <EOL> module = txt [ <NUM_LIT> : - <NUM_LIT:1> ] <EOL> return "<STR_LIT>" % module <EOL> if txt . startswith ( '<STR_LIT>' ) : <EOL> module = txt [ <NUM_LIT> : - <NUM_LIT:1> ] <EOL> return "<STR_LIT>" % module <EOL> if txt . startswith ( '<STR_LIT>' ) : <EOL> module = txt [ <NUM_LIT> : - <NUM_LIT:1> ] <EOL> if module == '<STR_LIT>' : <EOL> return "<STR_LIT>" <EOL> return "<STR_LIT>" % module <EOL> if txt . startswith ( '<STR_LIT>' ) : <EOL> module = txt [ <NUM_LIT> : - <NUM_LIT:1> ] <EOL> return "<STR_LIT>" % module <EOL> return '<STR_LIT>' <EOL> def convert_stupid_js_import_to_stupid_js_import ( txt ) : <EOL> """<STR_LIT>""" <EOL> txt = txt . replace ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> txt = txt . replace ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> return txt <EOL> def join_single_open_brace_to_previous_line ( txt ) : <EOL> res = [ ] <EOL> for l in txt . split ( "<STR_LIT:\n>" ) : <EOL> x = l . strip ( ) <EOL> if x == '<STR_LIT:{>' : <EOL> res [ - <NUM_LIT:1> ] += ( '<STR_LIT>' ) <EOL> else : <EOL> res . append ( l ) <EOL> return '<STR_LIT:\n>' . join ( res ) <EOL> def countspaces ( txt ) : <EOL> count = <NUM_LIT:0> <EOL> while count < len ( txt ) and txt [ count ] == '<STR_LIT:U+0020>' : <EOL> count += <NUM_LIT:1> <EOL> return count <EOL> def java2pythonlinebyline ( txt ) : <EOL> if txt . find ( '<STR_LIT>' ) >= <NUM_LIT:0> : <EOL> if not txt . strip ( ) . endswith ( "<STR_LIT:{>" ) : <EOL> print txt <EOL> error <EOL> txt = txt . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> txt = txt . replace ( '<STR_LIT:!>' , '<STR_LIT>' ) <EOL> txt = txt . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> txt = txt . replace ( '<STR_LIT>' , '<STR_LIT::>' ) <EOL> elif txt . endswith ( "<STR_LIT>" ) : <EOL> txt = txt . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif txt . find ( '<STR_LIT>' ) >= <NUM_LIT:0> and txt . endswith ( "<STR_LIT:{>" ) : <EOL> txt = txt . replace ( '<STR_LIT:{>' , '<STR_LIT::>' ) <EOL> elif txt . find ( '<STR_LIT>' ) >= <NUM_LIT:0> : <EOL> txt = txt . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif txt . find ( '<STR_LIT>' ) >= <NUM_LIT:0> : <EOL> txt = txt . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif txt . find ( '<STR_LIT>' ) >= <NUM_LIT:0> : <EOL> txt = txt . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif txt . find ( '<STR_LIT>' ) >= <NUM_LIT:0> : <EOL> txt = txt . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> txt = txt . replace ( '<STR_LIT>' , '<STR_LIT::>' ) <EOL> elif txt . find ( '<STR_LIT>' ) >= <NUM_LIT:0> : <EOL> txt = txt . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> txt = txt . replace ( '<STR_LIT>' , '<STR_LIT::>' ) <EOL> count = countspaces ( txt ) <EOL> if txt [ count : ] . startswith ( "<STR_LIT:}>" ) : <EOL> txt = count * '<STR_LIT:U+0020>' + txt [ count + <NUM_LIT:1> : ] <EOL> if txt [ count : ] . startswith ( "<STR_LIT>" ) >= <NUM_LIT:0> : <EOL> txt = txt . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if txt [ count : ] . startswith ( "<STR_LIT>" ) >= <NUM_LIT:0> : <EOL> txt = txt . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if txt [ count : ] . startswith ( "<STR_LIT>" ) >= <NUM_LIT:0> : <EOL> txt = txt . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if txt [ count : ] . startswith ( "<STR_LIT>" ) >= <NUM_LIT:0> : <EOL> txt = txt . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if txt [ count : ] . startswith ( "<STR_LIT>" ) >= <NUM_LIT:0> : <EOL> txt = txt . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if txt [ count : ] . startswith ( "<STR_LIT>" ) >= <NUM_LIT:0> : <EOL> txt = txt . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if txt . endswith ( "<STR_LIT:;>" ) : <EOL> txt = txt [ : - <NUM_LIT:1> ] <EOL> if txt . endswith ( "<STR_LIT>" ) : <EOL> txt = txt [ : - <NUM_LIT:2> ] + "<STR_LIT::>" <EOL> return txt <EOL> def redofunctions ( txt ) : <EOL> if txt . strip ( ) . startswith ( "<STR_LIT:#>" ) : <EOL> return txt <EOL> if not txt . endswith ( "<STR_LIT:{>" ) : <EOL> return txt <EOL> lbr = txt . find ( "<STR_LIT:(>" ) <EOL> rbr = txt . find ( "<STR_LIT>" ) <EOL> if lbr == - <NUM_LIT:1> or rbr == - <NUM_LIT:1> or lbr > rbr : <EOL> return txt <EOL> lbr2 = txt . find ( "<STR_LIT:(>" , lbr + <NUM_LIT:1> ) <EOL> if lbr2 > <NUM_LIT:0> : <EOL> return txt <EOL> count = countspaces ( txt ) <EOL> pre = txt [ count : lbr ] <EOL> args = txt [ lbr + <NUM_LIT:1> : rbr ] <EOL> if pre . strip ( ) == '<STR_LIT>' : <EOL> return txt <EOL> is_exception = <NUM_LIT:0> <EOL> if pre . find ( "<STR_LIT>" ) >= <NUM_LIT:0> : <EOL> is_exception = <NUM_LIT:1> <EOL> else : <EOL> pre = map ( string . strip , pre . split ( '<STR_LIT:U+0020>' ) ) <EOL> if len ( pre ) == <NUM_LIT:1> : <EOL> pre = '<STR_LIT>' <EOL> elif len ( pre ) == <NUM_LIT:2> : <EOL> pre = pre [ - <NUM_LIT:1> ] <EOL> else : <EOL> print txt , pre <EOL> error <EOL> args = map ( string . strip , args . split ( '<STR_LIT:U+002C>' ) ) <EOL> newargs = [ ] <EOL> for arg in args : <EOL> if arg == '<STR_LIT>' : <EOL> continue <EOL> arg = map ( string . strip , arg . split ( '<STR_LIT:U+0020>' ) ) <EOL> if len ( arg ) == <NUM_LIT:2> : <EOL> newargs . append ( arg [ <NUM_LIT:1> ] ) <EOL> else : <EOL> print txt <EOL> print pre , args , arg <EOL> error <EOL> if count != <NUM_LIT:0> and not is_exception : <EOL> newargs = [ '<STR_LIT>' ] + newargs <EOL> newargs = '<STR_LIT:U+002CU+0020>' . join ( newargs ) <EOL> if is_exception : <EOL> return "<STR_LIT>" % ( count * '<STR_LIT:U+0020>' , pre , newargs ) <EOL> return "<STR_LIT>" % ( count * '<STR_LIT:U+0020>' , pre , newargs ) <EOL> def reindent ( txt ) : <EOL> """<STR_LIT>""" <EOL> res = '<STR_LIT>' <EOL> indent = <NUM_LIT:0> <EOL> for l in txt . split ( "<STR_LIT:\n>" ) : <EOL> l = l . strip ( ) <EOL> if l . startswith ( "<STR_LIT:}>" ) : <EOL> indent -= <NUM_LIT:1> <EOL> if indent < <NUM_LIT:0> : <EOL> res += "<STR_LIT>" <EOL> res += '<STR_LIT:U+0020>' * indent + l + "<STR_LIT:\n>" <EOL> if l . endswith ( "<STR_LIT:{>" ) : <EOL> indent += <NUM_LIT:1> <EOL> return res <EOL> def java_replace ( txt , rep , repwith ) : <EOL> res = '<STR_LIT>' <EOL> while txt : <EOL> i = txt . find ( '<STR_LIT>' ) <EOL> if i == - <NUM_LIT:1> : <EOL> return res + txt . replace ( rep , repwith ) <EOL> j = txt . find ( '<STR_LIT>' , i ) <EOL> if ( j == - <NUM_LIT:1> ) : <EOL> error <EOL> res += txt [ : i ] . replace ( rep , repwith ) + txt [ i : j ] <EOL> txt = txt [ j : ] <EOL> return txt <EOL> def java_linemap ( fn , lines ) : <EOL> res = [ ] <EOL> in_stupid_js = False <EOL> for l in lines : <EOL> if in_stupid_js : <EOL> res . append ( l ) <EOL> if l . find ( '<STR_LIT>' ) >= <NUM_LIT:0> : <EOL> in_stupid_js = False <EOL> continue <EOL> if l . find ( '<STR_LIT>' ) >= <NUM_LIT:0> : <EOL> in_stupid_js = True <EOL> res . append ( l ) <EOL> continue <EOL> res . append ( fn ( l ) ) <EOL> return res <EOL> def java2python ( txt ) : <EOL> txt = txt . replace ( "<STR_LIT:\r\n>" , '<STR_LIT:\n>' ) <EOL> txt = convert_stupid_js_import_to_stupid_js_import ( txt ) <EOL> txt = join_single_open_brace_to_previous_line ( txt ) <EOL> txt = reindent ( txt ) <EOL> txt = java_replace ( txt , "<STR_LIT>" , '<STR_LIT>' ) <EOL> txt = java_replace ( txt , "<STR_LIT>" , '<STR_LIT>' ) <EOL> txt = java_replace ( txt , "<STR_LIT>" , '<STR_LIT>' ) <EOL> txt = java_replace ( txt , "<STR_LIT>" , '<STR_LIT>' ) <EOL> txt = java_replace ( txt , "<STR_LIT>" , '<STR_LIT>' ) <EOL> txt = java_replace ( txt , "<STR_LIT:null>" , '<STR_LIT:None>' ) <EOL> txt = java_replace ( txt , "<STR_LIT>" , '<STR_LIT>' ) <EOL> txt = java_replace ( txt , "<STR_LIT>" , '<STR_LIT>' ) <EOL> txt = java_replace ( txt , "<STR_LIT>" , '<STR_LIT>' ) <EOL> txt = java_replace ( txt , "<STR_LIT:true>" , '<STR_LIT:True>' ) <EOL> txt = java_replace ( txt , "<STR_LIT:false>" , '<STR_LIT:False>' ) <EOL> txt = java_replace ( txt , "<STR_LIT>" , '<STR_LIT:#>' ) <EOL> txt = java_replace ( txt , "<STR_LIT>" , '<STR_LIT>' ) <EOL> txt = java_replace ( txt , "<STR_LIT>" , '<STR_LIT>' ) <EOL> txt = java_replace ( txt , "<STR_LIT>" , '<STR_LIT>' ) <EOL> l = txt . split ( "<STR_LIT:\n>" ) <EOL> l = java_linemap ( import_gwt_to_pyjamas , l ) <EOL> l = java_linemap ( java2pythonlinebyline , l ) <EOL> l = java_linemap ( redofunctions , l ) <EOL> txt = java_replace ( txt , "<STR_LIT:}>" , '<STR_LIT>' ) <EOL> return '<STR_LIT:\n>' . join ( l ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> fname = sys . argv [ <NUM_LIT:1> ] <EOL> f = open ( fname + "<STR_LIT>" , "<STR_LIT:r>" ) <EOL> txt = java2python ( f . read ( ) ) <EOL> f . close ( ) <EOL> f = open ( fname + "<STR_LIT>" , "<STR_LIT:w>" ) <EOL> f . write ( txt ) <EOL> f . close ( ) </s>
