Пример #1
0
 def visit_Assign(self, node):
     try:
         for n in node.targets:
             # CASA <1>: def foobar( ): return (1,2,3)
             # CASA <2>: True,b,c = foobar( )
             #
             #           generates a [<ast.Tuple>] for 'node'
             #           and tuple.elts provides access to the
             #           strings/names within the ast.Tuple
             #
             tgts = n.elts if isinstance(n, ast.Tuple) else [n]
             for t in tgts:
                 if not isinstance(t,ast.Attribute) and \
                    not isinstance(t,ast.Subscript):
                     if __builtins__.has_key(t.id):
                         raise InputRejected(
                             "attempt to modify a python builtin value")
                     if self.casa_builtins.has_key(t.id):
                         raise InputRejected(
                             "attempt to modify a casa builtin value")
     except InputRejected as ir:
         raise ir
     except:
         print "-----------------------------------------------------------------"
         print "internal error in CASA assignment filter..."
         print traceback.format_exc()
         print "-----------------------------------------------------------------"
     return node
Пример #2
0
 def visit_Assign(self, node):
     for n in node.targets:
         if not isinstance(n,ast.Attribute) and \
            not isinstance(n,ast.Subscript):
             if __builtins__.has_key(n.id):
                 raise InputRejected(
                     "attempt to modify a python builtin value")
             if self.casa_builtins.has_key(n.id):
                 raise InputRejected(
                     "attempt to modify a casa builtin value")
     return node
Пример #3
0
 def visit(self, tree):
     try:
         sys.modules[_magic_module_name].__dict__.clear()
         sys.modules[_magic_module_name].__dict__.update(
             self._ipyextension.shell.user_ns)  # for self-macro-imports
         # We treat the initial magic module metadata as write-protected: even if the user
         # defines a variable of the same name in the user namespace, the metadata fields
         # in the magic module won't be overwritten. (IPython actually defines e.g. `__name__`
         # in `user_ns` even if the user explicitly doesn't.)
         sys.modules[_magic_module_name].__dict__.update(
             self._ipyextension.magic_module_metadata)
         # macro-imports (this will import the modules)
         bindings = find_macros(tree,
                                filename=self.expander.filename,
                                reload=True,
                                self_module=_magic_module_name)
         if bindings:
             self._ipyextension._macro_bindings_changed = True
             self.expander.bindings.update(bindings)
         new_tree = self.expander.visit(tree)
         new_tree = global_postprocess(new_tree)
         self._ipyextension.src = _placeholder
         return new_tree
     except Exception as err:
         # see IPython.core.interactiveshell.InteractiveShell.transform_ast()
         raise InputRejected(*err.args)
Пример #4
0
 def visit(self, tree):
     try:
         bindings = find_macros(
             tree, filename=self.expander.filename,
             reload=True)  # macro-imports (this will import the modules)
         if bindings:
             self._ipyextension._macro_bindings_changed = True
             self.expander.bindings.update(bindings)
         newtree = self.expander.visit(tree)
         newtree = global_postprocess(newtree)
         self._ipyextension.src = _placeholder
         return newtree
     except Exception as err:
         # see IPython.core.interactiveshell.InteractiveShell.transform_ast()
         raise InputRejected(*err.args)
Пример #5
0
 def visit(self, tree):
     try:
         bindings = detect_macros(tree, '__main__')  # macro imports
         if bindings:
             self.ext.macro_bindings_changed = True
             for fullname, macro_bindings in bindings:
                 mod = importlib.import_module(fullname)
                 self.bindings[fullname] = (mod, macro_bindings)
         newtree = ModuleExpansionContext(
             tree, self.ext.src, self.bindings.values()).expand_macros()
         self.ext.src = _placeholder
         return newtree
     except Exception as err:
         # see IPython.core.interactiveshell.InteractiveShell.transform_ast()
         raise InputRejected(*err.args)
Пример #6
0
 def visit_Constant(self, node):
     if isinstance(node.value, str):
         raise InputRejected("test")
     return node
Пример #7
0
 def visit_Str(self, node):
     raise InputRejected("test")