<s> import sys <EOL> import types <EOL> import os <EOL> import copy <EOL> from six . moves import cStringIO as StringIO <EOL> import re <EOL> try : <EOL> from hashlib import md5 <EOL> except : <EOL> from md5 import md5 <EOL> import logging <EOL> from pyjs . options import ( all_compile_options , add_compile_options , <EOL> get_compile_options , debug_options , speed_options , <EOL> pythonic_options ) <EOL> if '<STR_LIT>' in os . environ : <EOL> sys . path [ <NUM_LIT:0> : <NUM_LIT:0> ] = [ os . environ [ '<STR_LIT>' ] ] <EOL> sys . path [ <NUM_LIT:1> : <NUM_LIT:1> ] = [ os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT>" ) ] <EOL> import pycompiler as compiler <EOL> from pycompiler . visitor import ASTVisitor <EOL> import pyjs <EOL> escaped_subst = re . compile ( '<STR_LIT>' ) <EOL> JavaScript_Reserved_Words = frozenset ( ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:default>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:label>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:true>' , <EOL> '<STR_LIT:false>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) ) <EOL> ECMAScipt_Reserved_Words = frozenset ( ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:class>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) ) <EOL> Java_Keywords = frozenset ( ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:false>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:float>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:int>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:null>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:true>' , <EOL> ) ) <EOL> Other_JavaScript_Keywords = frozenset ( ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:location>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:name>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:status>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) ) <EOL> PYJSLIB_BUILTIN_FUNCTIONS = frozenset ( ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:all>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:bool>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:float>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:str>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:type>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ) ) <EOL> PYJSLIB_BUILTIN_CLASSES = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:int>" , <EOL> "<STR_LIT:list>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT:object>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> PYJSLIB_BUILTIN_MAPPING = { '<STR_LIT:True>' : '<STR_LIT:true>' , <EOL> '<STR_LIT:False>' : '<STR_LIT:false>' , <EOL> '<STR_LIT:None>' : '<STR_LIT:null>' , <EOL> } <EOL> SCOPE_KEY = <NUM_LIT:0> <EOL> BIND_TYPES_NUMERIC = { <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT:class>" : <NUM_LIT:2> , <EOL> "<STR_LIT>" : <NUM_LIT:3> , <EOL> } <EOL> pyjs_vars_remap_names = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> pyjs_vars_remap = { } <EOL> for a in pyjs_vars_remap_names : <EOL> pyjs_vars_remap [ a ] = '<STR_LIT>' + a <EOL> for a in JavaScript_Reserved_Words : <EOL> pyjs_vars_remap [ a ] = '<STR_LIT>' + a <EOL> for a in ECMAScipt_Reserved_Words : <EOL> pyjs_vars_remap [ a ] = '<STR_LIT>' + a <EOL> pyjs_attrib_remap_names = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:name>' , <EOL> '<STR_LIT>' , '<STR_LIT:replace>' , <EOL> ] <EOL> pyjs_attrib_remap = { } <EOL> for a in pyjs_attrib_remap_names : <EOL> pyjs_attrib_remap [ a ] = '<STR_LIT>' + a <EOL> for a in JavaScript_Reserved_Words : <EOL> pyjs_attrib_remap [ a ] = '<STR_LIT>' + a <EOL> for a in ECMAScipt_Reserved_Words : <EOL> pyjs_attrib_remap [ a ] = '<STR_LIT>' + a <EOL> def bracket_fn ( s ) : <EOL> return s <EOL> def monkey_patch_broken_transformer ( compiler ) : <EOL> if compiler . __name__ != '<STR_LIT>' : <EOL> return <EOL> extractLineNo = compiler . transformer . extractLineNo <EOL> token = compiler . transformer . token <EOL> symbol = compiler . transformer . symbol <EOL> Subscript = compiler . transformer . Subscript <EOL> Tuple = compiler . transformer . Tuple <EOL> Ellipsis = compiler . transformer . Ellipsis <EOL> Sliceobj = compiler . transformer . Sliceobj <EOL> def com_subscriptlist ( self , primary , nodelist , assigning ) : <EOL> if len ( nodelist ) == <NUM_LIT:2> : <EOL> sub = nodelist [ <NUM_LIT:1> ] <EOL> if ( sub [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] == token . COLON or ( len ( sub ) > <NUM_LIT:2> and sub [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] == token . COLON ) ) and sub [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] != symbol . sliceop : <EOL> return self . com_slice ( primary , sub , assigning ) <EOL> subscripts = [ ] <EOL> for i in range ( <NUM_LIT:1> , len ( nodelist ) , <NUM_LIT:2> ) : <EOL> subscripts . append ( self . com_subscript ( nodelist [ i ] ) ) <EOL> if len ( nodelist ) > <NUM_LIT:2> : <EOL> tulplesub = [ sub for sub in subscripts if not ( isinstance ( sub , Ellipsis ) or isinstance ( sub , Sliceobj ) ) ] <EOL> if len ( tulplesub ) == len ( subscripts ) : <EOL> subscripts = [ Tuple ( subscripts ) ] <EOL> return Subscript ( primary , assigning , subscripts , <EOL> lineno = extractLineNo ( nodelist ) ) <EOL> compiler . transformer . Transformer . com_subscriptlist = com_subscriptlist <EOL> re_return = re . compile ( r'<STR_LIT>' ) <EOL> class __Pyjamas__ ( object ) : <EOL> console = "<STR_LIT>" <EOL> native_js_funcs = [ ] <EOL> @ classmethod <EOL> def register_native_js_func ( cls , name , func ) : <EOL> def native ( self , translator , node , current_klass , is_statement = False ) : <EOL> if len ( node . args ) != <NUM_LIT:1> : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" % name , <EOL> node . node ) <EOL> if ( isinstance ( node . args [ <NUM_LIT:0> ] , translator . ast . Const ) <EOL> and isinstance ( node . args [ <NUM_LIT:0> ] . value , str ) <EOL> ) : <EOL> translator . ignore_debug = True <EOL> unescape = lambda content : translator . translate_escaped_names ( content , current_klass ) <EOL> converted = func ( node . args [ <NUM_LIT:0> ] . value , unescape = unescape , translator = translator , current_klass = current_klass , is_statement = is_statement ) <EOL> return converted , re_return . search ( converted ) is not None <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" % name , <EOL> node . node ) <EOL> cls . native_js_funcs . append ( name ) <EOL> setattr ( cls , name , native ) <EOL> def wnd ( self , translator , node , * args , ** kwargs ) : <EOL> if len ( node . args ) != <NUM_LIT:0> : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> node . node ) <EOL> translator . ignore_debug = True <EOL> return '<STR_LIT>' , False <EOL> def doc ( self , translator , node , * args , ** kwargs ) : <EOL> if len ( node . args ) != <NUM_LIT:0> : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> node . node ) <EOL> translator . ignore_debug = True <EOL> return '<STR_LIT>' , False <EOL> def jsinclude ( self , translator , node , * args , ** kwargs ) : <EOL> if len ( node . args ) != <NUM_LIT:1> : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> node . node ) <EOL> if ( isinstance ( node . args [ <NUM_LIT:0> ] , translator . ast . Const ) <EOL> and isinstance ( node . args [ <NUM_LIT:0> ] . value , str ) <EOL> ) : <EOL> try : <EOL> data = open ( node . args [ <NUM_LIT:0> ] . value , '<STR_LIT:r>' ) . read ( ) <EOL> except IOError ( e ) : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" % ( node . args [ <NUM_LIT:0> ] . value , e ) , node . node ) <EOL> translator . ignore_debug = True <EOL> return data , False <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> node . node ) <EOL> def jsimport ( self , translator , node , * args , ** kwargs ) : <EOL> if len ( node . args ) == <NUM_LIT:0> or len ( node . args ) > <NUM_LIT:3> : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> node . node ) <EOL> for arg in node . args : <EOL> if not isinstance ( arg , translator . ast . Const ) : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> node . node ) <EOL> if not isinstance ( node . args [ <NUM_LIT:0> ] . value , str ) : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> node . node ) <EOL> path = node . args [ <NUM_LIT:0> ] . value <EOL> if len ( node . args ) < <NUM_LIT:2> : <EOL> mode = '<STR_LIT:default>' <EOL> else : <EOL> if isinstance ( node . args [ <NUM_LIT:1> ] . value , str ) : <EOL> mode = node . args [ <NUM_LIT:1> ] . value <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> node . node ) <EOL> if not mode in [ '<STR_LIT:default>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> node . node ) <EOL> if len ( node . args ) < <NUM_LIT:3> : <EOL> location = '<STR_LIT>' <EOL> else : <EOL> if isinstance ( node . args [ <NUM_LIT:2> ] . value , str ) : <EOL> location = node . args [ <NUM_LIT:2> ] . value <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> node . node ) <EOL> if not location in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> node . node ) <EOL> translator . add_imported_js ( path , mode , location ) <EOL> translator . ignore_debug = True <EOL> return '<STR_LIT>' , False <EOL> def debugger ( self , translator , node , * args , ** kwargs ) : <EOL> if len ( node . args ) != <NUM_LIT:0> : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> node . node ) <EOL> translator . ignore_debug = True <EOL> return '<STR_LIT>' , False <EOL> def setCompilerOptions ( self , translator , node , * args , ** kwargs ) : <EOL> global speed_options , pythonic_options <EOL> for arg in node . args : <EOL> if not isinstance ( arg , translator . ast . Const ) or not isinstance ( arg . value , str ) : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> node . node ) <EOL> option = arg . value <EOL> if translator . decorator_compiler_options . has_key ( option ) : <EOL> for var , val in translator . decorator_compiler_options [ option ] : <EOL> setattr ( translator , var , val ) <EOL> elif option == "<STR_LIT>" : <EOL> for var in speed_options : <EOL> setattr ( translator , var , speed_options [ var ] ) <EOL> elif option == "<STR_LIT>" : <EOL> for var in pythonic_options : <EOL> setattr ( translator , var , pythonic_options [ var ] ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" % option , <EOL> node . node ) <EOL> translator . ignore_debug = True <EOL> return '<STR_LIT>' , False <EOL> def INT ( self , translator , node , * args , ** kwargs ) : <EOL> if len ( node . args ) != <NUM_LIT:1> : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> node . node ) <EOL> expr = translator . expr ( node . args [ <NUM_LIT:0> ] , None ) <EOL> opt_var = translator . decorator_compiler_options [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> if getattr ( translator , opt_var ) : <EOL> return "<STR_LIT>" % expr , False <EOL> return expr , False <EOL> def native_js_func ( func ) : <EOL> __Pyjamas__ . register_native_js_func ( func . __name__ , func ) <EOL> return func <EOL> @ native_js_func <EOL> def JS ( content , unescape , ** kwargs ) : <EOL> return unescape ( content ) <EOL> __pyjamas__ = __Pyjamas__ ( ) <EOL> class __Future__ ( object ) : <EOL> def division ( self , translator ) : <EOL> translator . future_division = True <EOL> __future__ = __Future__ ( ) <EOL> JS_ESCAPES = ( <EOL> ( '<STR_LIT:\\>' , r'<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , r'<STR_LIT>' ) , <EOL> ( '<STR_LIT:">' , r'<STR_LIT>' ) , <EOL> ( '<STR_LIT:>>' , r'<STR_LIT>' ) , <EOL> ( '<STR_LIT:<>' , r'<STR_LIT>' ) , <EOL> ( '<STR_LIT:&>' , r'<STR_LIT>' ) , <EOL> ( '<STR_LIT:;>' , r'<STR_LIT>' ) <EOL> ) + tuple ( [ ( '<STR_LIT>' % z , '<STR_LIT>' % z ) for z in range ( <NUM_LIT:32> ) ] ) <EOL> def escapejs ( value ) : <EOL> """<STR_LIT>""" <EOL> for bad , good in JS_ESCAPES : <EOL> value = value . replace ( bad , good ) <EOL> return value <EOL> def uescapejs ( value ) : <EOL> """<STR_LIT>""" <EOL> data = repr ( value ) <EOL> return data . lstrip ( "<STR_LIT:u>" ) <EOL> class YieldVisitor ( ASTVisitor ) : <EOL> has_yield = False <EOL> def visitYield ( self , node , * args ) : <EOL> self . has_yield = True <EOL> class GeneratorExitVisitor ( YieldVisitor ) : <EOL> has_yield = False <EOL> def visitReturn ( self , node , * args ) : <EOL> self . has_yield = True <EOL> class Klass : <EOL> klasses = { } <EOL> def __init__ ( self , name , name_scope ) : <EOL> self . name = name <EOL> self . name_scope = name_scope <EOL> self . klasses [ name ] = self <EOL> self . functions = set ( ) <EOL> def set_base ( self , base_name ) : <EOL> self . base = self . klasses . get ( base_name ) <EOL> def add_function ( self , function_name ) : <EOL> self . functions . add ( function_name ) <EOL> class TranslationError ( Exception ) : <EOL> def __init__ ( self , msg , node = '<STR_LIT>' , module_name = '<STR_LIT>' ) : <EOL> if node : <EOL> lineno = node . lineno <EOL> else : <EOL> lineno = "<STR_LIT>" <EOL> self . msg = msg <EOL> self . node = node <EOL> self . module_name = module_name <EOL> self . lineno = lineno <EOL> Exception . __init__ ( self , "<STR_LIT>" % ( module_name , lineno , msg , node ) ) <EOL> def __str__ ( self ) : <EOL> return self . args [ <NUM_LIT:0> ] <EOL> def strip_py ( name ) : <EOL> return name <EOL> class Translator ( object ) : <EOL> decorator_compiler_options = { '<STR_LIT>' : [ ( '<STR_LIT>' , True ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , True ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , True ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , True ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , True ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , True ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , True ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , True ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , True ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , True ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , True ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , True ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , True ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , True ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , True ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) , ( '<STR_LIT>' , False ) , ( '<STR_LIT>' , False ) , ( '<STR_LIT>' , False ) , ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , True ) , ( '<STR_LIT>' , True ) , ( '<STR_LIT>' , True ) , ( '<STR_LIT>' , True ) , ( '<STR_LIT>' , True ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , True ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , False ) ] , <EOL> '<STR_LIT>' : [ ( '<STR_LIT>' , True ) ] , <EOL> } <EOL> pyjslib_prefix = "<STR_LIT>" <EOL> def __init__ ( self , compiler , <EOL> module_name , module_file_name , src , mod , output , <EOL> dynamic = <NUM_LIT:0> , findFile = None , ** kw ) : <EOL> self . compiler = compiler <EOL> self . ast = compiler . ast <EOL> self . js_module_name = self . jsname ( "<STR_LIT>" , module_name ) <EOL> if module_name : <EOL> self . module_prefix = "<STR_LIT>" <EOL> else : <EOL> self . module_prefix = "<STR_LIT>" <EOL> self . module_name = module_name <EOL> src = src . replace ( "<STR_LIT:\r\n>" , "<STR_LIT:\n>" ) <EOL> src = src . replace ( "<STR_LIT>" , "<STR_LIT:\n>" ) <EOL> src = src . replace ( "<STR_LIT:\r>" , "<STR_LIT:\n>" ) <EOL> self . src = src . split ( "<STR_LIT:\n>" ) <EOL> self . output = output <EOL> self . dynamic = dynamic <EOL> self . findFile = findFile <EOL> self . set_compile_options ( kw ) <EOL> self . future_division = False <EOL> self . imported_modules = [ ] <EOL> self . imported_js = [ ] <EOL> self . is_class_definition = False <EOL> self . local_prefix = None <EOL> self . track_lines = { } <EOL> self . stacksize_depth = <NUM_LIT:0> <EOL> self . option_stack = [ ] <EOL> self . lookup_stack = [ { } ] <EOL> self . indent_level = <NUM_LIT:0> <EOL> self . __unique_ids__ = { } <EOL> self . try_depth = - <NUM_LIT:1> <EOL> self . is_generator = False <EOL> self . generator_states = [ ] <EOL> self . state_max_depth = len ( self . generator_states ) <EOL> self . constant_int = { } <EOL> self . constant_long = { } <EOL> self . top_level = True <EOL> PYJSLIB_BUILTIN_MAPPING [ '<STR_LIT>' ] = "<STR_LIT>" % module_file_name <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % module_name ) <EOL> if not '<STR_LIT:.>' in module_name : <EOL> self . parent_module_name = None <EOL> else : <EOL> self . parent_module_name = '<STR_LIT:.>' . join ( module_name . split ( '<STR_LIT:.>' ) [ : - <NUM_LIT:1> ] ) <EOL> if module_file_name . endswith ( '<STR_LIT>' ) : <EOL> self . import_context = "<STR_LIT>" % module_name <EOL> self . relative_import_context = module_name <EOL> elif self . parent_module_name : <EOL> self . import_context = "<STR_LIT>" % self . parent_module_name <EOL> self . relative_import_context = self . parent_module_name <EOL> else : <EOL> self . import_context = "<STR_LIT:null>" <EOL> self . relative_import_context = None <EOL> self . w ( self . indent ( ) + "<STR_LIT>" % module_name ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( module_name , module_name ) ) <EOL> if self . parent_module_name : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( self . parent_module_name , self . parent_module_name , self . parent_module_name ) ) <EOL> parts = self . js_module_name . split ( '<STR_LIT:.>' ) <EOL> if len ( parts ) > <NUM_LIT:1> : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( parts [ <NUM_LIT:0> ] , module_name . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] ) ) <EOL> if self . js_module_name in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( self . module_prefix [ : - <NUM_LIT:1> ] , self . js_module_name , module_name , ) ) <EOL> else : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( self . module_prefix [ : - <NUM_LIT:1> ] , module_name , ) ) <EOL> self . w ( self . spacing ( ) + self . module_prefix [ : - <NUM_LIT:1> ] + "<STR_LIT>" % ( module_name ) ) <EOL> self . w ( self . spacing ( ) + self . module_prefix [ : - <NUM_LIT:1> ] + "<STR_LIT>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( module_name ) ) <EOL> lhs = self . closureSafe ( self . scopeName ( '<STR_LIT>' , <NUM_LIT:0> , False ) ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( lhs ) ) <EOL> if self . source_tracking : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % self . module_prefix ) <EOL> name = module_name . split ( "<STR_LIT:.>" ) <EOL> if len ( name ) > <NUM_LIT:1> : <EOL> jsname = self . jsname ( '<STR_LIT>' , name [ - <NUM_LIT:1> ] ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( <EOL> '<STR_LIT:.>' . join ( name [ : - <NUM_LIT:1> ] ) , jsname , module_name , <EOL> ) ) <EOL> if self . attribute_checking and not module_name in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> attribute_checking = True <EOL> self . w ( self . indent ( ) + '<STR_LIT>' ) <EOL> else : <EOL> attribute_checking = False <EOL> save_output = self . output <EOL> self . output = StringIO ( ) <EOL> mod . lineno = <NUM_LIT:1> <EOL> self . track_lineno ( mod , True ) <EOL> for child in mod . node : <EOL> self . has_js_return = False <EOL> self . has_yield = False <EOL> self . is_generator = False <EOL> self . track_lineno ( child ) <EOL> assert self . top_level <EOL> if isinstance ( child , self . ast . Function ) : <EOL> self . _function ( child , None ) <EOL> elif isinstance ( child , self . ast . Class ) : <EOL> self . _class ( child ) <EOL> elif isinstance ( child , self . ast . Import ) : <EOL> self . _import ( child , None , True ) <EOL> elif isinstance ( child , self . ast . From ) : <EOL> self . _from ( child , None , True ) <EOL> elif isinstance ( child , self . ast . Discard ) : <EOL> self . _discard ( child , None ) <EOL> elif isinstance ( child , self . ast . Assign ) : <EOL> self . _assign ( child , None ) <EOL> elif isinstance ( child , self . ast . AugAssign ) : <EOL> self . _augassign ( child , None ) <EOL> elif isinstance ( child , self . ast . If ) : <EOL> self . _if ( child , None ) <EOL> elif isinstance ( child , self . ast . For ) : <EOL> self . _for ( child , None ) <EOL> elif isinstance ( child , self . ast . While ) : <EOL> self . _while ( child , None ) <EOL> elif isinstance ( child , self . ast . Subscript ) : <EOL> self . _subscript_stmt ( child , None ) <EOL> elif isinstance ( child , self . ast . Global ) : <EOL> self . _global ( child , None ) <EOL> elif isinstance ( child , self . ast . Printnl ) : <EOL> self . _print ( child , None ) <EOL> elif isinstance ( child , self . ast . Print ) : <EOL> self . _print ( child , None ) <EOL> elif isinstance ( child , self . ast . TryExcept ) : <EOL> self . _tryExcept ( child , None ) <EOL> elif isinstance ( child , self . ast . TryFinally ) : <EOL> self . _tryFinally ( child , None ) <EOL> elif isinstance ( child , self . ast . With ) : <EOL> self . _with ( child , None ) <EOL> elif isinstance ( child , self . ast . Raise ) : <EOL> self . _raise ( child , None ) <EOL> elif isinstance ( child , self . ast . Assert ) : <EOL> self . _assert ( child , None ) <EOL> elif isinstance ( child , self . ast . Stmt ) : <EOL> self . _stmt ( child , None , True ) <EOL> elif isinstance ( child , self . ast . AssAttr ) : <EOL> self . _assattr ( child , None ) <EOL> elif isinstance ( child , self . ast . AssName ) : <EOL> self . _assname ( child , None ) <EOL> elif isinstance ( child , self . ast . AssTuple ) : <EOL> for node in child . nodes : <EOL> self . _stmt ( node , None ) <EOL> elif isinstance ( child , self . ast . Slice ) : <EOL> self . w ( self . spacing ( ) + self . _slice ( child , None ) ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> child , self . module_name ) <EOL> captured_output = self . output . getvalue ( ) <EOL> self . output = save_output <EOL> if self . source_tracking and self . store_source : <EOL> for l in self . track_lines . keys ( ) : <EOL> self . w ( self . spacing ( ) + '''<STR_LIT>''' % ( self . module_prefix , l , uescapejs ( self . track_lines [ l ] ) ) , translate = False ) <EOL> self . w ( self . local_js_vars_decl ( [ ] ) ) <EOL> if captured_output . find ( "<STR_LIT>" ) >= <NUM_LIT:0> : <EOL> captured_output = captured_output . replace ( "<STR_LIT>" , self . constant_decl ( ) ) <EOL> else : <EOL> self . w ( self . constant_decl ( ) ) <EOL> if captured_output . find ( "<STR_LIT>" ) >= <NUM_LIT:0> : <EOL> captured_output = captured_output . replace ( "<STR_LIT>" , self . attrib_remap_decl ( ) ) <EOL> self . w ( captured_output , False ) <EOL> if attribute_checking : <EOL> self . w ( self . dedent ( ) + "<STR_LIT>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> self . w ( self . dedent ( ) + "<STR_LIT>" % module_name ) <EOL> self . w ( "<STR_LIT:\n>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % module_name ) <EOL> self . w ( "<STR_LIT:\n>" ) <EOL> if self . imported_modules : <EOL> self . w ( '<STR_LIT>' ) <EOL> self . w ( '<STR_LIT>' % self . imported_modules ) <EOL> self . w ( '<STR_LIT>' ) <EOL> if self . imported_js : <EOL> self . w ( '<STR_LIT>' ) <EOL> self . w ( '<STR_LIT>' % repr ( self . imported_js ) ) <EOL> self . w ( '<STR_LIT>' ) <EOL> def set_compile_options ( self , opts ) : <EOL> opts = dict ( all_compile_options , ** opts ) <EOL> for opt , value in opts . iteritems ( ) : <EOL> if opt in all_compile_options : <EOL> setattr ( self , opt , value ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" % opt ) <EOL> self . ignore_debug = False <EOL> self . inline_bool = self . inline_code <EOL> self . inline_len = self . inline_code <EOL> self . inline_eq = self . inline_code <EOL> self . inline_cmp = self . inline_code <EOL> self . inline_getitem = self . inline_code <EOL> if self . number_classes : <EOL> self . operator_funcs = True <EOL> def w ( self , txt , newline = True , output = None , translate = True ) : <EOL> if translate and txt : <EOL> txt = self . translate_escaped_names ( txt , None ) <EOL> output = output or self . output <EOL> assert ( isinstance ( newline , bool ) ) <EOL> if newline : <EOL> if txt is None : <EOL> print >> self . output <EOL> return <EOL> print >> self . output , txt <EOL> else : <EOL> print >> self . output , txt , <EOL> def uniqid ( self , prefix = "<STR_LIT>" ) : <EOL> if not self . __unique_ids__ . has_key ( prefix ) : <EOL> self . __unique_ids__ [ prefix ] = <NUM_LIT:0> <EOL> self . __unique_ids__ [ prefix ] += <NUM_LIT:1> <EOL> return "<STR_LIT>" % ( prefix , self . __unique_ids__ [ prefix ] ) <EOL> def spacing ( self ) : <EOL> return "<STR_LIT:\t>" * self . indent_level <EOL> def indent ( self ) : <EOL> spacing = self . spacing ( ) <EOL> self . indent_level += <NUM_LIT:1> <EOL> return spacing <EOL> def dedent ( self ) : <EOL> if self . indent_level == <NUM_LIT:0> : <EOL> raise TranslationError ( "<STR_LIT>" , None , self . module_name ) <EOL> self . indent_level -= <NUM_LIT:1> <EOL> return self . spacing ( ) <EOL> def push_options ( self ) : <EOL> self . option_stack . append ( ( self . debug , self . print_statements , self . function_argument_checking , <EOL> self . attribute_checking , self . getattr_support , self . bound_methods , self . descriptors , <EOL> self . source_tracking , self . line_tracking , self . store_source , <EOL> self . inline_bool , self . inline_eq , self . inline_len , self . inline_cmp , self . inline_getitem , <EOL> self . operator_funcs , self . number_classes , <EOL> ) ) <EOL> def pop_options ( self ) : <EOL> ( self . debug , self . print_statements , self . function_argument_checking , <EOL> self . attribute_checking , self . getattr_support , self . bound_methods , self . descriptors , <EOL> self . source_tracking , self . line_tracking , self . store_source , <EOL> self . inline_bool , self . inline_eq , self . inline_len , self . inline_cmp , self . inline_getitem , <EOL> self . operator_funcs , self . number_classes , <EOL> ) = self . option_stack . pop ( ) <EOL> def parse_decorators ( self , node , funcname , current_class = None , <EOL> is_method = False , bind_type = None ) : <EOL> if node . decorators is None : <EOL> return False , False , '<STR_LIT:%s>' <EOL> self . push_lookup ( ) <EOL> self . add_lookup ( '<STR_LIT>' , '<STR_LIT:%s>' , '<STR_LIT:%s>' ) <EOL> code = '<STR_LIT:%s>' <EOL> staticmethod = False <EOL> classmethod = False <EOL> lineno = node . lineno <EOL> if is_method : <EOL> bind_type = bind_type or "<STR_LIT>" <EOL> def add_callfunc ( code , d , generic = True ) : <EOL> tnode = self . ast . CallFunc ( d , [ self . ast . Name ( '<STR_LIT:%s>' ) ] , <EOL> star_args = None , <EOL> dstar_args = None , <EOL> lineno = lineno ) <EOL> code = code % self . _callfunc_code ( tnode , None ) <EOL> if is_method and ( bind_type == "<STR_LIT>" ) and generic : <EOL> try : <EOL> bind_type_num = BIND_TYPES_NUMERIC [ bind_type ] <EOL> except KeyError : <EOL> raise TranslationError ( "<STR_LIT>" % bind_type , node ) <EOL> code = "<STR_LIT>" % { <EOL> "<STR_LIT>" : node . name , <EOL> "<STR_LIT:code>" : code , <EOL> "<STR_LIT>" : bind_type_num <EOL> } <EOL> return code <EOL> for d in node . decorators : <EOL> if isinstance ( d , self . ast . Getattr ) : <EOL> if isinstance ( d . expr , self . ast . Name ) : <EOL> if d . expr . name == '<STR_LIT>' : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node , self . module_name ) <EOL> if d . attrname in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> code = add_callfunc ( code , d , generic = False ) <EOL> else : <EOL> code = add_callfunc ( code , d ) <EOL> else : <EOL> code = add_callfunc ( code , d ) <EOL> elif isinstance ( d , self . ast . Name ) : <EOL> if d . name == '<STR_LIT>' : <EOL> staticmethod = True <EOL> elif d . name == '<STR_LIT>' : <EOL> classmethod = True <EOL> elif d . name == '<STR_LIT>' : <EOL> code = add_callfunc ( code , d , generic = False ) <EOL> else : <EOL> code = add_callfunc ( code , d ) <EOL> elif isinstance ( d , self . ast . CallFunc ) : <EOL> code = add_callfunc ( code , d ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" % d , node , self . module_name ) <EOL> self . pop_lookup ( ) <EOL> if code != '<STR_LIT:%s>' : <EOL> code = code % ( "<STR_LIT:@>" + "<STR_LIT>" ) <EOL> if staticmethod : <EOL> code = "<STR_LIT>" % code <EOL> return ( staticmethod , classmethod , code ) <EOL> def attrib_join ( self , splitted ) : <EOL> if not isinstance ( splitted , list ) : <EOL> raise TranslationError ( "<STR_LIT>" % splitted ) <EOL> attr = [ ] <EOL> if splitted [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] in [ "<STR_LIT:'>" , '<STR_LIT:">' ] : <EOL> attr . append ( splitted [ <NUM_LIT:0> ] [ <NUM_LIT:1> : - <NUM_LIT:1> ] ) <EOL> else : <EOL> attr . append ( splitted [ <NUM_LIT:0> ] ) <EOL> for word in splitted [ <NUM_LIT:1> : ] : <EOL> if word [ <NUM_LIT:0> ] in [ "<STR_LIT:'>" , '<STR_LIT:">' ] : <EOL> word = word [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> if word in pyjs_attrib_remap : <EOL> attr . append ( "<STR_LIT>" % pyjs_attrib_remap [ word ] ) <EOL> elif word . find ( '<STR_LIT:(>' ) >= <NUM_LIT:0> : <EOL> print ( '<STR_LIT>' , splitted , attr , word ) <EOL> attr . append ( word ) <EOL> else : <EOL> attr . append ( "<STR_LIT>" % word ) <EOL> if len ( attr ) == <NUM_LIT:1> : <EOL> return attr [ <NUM_LIT:0> ] <EOL> return "<STR_LIT>" % ( attr [ <NUM_LIT:0> ] , ( '<STR_LIT:[>' + "<STR_LIT>" . join ( attr [ <NUM_LIT:1> : ] ) + '<STR_LIT:]>' ) ) <EOL> def vars_remap ( self , word ) : <EOL> if word in pyjs_vars_remap : <EOL> return pyjs_vars_remap [ word ] <EOL> return word <EOL> def attrib_remap ( self , word ) : <EOL> attr = [ ] <EOL> words = word . split ( '<STR_LIT:.>' ) <EOL> if len ( words ) == <NUM_LIT:1> : <EOL> if word in pyjs_attrib_remap : <EOL> return pyjs_attrib_remap [ word ] <EOL> return word <EOL> raise RuntimeError ( "<STR_LIT>" % words ) <EOL> def push_lookup ( self , scope = None ) : <EOL> if scope is None : <EOL> scope = { } <EOL> self . lookup_stack . append ( scope ) <EOL> def pop_lookup ( self ) : <EOL> return self . lookup_stack . pop ( ) <EOL> def jsname ( self , name_type , jsname ) : <EOL> words = jsname . split ( '<STR_LIT:.>' ) <EOL> if name_type != '<STR_LIT>' : <EOL> words [ <NUM_LIT:0> ] = self . vars_remap ( words [ <NUM_LIT:0> ] ) <EOL> if len ( words ) == <NUM_LIT:0> : <EOL> return words [ <NUM_LIT:0> ] <EOL> return self . attrib_join ( words ) <EOL> def pyjslib_name ( self , name , args = None ) : <EOL> if args is None : <EOL> return "<STR_LIT>" + name + "<STR_LIT>" <EOL> else : <EOL> if isinstance ( args , ( tuple , list ) ) : <EOL> args = map ( lambda x : str ( x ) , args ) <EOL> args = '<STR_LIT:U+002CU+0020>' . join ( args ) <EOL> return "<STR_LIT>" % dict ( name = name , args = args ) <EOL> def add_lookup ( self , name_type , pyname , jsname , depth = - <NUM_LIT:1> ) : <EOL> jsname = self . jsname ( name_type , jsname ) <EOL> if self . local_prefix is not None : <EOL> if jsname . find ( self . local_prefix ) != <NUM_LIT:0> : <EOL> jsname = self . jsname ( name_type , "<STR_LIT>" % ( self . local_prefix , jsname ) ) <EOL> if self . lookup_stack [ depth ] . has_key ( pyname ) : <EOL> name_type = self . lookup_stack [ depth ] [ pyname ] [ <NUM_LIT:0> ] <EOL> if self . module_name != '<STR_LIT>' or pyname != '<STR_LIT:int>' : <EOL> self . lookup_stack [ depth ] [ pyname ] = ( name_type , pyname , jsname ) <EOL> return jsname <EOL> def lookup ( self , name ) : <EOL> name_type = None <EOL> pyname = name <EOL> jsname = None <EOL> max_depth = depth = len ( self . lookup_stack ) - <NUM_LIT:1> <EOL> while depth >= <NUM_LIT:0> : <EOL> if self . lookup_stack [ depth ] . has_key ( name ) : <EOL> name_type , pyname , jsname = self . lookup_stack [ depth ] [ name ] <EOL> break <EOL> depth -= <NUM_LIT:1> <EOL> if depth < <NUM_LIT:0> : <EOL> if name in PYJSLIB_BUILTIN_FUNCTIONS : <EOL> name_type = '<STR_LIT>' <EOL> pyname = name <EOL> jsname = self . jsname ( "<STR_LIT>" , "<STR_LIT>" % self . attrib_remap ( name ) ) <EOL> elif name in PYJSLIB_BUILTIN_CLASSES : <EOL> name_type = '<STR_LIT>' <EOL> pyname = name <EOL> if not self . number_classes : <EOL> if pyname in [ '<STR_LIT:int>' , '<STR_LIT>' ] : <EOL> name = '<STR_LIT>' <EOL> jsname = self . jsname ( "<STR_LIT>" , "<STR_LIT>" % self . attrib_remap ( name ) ) <EOL> elif PYJSLIB_BUILTIN_MAPPING . has_key ( name ) : <EOL> name_type = '<STR_LIT>' <EOL> pyname = name <EOL> jsname = PYJSLIB_BUILTIN_MAPPING [ name ] <EOL> is_local = ( name_type is not None ) and ( max_depth > <NUM_LIT:0> ) and ( max_depth == depth ) <EOL> return ( name_type , pyname , jsname , depth , is_local ) <EOL> def translate_escaped_names ( self , txt , current_klass ) : <EOL> """<STR_LIT>""" <EOL> l = escaped_subst . split ( txt ) <EOL> txt = l [ <NUM_LIT:0> ] <EOL> for i in xrange ( <NUM_LIT:1> , len ( l ) - <NUM_LIT:1> , <NUM_LIT:2> ) : <EOL> varname = l [ i ] . strip ( ) <EOL> if varname . startswith ( '<STR_LIT:!>' ) : <EOL> txt += varname [ <NUM_LIT:1> : ] <EOL> else : <EOL> name_type , pyname , jsname , depth , is_local = self . lookup ( varname ) <EOL> if name_type is None : <EOL> substname = self . scopeName ( varname , depth , is_local ) <EOL> else : <EOL> substname = jsname <EOL> substname = self . closureSafe ( substname ) <EOL> txt += substname <EOL> txt += l [ i + <NUM_LIT:1> ] <EOL> return txt <EOL> def scopeName ( self , name , depth , local ) : <EOL> if local : <EOL> return name <EOL> while depth >= <NUM_LIT:0> : <EOL> scopeName = self . lookup_stack [ depth ] . get ( SCOPE_KEY , None ) <EOL> if scopeName is not None : <EOL> return scopeName + name <EOL> depth -= <NUM_LIT:1> <EOL> return self . modpfx ( ) + name <EOL> def closureSafe ( self , varname ) : <EOL> varname = varname . split ( '<STR_LIT:.>' ) <EOL> if len ( varname ) == <NUM_LIT:1> : <EOL> return varname [ <NUM_LIT:0> ] <EOL> return "<STR_LIT>" % ( varname [ <NUM_LIT:0> ] , "<STR_LIT>" . join ( varname [ <NUM_LIT:1> : ] ) ) <EOL> def attrib_remap_decl ( self ) : <EOL> s = self . spacing ( ) <EOL> lines = [ ] <EOL> module_prefix = self . module_prefix [ : - <NUM_LIT:1> ] <EOL> remap = pyjs_attrib_remap . keys ( ) <EOL> remap . sort ( ) <EOL> lines . append ( "<STR_LIT>" % locals ( ) ) <EOL> remap = pyjs_vars_remap . keys ( ) <EOL> remap . sort ( ) <EOL> lines . append ( "<STR_LIT>" % locals ( ) ) <EOL> return "<STR_LIT:\n>" . join ( lines ) <EOL> def constant_decl ( self ) : <EOL> s = self . spacing ( ) <EOL> lines = [ ] <EOL> for name in self . constant_int : <EOL> lines . append ( "<STR_LIT>" % locals ( ) ) <EOL> for name in self . constant_long : <EOL> lines . append ( "<STR_LIT>" % locals ( ) ) <EOL> return "<STR_LIT:\n>" . join ( lines ) <EOL> def is_local_name ( self , jsname , pyname , nametype , ignore_py_vars ) : <EOL> return ( not jsname . find ( '<STR_LIT:[>' ) >= <NUM_LIT:0> <EOL> and not pyname in ignore_py_vars <EOL> and not nametype in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ) <EOL> def local_js_vars_decl ( self , ignore_py_vars ) : <EOL> names = [ ] <EOL> for name in self . lookup_stack [ - <NUM_LIT:1> ] . keys ( ) : <EOL> nametype = self . lookup_stack [ - <NUM_LIT:1> ] [ name ] [ <NUM_LIT:0> ] <EOL> pyname = self . lookup_stack [ - <NUM_LIT:1> ] [ name ] [ <NUM_LIT:1> ] <EOL> jsname = self . lookup_stack [ - <NUM_LIT:1> ] [ name ] [ <NUM_LIT:2> ] <EOL> if self . is_local_name ( jsname , pyname , nametype , ignore_py_vars ) : <EOL> names . append ( jsname ) <EOL> if len ( names ) > <NUM_LIT:0> : <EOL> return self . spacing ( ) + "<STR_LIT>" % '<STR_LIT:U+002C>' . join ( names ) <EOL> return '<STR_LIT>' <EOL> def add_imported_js ( self , path , mode , location ) : <EOL> self . imported_js . append ( ( path , mode , location ) ) <EOL> def add_imported_module ( self , importName ) : <EOL> names = importName . split ( "<STR_LIT:.>" ) <EOL> if not importName in self . imported_modules : <EOL> self . imported_modules . append ( importName ) <EOL> if importName . endswith ( '<STR_LIT>' ) : <EOL> return <EOL> _importName = '<STR_LIT>' <EOL> for name in names : <EOL> _importName += name <EOL> if not _importName in self . imported_modules : <EOL> self . imported_modules . append ( _importName ) <EOL> _importName += '<STR_LIT:.>' <EOL> __inline_bool_code_str = """<STR_LIT>""" <EOL> __inline_bool_code_str = __inline_bool_code_str . replace ( "<STR_LIT:U+0020>" , "<STR_LIT:\t>" ) . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) <EOL> def inline_bool_code ( self , e ) : <EOL> if self . stupid_mode : <EOL> return bracket_fn ( e ) <EOL> if self . inline_bool : <EOL> v = self . uniqid ( '<STR_LIT>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v , v ) <EOL> s = self . spacing ( ) <EOL> return self . __inline_bool_code_str % locals ( ) <EOL> return "<STR_LIT>" % locals ( ) <EOL> __inline_len_code_str1 = """<STR_LIT>""" <EOL> __inline_len_code_str1 = __inline_len_code_str1 . replace ( "<STR_LIT:U+0020>" , "<STR_LIT:\t>" ) . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) <EOL> __inline_len_code_str2 = """<STR_LIT>""" <EOL> __inline_len_code_str2 = __inline_len_code_str2 . replace ( "<STR_LIT:U+0020>" , "<STR_LIT:\t>" ) . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) <EOL> def inline_len_code ( self , e ) : <EOL> if self . inline_len : <EOL> v = self . uniqid ( '<STR_LIT>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v , v ) <EOL> zero = '<STR_LIT:0>' <EOL> s = self . spacing ( ) <EOL> if not self . number_classes : <EOL> return self . __inline_len_code_str1 % locals ( ) <EOL> self . constant_int [ '<STR_LIT:0>' ] = <NUM_LIT:1> <EOL> zero = "<STR_LIT>" <EOL> return self . __inline_len_code_str2 % locals ( ) <EOL> return "<STR_LIT>" % locals ( ) <EOL> __inline_eq_code_str = """<STR_LIT>""" <EOL> __inline_eq_code_str = __inline_eq_code_str . replace ( "<STR_LIT:U+0020>" , "<STR_LIT:\t>" ) . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) <EOL> def inline_eq_code ( self , e1 , e2 ) : <EOL> if self . inline_eq and not self . number_classes : <EOL> v1 = self . uniqid ( '<STR_LIT>' ) <EOL> v2 = self . uniqid ( '<STR_LIT>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v1 , v1 ) <EOL> self . add_lookup ( '<STR_LIT>' , v2 , v2 ) <EOL> s = self . spacing ( ) <EOL> return self . __inline_eq_code_str % locals ( ) <EOL> return "<STR_LIT>" % locals ( ) <EOL> __inline_cmp_code_str = """<STR_LIT>""" <EOL> __inline_cmp_code_str = __inline_cmp_code_str . replace ( "<STR_LIT:U+0020>" , "<STR_LIT:\t>" ) . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) <EOL> def inline_cmp_code ( self , e1 , e2 ) : <EOL> if self . inline_cmp : <EOL> v1 = self . uniqid ( '<STR_LIT>' ) <EOL> v2 = self . uniqid ( '<STR_LIT>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v1 , v1 ) <EOL> self . add_lookup ( '<STR_LIT>' , v2 , v2 ) <EOL> s = self . spacing ( ) <EOL> return self . __inline_cmp_code_str % locals ( ) <EOL> return "<STR_LIT>" % locals ( ) <EOL> __inline_getitem_code_str = """<STR_LIT>""" <EOL> __inline_getitem_code_str = __inline_getitem_code_str . replace ( "<STR_LIT:U+0020>" , "<STR_LIT:\t>" ) . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) <EOL> def inline_getitem_code ( self , e , i ) : <EOL> if self . inline_getitem : <EOL> v1 = self . uniqid ( '<STR_LIT:$>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v1 , v1 ) <EOL> v2 = self . uniqid ( '<STR_LIT:$>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v2 , v2 ) <EOL> s = self . spacing ( ) <EOL> return self . __inline_getitem_code_str % locals ( ) <EOL> return "<STR_LIT>" % locals ( ) <EOL> def md5 ( self , node ) : <EOL> return md5 ( self . module_name + str ( node . lineno ) + repr ( node ) ) . hexdigest ( ) <EOL> def track_lineno ( self , node , module = False ) : <EOL> if self . source_tracking and node . lineno : <EOL> if module : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % self . module_name ) <EOL> if self . line_tracking : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % node . lineno ) <EOL> if self . store_source : <EOL> self . track_lines [ node . lineno ] = self . get_line_trace ( node ) <EOL> def track_call ( self , call_code , lineno = None ) : <EOL> if not self . ignore_debug and self . debug and len ( call_code . strip ( ) ) > <NUM_LIT:0> : <EOL> dbg = self . uniqid ( "<STR_LIT>" ) <EOL> mod = self . module_name <EOL> s = self . spacing ( ) <EOL> call_code = """<STR_LIT>""" % locals ( ) <EOL> return call_code <EOL> __generator_code_str = """<STR_LIT>""" <EOL> __generator_code_str = __generator_code_str . replace ( "<STR_LIT:U+0020>" , "<STR_LIT:\t>" ) . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) <EOL> def generator ( self , code ) : <EOL> if self . is_generator : <EOL> s = self . spacing ( ) <EOL> if self . source_tracking : <EOL> src1 = "<STR_LIT>" % self . stacksize_depth <EOL> src2 = """<STR_LIT>""" % { '<STR_LIT:s>' : self . spacing ( ) , '<STR_LIT:d>' : self . stacksize_depth , '<STR_LIT:m>' : self . module_name } <EOL> else : <EOL> src1 = src2 = "<STR_LIT>" <EOL> self . w ( self . __generator_code_str % locals ( ) ) <EOL> self . indent ( ) <EOL> self . w ( code ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> self . w ( self . dedent ( ) + "<STR_LIT>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> else : <EOL> self . w ( captured_output , False ) <EOL> def generator_switch_open ( self ) : <EOL> if self . is_generator : <EOL> self . indent ( ) <EOL> def generator_switch_case ( self , increment ) : <EOL> if self . is_generator : <EOL> if increment : <EOL> self . generator_states [ - <NUM_LIT:1> ] += <NUM_LIT:1> <EOL> n_states = len ( self . generator_states ) <EOL> state = self . generator_states [ - <NUM_LIT:1> ] <EOL> if self . generator_states [ - <NUM_LIT:1> ] == <NUM_LIT:0> : <EOL> self . dedent ( ) <EOL> self . w ( self . indent ( ) + """<STR_LIT>""" % ( n_states - <NUM_LIT:1> , n_states - <NUM_LIT:1> ) ) <EOL> self . generator_clear_state ( ) <EOL> if n_states == <NUM_LIT:1> : <EOL> self . generator_throw ( ) <EOL> else : <EOL> if increment : <EOL> self . w ( self . spacing ( ) + """<STR_LIT>""" % ( n_states - <NUM_LIT:1> , state ) ) <EOL> self . w ( self . dedent ( ) + "<STR_LIT:}>" ) <EOL> self . w ( self . indent ( ) + """<STR_LIT>""" % ( n_states - <NUM_LIT:1> , state ) ) <EOL> def generator_switch_close ( self ) : <EOL> if self . is_generator : <EOL> self . w ( self . dedent ( ) + "<STR_LIT:}>" ) <EOL> def generator_add_state ( self ) : <EOL> if self . is_generator : <EOL> self . generator_states . append ( <NUM_LIT:0> ) <EOL> self . state_max_depth = len ( self . generator_states ) <EOL> def generator_del_state ( self ) : <EOL> if self . is_generator : <EOL> del self . generator_states [ - <NUM_LIT:1> ] <EOL> def generator_clear_state ( self ) : <EOL> if self . is_generator : <EOL> n_states = len ( self . generator_states ) <EOL> self . w ( self . spacing ( ) + """<STR_LIT>""" % ( n_states - <NUM_LIT:1> , n_states + <NUM_LIT:1> , n_states + <NUM_LIT:1> ) ) <EOL> def generator_reset_state ( self ) : <EOL> if self . is_generator : <EOL> n_states = len ( self . generator_states ) <EOL> self . w ( self . spacing ( ) + """<STR_LIT>""" % ( n_states , n_states ) ) <EOL> def generator_throw ( self ) : <EOL> self . w ( self . indent ( ) + "<STR_LIT>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( len ( self . generator_states ) - <NUM_LIT:1> , ) ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> self . w ( self . dedent ( ) + "<STR_LIT:}>" ) <EOL> def func_args ( self , node , current_klass , function_name , bind_type , args , stararg , dstararg ) : <EOL> try : <EOL> bind_type = BIND_TYPES_NUMERIC [ bind_type ] <EOL> except KeyError : <EOL> raise TranslationError ( "<STR_LIT>" % bind_type , node ) <EOL> _args = [ ] <EOL> default_pos = len ( args ) - len ( node . defaults ) <EOL> for idx , arg in enumerate ( args ) : <EOL> if idx < default_pos : <EOL> _args . append ( "<STR_LIT>" % arg ) <EOL> else : <EOL> default_value = self . expr ( node . defaults [ idx - default_pos ] , current_klass ) <EOL> _args . append ( """<STR_LIT>""" % ( arg , default_value ) ) <EOL> args = "<STR_LIT:U+002C>" . join ( _args ) <EOL> if dstararg : <EOL> args = "<STR_LIT>" % ( dstararg , args ) <EOL> else : <EOL> args = "<STR_LIT>" % args <EOL> if stararg : <EOL> args = "<STR_LIT>" % ( stararg , args ) <EOL> else : <EOL> args = "<STR_LIT>" % args <EOL> args = '<STR_LIT:[>' + args + '<STR_LIT:]>' <EOL> if args . endswith ( '<STR_LIT>' ) : <EOL> args = args [ : - <NUM_LIT:2> ] + '<STR_LIT:]>' <EOL> if function_name is None : <EOL> self . w ( "<STR_LIT>" % ( bind_type , args ) ) <EOL> else : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( function_name , bind_type ) ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( function_name , args ) ) <EOL> def _instance_method_init ( self , node , arg_names , varargname , kwargname , <EOL> current_klass , output = None ) : <EOL> output = output or self . output <EOL> maxargs1 = len ( arg_names ) - <NUM_LIT:1> <EOL> maxargs2 = len ( arg_names ) <EOL> minargs1 = maxargs1 - len ( node . defaults ) <EOL> minargs2 = maxargs2 - len ( node . defaults ) <EOL> if node . kwargs : <EOL> maxargs1 += <NUM_LIT:1> <EOL> maxargs2 += <NUM_LIT:1> <EOL> maxargs1str = "<STR_LIT>" % maxargs1 <EOL> maxargs2str = "<STR_LIT>" % maxargs2 <EOL> if node . varargs : <EOL> argcount1 = "<STR_LIT>" % minargs1 <EOL> maxargs1str = "<STR_LIT:null>" <EOL> elif minargs1 == maxargs1 : <EOL> argcount1 = "<STR_LIT>" % minargs1 <EOL> else : <EOL> argcount1 = "<STR_LIT>" % ( minargs1 , maxargs1 ) <EOL> if node . varargs : <EOL> argcount2 = "<STR_LIT>" % minargs2 <EOL> maxargs2str = "<STR_LIT:null>" <EOL> elif minargs2 == maxargs2 : <EOL> argcount2 = "<STR_LIT>" % minargs2 <EOL> else : <EOL> argcount2 = "<STR_LIT>" % ( minargs2 , maxargs2 ) <EOL> s = self . spacing ( ) <EOL> if self . create_locals : <EOL> args = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> args . append ( "<STR_LIT>" % len ( node . defaults ) ) <EOL> args . append ( bool ( node . varargs ) and "<STR_LIT:true>" or "<STR_LIT:false>" ) <EOL> args . append ( bool ( node . kwargs ) and "<STR_LIT:true>" or "<STR_LIT:false>" ) <EOL> args = "<STR_LIT:U+002CU+0020>" . join ( args ) <EOL> self . w ( s + "<STR_LIT>" % args ) <EOL> args = [ ] <EOL> if node . varargs : <EOL> args . append ( "<STR_LIT>" % locals ( ) ) <EOL> if node . kwargs : <EOL> args . append ( "<STR_LIT>" % locals ( ) ) <EOL> args = "<STR_LIT:U+002CU+0020>" . join ( args ) <EOL> if args : <EOL> self . w ( s + "<STR_LIT>" % args ) <EOL> if arg_names : <EOL> an = arg_names [ <NUM_LIT:0> ] <EOL> self . w ( s + "<STR_LIT>" % ( an , an ) ) <EOL> args = [ ] <EOL> for an in arg_names [ <NUM_LIT:1> : ] : <EOL> args . append ( "<STR_LIT>" % ( an , an ) ) <EOL> if args : <EOL> args = "<STR_LIT:U+002CU+0020>" . join ( args ) <EOL> self . w ( s + "<STR_LIT>" % args ) <EOL> if False : <EOL> an = arg_names [ <NUM_LIT:0> ] <EOL> self . w ( s + "<STR_LIT>" ) <EOL> self . w ( s + "<STR_LIT>" % an ) <EOL> self . w ( s + "<STR_LIT>" ) <EOL> self . w ( s + "<STR_LIT>" % ( an , an ) ) <EOL> self . w ( s + "<STR_LIT:}>" ) <EOL> for an in arg_names [ <NUM_LIT:1> : ] : <EOL> an = ( an , an , an ) <EOL> self . w ( s + "<STR_LIT>" % an ) <EOL> return <EOL> lpself = "<STR_LIT>" <EOL> lp = "<STR_LIT>" <EOL> self . w ( self . indent ( ) + """<STR_LIT>""" , output = output ) <EOL> if arg_names : <EOL> self . w ( self . spacing ( ) + """<STR_LIT>""" % ( lpself , arg_names [ <NUM_LIT:0> ] ) , output = output ) <EOL> if node . varargs : <EOL> self . _varargs_handler ( node , varargname , maxargs1 , lp ) <EOL> if node . kwargs : <EOL> self . w ( self . spacing ( ) + """<STR_LIT>""" % ( lpself , kwargname , maxargs1 ) , output = output ) <EOL> s = self . spacing ( ) <EOL> self . w ( """<STR_LIT>""" % locals ( ) , output = output ) <EOL> if node . varargs : <EOL> self . w ( """<STR_LIT>""" % locals ( ) , output = output ) <EOL> self . w ( """<STR_LIT>""" % locals ( ) , output = output ) <EOL> if self . function_argument_checking : <EOL> self . w ( self . spacing ( ) + """<STR_LIT>""" % ( argcount1 , minargs2 , maxargs2str ) , output = output ) <EOL> self . w ( self . dedent ( ) + """<STR_LIT>""" , output = output ) <EOL> self . indent ( ) <EOL> if arg_names : <EOL> self . w ( self . spacing ( ) + """<STR_LIT>""" % ( lpself , arg_names [ <NUM_LIT:0> ] ) , output = output ) <EOL> arg_idx = <NUM_LIT:0> <EOL> for arg_name in arg_names [ <NUM_LIT:1> : ] : <EOL> arg_idx += <NUM_LIT:1> <EOL> self . w ( self . spacing ( ) + """<STR_LIT>""" % ( lp , arg_name , arg_idx ) , output = output ) <EOL> if node . varargs : <EOL> self . _varargs_handler ( node , varargname , maxargs2 , lp ) <EOL> if node . kwargs : <EOL> self . w ( self . spacing ( ) + """<STR_LIT>""" % ( lpself , kwargname , maxargs2 ) , output = output ) <EOL> s = self . spacing ( ) <EOL> self . w ( """<STR_LIT>""" % locals ( ) , output = output ) <EOL> if node . varargs : <EOL> self . w ( """<STR_LIT>""" % locals ( ) , output = output ) <EOL> self . w ( """<STR_LIT>""" % locals ( ) , output = output ) <EOL> if self . function_argument_checking : <EOL> self . w ( """<STR_LIT>""" % ( self . spacing ( ) , self . spacing ( ) , argcount2 , minargs2 , maxargs2str ) , output = output ) <EOL> self . w ( self . dedent ( ) + "<STR_LIT:}>" , output = output ) <EOL> if arg_names and self . function_argument_checking : <EOL> self . w ( """<STR_LIT>""" % { '<STR_LIT:s>' : self . spacing ( ) , '<STR_LIT>' : arg_names [ <NUM_LIT:0> ] , '<STR_LIT>' : current_klass . __md5__ } , output = output ) <EOL> def _static_method_init ( self , node , arg_names , varargname , kwargname , <EOL> current_klass , output = None ) : <EOL> output = output or self . output <EOL> maxargs = len ( arg_names ) <EOL> minargs = maxargs - len ( node . defaults ) <EOL> maxargsstr = "<STR_LIT>" % maxargs <EOL> s = self . spacing ( ) <EOL> if False : <EOL> lp = "<STR_LIT>" <EOL> lpdec = "<STR_LIT>" <EOL> self . w ( s + "<STR_LIT>" ) <EOL> arg_idx = <NUM_LIT:0> <EOL> for arg_name in arg_names : <EOL> self . w ( s + """<STR_LIT>""" % ( lp , arg_name , arg_idx ) , output = output ) <EOL> arg_idx += <NUM_LIT:1> <EOL> else : <EOL> lpdec = "<STR_LIT>" <EOL> lp = "<STR_LIT>" <EOL> if node . kwargs : <EOL> maxargs += <NUM_LIT:1> <EOL> if node . varargs : <EOL> argcount = "<STR_LIT>" % minargs <EOL> maxargsstr = "<STR_LIT:null>" <EOL> elif minargs == maxargs : <EOL> argcount = "<STR_LIT>" % minargs <EOL> else : <EOL> argcount = "<STR_LIT>" % ( minargs , maxargs ) <EOL> if self . function_argument_checking : <EOL> self . w ( self . spacing ( ) + """<STR_LIT>""" % ( argcount , minargs , maxargsstr ) , output = output ) <EOL> if node . varargs : <EOL> self . _varargs_handler ( node , varargname , maxargs , lp ) <EOL> if node . kwargs : <EOL> self . w ( self . spacing ( ) + """<STR_LIT>""" % ( lpdec , kwargname , maxargs ) , output = output ) <EOL> s = self . spacing ( ) <EOL> self . w ( """<STR_LIT>""" % locals ( ) , output = output ) <EOL> if node . varargs : <EOL> self . w ( """<STR_LIT>""" % locals ( ) , output = output ) <EOL> self . w ( """<STR_LIT>""" % locals ( ) , output = output ) <EOL> def _class_method_init ( self , node , arg_names , varargname , kwargname , <EOL> current_klass , output = None ) : <EOL> output = output or self . output <EOL> maxargs = max ( <NUM_LIT:0> , len ( arg_names ) - <NUM_LIT:1> ) <EOL> minargs = max ( <NUM_LIT:0> , maxargs - len ( node . defaults ) ) <EOL> maxargsstr = "<STR_LIT>" % ( maxargs + <NUM_LIT:1> ) <EOL> if node . kwargs : <EOL> maxargs += <NUM_LIT:1> <EOL> if node . varargs : <EOL> argcount = "<STR_LIT>" % minargs <EOL> maxargsstr = "<STR_LIT:null>" <EOL> elif minargs == maxargs : <EOL> argcount = "<STR_LIT>" % minargs <EOL> maxargsstr = "<STR_LIT>" % ( maxargs ) <EOL> else : <EOL> argcount = "<STR_LIT>" % ( minargs , maxargs ) <EOL> if self . function_argument_checking : <EOL> self . w ( """<STR_LIT>""" % ( argcount , minargs + <NUM_LIT:1> , maxargsstr ) , output = output ) <EOL> self . w ( """<STR_LIT>""" % ( arg_names [ <NUM_LIT:0> ] , ) , output = output ) <EOL> if node . varargs : <EOL> self . _varargs_handler ( node , varargname , maxargs , "<STR_LIT>" ) <EOL> if node . kwargs : <EOL> self . w ( self . spacing ( ) + """<STR_LIT>""" % ( kwargname , maxargs ) , output = output ) <EOL> s = self . spacing ( ) <EOL> self . w ( """<STR_LIT>""" % locals ( ) , output = output ) <EOL> if node . varargs : <EOL> self . w ( """<STR_LIT>""" % locals ( ) , output = output ) <EOL> self . w ( """<STR_LIT>""" % locals ( ) , output = output ) <EOL> def _default_args_handler ( self , node , arg_names , current_klass , kwargname , <EOL> lp , output = None ) : <EOL> output = output or self . output <EOL> if node . kwargs : <EOL> revargs = arg_names [ <NUM_LIT:0> : ] <EOL> revargs . reverse ( ) <EOL> self . w ( """<STR_LIT>""" % { '<STR_LIT>' : lp , '<STR_LIT:s>' : self . spacing ( ) , '<STR_LIT:k>' : kwargname } , output = output ) <EOL> for v in revargs : <EOL> self . w ( """<STR_LIT>""" % { '<STR_LIT>' : lp , '<STR_LIT:s>' : self . spacing ( ) , '<STR_LIT:v>' : v , '<STR_LIT:k>' : kwargname , '<STR_LIT:a>' : len ( arg_names ) } , False , output = output ) <EOL> self . w ( """<STR_LIT>""" % { '<STR_LIT:s>' : self . spacing ( ) } , output = output ) <EOL> if len ( node . defaults ) : <EOL> default_pos = len ( arg_names ) - len ( node . defaults ) <EOL> for default_node in node . defaults : <EOL> default_name = arg_names [ default_pos ] <EOL> default_pos += <NUM_LIT:1> <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( lp , default_name , lp , default_name , default_pos + <NUM_LIT:1> ) , output = output ) <EOL> def _varargs_handler ( self , node , varargname , start , lp ) : <EOL> if node . kwargs : <EOL> end = "<STR_LIT>" <EOL> start -= <NUM_LIT:1> <EOL> else : <EOL> end = "<STR_LIT>" <EOL> if not lp : <EOL> lp = '<STR_LIT>' <EOL> self . w ( """<STR_LIT>""" % { '<STR_LIT:s>' : self . spacing ( ) , '<STR_LIT:v>' : varargname , '<STR_LIT:b>' : start , '<STR_LIT:e>' : end , '<STR_LIT>' : lp } ) <EOL> def _kwargs_parser ( self , node , function_name , arg_names , current_klass , method_ = False ) : <EOL> default_pos = len ( arg_names ) - len ( node . defaults ) <EOL> if not method_ : <EOL> self . w ( self . indent ( ) + function_name + "<STR_LIT>" , "<STR_LIT:U+002CU+0020>" . join ( [ "<STR_LIT>" ] + arg_names ) + "<STR_LIT>" ) <EOL> else : <EOL> self . w ( self . indent ( ) + "<STR_LIT>" , "<STR_LIT:U+002CU+0020>" . join ( [ "<STR_LIT>" ] + arg_names ) + "<STR_LIT>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( len ( arg_names ) + <NUM_LIT:1> ) ) <EOL> if len ( arg_names ) > <NUM_LIT:0> : <EOL> self . w ( """<STR_LIT>""" % { '<STR_LIT:s>' : self . spacing ( ) , '<STR_LIT>' : arg_names [ <NUM_LIT:0> ] } ) <EOL> idx = <NUM_LIT:1> <EOL> for arg_name in arg_names : <EOL> idx += <NUM_LIT:1> <EOL> self . w ( """<STR_LIT>""" % { '<STR_LIT:s>' : self . spacing ( ) , '<STR_LIT>' : arg_name , '<STR_LIT>' : idx } ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT:}>" ) <EOL> for arg_name in arg_names : <EOL> if self . function_argument_checking : <EOL> self . w ( """<STR_LIT>""" % { '<STR_LIT:s>' : self . spacing ( ) , '<STR_LIT>' : arg_name , '<STR_LIT>' : function_name } ) <EOL> else : <EOL> self . w ( self . indent ( ) + "<STR_LIT>" % ( arg_name ) ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( arg_name , arg_name ) ) <EOL> self . w ( self . dedent ( ) + "<STR_LIT:}>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % arg_name ) <EOL> if self . function_argument_checking and not node . kwargs : <EOL> self . w ( """<STR_LIT>""" % { '<STR_LIT:s>' : self . spacing ( ) , '<STR_LIT>' : function_name } ) <EOL> self . w ( """<STR_LIT>""" % { '<STR_LIT:s>' : self . spacing ( ) } ) <EOL> if node . kwargs : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> if not method_ : <EOL> self . w ( self . dedent ( ) + "<STR_LIT>" ) <EOL> else : <EOL> self . w ( self . dedent ( ) + "<STR_LIT>" ) <EOL> def _import ( self , node , current_klass , root_level = False ) : <EOL> self . _doImport ( node . names , current_klass , root_level , True ) <EOL> def _doImport ( self , names , current_klass , root_level , assignBase , <EOL> absPath = False , all = False ) : <EOL> if root_level : <EOL> modtype = '<STR_LIT>' <EOL> else : <EOL> modtype = '<STR_LIT>' <EOL> for importName , importAs in names : <EOL> if importName == '<STR_LIT>' : <EOL> continue <EOL> if importName . endswith ( "<STR_LIT>" ) : <EOL> self . add_imported_module ( importName ) <EOL> continue <EOL> searchList = [ ] <EOL> context = self . module_name <EOL> if '<STR_LIT:.>' in context : <EOL> package = context . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> relName = package + '<STR_LIT:.>' + importName <EOL> searchList . append ( relName ) <EOL> if '<STR_LIT:.>' in importName : <EOL> searchList . append ( relName . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] ) <EOL> searchList . append ( importName ) <EOL> if '<STR_LIT:.>' in importName : <EOL> searchList . append ( importName . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] ) <EOL> mod = self . lookup ( importName ) <EOL> package_mod = self . lookup ( importName . split ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] ) <EOL> if self . source_tracking : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> import_stmt = None <EOL> if ( mod [ <NUM_LIT:0> ] != '<STR_LIT>' <EOL> or ( assignBase and not package_mod [ <NUM_LIT:0> ] in [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> ) : <EOL> if absPath : <EOL> context = '<STR_LIT:null>' <EOL> else : <EOL> context = self . import_context <EOL> if not all : <EOL> import_stmt = "<STR_LIT>" % ( <EOL> importName , <EOL> context , <EOL> ) <EOL> else : <EOL> import_stmt = "<STR_LIT>" % ( <EOL> importName , <EOL> context , <EOL> self . modpfx ( ) [ : - <NUM_LIT:1> ] , <EOL> ) <EOL> if not assignBase : <EOL> self . w ( self . spacing ( ) + import_stmt + '<STR_LIT>' ) <EOL> self . _lhsFromName ( importName , current_klass , modtype ) <EOL> self . add_imported_module ( importName ) <EOL> if assignBase : <EOL> package_name = importName . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> if importAs : <EOL> ass_name = importAs <EOL> if not import_stmt is None : <EOL> import_stmt += '<STR_LIT>' <EOL> else : <EOL> ass_name = package_name <EOL> lhs = self . _lhsFromName ( ass_name , current_klass , modtype ) <EOL> if importAs : <EOL> mod_name = importName <EOL> else : <EOL> mod_name = ass_name <EOL> if import_stmt is None : <EOL> parent_mod_name = mod_name . split ( '<STR_LIT:.>' ) <EOL> if len ( parent_mod_name ) == <NUM_LIT:1> : <EOL> stmt = "<STR_LIT>" % ( lhs , mod_name ) <EOL> else : <EOL> mod_name = parent_mod_name [ - <NUM_LIT:1> ] <EOL> parent_mod_name = '<STR_LIT:.>' . join ( parent_mod_name [ : - <NUM_LIT:1> ] ) <EOL> stmt = "<STR_LIT>" % ( lhs , parent_mod_name , mod_name ) <EOL> else : <EOL> stmt = "<STR_LIT>" % ( lhs , import_stmt ) <EOL> self . w ( self . spacing ( ) + stmt ) <EOL> if self . source_tracking : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> def _from ( self , node , current_klass , root_level = False ) : <EOL> if node . modname == '<STR_LIT>' : <EOL> for name in node . names : <EOL> ass_name = name [ <NUM_LIT:1> ] or name [ <NUM_LIT:0> ] <EOL> try : <EOL> jsname = getattr ( __pyjamas__ , name [ <NUM_LIT:0> ] ) <EOL> if callable ( jsname ) : <EOL> self . add_lookup ( "<STR_LIT>" , ass_name , name [ <NUM_LIT:0> ] ) <EOL> else : <EOL> self . add_lookup ( "<STR_LIT>" , ass_name , jsname ) <EOL> except AttributeError , e : <EOL> pass <EOL> return <EOL> if node . modname == '<STR_LIT>' : <EOL> for name in node . names : <EOL> ass_name = name [ <NUM_LIT:1> ] or name [ <NUM_LIT:0> ] <EOL> self . add_lookup ( "<STR_LIT>" , ass_name , name [ <NUM_LIT:0> ] ) <EOL> return <EOL> if node . modname == '<STR_LIT>' : <EOL> for name in node . names : <EOL> future = getattr ( __future__ , name [ <NUM_LIT:0> ] , None ) <EOL> if callable ( future ) : <EOL> future ( self ) <EOL> else : <EOL> pass <EOL> return <EOL> absPath = False <EOL> modname = node . modname <EOL> if hasattr ( node , '<STR_LIT>' ) and node . level > <NUM_LIT:0> : <EOL> absPath = True <EOL> if self . relative_import_context is not None : <EOL> modname = self . relative_import_context . split ( '<STR_LIT:.>' ) <EOL> level = node . level - <NUM_LIT:1> <EOL> if self . relative_import_context is None or len ( modname ) <= level : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> node , self . module_name ) <EOL> if level : <EOL> modname = '<STR_LIT:.>' . join ( modname [ : - level ] ) <EOL> else : <EOL> modname = self . relative_import_context <EOL> if node . modname : <EOL> modname += '<STR_LIT:.>' + node . modname <EOL> for name in node . names : <EOL> if name [ <NUM_LIT:0> ] == "<STR_LIT:*>" : <EOL> self . _doImport ( ( ( modname , name [ <NUM_LIT:0> ] ) , ) , current_klass , <EOL> root_level , False , absPath , True ) <EOL> continue <EOL> sub = modname + '<STR_LIT:.>' + name [ <NUM_LIT:0> ] <EOL> ass_name = name [ <NUM_LIT:1> ] or name [ <NUM_LIT:0> ] <EOL> self . _doImport ( ( ( sub , ass_name ) , ) , current_klass , root_level , True , absPath ) <EOL> def _function ( self , node , current_klass , force_local = False ) : <EOL> if self . is_class_definition : <EOL> return self . _method ( node , current_klass ) <EOL> save_top_level = self . top_level <EOL> self . push_options ( ) <EOL> save_has_js_return = self . has_js_return <EOL> self . has_js_return = False <EOL> save_has_yield = self . has_yield <EOL> self . has_yield = False <EOL> save_is_generator = self . is_generator <EOL> self . is_generator = False <EOL> save_generator_states = self . generator_states <EOL> self . generator_states = [ <NUM_LIT:0> ] <EOL> self . state_max_depth = len ( self . generator_states ) <EOL> if not save_top_level or force_local : <EOL> function_name = node . name <EOL> else : <EOL> function_name = self . modpfx ( ) + node . name <EOL> function_name = self . add_lookup ( '<STR_LIT>' , node . name , function_name ) <EOL> staticmethod , classmethod , decorator_code = self . parse_decorators ( node , node . name , current_klass ) <EOL> if staticmethod or classmethod : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> v . node , self . module_name ) <EOL> self . push_lookup ( ) <EOL> arg_names = [ ] <EOL> for arg in node . argnames : <EOL> if isinstance ( arg , tuple ) : <EOL> for a in arg : <EOL> arg_names . append ( self . add_lookup ( '<STR_LIT>' , a , a ) ) <EOL> else : <EOL> arg_names . append ( self . add_lookup ( '<STR_LIT>' , arg , arg ) ) <EOL> normal_arg_names = list ( arg_names ) <EOL> if node . kwargs : <EOL> kwargname = normal_arg_names . pop ( ) <EOL> else : <EOL> kwargname = None <EOL> if node . varargs : <EOL> varargname = normal_arg_names . pop ( ) <EOL> else : <EOL> varargname = None <EOL> declared_arg_names = list ( normal_arg_names ) <EOL> function_args = "<STR_LIT:(>" + "<STR_LIT:U+002CU+0020>" . join ( declared_arg_names ) + "<STR_LIT:)>" <EOL> self . w ( self . indent ( ) + "<STR_LIT>" % ( function_name , function_args ) ) <EOL> self . _static_method_init ( node , declared_arg_names , varargname , kwargname , None ) <EOL> self . _default_args_handler ( node , declared_arg_names , None , kwargname , "<STR_LIT>" ) <EOL> local_arg_names = normal_arg_names + declared_arg_names <EOL> if node . kwargs : <EOL> local_arg_names . append ( kwargname ) <EOL> if node . varargs : <EOL> local_arg_names . append ( varargname ) <EOL> self . top_level = False <EOL> save_output = self . output <EOL> self . output = StringIO ( ) <EOL> if self . source_tracking : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( self . module_name , node . lineno ) ) <EOL> self . track_lineno ( node , True ) <EOL> for child in node . code : <EOL> self . _stmt ( child , None ) <EOL> if not self . has_yield and self . source_tracking and self . has_js_return : <EOL> self . source_tracking = False <EOL> self . output = StringIO ( ) <EOL> for child in node . code : <EOL> self . _stmt ( child , None ) <EOL> elif self . has_yield : <EOL> if self . has_js_return : <EOL> self . source_tracking = False <EOL> self . is_generator = True <EOL> self . generator_states = [ <NUM_LIT:0> ] <EOL> self . output = StringIO ( ) <EOL> self . indent ( ) <EOL> if self . source_tracking : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( self . module_name , node . lineno ) ) <EOL> self . track_lineno ( node , True ) <EOL> self . generator_switch_open ( ) <EOL> self . generator_switch_case ( increment = False ) <EOL> for child in node . code : <EOL> self . _stmt ( child , None ) <EOL> self . generator_switch_case ( increment = True ) <EOL> self . generator_switch_close ( ) <EOL> self . dedent ( ) <EOL> captured_output = self . output . getvalue ( ) <EOL> self . output = save_output <EOL> self . w ( self . local_js_vars_decl ( local_arg_names ) ) <EOL> if self . is_generator : <EOL> self . generator ( captured_output ) <EOL> else : <EOL> self . w ( captured_output , False ) <EOL> if node . code . nodes : <EOL> lastStmt = node . code . nodes [ - <NUM_LIT:1> ] <EOL> else : <EOL> lastStmt = None <EOL> if not isinstance ( lastStmt , self . ast . Return ) : <EOL> if self . source_tracking : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> if not self . _isNativeFunc ( lastStmt ) : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> self . w ( self . dedent ( ) + "<STR_LIT>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( function_name , node . name ) ) <EOL> self . pop_lookup ( ) <EOL> self . func_args ( node , current_klass , function_name , '<STR_LIT>' , declared_arg_names , varargname , kwargname ) <EOL> if decorator_code : <EOL> decorator_code = decorator_code % function_name <EOL> if function_name != decorator_code : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( function_name , decorator_code ) ) <EOL> self . generator_states = save_generator_states <EOL> self . state_max_depth = len ( self . generator_states ) <EOL> self . is_generator = save_is_generator <EOL> self . has_yield = save_has_yield <EOL> self . has_js_return = save_has_js_return <EOL> self . pop_options ( ) <EOL> self . top_level = save_top_level <EOL> def _assert ( self , node , current_klass ) : <EOL> expr = self . expr ( node . test , current_klass ) <EOL> if node . fail : <EOL> fail = self . expr ( node . fail , current_klass ) <EOL> else : <EOL> fail = '<STR_LIT>' <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" + expr + "<STR_LIT>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % fail ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> def _return ( self , node , current_klass ) : <EOL> expr = self . expr ( node . value , current_klass ) <EOL> self . track_lineno ( node ) <EOL> if self . is_generator : <EOL> if isinstance ( node . value , self . ast . Const ) : <EOL> if node . value . value is None : <EOL> if self . source_tracking : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> return <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> node , self . module_name ) <EOL> elif self . source_tracking : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" + expr + "<STR_LIT:;>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> else : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" + expr + "<STR_LIT:;>" ) <EOL> def _yield ( self , node , current_klass ) : <EOL> self . has_yield = True <EOL> expr = self . expr ( node . value , current_klass ) <EOL> self . track_lineno ( node ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" + expr + "<STR_LIT:;>" ) <EOL> if self . source_tracking : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( len ( self . generator_states ) - <NUM_LIT:1> , self . generator_states [ - <NUM_LIT:1> ] + <NUM_LIT:1> ) ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> self . generator_switch_case ( increment = True ) <EOL> self . generator_throw ( ) <EOL> def _yield_expr ( self , node , current_klass ) : <EOL> self . _yield ( node , current_klass ) <EOL> return '<STR_LIT>' <EOL> def _break ( self , node , current_klass ) : <EOL> self . generator_switch_case ( increment = True ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> def _continue ( self , node , current_klass ) : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> def _callfunc_code ( self , v , current_klass , is_statement = False , optlocal_var = False ) : <EOL> self . ignore_debug = False <EOL> method_name = None <EOL> if isinstance ( v . node , self . ast . Name ) : <EOL> name_type , pyname , jsname , depth , is_local = self . lookup ( v . node . name ) <EOL> if name_type == '<STR_LIT>' : <EOL> try : <EOL> raw_js = getattr ( __pyjamas__ , v . node . name ) <EOL> if callable ( raw_js ) : <EOL> raw_js , has_js_return = raw_js ( self , v , current_klass , <EOL> is_statement = is_statement ) <EOL> if has_js_return : <EOL> self . has_js_return = True <EOL> else : <EOL> raw_js = self . translate_escaped_names ( raw_js , current_klass ) <EOL> return raw_js <EOL> except AttributeError ( e ) : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" % pyname , <EOL> v . node , self . module_name ) <EOL> except TranslationError ( e ) : <EOL> raise TranslationError ( e . msg , v , self . module_name ) <EOL> elif v . node . name == '<STR_LIT>' : <EOL> return """<STR_LIT>""" % ( "<STR_LIT:U+002C>" . join ( [ "<STR_LIT>" % ( pyname , self . lookup_stack [ - <NUM_LIT:1> ] [ pyname ] [ <NUM_LIT:2> ] ) for pyname in self . lookup_stack [ - <NUM_LIT:1> ] if self . lookup_stack [ - <NUM_LIT:1> ] [ pyname ] [ <NUM_LIT:0> ] not in [ '<STR_LIT>' , '<STR_LIT>' ] ] ) ) <EOL> elif v . node . name == '<STR_LIT>' : <EOL> return "<STR_LIT>" % self . modpfx ( ) [ : - <NUM_LIT:1> ] <EOL> elif v . node . name == '<STR_LIT>' and depth == - <NUM_LIT:1> and len ( v . args ) == <NUM_LIT:1> : <EOL> expr = self . expr ( v . args [ <NUM_LIT:0> ] , current_klass ) <EOL> return self . inline_len_code ( expr ) <EOL> else : <EOL> if name_type is None : <EOL> if optlocal_var : <EOL> call_name = '<STR_LIT>' % ( <EOL> v . node . name , <EOL> self . closureSafe ( self . scopeName ( v . node . name , depth , is_local ) ) , <EOL> v . node . name , <EOL> ) <EOL> else : <EOL> call_name = self . closureSafe ( self . scopeName ( v . node . name , depth , is_local ) ) <EOL> else : <EOL> call_name = jsname <EOL> call_args = [ ] <EOL> elif isinstance ( v . node , self . ast . Getattr ) : <EOL> attrname = self . attrib_remap ( v . node . attrname ) <EOL> if isinstance ( v . node . expr , self . ast . Name ) : <EOL> call_name , method_name = self . _name2 ( v . node . expr , current_klass , attrname ) <EOL> call_args = [ ] <EOL> elif isinstance ( v . node . expr , self . ast . Getattr ) : <EOL> call_name = self . _getattr2 ( v . node . expr , current_klass , v . node . attrname ) <EOL> method_name = call_name . pop ( ) <EOL> call_name = self . attrib_join ( call_name ) <EOL> call_args = [ ] <EOL> elif isinstance ( v . node . expr , self . ast . CallFunc ) : <EOL> call_name = self . _callfunc ( v . node . expr , current_klass ) <EOL> method_name = attrname <EOL> call_args = [ ] <EOL> elif isinstance ( v . node . expr , self . ast . Subscript ) : <EOL> call_name = self . _subscript ( v . node . expr , current_klass ) <EOL> method_name = attrname <EOL> call_args = [ ] <EOL> elif isinstance ( v . node . expr , self . ast . Const ) : <EOL> call_name = self . expr ( v . node . expr , current_klass ) <EOL> method_name = attrname <EOL> call_args = [ ] <EOL> elif isinstance ( v . node . expr , self . ast . Slice ) : <EOL> call_name = self . _slice ( v . node . expr , current_klass ) <EOL> method_name = attrname <EOL> call_args = [ ] <EOL> else : <EOL> call_name = self . expr ( v . node . expr , current_klass ) <EOL> method_name = attrname <EOL> call_args = [ ] <EOL> elif isinstance ( v . node , self . ast . CallFunc ) : <EOL> call_name = self . _callfunc ( v . node , current_klass ) <EOL> call_args = [ ] <EOL> elif isinstance ( v . node , self . ast . Subscript ) : <EOL> call_name = self . _subscript ( v . node , current_klass ) <EOL> call_args = [ ] <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , v . node , self . module_name ) <EOL> if method_name in pyjs_attrib_remap : <EOL> method_name = pyjs_attrib_remap [ method_name ] <EOL> call_name = strip_py ( call_name ) <EOL> kwargs = [ ] <EOL> star_arg_name = None <EOL> if v . star_args : <EOL> star_arg_name = self . expr ( v . star_args , current_klass ) <EOL> dstar_arg_name = None <EOL> if v . dstar_args : <EOL> dstar_arg_name = self . expr ( v . dstar_args , current_klass ) <EOL> for ch4 in v . args : <EOL> if isinstance ( ch4 , self . ast . Keyword ) : <EOL> kwarg = "<STR_LIT>" % ( <EOL> self . vars_remap ( ch4 . name ) , <EOL> self . expr ( ch4 . expr , current_klass ) , <EOL> ) <EOL> kwargs . append ( kwarg ) <EOL> else : <EOL> arg = self . expr ( ch4 , current_klass ) <EOL> call_args . append ( arg ) <EOL> if kwargs : <EOL> fn_args = "<STR_LIT:U+002CU+0020>" . join ( [ '<STR_LIT:{>' + '<STR_LIT:U+002CU+0020>' . join ( kwargs ) + '<STR_LIT:}>' ] + call_args ) <EOL> else : <EOL> fn_args = "<STR_LIT:U+002CU+0020>" . join ( [ '<STR_LIT:{}>' ] + call_args ) <EOL> if kwargs or star_arg_name or dstar_arg_name : <EOL> if not star_arg_name : <EOL> star_arg_name = '<STR_LIT:null>' <EOL> if not dstar_arg_name : <EOL> dstar_arg_name = '<STR_LIT:null>' <EOL> if method_name is None : <EOL> call_code = ( "<STR_LIT>" + call_name + "<STR_LIT:U+002CU+0020>" <EOL> + star_arg_name <EOL> + "<STR_LIT:U+002CU+0020>" + dstar_arg_name <EOL> + "<STR_LIT>" + fn_args + "<STR_LIT:]>" <EOL> + "<STR_LIT:)>" ) <EOL> else : <EOL> call_code = ( "<STR_LIT>" + call_name + "<STR_LIT>" + method_name + "<STR_LIT>" <EOL> + star_arg_name <EOL> + "<STR_LIT:U+002CU+0020>" + dstar_arg_name <EOL> + "<STR_LIT>" + fn_args + "<STR_LIT:]>" <EOL> + "<STR_LIT:)>" ) <EOL> else : <EOL> if not method_name is None : <EOL> call_name = "<STR_LIT>" % ( call_name , method_name ) <EOL> call_code = call_name + "<STR_LIT:(>" + "<STR_LIT:U+002CU+0020>" . join ( call_args ) + "<STR_LIT:)>" <EOL> return call_code <EOL> def _callfunc ( self , v , current_klass , is_statement = False , optlocal_var = False ) : <EOL> call_code = self . _callfunc_code ( <EOL> v , <EOL> current_klass , <EOL> is_statement = is_statement , <EOL> optlocal_var = optlocal_var , <EOL> ) <EOL> if not self . ignore_debug : <EOL> call_code = self . track_call ( call_code , v . lineno ) <EOL> return call_code <EOL> def _print ( self , node , current_klass ) : <EOL> if not self . print_statements : <EOL> return <EOL> call_args = [ ] <EOL> for ch4 in node . nodes : <EOL> arg = self . expr ( ch4 , current_klass ) <EOL> call_args . append ( arg ) <EOL> self . w ( self . spacing ( ) + self . track_call ( "<STR_LIT>" % ( '<STR_LIT:U+002CU+0020>' . join ( call_args ) , int ( isinstance ( node , self . ast . Printnl ) ) ) , node . lineno ) + '<STR_LIT:;>' ) <EOL> def _tryFinally ( self , node , current_klass ) : <EOL> body = node . body <EOL> if not isinstance ( node . body , self . ast . TryExcept ) : <EOL> body = node <EOL> try : <EOL> node . body . final = node . final <EOL> except : <EOL> node . body . final_ = node . final_ <EOL> self . _tryExcept ( body , current_klass ) <EOL> def _tryExcept ( self , node , current_klass ) : <EOL> save_is_generator = self . is_generator <EOL> if self . is_generator : <EOL> self . is_generator = self . compiler . walk ( node , GeneratorExitVisitor ( ) , walker = GeneratorExitVisitor ( ) ) . has_yield <EOL> self . try_depth += <NUM_LIT:1> <EOL> self . stacksize_depth += <NUM_LIT:1> <EOL> save_state_max_depth = self . state_max_depth <EOL> start_states = len ( self . generator_states ) <EOL> pyjs_try_err = '<STR_LIT>' <EOL> if self . source_tracking : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % self . stacksize_depth ) <EOL> self . generator_switch_case ( increment = True ) <EOL> self . w ( self . indent ( ) + "<STR_LIT>" ) <EOL> added_try_except_counter = not self . ignore_debug and self . debug <EOL> if added_try_except_counter : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> self . indent ( ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> if self . is_generator : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( self . try_depth , self . try_depth , self . try_depth ) ) <EOL> self . generator_add_state ( ) <EOL> self . generator_switch_open ( ) <EOL> self . generator_switch_case ( increment = False ) <EOL> if self . is_generator : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( self . try_depth , ) ) <EOL> self . generator_switch_case ( increment = True ) <EOL> for stmt in node . body . nodes : <EOL> self . _stmt ( stmt , current_klass ) <EOL> self . generator_switch_case ( increment = True ) <EOL> if hasattr ( node , '<STR_LIT>' ) and node . else_ : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> self . generator_switch_case ( increment = True ) <EOL> self . generator_switch_case ( increment = True ) <EOL> self . generator_switch_close ( ) <EOL> if added_try_except_counter : <EOL> self . w ( self . dedent ( ) + "<STR_LIT>" ) <EOL> self . w ( self . dedent ( ) + "<STR_LIT>" % pyjs_try_err ) <EOL> self . indent ( ) <EOL> if self . source_tracking : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % self . stacksize_depth ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> if self . is_generator : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( self . try_depth , pyjs_try_err ) ) <EOL> try_state_max_depth = self . state_max_depth <EOL> self . generator_states += [ <NUM_LIT:0> for i in range ( save_state_max_depth + <NUM_LIT:1> , try_state_max_depth ) ] <EOL> if hasattr ( node , '<STR_LIT>' ) and node . else_ : <EOL> self . w ( self . indent ( ) + """<STR_LIT>""" % { '<STR_LIT:e>' : pyjs_try_err } ) <EOL> self . generator_add_state ( ) <EOL> self . generator_switch_open ( ) <EOL> self . generator_switch_case ( increment = False ) <EOL> for stmt in node . else_ : <EOL> self . _stmt ( stmt , current_klass ) <EOL> self . generator_switch_case ( increment = True ) <EOL> self . generator_switch_close ( ) <EOL> self . generator_del_state ( ) <EOL> self . w ( self . dedent ( ) + """<STR_LIT>""" ) <EOL> self . indent ( ) <EOL> if self . attribute_checking : <EOL> self . w ( self . spacing ( ) + """<STR_LIT>""" % ( pyjs_try_err , pyjs_try_err ) ) <EOL> self . w ( self . spacing ( ) + """<STR_LIT>""" % { '<STR_LIT:e>' : pyjs_try_err } ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( pyjs_try_err , self . module_prefix [ : - <NUM_LIT:1> ] ) ) <EOL> if self . source_tracking : <EOL> self . w ( """<STR_LIT>""" % { '<STR_LIT:s>' : self . spacing ( ) , '<STR_LIT:d>' : self . stacksize_depth , '<STR_LIT:m>' : self . module_name } ) <EOL> pyjs_try_err = self . add_lookup ( '<STR_LIT>' , pyjs_try_err , pyjs_try_err ) <EOL> pyjs_try_err_name = pyjs_try_err + "<STR_LIT>" <EOL> if hasattr ( node , '<STR_LIT>' ) : <EOL> else_str = self . spacing ( ) <EOL> if len ( node . handlers ) == <NUM_LIT:1> and node . handlers [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] is None : <EOL> else_str += "<STR_LIT>" <EOL> for handler in node . handlers : <EOL> lineno = handler [ <NUM_LIT:2> ] . nodes [ <NUM_LIT:0> ] . lineno <EOL> expr = handler [ <NUM_LIT:0> ] <EOL> as_ = handler [ <NUM_LIT:1> ] <EOL> if as_ : <EOL> errName = as_ . name <EOL> else : <EOL> errName = None <EOL> if not expr : <EOL> self . w ( "<STR_LIT>" % else_str ) <EOL> else : <EOL> if expr . lineno : <EOL> lineno = expr . lineno <EOL> l = [ ] <EOL> if isinstance ( expr , self . ast . Tuple ) : <EOL> for x in expr . nodes : <EOL> l . append ( "<STR_LIT>" % ( pyjs_try_err , <EOL> self . expr ( x , current_klass ) , pyjs_try_err , self . expr ( x , current_klass ) ) ) <EOL> else : <EOL> l = [ "<STR_LIT>" % ( pyjs_try_err , <EOL> self . expr ( expr , current_klass ) , pyjs_try_err , self . expr ( expr , current_klass ) ) ] <EOL> self . w ( "<STR_LIT>" % ( else_str , "<STR_LIT>" . join ( l ) ) ) <EOL> self . indent ( ) <EOL> if errName : <EOL> tnode = self . ast . Assign ( [ self . ast . AssName ( errName , "<STR_LIT>" , lineno ) ] , self . ast . Name ( pyjs_try_err , lineno ) , lineno ) <EOL> self . _assign ( tnode , current_klass ) <EOL> self . generator_add_state ( ) <EOL> self . generator_switch_open ( ) <EOL> self . generator_switch_case ( increment = False ) <EOL> for stmt in handler [ <NUM_LIT:2> ] : <EOL> self . _stmt ( stmt , current_klass ) <EOL> self . generator_switch_case ( increment = True ) <EOL> self . generator_switch_close ( ) <EOL> self . generator_del_state ( ) <EOL> self . w ( self . dedent ( ) + "<STR_LIT:}>" , False ) <EOL> else_str = "<STR_LIT>" <EOL> if node . handlers [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] : <EOL> self . w ( "<STR_LIT>" % ( else_str , pyjs_try_err ) ) <EOL> else : <EOL> self . w ( None ) <EOL> if hasattr ( node , '<STR_LIT>' ) and node . else_ : <EOL> self . w ( self . dedent ( ) + "<STR_LIT:}>" ) <EOL> final = None <EOL> if hasattr ( node , '<STR_LIT>' ) : <EOL> final = node . final <EOL> if hasattr ( node , '<STR_LIT>' ) : <EOL> final = node . final_ <EOL> if final is not None : <EOL> self . w ( self . dedent ( ) + "<STR_LIT>" ) <EOL> self . indent ( ) <EOL> if self . is_generator : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> else_except_state_max_depth = self . state_max_depth <EOL> self . generator_states = self . generator_states [ : save_state_max_depth ] <EOL> self . generator_states += [ <NUM_LIT:0> for i in range ( save_state_max_depth , else_except_state_max_depth ) ] <EOL> self . generator_add_state ( ) <EOL> self . generator_switch_open ( ) <EOL> self . generator_switch_case ( increment = False ) <EOL> for stmt in final : <EOL> self . _stmt ( stmt , current_klass ) <EOL> self . generator_switch_case ( increment = True ) <EOL> self . generator_switch_close ( ) <EOL> self . generator_states = self . generator_states [ : start_states + <NUM_LIT:1> ] <EOL> self . w ( self . dedent ( ) + "<STR_LIT:}>" ) <EOL> if self . is_generator : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( self . try_depth , ) ) <EOL> self . generator_clear_state ( ) <EOL> self . generator_del_state ( ) <EOL> self . try_depth -= <NUM_LIT:1> <EOL> self . stacksize_depth -= <NUM_LIT:1> <EOL> self . generator_switch_case ( increment = True ) <EOL> self . is_generator = save_is_generator <EOL> def _with ( self , v , current_klass ) : <EOL> """<STR_LIT>""" <EOL> expr = self . expr ( v . expr , current_klass ) <EOL> withvar = self . uniqid ( "<STR_LIT>" ) <EOL> if isinstance ( v . body , self . ast . Stmt ) : <EOL> body_nodes = list ( v . body . nodes ) <EOL> else : <EOL> body_nodes = [ v . body ] <EOL> if v . vars : <EOL> body_nodes [ <NUM_LIT:0> : <NUM_LIT:0> ] = [ self . ast . Assign ( [ v . vars ] , <EOL> self . ast . Name ( withvar ) ) ] <EOL> save_output = self . output <EOL> self . output = StringIO ( ) <EOL> self . indent ( ) <EOL> for node in body_nodes : <EOL> self . _stmt ( node , current_klass ) <EOL> self . dedent ( ) <EOL> captured_output = self . output <EOL> self . output = save_output <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % <EOL> dict ( expr = expr , <EOL> __with = self . pyjslib_name ( '<STR_LIT>' ) , <EOL> withvar = withvar ) ) <EOL> self . w ( captured_output . getvalue ( ) . rstrip ( ) ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> def _getattr ( self , v , current_klass , use_getattr = None ) : <EOL> return self . __getattr ( v , current_klass , use_getattr ) <EOL> def __getattr ( self , v , current_klass , use_getattr = None ) : <EOL> if use_getattr is None : <EOL> use_getattr = self . getattr_support <EOL> attr_name = self . attrib_remap ( v . attrname ) <EOL> if use_getattr : <EOL> expr = self . expr ( v . expr , current_klass ) <EOL> return [ "<STR_LIT>" % ( expr , attr_name ) ] <EOL> if isinstance ( v . expr , self . ast . Name ) : <EOL> obj = self . _name ( v . expr , current_klass , return_none_for_module = True ) <EOL> if not use_getattr or attr_name == '<STR_LIT>' or attr_name == '<STR_LIT>' : <EOL> return [ obj , attr_name ] <EOL> return [ "<STR_LIT>" % ( obj , attr_name ) ] <EOL> elif isinstance ( v . expr , self . ast . Getattr ) : <EOL> return self . __getattr ( v . expr , current_klass ) + [ attr_name ] <EOL> elif isinstance ( v . expr , self . ast . Subscript ) : <EOL> return [ self . _subscript ( v . expr , self . modpfx ( ) ) , attr_name ] <EOL> elif isinstance ( v . expr , self . ast . CallFunc ) : <EOL> return [ self . _callfunc ( v . expr , self . modpfx ( ) ) , attr_name ] <EOL> elif isinstance ( v . expr , self . ast . Const ) : <EOL> return [ self . _const ( v . expr ) , attr_name ] <EOL> elif isinstance ( v . expr , self . ast . List ) : <EOL> return [ self . _list ( v . expr , current_klass ) , attr_name ] <EOL> elif isinstance ( v . expr , self . ast . Dict ) : <EOL> return [ self . _dict ( v . expr , current_klass ) , attr_name ] <EOL> elif isinstance ( v . expr , self . ast . Tuple ) : <EOL> return [ self . _tuple ( v . expr , current_klass ) , attr_name ] <EOL> elif isinstance ( v . expr , self . ast . Lambda ) : <EOL> return [ self . _lambda ( v . expr , current_klass ) , attr_name ] <EOL> elif isinstance ( v . expr , self . ast . Slice ) : <EOL> return [ self . _slice ( v . expr , current_klass ) , attr_name ] <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , v . expr , self . module_name ) <EOL> def modpfx ( self ) : <EOL> return strip_py ( self . module_prefix ) <EOL> def _name ( self , v , current_klass , <EOL> return_none_for_module = False , <EOL> optlocal_var = False , <EOL> ) : <EOL> if not hasattr ( v , '<STR_LIT:name>' ) : <EOL> name = v . attrname <EOL> else : <EOL> name = v . name <EOL> name_type , pyname , jsname , depth , is_local = self . lookup ( name ) <EOL> if name_type is None : <EOL> if not optlocal_var : <EOL> return self . closureSafe ( self . scopeName ( name , depth , is_local ) ) <EOL> return '<STR_LIT>' % ( <EOL> name , <EOL> self . closureSafe ( self . scopeName ( name , depth , is_local ) ) , <EOL> name , <EOL> ) <EOL> return jsname <EOL> def _name2 ( self , v , current_klass , attr_name ) : <EOL> name_type , pyname , jsname , depth , is_local = self . lookup ( v . name ) <EOL> if name_type is None : <EOL> jsname = self . scopeName ( v . name , depth , is_local ) <EOL> jsname = self . closureSafe ( jsname ) <EOL> return jsname , attr_name <EOL> def _getattr2 ( self , v , current_klass , attr_name ) : <EOL> if isinstance ( v . expr , self . ast . Getattr ) : <EOL> return self . _getattr2 ( v . expr , current_klass , v . attrname ) + [ attr_name ] <EOL> if isinstance ( v . expr , self . ast . Name ) : <EOL> name_type , pyname , jsname , depth , is_local = self . lookup ( v . expr . name ) <EOL> if name_type is None : <EOL> jsname = self . closureSafe ( self . scopeName ( v . expr . name , depth , is_local ) ) <EOL> return [ jsname , v . attrname , attr_name ] <EOL> return [ self . expr ( v . expr , current_klass ) , v . attrname , attr_name ] <EOL> def _class ( self , node , parent_class = None ) : <EOL> save_top_level = self . top_level <EOL> if parent_class is None : <EOL> class_name = self . modpfx ( ) + node . name <EOL> else : <EOL> class_name = node . name <EOL> self . top_level = False <EOL> local_prefix = '<STR_LIT>' <EOL> name_scope = { } <EOL> current_klass = Klass ( class_name , name_scope ) <EOL> if self . function_argument_checking or self . module_name == '<STR_LIT>' : <EOL> current_klass . __md5__ = self . md5 ( node ) <EOL> if len ( node . bases ) == <NUM_LIT:0> : <EOL> base_classes = [ ( "<STR_LIT:object>" , "<STR_LIT>" ) ] <EOL> else : <EOL> base_classes = [ ] <EOL> for node_base in node . bases : <EOL> if isinstance ( node_base , self . ast . Name ) : <EOL> node_base_name = node_base . name <EOL> base_class = self . _name ( node_base , None ) <EOL> elif isinstance ( node_base , self . ast . Getattr ) : <EOL> node_base_name = node_base . attrname <EOL> base_class = self . expr ( node_base , None ) <EOL> else : <EOL> node_base_name = '<STR_LIT>' <EOL> base_class = self . expr ( node_base , parent_class ) <EOL> base_classes . append ( ( node_base_name , base_class ) ) <EOL> current_klass . set_base ( base_classes [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) <EOL> if node . name in [ '<STR_LIT:object>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> base_classes = [ ] <EOL> class_name = self . add_lookup ( '<STR_LIT:class>' , node . name , class_name ) <EOL> self . w ( self . indent ( ) + class_name + """<STR_LIT>""" % { '<STR_LIT:s>' : self . spacing ( ) , '<STR_LIT:p>' : local_prefix , '<STR_LIT>' : self . module_name } ) <EOL> if self . function_argument_checking or self . module_name == '<STR_LIT>' : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % { '<STR_LIT:p>' : local_prefix , '<STR_LIT:m>' : current_klass . __md5__ } ) <EOL> self . push_lookup ( name_scope ) <EOL> for child in node . code : <EOL> self . is_class_definition = True <EOL> self . local_prefix = local_prefix <EOL> self . _stmt ( child , current_klass ) <EOL> self . track_lineno ( node , False ) <EOL> create_class = """<STR_LIT>""" <EOL> if self . module_name == '<STR_LIT>' : <EOL> create_class += """<STR_LIT>""" <EOL> else : <EOL> create_class += """<STR_LIT>""" <EOL> create_class %= { '<STR_LIT:n>' : node . name , '<STR_LIT:s>' : self . spacing ( ) , '<STR_LIT>' : local_prefix , '<STR_LIT>' : "<STR_LIT:U+002C>" . join ( map ( lambda x : x [ <NUM_LIT:1> ] , base_classes ) ) } <EOL> create_class += """<STR_LIT>""" % self . dedent ( ) <EOL> self . w ( create_class ) <EOL> self . pop_lookup ( ) <EOL> self . is_class_definition = None <EOL> self . local_prefix = None <EOL> self . top_level = save_top_level <EOL> def classattr ( self , node , current_klass ) : <EOL> self . _assign ( node , current_klass ) <EOL> def _raise ( self , node , current_klass ) : <EOL> if self . is_generator : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( len ( self . generator_states ) - <NUM_LIT:1> , self . generator_states [ - <NUM_LIT:1> ] + <NUM_LIT:1> ) ) <EOL> if node . expr1 : <EOL> if self . source_tracking : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> if node . expr2 : <EOL> if node . expr3 : <EOL> self . w ( """<STR_LIT>""" % { '<STR_LIT:s>' : self . spacing ( ) , <EOL> '<STR_LIT>' : self . expr ( node . expr1 , current_klass ) , <EOL> '<STR_LIT>' : self . expr ( node . expr2 , current_klass ) , <EOL> '<STR_LIT>' : self . expr ( node . expr3 , current_klass ) , <EOL> } ) <EOL> else : <EOL> self . w ( """<STR_LIT>""" % { '<STR_LIT:s>' : self . spacing ( ) , <EOL> '<STR_LIT>' : self . expr ( node . expr1 , current_klass ) , <EOL> '<STR_LIT>' : self . expr ( node . expr2 , current_klass ) , <EOL> } ) <EOL> else : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % self . expr ( <EOL> node . expr1 , current_klass ) ) <EOL> else : <EOL> if self . source_tracking : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> s = self . spacing ( ) <EOL> self . w ( """<STR_LIT>""" % locals ( ) ) <EOL> self . generator_switch_case ( increment = True ) <EOL> def _method ( self , node , current_klass ) : <EOL> save_top_level = self . top_level <EOL> self . push_options ( ) <EOL> save_has_js_return = self . has_js_return <EOL> self . has_js_return = False <EOL> save_has_yield = self . has_yield <EOL> self . has_yield = False <EOL> save_is_generator = self . is_generator <EOL> self . is_generator = False <EOL> save_generator_states = self . generator_states <EOL> self . generator_states = [ <NUM_LIT:0> ] <EOL> self . state_max_depth = len ( self . generator_states ) <EOL> save_local_prefix = self . local_prefix <EOL> method_name = self . attrib_remap ( node . name ) <EOL> jsmethod_name = self . add_lookup ( '<STR_LIT>' , method_name , method_name ) <EOL> self . local_prefix = None <EOL> self . is_class_definition = None <EOL> staticmethod , classmethod , decorator_code = self . parse_decorators ( node , method_name , current_klass ) <EOL> if node . name == '<STR_LIT>' : <EOL> staticmethod = True <EOL> self . pop_lookup ( ) <EOL> self . push_lookup ( ) <EOL> arg_names = [ ] <EOL> for arg in node . argnames : <EOL> if isinstance ( arg , tuple ) : <EOL> for a in arg : <EOL> arg_names . append ( self . add_lookup ( '<STR_LIT>' , a , a ) ) <EOL> else : <EOL> arg_names . append ( self . add_lookup ( '<STR_LIT>' , arg , arg ) ) <EOL> normal_arg_names = arg_names [ <NUM_LIT:0> : ] <EOL> if node . kwargs : <EOL> kwargname = normal_arg_names . pop ( ) <EOL> else : <EOL> kwargname = None <EOL> if node . varargs : <EOL> varargname = normal_arg_names . pop ( ) <EOL> else : <EOL> varargname = None <EOL> declared_arg_names = list ( normal_arg_names ) <EOL> if staticmethod : <EOL> function_args = "<STR_LIT:(>" + "<STR_LIT:U+002CU+0020>" . join ( declared_arg_names ) + "<STR_LIT:)>" <EOL> else : <EOL> function_args = "<STR_LIT:(>" + "<STR_LIT:U+002CU+0020>" . join ( declared_arg_names [ <NUM_LIT:1> : ] ) + "<STR_LIT:)>" <EOL> self . w ( self . indent ( ) + "<STR_LIT>" + method_name + "<STR_LIT>" + function_args + "<STR_LIT>" ) <EOL> defaults_done_by_inline = False <EOL> if staticmethod : <EOL> self . _static_method_init ( node , declared_arg_names , varargname , kwargname , current_klass ) <EOL> elif classmethod : <EOL> self . _class_method_init ( node , declared_arg_names , varargname , kwargname , current_klass ) <EOL> else : <EOL> if self . create_locals : <EOL> defaults_done_by_inline = True <EOL> self . _instance_method_init ( node , declared_arg_names , varargname , kwargname , current_klass ) <EOL> if not defaults_done_by_inline : <EOL> self . _default_args_handler ( node , declared_arg_names , current_klass , kwargname , "<STR_LIT>" ) <EOL> local_arg_names = normal_arg_names + declared_arg_names <EOL> if node . kwargs : <EOL> local_arg_names . append ( kwargname ) <EOL> if node . varargs : <EOL> local_arg_names . append ( varargname ) <EOL> self . top_level = False <EOL> save_output = self . output <EOL> self . output = StringIO ( ) <EOL> if self . source_tracking : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( self . module_name , node . lineno ) ) <EOL> self . track_lineno ( node , True ) <EOL> for child in node . code : <EOL> self . _stmt ( child , current_klass ) <EOL> if not self . has_yield and self . source_tracking and self . has_js_return : <EOL> self . source_tracking = False <EOL> self . output = StringIO ( ) <EOL> for child in node . code : <EOL> self . _stmt ( child , None ) <EOL> elif self . has_yield : <EOL> if self . has_js_return : <EOL> self . source_tracking = False <EOL> self . is_generator = True <EOL> self . generator_states = [ <NUM_LIT:0> ] <EOL> self . output = StringIO ( ) <EOL> self . indent ( ) <EOL> if self . source_tracking : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( self . module_name , node . lineno ) ) <EOL> self . track_lineno ( node , True ) <EOL> self . generator_switch_open ( ) <EOL> self . generator_switch_case ( increment = False ) <EOL> for child in node . code : <EOL> self . _stmt ( child , None ) <EOL> self . generator_switch_case ( increment = True ) <EOL> self . generator_switch_close ( ) <EOL> self . dedent ( ) <EOL> captured_output = self . output . getvalue ( ) <EOL> self . output = save_output <EOL> self . w ( self . local_js_vars_decl ( local_arg_names ) ) <EOL> if self . is_generator : <EOL> self . generator ( captured_output ) <EOL> else : <EOL> self . w ( captured_output , False ) <EOL> if node . code . nodes : <EOL> lastStmt = node . code . nodes [ - <NUM_LIT:1> ] <EOL> else : <EOL> lastStmt = None <EOL> if not isinstance ( lastStmt , self . ast . Return ) : <EOL> if self . source_tracking : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> if not self . _isNativeFunc ( lastStmt ) : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" ) <EOL> self . w ( self . dedent ( ) + "<STR_LIT:}>" ) <EOL> bind_type = '<STR_LIT>' <EOL> if staticmethod : <EOL> bind_type = '<STR_LIT>' <EOL> elif classmethod : <EOL> bind_type = '<STR_LIT:class>' <EOL> self . pop_lookup ( ) <EOL> self . func_args ( node , current_klass , None , bind_type , declared_arg_names , varargname , kwargname ) <EOL> self . generator_states = save_generator_states <EOL> self . state_max_depth = len ( self . generator_states ) <EOL> self . is_generator = save_is_generator <EOL> self . has_yield = save_has_yield <EOL> self . has_js_return = save_has_js_return <EOL> self . pop_options ( ) <EOL> self . push_lookup ( current_klass . name_scope ) <EOL> staticmethod , classmethod , decorator_code = self . parse_decorators ( node , node . name , current_klass , <EOL> True , bind_type ) <EOL> decorator_code = decorator_code % '<STR_LIT>' <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( jsmethod_name , decorator_code ) ) <EOL> self . add_lookup ( '<STR_LIT>' , node . name , "<STR_LIT>" % jsmethod_name ) <EOL> self . local_prefix = save_local_prefix <EOL> self . is_class_definition = True <EOL> self . top_level = save_top_level <EOL> def _isNativeFunc ( self , node ) : <EOL> if isinstance ( node , self . ast . Discard ) : <EOL> if isinstance ( node . expr , self . ast . CallFunc ) : <EOL> if isinstance ( node . expr . node , self . ast . Name ) : <EOL> name_type , pyname , jsname , depth , is_local = self . lookup ( node . expr . node . name ) <EOL> if name_type == '<STR_LIT>' and jsname in __pyjamas__ . native_js_funcs : <EOL> return True <EOL> return False <EOL> def _exec ( self , node , current_klass ) : <EOL> pass <EOL> def _stmt ( self , node , current_klass ) : <EOL> self . track_lineno ( node ) <EOL> if isinstance ( node , self . ast . Return ) : <EOL> self . _return ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Yield ) : <EOL> self . _yield ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Break ) : <EOL> self . _break ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Continue ) : <EOL> self . _continue ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Assign ) : <EOL> self . _assign ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . AugAssign ) : <EOL> self . _augassign ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Discard ) : <EOL> self . _discard ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . If ) : <EOL> self . _if ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . For ) : <EOL> self . _for ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . While ) : <EOL> self . _while ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Subscript ) : <EOL> self . _subscript_stmt ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Global ) : <EOL> self . _global ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Pass ) : <EOL> pass <EOL> elif isinstance ( node , self . ast . Function ) : <EOL> self . _function ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Printnl ) : <EOL> self . _print ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Print ) : <EOL> self . _print ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . TryExcept ) : <EOL> self . _tryExcept ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . TryFinally ) : <EOL> self . _tryFinally ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . With ) : <EOL> self . _with ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Raise ) : <EOL> self . _raise ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Import ) : <EOL> self . _import ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . From ) : <EOL> self . _from ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . AssAttr ) : <EOL> self . _assattr ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Exec ) : <EOL> self . _exec ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Assert ) : <EOL> self . _assert ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Class ) : <EOL> self . _class ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Slice ) : <EOL> self . w ( self . spacing ( ) + self . _slice ( node , current_klass ) ) <EOL> elif isinstance ( node , self . ast . AssName ) : <EOL> if node . flags == "<STR_LIT>" : <EOL> name = self . _lhsFromName ( node . name , current_klass ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % name ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node , self . module_name ) <EOL> elif isinstance ( node , self . ast . AssTuple ) : <EOL> for node in node . nodes : <EOL> self . _stmt ( node , current_klass ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node , self . module_name ) <EOL> def get_start_line ( self , node , lineno ) : <EOL> if node : <EOL> if hasattr ( node , "<STR_LIT>" ) and node . lineno != None and node . lineno < lineno : <EOL> lineno = node . lineno <EOL> if hasattr ( node , '<STR_LIT>' ) : <EOL> for n in node . getChildren ( ) : <EOL> lineno = self . get_start_line ( n , lineno ) <EOL> return lineno <EOL> def get_line_trace ( self , node ) : <EOL> lineNum1 = "<STR_LIT>" <EOL> srcLine = "<STR_LIT>" <EOL> if hasattr ( node , "<STR_LIT>" ) : <EOL> if node . lineno != None : <EOL> lineNum2 = node . lineno <EOL> lineNum1 = self . get_start_line ( node , lineNum2 ) <EOL> srcLine = self . src [ min ( lineNum1 , len ( self . src ) ) - <NUM_LIT:1> ] . strip ( ) <EOL> if lineNum1 < lineNum2 : <EOL> srcLine += '<STR_LIT>' + self . src [ min ( lineNum2 , len ( self . src ) ) - <NUM_LIT:1> ] . strip ( ) <EOL> return self . module_name + "<STR_LIT>" + str ( lineNum1 ) + "<STR_LIT::>" + "<STR_LIT:\n>" + "<STR_LIT:U+0020>" + srcLine <EOL> def _augassign ( self , node , current_klass ) : <EOL> def astOP ( op ) : <EOL> if op == "<STR_LIT>" : <EOL> return self . ast . Add <EOL> if op == "<STR_LIT>" : <EOL> return self . ast . Sub <EOL> if op == "<STR_LIT>" : <EOL> return self . ast . Mul <EOL> if op == "<STR_LIT>" : <EOL> return self . ast . Div <EOL> if op == "<STR_LIT>" : <EOL> return self . ast . Mod <EOL> if op == "<STR_LIT>" : <EOL> return self . ast . FloorDiv <EOL> if op == "<STR_LIT>" : <EOL> return self . ast . Power <EOL> if self . number_classes : <EOL> if op == "<STR_LIT>" : <EOL> return self . ast . Bitand <EOL> if op == "<STR_LIT>" : <EOL> return self . ast . Bitxor <EOL> if op == "<STR_LIT>" : <EOL> return self . ast . Bitor <EOL> if op == "<STR_LIT>" : <EOL> return self . ast . RightShift <EOL> if op == "<STR_LIT>" : <EOL> return self . ast . LeftShift <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node , self . module_name ) <EOL> v = node . node <EOL> if isinstance ( v , self . ast . Getattr ) : <EOL> lhs = self . attrib_join ( self . _getattr ( v , current_klass , False ) ) <EOL> lhs_ass = self . ast . AssAttr ( v . expr , v . attrname , "<STR_LIT>" , node . lineno ) <EOL> elif isinstance ( v , self . ast . Name ) : <EOL> lhs = self . _name ( v , current_klass ) <EOL> lhs_ass = self . ast . AssName ( v . name , "<STR_LIT>" , node . lineno ) <EOL> elif isinstance ( v , self . ast . Subscript ) or self . operator_funcs : <EOL> if len ( v . subs ) != <NUM_LIT:1> : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , v , self . module_name ) <EOL> lhs = self . ast . Subscript ( v . expr , "<STR_LIT>" , v . subs ) <EOL> expr = v . expr <EOL> subs = v . subs <EOL> if not ( isinstance ( v . subs [ <NUM_LIT:0> ] , self . ast . Const ) or isinstance ( v . subs [ <NUM_LIT:0> ] , self . ast . Name ) ) or not isinstance ( v . expr , self . ast . Name ) : <EOL> augexpr = self . uniqid ( '<STR_LIT>' ) <EOL> augsub = self . uniqid ( '<STR_LIT>' ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" + augsub + "<STR_LIT>" + self . expr ( subs [ <NUM_LIT:0> ] , current_klass ) + "<STR_LIT:;>" ) <EOL> self . add_lookup ( '<STR_LIT>' , augexpr , augexpr ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" + augexpr + "<STR_LIT>" + self . expr ( expr , current_klass ) + "<STR_LIT:;>" ) <EOL> self . add_lookup ( '<STR_LIT>' , augsub , augsub ) <EOL> lhs = self . ast . Subscript ( self . ast . Name ( augexpr ) , "<STR_LIT>" , [ self . ast . Name ( augsub ) ] ) <EOL> v = self . ast . Subscript ( self . ast . Name ( augexpr ) , v . flags , [ self . ast . Name ( augsub ) ] ) <EOL> op = astOP ( node . op ) <EOL> try : <EOL> tnode = self . ast . Assign ( [ lhs ] , op ( ( v , node . expr ) ) ) <EOL> except : <EOL> tnode = self . ast . Assign ( [ lhs ] , op ( v , node . expr ) ) <EOL> return self . _assign ( tnode , current_klass ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , v , self . module_name ) <EOL> try : <EOL> op_ass = astOP ( node . op ) <EOL> except : <EOL> op_ass = None <EOL> if not self . operator_funcs or op_ass is None : <EOL> op = node . op <EOL> rhs = self . expr ( node . expr , current_klass ) <EOL> self . w ( self . spacing ( ) + lhs + "<STR_LIT:U+0020>" + op + "<STR_LIT:U+0020>" + rhs + "<STR_LIT:;>" ) <EOL> return <EOL> if isinstance ( v , self . ast . Name ) : <EOL> self . add_lookup ( '<STR_LIT>' , v . name , lhs ) <EOL> op = astOP ( node . op ) <EOL> try : <EOL> tnode = self . ast . Assign ( [ lhs_ass ] , op ( ( v , node . expr ) ) ) <EOL> except : <EOL> tnode = self . ast . Assign ( [ lhs_ass ] , op ( v , node . expr ) ) <EOL> return self . _assign ( tnode , current_klass ) <EOL> def _lhsFromName ( self , name , current_klass , set_name_type = '<STR_LIT>' ) : <EOL> name_type , pyname , jsname , depth , is_local = self . lookup ( name ) <EOL> if name_type == "<STR_LIT>" : <EOL> lhs = jsname <EOL> elif is_local : <EOL> lhs = jsname <EOL> self . add_lookup ( set_name_type , name , jsname ) <EOL> elif self . top_level : <EOL> if current_klass : <EOL> lhs = current_klass . name + "<STR_LIT:.>" + name <EOL> else : <EOL> vname = self . modpfx ( ) + name <EOL> vname = self . add_lookup ( set_name_type , name , vname ) <EOL> lhs = vname <EOL> else : <EOL> vname = self . add_lookup ( set_name_type , name , name ) <EOL> if self . create_locals : <EOL> name_type , pyname , jsname , depth , is_local = self . lookup ( name ) <EOL> if is_local : <EOL> lhs = jsname <EOL> self . add_lookup ( set_name_type , name , jsname ) <EOL> else : <EOL> lhs = vname <EOL> else : <EOL> lhs = vname <EOL> return lhs <EOL> def _lhsFromAttr ( self , v , current_klass ) : <EOL> if isinstance ( v . expr , self . ast . Name ) : <EOL> lhs = self . _name ( v . expr , current_klass ) <EOL> elif isinstance ( v . expr , self . ast . Getattr ) : <EOL> lhs = self . attrib_join ( self . _getattr ( v , current_klass , False ) [ : - <NUM_LIT:1> ] ) <EOL> elif isinstance ( v . expr , self . ast . Subscript ) : <EOL> lhs = self . _subscript ( v . expr , current_klass ) <EOL> elif isinstance ( v . expr , self . ast . CallFunc ) : <EOL> lhs = self . _callfunc ( v . expr , current_klass ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , v . expr , self . module_name ) <EOL> return self . closureSafe ( lhs ) <EOL> def _assigns_list ( self , v , current_klass , expr ) : <EOL> """<STR_LIT>""" <EOL> assigns = [ ] <EOL> if isinstance ( v , self . ast . AssAttr ) : <EOL> attr_name = self . attrib_remap ( v . attrname ) <EOL> lhs = self . _lhsFromAttr ( v , current_klass ) <EOL> if v . flags == "<STR_LIT>" : <EOL> op = "<STR_LIT:=>" <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , v , self . module_name ) <EOL> if self . descriptors : <EOL> desc_setattr = ( """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" % <EOL> dict ( <EOL> setattr = self . pyjslib_name ( '<STR_LIT>' ) , <EOL> l = lhs , <EOL> a = attr_name , <EOL> r = expr ) <EOL> ) <EOL> assigns . append ( desc_setattr ) <EOL> return assigns <EOL> lhs += "<STR_LIT>" % attr_name <EOL> elif isinstance ( v , self . ast . AssName ) : <EOL> lhs = self . _lhsFromName ( v . name , current_klass ) <EOL> if v . flags == "<STR_LIT>" : <EOL> op = "<STR_LIT:=>" <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , v , self . module_name ) <EOL> elif isinstance ( v , self . ast . Subscript ) : <EOL> if v . flags == "<STR_LIT>" : <EOL> obj = self . expr ( v . expr , current_klass ) <EOL> if len ( v . subs ) != <NUM_LIT:1> : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , v , self . module_name ) <EOL> idx = self . expr ( v . subs [ <NUM_LIT:0> ] , current_klass ) <EOL> assigns . append ( self . track_call ( obj + "<STR_LIT>" + idx + "<STR_LIT:U+002CU+0020>" + expr + "<STR_LIT:)>" , v . lineno ) + '<STR_LIT:;>' ) <EOL> return assigns <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , v , self . module_name ) <EOL> elif isinstance ( v , self . ast . Slice ) : <EOL> if v . flags == "<STR_LIT>" : <EOL> if not v . lower : <EOL> lower = <NUM_LIT:0> <EOL> else : <EOL> lower = self . expr ( v . lower , current_klass ) <EOL> if not v . upper : <EOL> upper = '<STR_LIT:null>' <EOL> else : <EOL> upper = self . expr ( v . upper , current_klass ) <EOL> obj = self . expr ( v . expr , current_klass ) <EOL> assigns . append ( self . track_call ( <EOL> self . pyjslib_name ( "<STR_LIT>" , <EOL> args = [ obj , lower , upper , expr ] ) , <EOL> v . lineno ) + '<STR_LIT:;>' ) <EOL> return assigns <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , v , self . module_name ) <EOL> elif isinstance ( v , ( self . ast . AssList , self . ast . AssTuple ) ) : <EOL> """<STR_LIT>""" <EOL> child_nodes = v . getChildNodes ( ) <EOL> extended_unpack = '<STR_LIT:null>' <EOL> for child in child_nodes : <EOL> pass <EOL> tempName = self . uniqid ( "<STR_LIT>" ) <EOL> unpack_call = self . track_call ( <EOL> self . pyjslib_name ( '<STR_LIT>' , <EOL> args = [ expr , len ( child_nodes ) , extended_unpack ] <EOL> ) , v . lineno ) <EOL> assigns . append ( "<STR_LIT>" + tempName + "<STR_LIT>" + unpack_call + "<STR_LIT:;>" ) <EOL> for index , child in enumerate ( child_nodes ) : <EOL> unpacked_value = tempName + "<STR_LIT:[>" + str ( index ) + "<STR_LIT:]>" ; <EOL> assigns . extend ( self . _assigns_list ( child , current_klass , unpacked_value ) ) <EOL> return assigns <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , v , self . module_name ) <EOL> assigns . append ( lhs + "<STR_LIT:U+0020>" + op + "<STR_LIT:U+0020>" + expr + "<STR_LIT:;>" ) <EOL> return assigns <EOL> def _assign ( self , node , current_klass ) : <EOL> if len ( node . nodes ) != <NUM_LIT:1> : <EOL> tempvar = self . uniqid ( "<STR_LIT>" ) <EOL> tnode = self . ast . Assign ( [ self . ast . AssName ( tempvar , "<STR_LIT>" , node . lineno ) ] , node . expr , node . lineno ) <EOL> self . _assign ( tnode , current_klass ) <EOL> for v in node . nodes : <EOL> tnode2 = self . ast . Assign ( [ v ] , self . ast . Name ( tempvar , node . lineno ) , node . lineno ) <EOL> self . _assign ( tnode2 , current_klass ) <EOL> return <EOL> v = node . nodes [ <NUM_LIT:0> ] <EOL> rhs = self . expr ( node . expr , current_klass ) <EOL> assigns = self . _assigns_list ( v , current_klass , rhs ) <EOL> for line in assigns : <EOL> self . w ( self . spacing ( ) + line ) <EOL> def _discard ( self , node , current_klass ) : <EOL> if isinstance ( node . expr , self . ast . CallFunc ) : <EOL> expr = self . _callfunc ( <EOL> node . expr , <EOL> current_klass , <EOL> is_statement = True , <EOL> optlocal_var = isinstance ( node . expr . node , self . ast . Name ) , <EOL> ) <EOL> if isinstance ( node . expr . node , self . ast . Name ) : <EOL> name_type , pyname , jsname , depth , is_local = self . lookup ( node . expr . node . name ) <EOL> if name_type == '<STR_LIT>' and jsname in __pyjamas__ . native_js_funcs : <EOL> self . w ( expr ) <EOL> return <EOL> self . w ( self . spacing ( ) + expr + "<STR_LIT:;>" ) <EOL> elif isinstance ( node . expr , self . ast . Const ) : <EOL> if node . expr . value in [ "<STR_LIT:@>" + "<STR_LIT>" , "<STR_LIT:@>" + "<STR_LIT>" ] : <EOL> self . w ( node . expr . value ) <EOL> return <EOL> elif isinstance ( node . expr , self . ast . Yield ) : <EOL> self . _yield ( node . expr , current_klass ) <EOL> else : <EOL> expr = self . expr ( node . expr , current_klass ) <EOL> self . w ( self . spacing ( ) + expr + "<STR_LIT:;>" ) <EOL> def _if ( self , node , current_klass ) : <EOL> save_is_generator = self . is_generator <EOL> if self . is_generator : <EOL> self . is_generator = self . compiler . walk ( node , GeneratorExitVisitor ( ) , walker = GeneratorExitVisitor ( ) ) . has_yield <EOL> if self . is_generator : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( len ( self . generator_states ) + <NUM_LIT:1> , ) ) <EOL> self . generator_switch_case ( increment = True ) <EOL> self . generator_add_state ( ) <EOL> for i in range ( len ( node . tests ) ) : <EOL> test , consequence = node . tests [ i ] <EOL> if i == <NUM_LIT:0> : <EOL> keyword = "<STR_LIT>" <EOL> else : <EOL> keyword = "<STR_LIT>" <EOL> self . lookup_stack [ - <NUM_LIT:1> ] <EOL> self . _if_test ( keyword , test , consequence , node , current_klass ) <EOL> if node . else_ : <EOL> keyword = "<STR_LIT>" <EOL> test = None <EOL> consequence = node . else_ <EOL> self . _if_test ( keyword , test , consequence , node , current_klass ) <EOL> if self . is_generator : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( len ( self . generator_states ) - <NUM_LIT:1> , ) ) <EOL> self . generator_del_state ( ) <EOL> self . is_generator = save_is_generator <EOL> def _if_test ( self , keyword , test , consequence , node , current_klass ) : <EOL> if test : <EOL> expr = self . expr ( test , current_klass ) <EOL> if not self . is_generator : <EOL> self . w ( self . indent ( ) + keyword + "<STR_LIT>" + self . track_call ( self . inline_bool_code ( expr ) , test . lineno ) + "<STR_LIT>" ) <EOL> else : <EOL> self . generator_states [ - <NUM_LIT:1> ] += <NUM_LIT:1> <EOL> self . w ( self . indent ( ) + keyword + "<STR_LIT>" % ( len ( self . generator_states ) - <NUM_LIT:1> , self . generator_states [ - <NUM_LIT:1> ] , len ( self . generator_states ) - <NUM_LIT:1> , self . generator_states [ - <NUM_LIT:1> ] , ) + self . track_call ( self . inline_bool_code ( expr ) , test . lineno ) + "<STR_LIT>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( len ( self . generator_states ) - <NUM_LIT:1> , self . generator_states [ - <NUM_LIT:1> ] ) ) <EOL> else : <EOL> if not self . is_generator : <EOL> self . w ( self . indent ( ) + keyword + "<STR_LIT>" ) <EOL> else : <EOL> self . generator_states [ - <NUM_LIT:1> ] += <NUM_LIT:1> <EOL> self . w ( self . indent ( ) + keyword + "<STR_LIT>" % ( len ( self . generator_states ) - <NUM_LIT:1> , len ( self . generator_states ) - <NUM_LIT:1> , self . generator_states [ - <NUM_LIT:1> ] , ) ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( len ( self . generator_states ) - <NUM_LIT:1> , self . generator_states [ - <NUM_LIT:1> ] ) ) <EOL> if self . is_generator : <EOL> self . generator_add_state ( ) <EOL> self . generator_switch_open ( ) <EOL> self . generator_switch_case ( increment = False ) <EOL> if isinstance ( consequence , self . ast . Stmt ) : <EOL> for child in consequence . nodes : <EOL> self . _stmt ( child , current_klass ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , consequence , self . module_name ) <EOL> if self . is_generator : <EOL> self . generator_switch_case ( increment = True ) <EOL> self . generator_switch_close ( ) <EOL> self . generator_del_state ( ) <EOL> self . w ( self . dedent ( ) + "<STR_LIT:}>" ) <EOL> def _compare ( self , node , current_klass ) : <EOL> lhs = self . expr ( node . expr , current_klass ) <EOL> if len ( node . ops ) != <NUM_LIT:1> : <EOL> cmp = [ ] <EOL> for op , rhs_node in node . ops : <EOL> rhsname = self . uniqid ( "<STR_LIT>" ) <EOL> rhs = self . expr ( rhs_node , current_klass ) <EOL> rhs = "<STR_LIT>" % ( rhsname , rhs ) <EOL> cmp . append ( self . compare_code ( op , lhs , rhs ) ) <EOL> lhs = rhsname <EOL> return "<STR_LIT>" % "<STR_LIT>" . join ( cmp ) <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node , self . module_name ) <EOL> op = node . ops [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> rhs_node = node . ops [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> rhs = self . expr ( rhs_node , current_klass ) <EOL> return self . compare_code ( op , lhs , rhs ) <EOL> def compare_code ( self , op , lhs , rhs ) : <EOL> if op == "<STR_LIT>" : <EOL> if not self . stupid_mode : <EOL> return self . inline_eq_code ( lhs , rhs ) <EOL> if op == "<STR_LIT>" : <EOL> if not self . stupid_mode : <EOL> return "<STR_LIT:!>" + self . inline_eq_code ( lhs , rhs ) <EOL> if op == "<STR_LIT:<>" : <EOL> if not self . stupid_mode : <EOL> return "<STR_LIT>" % self . inline_cmp_code ( lhs , rhs ) <EOL> if op == "<STR_LIT>" : <EOL> if not self . stupid_mode : <EOL> return "<STR_LIT>" % self . inline_cmp_code ( lhs , rhs ) <EOL> if op == "<STR_LIT:>>" : <EOL> if not self . stupid_mode : <EOL> return "<STR_LIT>" % self . inline_cmp_code ( lhs , rhs ) <EOL> if op == "<STR_LIT>" : <EOL> if not self . stupid_mode : <EOL> return "<STR_LIT>" % self . inline_cmp_code ( lhs , rhs ) <EOL> if op == "<STR_LIT>" : <EOL> return rhs + "<STR_LIT>" + lhs + "<STR_LIT:)>" <EOL> elif op == "<STR_LIT>" : <EOL> return "<STR_LIT:!>" + rhs + "<STR_LIT>" + lhs + "<STR_LIT:)>" <EOL> if op == "<STR_LIT>" : <EOL> if self . number_classes : <EOL> return "<STR_LIT>" % ( lhs , rhs ) <EOL> op = "<STR_LIT>" <EOL> if op == "<STR_LIT>" : <EOL> if self . number_classes : <EOL> return "<STR_LIT>" % ( lhs , rhs ) <EOL> op = "<STR_LIT>" <EOL> return "<STR_LIT:(>" + lhs + "<STR_LIT:U+0020>" + op + "<STR_LIT:U+0020>" + rhs + "<STR_LIT:)>" <EOL> def _not ( self , node , current_klass ) : <EOL> expr = self . expr ( node . expr , current_klass ) <EOL> if self . stupid_mode : <EOL> return "<STR_LIT>" % expr <EOL> return "<STR_LIT:!>" + self . inline_bool_code ( expr ) <EOL> def _or ( self , node , current_klass ) : <EOL> if self . stupid_mode : <EOL> return "<STR_LIT>" . join ( map ( bracket_fn , [ self . expr ( child , current_klass ) for child in node . nodes ] ) ) <EOL> s = self . spacing ( ) <EOL> expr = "<STR_LIT>" <EOL> for e in [ self . expr ( child , current_klass ) for child in node . nodes [ : - <NUM_LIT:1> ] ] : <EOL> v = self . uniqid ( '<STR_LIT>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v , v ) <EOL> bool = self . inline_bool_code ( "<STR_LIT>" % locals ( ) ) <EOL> expr = expr . replace ( '<STR_LIT>' , "<STR_LIT>" % locals ( ) ) <EOL> v = self . uniqid ( '<STR_LIT>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v , v ) <EOL> return expr . replace ( '<STR_LIT>' , self . expr ( node . nodes [ - <NUM_LIT:1> ] , current_klass ) ) <EOL> expr = "<STR_LIT:U+002C>" . join ( [ self . expr ( child , current_klass ) for child in node . nodes ] ) <EOL> return "<STR_LIT>" % expr <EOL> def _and ( self , node , current_klass ) : <EOL> if self . stupid_mode : <EOL> return "<STR_LIT>" . join ( map ( bracket_fn , [ self . expr ( child , current_klass ) for child in node . nodes ] ) ) <EOL> s = self . spacing ( ) <EOL> expr = "<STR_LIT>" <EOL> for e in [ self . expr ( child , current_klass ) for child in node . nodes [ : - <NUM_LIT:1> ] ] : <EOL> v = self . uniqid ( '<STR_LIT>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v , v ) <EOL> bool = self . inline_bool_code ( "<STR_LIT>" % locals ( ) ) <EOL> expr = expr . replace ( '<STR_LIT>' , "<STR_LIT>" % locals ( ) ) <EOL> v = self . uniqid ( '<STR_LIT>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v , v ) <EOL> return expr . replace ( '<STR_LIT>' , self . expr ( node . nodes [ - <NUM_LIT:1> ] , current_klass ) ) <EOL> expr = "<STR_LIT:U+002C>" . join ( [ self . expr ( child , current_klass ) for child in node . nodes ] ) <EOL> return "<STR_LIT>" % expr <EOL> def _for ( self , node , current_klass ) : <EOL> save_is_generator = self . is_generator <EOL> if self . is_generator : <EOL> self . is_generator = self . compiler . walk ( node , GeneratorExitVisitor ( ) , walker = GeneratorExitVisitor ( ) ) . has_yield <EOL> assign_name = "<STR_LIT>" <EOL> assign_tuple = [ ] <EOL> iterid = self . uniqid ( '<STR_LIT>' ) <EOL> iterator_name = "<STR_LIT>" % iterid <EOL> self . add_lookup ( '<STR_LIT>' , iterator_name , iterator_name ) <EOL> nextval = "<STR_LIT>" % iterid <EOL> self . add_lookup ( '<STR_LIT>' , nextval , nextval ) <EOL> gentype = "<STR_LIT>" % iterid <EOL> self . add_lookup ( '<STR_LIT>' , gentype , gentype ) <EOL> array = "<STR_LIT>" % iterid <EOL> self . add_lookup ( '<STR_LIT>' , array , array ) <EOL> loopvar = "<STR_LIT>" % iterid <EOL> self . add_lookup ( '<STR_LIT>' , loopvar , loopvar ) <EOL> if node . else_ : <EOL> testvar = "<STR_LIT>" % iterid <EOL> self . add_lookup ( '<STR_LIT>' , testvar , testvar ) <EOL> assTestvar = "<STR_LIT>" % iterid <EOL> else : <EOL> assTestvar = "<STR_LIT>" <EOL> reuse_tuple = "<STR_LIT:false>" <EOL> if self . inline_code : <EOL> rhs = nextval <EOL> else : <EOL> rhs = "<STR_LIT>" % nextval <EOL> assigns = self . _assigns_list ( node . assign , current_klass , rhs ) <EOL> if isinstance ( node . list , self . ast . Name ) : <EOL> list_expr = self . _name ( node . list , current_klass ) <EOL> elif isinstance ( node . list , self . ast . Getattr ) : <EOL> list_expr = self . attrib_join ( self . _getattr ( node . list , current_klass ) ) <EOL> elif isinstance ( node . list , self . ast . CallFunc ) : <EOL> list_expr = self . _callfunc ( node . list , current_klass ) <EOL> else : <EOL> list_expr = self . expr ( node . list , current_klass ) <EOL> if self . source_tracking : <EOL> self . stacksize_depth += <NUM_LIT:1> <EOL> var_trackstack_size = "<STR_LIT>" % self . stacksize_depth <EOL> self . add_lookup ( '<STR_LIT>' , var_trackstack_size , var_trackstack_size ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % var_trackstack_size ) <EOL> s = self . spacing ( ) <EOL> if self . inline_code : <EOL> self . w ( """<STR_LIT>""" % locals ( ) + self . track_call ( "<STR_LIT>" % locals ( ) , node . lineno ) + '<STR_LIT:;>' ) <EOL> self . w ( """<STR_LIT>""" % locals ( ) ) <EOL> condition = "<STR_LIT>" % dict ( locals ( ) , wrapped_next = self . pyjslib_name ( '<STR_LIT>' ) ) <EOL> else : <EOL> self . w ( """<STR_LIT>""" % locals ( ) + self . track_call ( "<STR_LIT>" % locals ( ) , node . lineno ) + '<STR_LIT:;>' ) <EOL> self . w ( """<STR_LIT>""" % dict ( locals ( ) , __iter_prepare = self . pyjslib_name ( '<STR_LIT>' ) ) ) <EOL> condition = "<STR_LIT>" % dict ( locals ( ) , __wrapped_next = self . pyjslib_name ( '<STR_LIT>' ) ) <EOL> self . generator_switch_case ( increment = True ) <EOL> if self . is_generator : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( len ( self . generator_states ) , ) ) <EOL> self . generator_switch_case ( increment = True ) <EOL> self . w ( self . indent ( ) + "<STR_LIT>" % ( assTestvar , len ( self . generator_states ) , condition , len ( self . generator_states ) , ) ) <EOL> else : <EOL> self . w ( self . indent ( ) + """<STR_LIT>""" % ( assTestvar , condition ) ) <EOL> self . generator_add_state ( ) <EOL> self . generator_switch_open ( ) <EOL> self . generator_switch_case ( increment = False ) <EOL> for line in assigns : <EOL> self . w ( self . spacing ( ) + line ) <EOL> for n in node . body . nodes : <EOL> self . _stmt ( n , current_klass ) <EOL> self . generator_switch_case ( increment = True ) <EOL> self . generator_switch_close ( ) <EOL> self . generator_del_state ( ) <EOL> self . w ( self . dedent ( ) + "<STR_LIT:}>" ) <EOL> if node . else_ : <EOL> self . generator_switch_case ( increment = True ) <EOL> self . w ( self . indent ( ) + "<STR_LIT>" % locals ( ) ) <EOL> for n in node . else_ . nodes : <EOL> self . _stmt ( n , current_klass ) <EOL> self . w ( self . dedent ( ) + "<STR_LIT:}>" ) <EOL> if self . source_tracking : <EOL> self . w ( """<STR_LIT>""" % { '<STR_LIT:s>' : self . spacing ( ) , '<STR_LIT:d>' : self . stacksize_depth , '<STR_LIT:m>' : self . module_name } ) <EOL> self . stacksize_depth -= <NUM_LIT:1> <EOL> self . generator_switch_case ( increment = True ) <EOL> self . is_generator = save_is_generator <EOL> def _while ( self , node , current_klass ) : <EOL> save_is_generator = self . is_generator <EOL> if self . is_generator : <EOL> self . is_generator = self . compiler . walk ( node , GeneratorExitVisitor ( ) , walker = GeneratorExitVisitor ( ) ) . has_yield <EOL> test = self . expr ( node . test , current_klass ) <EOL> if self . is_generator : <EOL> self . generator_switch_case ( increment = True ) <EOL> self . generator_reset_state ( ) <EOL> self . generator_switch_case ( increment = True ) <EOL> self . w ( self . indent ( ) + "<STR_LIT>" % ( ( len ( self . generator_states ) , ) ) + self . track_call ( self . inline_bool_code ( test ) , node . lineno ) + "<STR_LIT>" % ( len ( self . generator_states ) , ) ) <EOL> self . generator_add_state ( ) <EOL> self . generator_switch_open ( ) <EOL> self . generator_switch_case ( increment = False ) <EOL> else : <EOL> self . w ( self . indent ( ) + "<STR_LIT>" + self . track_call ( self . inline_bool_code ( test ) , node . lineno ) + "<STR_LIT>" ) <EOL> if isinstance ( node . body , self . ast . Stmt ) : <EOL> for child in node . body . nodes : <EOL> self . _stmt ( child , current_klass ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node . body , self . module_name ) <EOL> if self . is_generator : <EOL> self . generator_switch_case ( increment = True ) <EOL> self . generator_switch_close ( ) <EOL> self . generator_del_state ( ) <EOL> self . w ( self . dedent ( ) + "<STR_LIT:}>" ) <EOL> self . generator_switch_case ( increment = True ) <EOL> self . is_generator = save_is_generator <EOL> def _const ( self , node ) : <EOL> if isinstance ( node . value , int ) : <EOL> if not self . number_classes : <EOL> return str ( node . value ) <EOL> self . constant_int [ node . value ] = <NUM_LIT:1> <EOL> return "<STR_LIT>" % str ( node . value ) <EOL> elif isinstance ( node . value , long ) : <EOL> v = str ( node . value ) <EOL> if v [ - <NUM_LIT:1> ] == '<STR_LIT:L>' : <EOL> v = v [ : - <NUM_LIT:1> ] <EOL> if not self . number_classes : <EOL> return v <EOL> self . constant_long [ node . value ] = <NUM_LIT:1> <EOL> return "<STR_LIT>" % v <EOL> elif isinstance ( node . value , float ) : <EOL> return str ( node . value ) <EOL> elif isinstance ( node . value , basestring ) : <EOL> v = node . value <EOL> if isinstance ( node . value , unicode ) : <EOL> v = v . encode ( '<STR_LIT:utf-8>' ) <EOL> return uescapejs ( node . value ) <EOL> elif node . value is None : <EOL> return "<STR_LIT:null>" <EOL> elif isinstance ( node . value , complex ) : <EOL> return self . pyjslib_name ( <EOL> "<STR_LIT>" , args = [ node . value . real , node . value . imag ] <EOL> ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node , self . module_name ) <EOL> def _unaryadd ( self , node , current_klass ) : <EOL> if not self . operator_funcs : <EOL> return "<STR_LIT>" % self . expr ( node . expr , current_klass ) <EOL> e = self . expr ( node . expr , current_klass ) <EOL> v = self . uniqid ( '<STR_LIT>' ) <EOL> s = self . spacing ( ) <EOL> return """<STR_LIT>""" % locals ( ) <EOL> def _unarysub ( self , node , current_klass ) : <EOL> if not self . operator_funcs : <EOL> return "<STR_LIT>" % self . expr ( node . expr , current_klass ) <EOL> e = self . expr ( node . expr , current_klass ) <EOL> v = self . uniqid ( '<STR_LIT>' ) <EOL> s = self . spacing ( ) <EOL> return """<STR_LIT>""" % locals ( ) <EOL> def _add ( self , node , current_klass ) : <EOL> if not self . operator_funcs : <EOL> return "<STR_LIT>" % ( self . expr ( node . left , current_klass ) , self . expr ( node . right , current_klass ) ) <EOL> e1 = self . expr ( node . left , current_klass ) <EOL> e2 = self . expr ( node . right , current_klass ) <EOL> v1 = self . uniqid ( '<STR_LIT>' ) <EOL> v2 = self . uniqid ( '<STR_LIT>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v1 , v1 ) <EOL> self . add_lookup ( '<STR_LIT>' , v2 , v2 ) <EOL> s = self . spacing ( ) <EOL> if self . inline_code : <EOL> return """<STR_LIT>""" % locals ( ) <EOL> return """<STR_LIT>""" % locals ( ) <EOL> def _sub ( self , node , current_klass ) : <EOL> if not self . operator_funcs : <EOL> return "<STR_LIT>" % ( self . expr ( node . left , current_klass ) , self . expr ( node . right , current_klass ) ) <EOL> e1 = self . expr ( node . left , current_klass ) <EOL> e2 = self . expr ( node . right , current_klass ) <EOL> v1 = self . uniqid ( '<STR_LIT>' ) <EOL> v2 = self . uniqid ( '<STR_LIT>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v1 , v1 ) <EOL> self . add_lookup ( '<STR_LIT>' , v2 , v2 ) <EOL> s = self . spacing ( ) <EOL> if self . inline_code : <EOL> return """<STR_LIT>""" % locals ( ) <EOL> return """<STR_LIT>""" % locals ( ) <EOL> def _floordiv ( self , node , current_klass ) : <EOL> if not self . operator_funcs : <EOL> return "<STR_LIT>" % ( self . expr ( node . left , current_klass ) , self . expr ( node . right , current_klass ) ) <EOL> e1 = self . expr ( node . left , current_klass ) <EOL> e2 = self . expr ( node . right , current_klass ) <EOL> v1 = self . uniqid ( '<STR_LIT>' ) <EOL> v2 = self . uniqid ( '<STR_LIT>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v1 , v1 ) <EOL> self . add_lookup ( '<STR_LIT>' , v2 , v2 ) <EOL> s = self . spacing ( ) <EOL> return """<STR_LIT>""" % locals ( ) <EOL> def _div ( self , node , current_klass ) : <EOL> if not self . operator_funcs : <EOL> return "<STR_LIT>" % ( self . expr ( node . left , current_klass ) , self . expr ( node . right , current_klass ) ) <EOL> e1 = self . expr ( node . left , current_klass ) <EOL> e2 = self . expr ( node . right , current_klass ) <EOL> v1 = self . uniqid ( '<STR_LIT>' ) <EOL> v2 = self . uniqid ( '<STR_LIT>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v1 , v1 ) <EOL> self . add_lookup ( '<STR_LIT>' , v2 , v2 ) <EOL> s = self . spacing ( ) <EOL> op_div = '<STR_LIT>' if self . future_division else '<STR_LIT>' <EOL> op_div = '<STR_LIT>' if self . future_division else '<STR_LIT>' <EOL> return """<STR_LIT>""" % locals ( ) <EOL> def _mul ( self , node , current_klass ) : <EOL> if not self . operator_funcs : <EOL> return "<STR_LIT>" % ( self . expr ( node . left , current_klass ) , self . expr ( node . right , current_klass ) ) <EOL> e1 = self . expr ( node . left , current_klass ) <EOL> e2 = self . expr ( node . right , current_klass ) <EOL> v1 = self . uniqid ( '<STR_LIT>' ) <EOL> v2 = self . uniqid ( '<STR_LIT>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v1 , v1 ) <EOL> self . add_lookup ( '<STR_LIT>' , v2 , v2 ) <EOL> s = self . spacing ( ) <EOL> return """<STR_LIT>""" % locals ( ) <EOL> def _mod ( self , node , current_klass ) : <EOL> if isinstance ( node . left , self . ast . Const ) and isinstance ( node . left . value , types . StringType ) : <EOL> return self . track_call ( "<STR_LIT>" + self . expr ( node . left , current_klass ) + "<STR_LIT:U+002CU+0020>" + self . expr ( node . right , current_klass ) + "<STR_LIT:)>" , node . lineno ) <EOL> e1 = self . expr ( node . left , current_klass ) <EOL> e2 = self . expr ( node . right , current_klass ) <EOL> if self . stupid_mode : <EOL> return "<STR_LIT>" % locals ( ) <EOL> v1 = self . uniqid ( '<STR_LIT>' ) <EOL> v2 = self . uniqid ( '<STR_LIT>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v1 , v1 ) <EOL> self . add_lookup ( '<STR_LIT>' , v2 , v2 ) <EOL> s = self . spacing ( ) <EOL> if not self . operator_funcs : <EOL> return """<STR_LIT>""" % locals ( ) <EOL> return """<STR_LIT>""" % locals ( ) <EOL> def _power ( self , node , current_klass ) : <EOL> if not self . operator_funcs : <EOL> return "<STR_LIT>" % ( self . expr ( node . left , current_klass ) , self . expr ( node . right , current_klass ) ) <EOL> e1 = self . expr ( node . left , current_klass ) <EOL> e2 = self . expr ( node . right , current_klass ) <EOL> v1 = self . uniqid ( '<STR_LIT>' ) <EOL> v2 = self . uniqid ( '<STR_LIT>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v1 , v1 ) <EOL> self . add_lookup ( '<STR_LIT>' , v2 , v2 ) <EOL> s = self . spacing ( ) <EOL> return """<STR_LIT>""" % locals ( ) <EOL> def _invert ( self , node , current_klass ) : <EOL> if not self . operator_funcs or not self . number_classes : <EOL> return "<STR_LIT>" % self . expr ( node . expr , current_klass ) <EOL> return "<STR_LIT>" % self . expr ( node . expr , current_klass ) <EOL> def _bitshiftleft ( self , node , current_klass ) : <EOL> if not self . operator_funcs or not self . number_classes : <EOL> return "<STR_LIT>" % ( self . expr ( node . left , current_klass ) , self . expr ( node . right , current_klass ) ) <EOL> return "<STR_LIT>" % ( self . expr ( node . left , current_klass ) , self . expr ( node . right , current_klass ) ) <EOL> def _bitshiftright ( self , node , current_klass ) : <EOL> if not self . operator_funcs or not self . number_classes : <EOL> return "<STR_LIT>" % ( self . expr ( node . left , current_klass ) , self . expr ( node . right , current_klass ) ) <EOL> return "<STR_LIT>" % ( self . expr ( node . left , current_klass ) , self . expr ( node . right , current_klass ) ) <EOL> def _bitand ( self , node , current_klass ) : <EOL> if not self . operator_funcs or not self . number_classes : <EOL> return "<STR_LIT>" % "<STR_LIT>" . join ( [ self . expr ( child , current_klass ) for child in node . nodes ] ) <EOL> if len ( node . nodes ) == <NUM_LIT:2> : <EOL> return "<STR_LIT>" % ( self . expr ( node . nodes [ <NUM_LIT:0> ] , current_klass ) , self . expr ( node . nodes [ <NUM_LIT:1> ] , current_klass ) ) <EOL> return "<STR_LIT>" % "<STR_LIT:U+002CU+0020>" . join ( [ self . expr ( child , current_klass ) for child in node . nodes ] ) <EOL> def _bitxor ( self , node , current_klass ) : <EOL> if not self . operator_funcs or not self . number_classes : <EOL> return "<STR_LIT>" % "<STR_LIT>" . join ( [ self . expr ( child , current_klass ) for child in node . nodes ] ) <EOL> if len ( node . nodes ) == <NUM_LIT:2> : <EOL> return "<STR_LIT>" % ( self . expr ( node . nodes [ <NUM_LIT:0> ] , current_klass ) , self . expr ( node . nodes [ <NUM_LIT:1> ] , current_klass ) ) <EOL> return "<STR_LIT>" % "<STR_LIT:U+002CU+0020>" . join ( [ self . expr ( child , current_klass ) for child in node . nodes ] ) <EOL> def _bitor ( self , node , current_klass ) : <EOL> if not self . operator_funcs or not self . number_classes : <EOL> return "<STR_LIT>" % "<STR_LIT>" . join ( [ self . expr ( child , current_klass ) for child in node . nodes ] ) <EOL> if len ( node . nodes ) == <NUM_LIT:2> : <EOL> return "<STR_LIT>" % ( self . expr ( node . nodes [ <NUM_LIT:0> ] , current_klass ) , self . expr ( node . nodes [ <NUM_LIT:1> ] , current_klass ) ) <EOL> return "<STR_LIT>" % "<STR_LIT:U+002CU+0020>" . join ( [ self . expr ( child , current_klass ) for child in node . nodes ] ) <EOL> def _subscript ( self , node , current_klass ) : <EOL> if node . flags == "<STR_LIT>" : <EOL> if len ( node . subs ) == <NUM_LIT:1> : <EOL> return self . inline_getitem_code ( self . expr ( node . expr , current_klass ) , self . expr ( node . subs [ <NUM_LIT:0> ] , current_klass ) ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node , self . module_name ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node , self . module_name ) <EOL> def _subscript_stmt ( self , node , current_klass ) : <EOL> if node . flags == "<STR_LIT>" : <EOL> self . w ( self . spacing ( ) + self . track_call ( self . expr ( node . expr , current_klass ) + "<STR_LIT>" + self . expr ( node . subs [ <NUM_LIT:0> ] , current_klass ) + "<STR_LIT:)>" , node . lineno ) + '<STR_LIT:;>' ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node , self . module_name ) <EOL> def _assattr ( self , node , current_klass ) : <EOL> attr_name = self . attrib_remap ( node . attrname ) <EOL> lhs = self . _lhsFromAttr ( node , current_klass ) <EOL> if node . flags == "<STR_LIT>" : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( lhs , attr_name ) ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , v , self . module_name ) <EOL> def _assname ( self , node , current_klass ) : <EOL> name_type , pyname , jsname , depth , is_local = self . lookup ( node . name ) <EOL> if node . flags == "<STR_LIT>" : <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" % ( jsname , ) ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , v , self . module_name ) <EOL> def _list ( self , node , current_klass ) : <EOL> return self . track_call ( "<STR_LIT>" + "<STR_LIT:U+002CU+0020>" . join ( [ self . expr ( x , current_klass ) for x in node . nodes ] ) + "<STR_LIT>" , node . lineno ) <EOL> def _dict ( self , node , current_klass ) : <EOL> items = [ ] <EOL> for x in node . items : <EOL> key = self . expr ( x [ <NUM_LIT:0> ] , current_klass ) <EOL> value = self . expr ( x [ <NUM_LIT:1> ] , current_klass ) <EOL> items . append ( "<STR_LIT:[>" + key + "<STR_LIT:U+002CU+0020>" + value + "<STR_LIT:]>" ) <EOL> return self . track_call ( "<STR_LIT>" + "<STR_LIT:U+002CU+0020>" . join ( items ) + "<STR_LIT>" ) <EOL> def _tuple ( self , node , current_klass ) : <EOL> return self . track_call ( "<STR_LIT>" + "<STR_LIT:U+002CU+0020>" . join ( [ self . expr ( x , current_klass ) for x in node . nodes ] ) + "<STR_LIT>" , node . lineno ) <EOL> def _set ( self , node , current_klass ) : <EOL> return self . track_call ( "<STR_LIT>" + "<STR_LIT:U+002CU+0020>" . join ( [ self . expr ( x , current_klass ) for x in node . nodes ] ) + "<STR_LIT>" , node . lineno ) <EOL> def _sliceobj ( self , node , current_klass ) : <EOL> args = "<STR_LIT:U+002CU+0020>" . join ( [ self . expr ( x , current_klass ) for x in node . nodes ] ) <EOL> return self . track_call ( self . pyjslib_name ( "<STR_LIT>" , args = args ) , <EOL> node . lineno ) <EOL> def _lambda ( self , node , current_klass ) : <EOL> save_local_prefix , self . local_prefix = self . local_prefix , None <EOL> save_is_class_definition , self . is_class_definition = self . is_class_definition , False <EOL> function_name = self . uniqid ( "<STR_LIT>" ) <EOL> self . w ( self . spacing ( ) + "<STR_LIT>" , False ) <EOL> code_node = self . ast . Stmt ( [ self . ast . Return ( node . code , node . lineno ) ] , node . lineno ) <EOL> try : <EOL> func_node = self . ast . Function ( None , function_name , node . argnames , node . defaults , node . flags , None , code_node , node . lineno ) <EOL> except : <EOL> func_node = self . ast . Function ( None , function_name , node . argnames , node . defaults , node . varargs , node . kwargs , None , code_node , node . lineno ) <EOL> self . _function ( func_node , current_klass , True ) <EOL> self . local_prefix = save_local_prefix <EOL> self . is_class_definition = save_is_class_definition <EOL> return function_name <EOL> def _collcomp ( self , node , current_klass ) : <EOL> self . push_lookup ( ) <EOL> resultvar = self . uniqid ( "<STR_LIT>" ) <EOL> self . add_lookup ( '<STR_LIT>' , resultvar , resultvar ) <EOL> save_output = self . output <EOL> self . output = StringIO ( ) <EOL> if isinstance ( node , self . ast . ListComp ) : <EOL> tnode = self . ast . Discard ( <EOL> self . ast . CallFunc ( <EOL> self . ast . Getattr ( self . ast . Name ( resultvar ) , '<STR_LIT>' ) , <EOL> [ node . expr ] , None , None ) <EOL> ) <EOL> varinit = self . pyjslib_name ( "<STR_LIT:list>" , args = '<STR_LIT>' ) <EOL> elif isinstance ( node , self . ast . SetComp ) : <EOL> tnode = self . ast . Discard ( <EOL> self . ast . CallFunc ( <EOL> self . ast . Getattr ( self . ast . Name ( resultvar ) , '<STR_LIT>' ) , <EOL> [ node . expr ] , None , None ) <EOL> ) <EOL> varinit = self . pyjslib_name ( "<STR_LIT>" , args = '<STR_LIT>' ) <EOL> elif isinstance ( node , self . ast . DictComp ) : <EOL> tnode = self . ast . Assign ( [ <EOL> self . ast . Subscript ( self . ast . Name ( resultvar ) , <EOL> '<STR_LIT>' , [ node . key ] ) <EOL> ] , node . value ) <EOL> varinit = self . pyjslib_name ( "<STR_LIT>" , args = '<STR_LIT>' ) <EOL> else : <EOL> raise TranslationError ( "<STR_LIT>" , <EOL> node , self . module_name ) <EOL> for qual in node . quals [ : : - <NUM_LIT:1> ] : <EOL> if len ( qual . ifs ) > <NUM_LIT:1> : <EOL> raise TranslationError ( "<STR_LIT>" , <EOL> node , self . module_name ) <EOL> tassign = qual . assign <EOL> tlist = qual . list <EOL> tbody = self . ast . Stmt ( [ tnode ] ) <EOL> if len ( qual . ifs ) == <NUM_LIT:1> : <EOL> tbody = self . ast . Stmt ( [ self . ast . If ( [ ( qual . ifs [ <NUM_LIT:0> ] . test , tbody ) ] , None , qual . ifs [ <NUM_LIT:0> ] . lineno ) ] ) <EOL> telse_ = None <EOL> tnode = self . ast . For ( tassign , tlist , tbody , telse_ , node . lineno ) <EOL> self . _for ( tnode , current_klass ) <EOL> captured_output = self . output <EOL> self . output = save_output <EOL> collcomp_code = ( <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" % dict ( <EOL> declarations = self . local_js_vars_decl ( [ ] ) , <EOL> resultvar = resultvar , <EOL> varinit = varinit , <EOL> code = captured_output . getvalue ( ) , <EOL> ) <EOL> ) <EOL> self . pop_lookup ( ) <EOL> return collcomp_code <EOL> def _genexpr ( self , node , current_klass ) : <EOL> save_has_yield = self . has_yield <EOL> self . has_yield = True <EOL> save_is_generator = self . is_generator <EOL> self . is_generator = True <EOL> save_generator_states = self . generator_states <EOL> self . generator_states = [ <NUM_LIT:0> ] <EOL> self . state_max_depth = len ( self . generator_states ) <EOL> self . push_options ( ) <EOL> self . source_tracking = self . debug = False <EOL> if not isinstance ( node . code , self . ast . GenExprInner ) : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node , self . module_name ) <EOL> if node . argnames != [ '<STR_LIT>' ] : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node , self . module_name ) <EOL> if node . kwargs : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node , self . module_name ) <EOL> if node . varargs : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node , self . module_name ) <EOL> save_output = self . output <EOL> self . output = StringIO ( ) <EOL> self . indent ( ) <EOL> self . generator_switch_open ( ) <EOL> self . generator_switch_case ( increment = False ) <EOL> tnode = self . ast . Yield ( node . code . expr , node . lineno ) <EOL> for qual in node . code . quals [ : : - <NUM_LIT:1> ] : <EOL> if isinstance ( qual , self . ast . GenExprFor ) : <EOL> if len ( qual . ifs ) > <NUM_LIT:1> : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node . code , self . module_name ) <EOL> tassign = qual . assign <EOL> titer = qual . iter <EOL> tbody = self . ast . Stmt ( [ tnode ] ) <EOL> tis_outmost = qual . is_outmost <EOL> if len ( qual . ifs ) == <NUM_LIT:1> : <EOL> tbody = self . ast . Stmt ( [ self . ast . If ( [ ( qual . ifs [ <NUM_LIT:0> ] . test , tbody ) ] , None , qual . ifs [ <NUM_LIT:0> ] . lineno ) ] ) <EOL> telse_ = None <EOL> tnode = self . ast . For ( tassign , titer , tbody , telse_ , node . lineno ) <EOL> self . _for ( tnode , current_klass ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node . code , self . module_name ) <EOL> self . generator_switch_case ( increment = True ) <EOL> self . generator_switch_close ( ) <EOL> captured_output = self . output . getvalue ( ) <EOL> self . output = StringIO ( ) <EOL> self . w ( "<STR_LIT>" ) <EOL> self . generator ( captured_output ) <EOL> self . w ( self . dedent ( ) + "<STR_LIT>" ) <EOL> captured_output = self . output . getvalue ( ) <EOL> self . output = save_output <EOL> self . generator_states = save_generator_states <EOL> self . state_max_depth = len ( self . generator_states ) <EOL> self . is_generator = save_is_generator <EOL> self . has_yield = save_has_yield <EOL> self . pop_options ( ) <EOL> return captured_output <EOL> def _slice ( self , node , current_klass ) : <EOL> lower = "<STR_LIT:0>" <EOL> upper = "<STR_LIT:null>" <EOL> if node . lower != None : <EOL> lower = self . expr ( node . lower , current_klass ) <EOL> if node . upper != None : <EOL> upper = self . expr ( node . upper , current_klass ) <EOL> if node . flags == "<STR_LIT>" : <EOL> return self . pyjslib_name ( "<STR_LIT>" , args = [ <EOL> self . expr ( node . expr , current_klass ) , lower , upper <EOL> ] ) <EOL> elif node . flags == "<STR_LIT>" : <EOL> return self . pyjslib_name ( "<STR_LIT>" , args = [ <EOL> self . expr ( node . expr , current_klass ) , lower , upper <EOL> ] ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node , self . module_name ) <EOL> def _global ( self , node , current_klass ) : <EOL> for name in node . names : <EOL> name_type , pyname , jsname , depth , is_local = self . lookup ( name ) <EOL> if name_type is None : <EOL> name_type = '<STR_LIT>' <EOL> pyname = name <EOL> jsname = self . closureSafe ( self . scopeName ( name , depth , is_local ) ) <EOL> else : <EOL> name_type = '<STR_LIT>' <EOL> self . add_lookup ( name_type , pyname , jsname ) <EOL> def _if_expr ( self , node , current_klass ) : <EOL> test = self . expr ( node . test , current_klass ) <EOL> then = self . expr ( node . then , current_klass ) <EOL> else_ = self . expr ( node . else_ , current_klass ) <EOL> return "<STR_LIT:(>" + self . inline_bool_code ( test ) + "<STR_LIT>" % locals ( ) <EOL> def _backquote ( self , node , current_klass ) : <EOL> return "<STR_LIT>" % self . expr ( node . expr , current_klass ) <EOL> def expr ( self , node , current_klass ) : <EOL> if isinstance ( node , self . ast . Const ) : <EOL> return self . _const ( node ) <EOL> elif isinstance ( node , self . ast . Mul ) : <EOL> return self . _mul ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Add ) : <EOL> return self . _add ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Sub ) : <EOL> return self . _sub ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Div ) : <EOL> return self . _div ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . FloorDiv ) : <EOL> return self . _floordiv ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Mod ) : <EOL> return self . _mod ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Power ) : <EOL> return self . _power ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . UnaryAdd ) : <EOL> return self . _unaryadd ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . UnarySub ) : <EOL> return self . _unarysub ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Not ) : <EOL> return self . _not ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Or ) : <EOL> return self . _or ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . And ) : <EOL> return self . _and ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Invert ) : <EOL> return self . _invert ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . LeftShift ) : <EOL> return self . _bitshiftleft ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . RightShift ) : <EOL> return self . _bitshiftright ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Bitand ) : <EOL> return self . _bitand ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Bitxor ) : <EOL> return self . _bitxor ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Bitor ) : <EOL> return self . _bitor ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Compare ) : <EOL> return self . _compare ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . CallFunc ) : <EOL> return self . _callfunc ( node , current_klass , optlocal_var = True ) <EOL> elif isinstance ( node , self . ast . Name ) : <EOL> return self . _name ( node , current_klass , optlocal_var = True ) <EOL> elif isinstance ( node , self . ast . Subscript ) : <EOL> return self . _subscript ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Getattr ) : <EOL> attr_ = self . _getattr ( node , current_klass ) <EOL> if len ( attr_ ) == <NUM_LIT:1> : <EOL> return attr_ [ <NUM_LIT:0> ] <EOL> attr = self . attrib_join ( attr_ ) <EOL> attr_left = self . attrib_join ( attr_ [ : - <NUM_LIT:1> ] ) <EOL> attr_right = attr_ [ - <NUM_LIT:1> ] <EOL> attrstr = attr <EOL> v = self . uniqid ( '<STR_LIT>' ) <EOL> vl = self . uniqid ( '<STR_LIT>' ) <EOL> self . add_lookup ( '<STR_LIT>' , v , v ) <EOL> self . add_lookup ( '<STR_LIT>' , vl , vl ) <EOL> if self . bound_methods or self . descriptors : <EOL> getattr_condition = """<STR_LIT>""" <EOL> if self . descriptors : <EOL> getattr_condition += """<STR_LIT>""" <EOL> attr_code = """<STR_LIT>""" + getattr_condition + """<STR_LIT>""" <EOL> attr_code = ( '<STR_LIT:\n>' + self . spacing ( ) + "<STR_LIT>" ) . join ( attr_code . split ( '<STR_LIT:\n>' ) ) <EOL> else : <EOL> attr_code = "<STR_LIT>" <EOL> attr_code = attr_code % locals ( ) <EOL> s = self . spacing ( ) <EOL> orig_attr = attr <EOL> if not self . attribute_checking : <EOL> attr = attr_code <EOL> else : <EOL> if attr . find ( '<STR_LIT:(>' ) < <NUM_LIT:0> and not self . debug : <EOL> attrstr = attr . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) <EOL> attr = """<STR_LIT>""" % locals ( ) <EOL> else : <EOL> attr_ = attr <EOL> if self . source_tracking or self . debug : <EOL> _source_tracking = self . source_tracking <EOL> _debug = self . debug <EOL> _attribute_checking = self . attribute_checking <EOL> self . attribute_checking = self . source_tracking = self . debug = False <EOL> attr_ = self . attrib_join ( self . _getattr ( node , current_klass ) ) <EOL> self . source_tracking = _source_tracking <EOL> self . debug = _debug <EOL> self . attribute_checking = _attribute_checking <EOL> attrstr = attr_ . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) <EOL> attr = """<STR_LIT>""" % locals ( ) <EOL> if True : <EOL> return attr <EOL> bound_methods = self . bound_methods and "<STR_LIT:true>" or "<STR_LIT:false>" <EOL> descriptors = self . descriptors and "<STR_LIT:true>" or "<STR_LIT:false>" <EOL> attribute_checking = self . attribute_checking and "<STR_LIT:true>" or "<STR_LIT:false>" <EOL> source_tracking = self . source_tracking and "<STR_LIT:true>" or "<STR_LIT:false>" <EOL> attr = """<STR_LIT>""" % locals ( ) <EOL> return attr <EOL> elif isinstance ( node , self . ast . List ) : <EOL> return self . _list ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Dict ) : <EOL> return self . _dict ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Tuple ) : <EOL> return self . _tuple ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Set ) : <EOL> return self . _set ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Sliceobj ) : <EOL> return self . _sliceobj ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Slice ) : <EOL> return self . _slice ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Lambda ) : <EOL> return self . _lambda ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . CollComp ) : <EOL> return self . _collcomp ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . IfExp ) : <EOL> return self . _if_expr ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Yield ) : <EOL> return self . _yield_expr ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . Backquote ) : <EOL> return self . _backquote ( node , current_klass ) <EOL> elif isinstance ( node , self . ast . GenExpr ) : <EOL> return self . _genexpr ( node , current_klass ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , node , self . module_name ) <EOL> def translate ( sources , output_file , module_name = None , ** kw ) : <EOL> kw = dict ( all_compile_options , ** kw ) <EOL> list_imports = kw . get ( '<STR_LIT>' , False ) <EOL> sources = map ( os . path . abspath , sources ) <EOL> if not module_name : <EOL> module_name , extension = os . path . splitext ( os . path . basename ( sources [ <NUM_LIT:0> ] ) ) <EOL> trees = [ ] <EOL> tree = None <EOL> for src in sources : <EOL> current_tree = compiler . parseFile ( src ) <EOL> flags = set ( ) <EOL> f = file ( src ) <EOL> for l in f : <EOL> if l . startswith ( '<STR_LIT>' ) : <EOL> flags . add ( l . strip ( ) [ <NUM_LIT:7> : ] ) <EOL> f . close ( ) <EOL> if tree : <EOL> tree = merge ( compiler . ast , module_name , tree , current_tree , flags ) <EOL> else : <EOL> tree = current_tree <EOL> f = file ( sources [ <NUM_LIT:0> ] , "<STR_LIT:r>" ) <EOL> src = f . read ( ) <EOL> f . close ( ) <EOL> if list_imports : <EOL> v = ImportVisitor ( module_name ) <EOL> compiler . walk ( tree , v ) <EOL> return v . imported_modules , v . imported_js <EOL> if hasattr ( output_file , '<STR_LIT>' ) : <EOL> output = output_file <EOL> elif output_file == '<STR_LIT:->' : <EOL> output = sys . stdout <EOL> else : <EOL> output = file ( output_file , '<STR_LIT:w>' ) <EOL> t = Translator ( compiler , <EOL> module_name , sources [ <NUM_LIT:0> ] , src , tree , output , ** kw ) <EOL> return t . imported_modules , t . imported_js <EOL> def merge ( ast , module_name , tree1 , tree2 , flags ) : <EOL> if '<STR_LIT>' in flags : <EOL> return tree2 <EOL> for child in tree2 . node : <EOL> if isinstance ( child , ast . Function ) : <EOL> replaceFunction ( ast , module_name , tree1 , child . name , child ) <EOL> elif isinstance ( child , ast . Class ) : <EOL> replaceClassMethods ( ast , module_name , tree1 , child . name , child ) <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" % child , child , module_name ) <EOL> return tree1 <EOL> def replaceFunction ( ast , module_name , tree , function_name , function_node ) : <EOL> for child in tree . node : <EOL> if isinstance ( child , ast . Function ) and child . name == function_name : <EOL> copyFunction ( child , function_node ) <EOL> return <EOL> raise TranslationError ( <EOL> "<STR_LIT>" + function_name , function_node , module_name ) <EOL> def copyFunction ( target , source ) : <EOL> target . code = source . code <EOL> target . argnames = source . argnames <EOL> target . defaults = source . defaults <EOL> target . doc = source . doc <EOL> def addCode ( target , source ) : <EOL> target . nodes . append ( source ) <EOL> def replaceClassMethods ( ast , module_name , tree , class_name , class_node ) : <EOL> old_class_node = None <EOL> for child in tree . node : <EOL> if isinstance ( child , ast . Class ) and child . name == class_name : <EOL> old_class_node = child <EOL> break <EOL> if not old_class_node : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" + class_name , class_node , module_name ) <EOL> for node in class_node . code : <EOL> if isinstance ( node , ast . Function ) : <EOL> found = False <EOL> for child in old_class_node . code : <EOL> if isinstance ( child , ast . Function ) and child . name == node . name : <EOL> found = True <EOL> copyFunction ( child , node ) <EOL> break <EOL> if not found : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" + class_name + "<STR_LIT:.>" + node . name , <EOL> node , module_name ) <EOL> elif isinstance ( node , ast . Assign ) and isinstance ( node . nodes [ <NUM_LIT:0> ] , ast . AssName ) : <EOL> found = False <EOL> for child in old_class_node . code : <EOL> if isinstance ( child , ast . Assign ) and eqNodes ( child . nodes , node . nodes ) : <EOL> found = True <EOL> copyAssign ( child , node ) <EOL> if not found : <EOL> addCode ( old_class_node . code , node ) <EOL> elif isinstance ( node , ast . Pass ) : <EOL> pass <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" % node , node , self . module_name ) <EOL> class PlatformParser : <EOL> def __init__ ( self , compiler , <EOL> platform_dir = "<STR_LIT>" , verbose = True , chain_plat = None ) : <EOL> self . platform_dir = platform_dir <EOL> self . parse_cache = { } <EOL> self . platform = "<STR_LIT>" <EOL> self . verbose = verbose <EOL> self . chain_plat = chain_plat <EOL> self . compiler = compiler <EOL> def setPlatform ( self , platform ) : <EOL> self . platform = platform <EOL> def parseModule ( self , module_name , file_name ) : <EOL> importing = False <EOL> if not self . parse_cache . has_key ( file_name ) : <EOL> importing = True <EOL> if self . chain_plat : <EOL> mod , override = self . chain_plat . parseModule ( module_name , <EOL> file_name ) <EOL> else : <EOL> mod = self . compiler . parseFile ( file_name ) <EOL> self . parse_cache [ file_name ] = mod <EOL> else : <EOL> mod = self . parse_cache [ file_name ] <EOL> override = False <EOL> platform_file_name = self . generatePlatformFilename ( file_name ) <EOL> if self . platform and os . path . isfile ( platform_file_name ) : <EOL> mod = copy . deepcopy ( mod ) <EOL> mod_override = self . compiler . parseFile ( platform_file_name ) <EOL> if self . verbose : <EOL> print ( "<STR_LIT>" , module_name , self . platform ) <EOL> self . merge ( smod , mod_override ) <EOL> override = True <EOL> if self . verbose : <EOL> if override : <EOL> print ( "<STR_LIT>" % ( module_name , self . platform ) ) <EOL> elif importing : <EOL> print ( "<STR_LIT>" % ( module_name ) ) <EOL> return mod , override <EOL> def generatePlatformFilename ( self , file_name ) : <EOL> ( module_name , extension ) = os . path . splitext ( os . path . basename ( file_name ) ) <EOL> platform_file_name = module_name + "<STR_LIT:.>" + self . platform + extension <EOL> pf = os . path . join ( os . path . dirname ( file_name ) , self . platform_dir , platform_file_name ) <EOL> return pf <EOL> def replaceFunction ( self , tree , function_name , function_node ) : <EOL> for child in tree . node : <EOL> if isinstance ( child , self . ast . Function ) and child . name == function_name : <EOL> self . copyFunction ( child , function_node ) <EOL> return <EOL> raise TranslationError ( <EOL> "<STR_LIT>" + function_name , <EOL> function_node , self . module_name ) <EOL> def replaceClassMethods ( self , tree , class_name , class_node ) : <EOL> old_class_node = None <EOL> for child in tree . node : <EOL> if isinstance ( child , self . ast . Class ) and child . name == class_name : <EOL> old_class_node = child <EOL> break <EOL> if not old_class_node : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" + class_name , class_node , self . module_name ) <EOL> for node in class_node . code : <EOL> if isinstance ( node , self . ast . Function ) : <EOL> found = False <EOL> for child in old_class_node . code : <EOL> if isinstance ( child , self . ast . Function ) and child . name == node . name : <EOL> found = True <EOL> self . copyFunction ( child , node ) <EOL> break <EOL> if not found : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" + class_name + "<STR_LIT:.>" + node . name , <EOL> node , self . module_name ) <EOL> elif isinstance ( node , self . ast . Assign ) and isinstance ( node . nodes [ <NUM_LIT:0> ] , self . ast . AssName ) : <EOL> found = False <EOL> for child in old_class_node . code : <EOL> if isinstance ( child , self . ast . Assign ) and self . eqNodes ( child . nodes , node . nodes ) : <EOL> found = True <EOL> self . copyAssign ( child , node ) <EOL> if not found : <EOL> self . addCode ( old_class_node . code , node ) <EOL> elif isinstance ( node , self . ast . Pass ) : <EOL> pass <EOL> else : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" % node , <EOL> node , self . module_name ) <EOL> def copyFunction ( self , target , source ) : <EOL> target . code = source . code <EOL> target . argnames = source . argnames <EOL> target . defaults = source . defaults <EOL> target . doc = source . doc <EOL> def copyAssign ( self , target , source ) : <EOL> target . nodes = source . nodes <EOL> target . expr = source . expr <EOL> target . lineno = source . lineno <EOL> return <EOL> def eqNodes ( self , nodes1 , nodes2 ) : <EOL> return str ( nodes1 ) == str ( nodes2 ) <EOL> def dotreplace ( fname ) : <EOL> path , ext = os . path . splitext ( fname ) <EOL> return path . replace ( "<STR_LIT:.>" , "<STR_LIT:/>" ) + ext <EOL> class ImportVisitor ( object ) : <EOL> def __init__ ( self , module_name ) : <EOL> self . module_name = module_name <EOL> self . imported_modules = [ ] <EOL> self . imported_js = [ ] <EOL> def add_imported_module ( self , importName ) : <EOL> if not importName in self . imported_modules : <EOL> self . imported_modules . append ( importName ) <EOL> def visitModule ( self , node ) : <EOL> self . visit ( node . node ) <EOL> def visitImport ( self , node ) : <EOL> self . _doImport ( node . names ) <EOL> def _doImport ( self , names ) : <EOL> for importName , importAs in names : <EOL> if importName == '<STR_LIT>' : <EOL> continue <EOL> if importName . endswith ( "<STR_LIT>" ) : <EOL> continue <EOL> imp . add_imported_js ( importName ) <EOL> continue <EOL> self . add_imported_module ( importName ) <EOL> def visitFrom ( self , node ) : <EOL> if node . modname == '<STR_LIT>' : <EOL> return <EOL> if node . modname == '<STR_LIT>' : <EOL> return <EOL> absPath = False <EOL> modname = node . modname <EOL> if hasattr ( node , '<STR_LIT>' ) and node . level > <NUM_LIT:0> : <EOL> absPath = True <EOL> modname = self . module_name . split ( '<STR_LIT:.>' ) <EOL> level = node . level <EOL> if len ( modname ) < level : <EOL> raise TranslationError ( <EOL> "<STR_LIT>" , <EOL> node , self . module_name ) <EOL> if node . modname != '<STR_LIT>' : <EOL> level += <NUM_LIT:1> <EOL> if level > <NUM_LIT:1> : <EOL> modname = '<STR_LIT:.>' . join ( modname [ : - ( node . level - <NUM_LIT:1> ) ] ) <EOL> else : <EOL> modname = self . module_name <EOL> if node . modname != '<STR_LIT>' : <EOL> modname += '<STR_LIT:.>' + node . modname <EOL> if modname [ <NUM_LIT:0> ] == '<STR_LIT:.>' : <EOL> modname = modname [ <NUM_LIT:1> : ] <EOL> for name in node . names : <EOL> sub = modname + '<STR_LIT:.>' + name [ <NUM_LIT:0> ] <EOL> ass_name = name [ <NUM_LIT:1> ] or name [ <NUM_LIT:0> ] <EOL> self . _doImport ( ( ( sub , ass_name ) , ) ) <EOL> class AppTranslator : <EOL> def __init__ ( self , compiler , <EOL> library_dirs = [ ] , parser = None , dynamic = False , <EOL> verbose = True , <EOL> debug = False , <EOL> print_statements = True , <EOL> function_argument_checking = True , <EOL> attribute_checking = True , <EOL> bound_methods = True , <EOL> descriptors = True , <EOL> source_tracking = True , <EOL> line_tracking = True , <EOL> store_source = True , <EOL> inline_code = False , <EOL> operator_funcs = True , <EOL> number_classes = True , <EOL> ) : <EOL> self . compiler = compiler <EOL> self . extension = "<STR_LIT>" <EOL> self . print_statements = print_statements <EOL> self . library_modules = [ ] <EOL> self . overrides = { } <EOL> self . library_dirs = path + library_dirs <EOL> self . dynamic = dynamic <EOL> self . verbose = verbose <EOL> self . debug = debug <EOL> self . print_statements = print_statements <EOL> self . function_argument_checking = function_argument_checking <EOL> self . attribute_checking = attribute_checking <EOL> self . bound_methods = bound_methods <EOL> self . descriptors = descriptors <EOL> self . source_tracking = source_tracking <EOL> self . line_tracking = line_tracking <EOL> self . store_source = store_source <EOL> self . inline_code = inline_code <EOL> self . operator_funcs = operator_funcs <EOL> self . number_classes = number_classes <EOL> if not parser : <EOL> self . parser = PlatformParser ( self . compiler ) <EOL> else : <EOL> self . parser = parser <EOL> self . parser . dynamic = dynamic <EOL> def findFile ( self , file_name ) : <EOL> if os . path . isfile ( file_name ) : <EOL> return file_name <EOL> for library_dir in self . library_dirs : <EOL> file_name = dotreplace ( file_name ) <EOL> full_file_name = os . path . join ( <EOL> LIBRARY_PATH , library_dir , file_name ) <EOL> if os . path . isfile ( full_file_name ) : <EOL> return full_file_name <EOL> fnameinit , ext = os . path . splitext ( file_name ) <EOL> fnameinit = fnameinit + "<STR_LIT>" <EOL> full_file_name = os . path . join ( <EOL> LIBRARY_PATH , library_dir , fnameinit ) <EOL> if os . path . isfile ( full_file_name ) : <EOL> return full_file_name <EOL> raise Exception ( "<STR_LIT>" + file_name ) <EOL> def _translate ( self , module_name , debug = False ) : <EOL> self . library_modules . append ( module_name ) <EOL> file_name = self . findFile ( module_name + self . extension ) <EOL> output = StringIO ( ) <EOL> f = file ( file_name , "<STR_LIT:r>" ) <EOL> src = f . read ( ) <EOL> f . close ( ) <EOL> mod , override = self . parser . parseModule ( module_name , file_name ) <EOL> if override : <EOL> override_name = "<STR_LIT>" % ( self . parser . platform . lower ( ) , <EOL> module_name ) <EOL> self . overrides [ override_name ] = override_name <EOL> t = Translator ( self . compiler , <EOL> module_name , file_name , src , mod , output , <EOL> self . dynamic , self . findFile , <EOL> debug = self . debug , <EOL> print_statements = self . print_statements , <EOL> function_argument_checking = self . function_argument_checking , <EOL> attribute_checking = self . attribute_checking , <EOL> bound_methods = self . bound_methods , <EOL> descriptors = self . descriptors , <EOL> source_tracking = self . source_tracking , <EOL> line_tracking = self . line_tracking , <EOL> store_source = self . store_source , <EOL> inline_code = self . inline_code , <EOL> operator_funcs = self . operator_funcs , <EOL> number_classes = self . number_classes , <EOL> ) <EOL> module_str = output . getvalue ( ) <EOL> imported_modules_str = "<STR_LIT>" <EOL> for module in t . imported_modules : <EOL> if module not in self . library_modules : <EOL> self . library_modules . append ( module ) <EOL> return imported_modules_str + module_str <EOL> def translate ( self , module_name , is_app = True , debug = False , <EOL> library_modules = [ ] ) : <EOL> app_code = StringIO ( ) <EOL> lib_code = StringIO ( ) <EOL> imported_js = [ ] <EOL> self . library_modules = [ ] <EOL> self . overrides = { } <EOL> for library in library_modules : <EOL> if library . endswith ( "<STR_LIT>" ) : <EOL> imported_js . append ( library ) <EOL> continue <EOL> self . library_modules . append ( library ) <EOL> if self . verbose : <EOL> print ( '<STR_LIT>' , library ) <EOL> print >> lib_code , '<STR_LIT>' + library + '<STR_LIT>' <EOL> print >> lib_code , self . _translate ( <EOL> library , False , debug = debug , imported_js = imported_js ) <EOL> print >> lib_code , "<STR_LIT>" <EOL> print >> lib_code , "<STR_LIT>" % library <EOL> print >> lib_code , '<STR_LIT>' + library + '<STR_LIT>' <EOL> if module_name : <EOL> print >> app_code , self . _translate ( <EOL> module_name , is_app , debug = debug , imported_js = imported_js ) <EOL> for js in imported_js : <EOL> path = self . findFile ( js ) <EOL> if os . path . isfile ( path ) : <EOL> if self . verbose : <EOL> print ( '<STR_LIT>' , js ) <EOL> print >> lib_code , '<STR_LIT>' + js + '<STR_LIT>' <EOL> print >> lib_code , file ( path ) . read ( ) <EOL> print >> lib_code , '<STR_LIT>' + js + '<STR_LIT>' <EOL> else : <EOL> print >> sys . stderr , '<STR_LIT>' , js <EOL> return lib_code . getvalue ( ) , app_code . getvalue ( ) <EOL> usage = """<STR_LIT>""" <EOL> def main ( ) : <EOL> import sys <EOL> from optparse import OptionParser <EOL> parser = OptionParser ( usage = usage ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> default = "<STR_LIT:->" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> default = False , <EOL> action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> add_compile_options ( parser ) <EOL> ( options , args ) = parser . parse_args ( ) <EOL> if len ( args ) < <NUM_LIT:1> : <EOL> parser . error ( "<STR_LIT>" ) <EOL> if not options . output : <EOL> parser . error ( "<STR_LIT>" ) <EOL> if options . output == '<STR_LIT:->' : <EOL> options . output = os . path . abspath ( options . output ) <EOL> file_names = map ( os . path . abspath , args ) <EOL> for fn in file_names : <EOL> if not os . path . isfile ( fn ) : <EOL> print >> sys . stderr , "<STR_LIT>" % fn <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> imports , js = translate ( compiler , file_names , options . output , <EOL> options . module_name , <EOL> ** get_compile_options ( options ) ) <EOL> if options . list_imports : <EOL> if imports : <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' % imports ) <EOL> print ( '<STR_LIT>' ) <EOL> if js : <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' % repr ( js ) ) <EOL> print ( '<STR_LIT>' ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
