Example #1
0
 def convert_module(self, filename):
     filename = os.path.abspath(filename)
     text = open(filename).read()
     node = ast.parse(text, filename)
     dct = {
         'filename': filename,
         'doc': utils.multiline(ast.get_docstring(node), False),
     }
     scope = Scope()
     contents = self.convert_block(node.body, scope)
     contents = utils.fix_undef(contents, scope, True)
     dct['contents'] = contents
     return MODULE_TEMPLATE % dct
Example #2
0
def convert_module(mod, filename):
    dct = {'scope':'_', 'filename':os.path.abspath(filename)}
    dct['doc'] = multiline(ast.get_docstring(mod))

    _globs = ['__name__','__doc__','__file__']
    scope = {
        'globals':[],
        'locals':[],
        'exp globals':[],
        'parent locals':(),
        'exp locals':False,
        'num iters':0,
        'in atomic':0,
    }
    scope['globals'] = scope['locals'] = _globs
    contents = convert_block(mod.body, scope)
    dct['contents'] = contents
    text = TEMPLATES['module'] % dct
    prefix = local_prefix(scope)
    for name in scope['locals']:
        text = re.sub('{:undef:' + name + ':[^:]*:}', prefix + name, text)
    text = re.sub('{:undef:(\w+):([^:]*):}', '$b.assertdefined(\\2\\1)', text)
    text = text.replace('&coln;', ':').replace('&', '&')
    return text
Example #3
0
def _str(node, scope):
    return '$b.str(%s)' % multiline(node.s)
Example #4
0
def _str(conv, node, scope):
    return '$b.str(%s)' % utils.multiline(node.s)