Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_exp_result(self): def print_exp_res(): res = "\n" res += " cat < {}".format(exp_res_file) + "\n" res += json.dumps(dic, indent=2) + "\n" res += "EOF" + "\n" res += "\n" return res self.maxDiff = None parser = RPSLViaParser() ast = parser.parse(line, rule_name="start") dic = asjson(ast) if exp_res: self.assertDictEqual(dic, exp_res, "\n\nTo fix it:\n{}".format(print_exp_res())) return print(print_exp_res())
def _test_syntax(self, line): parser = RPSLViaParser() ast = parser.parse(line, rule_name="start") # Build the reverse statement starting from the result of the parser # and check that it matches the input line. # Do this only when there are no actions in the original line, too # much effort to rebuild the action list. if "action" in line: return dic = asjson(ast) from_to = "from" if dic["action"] == "import-via:" else "to" accept_announce = "accept" if dic["action"] == "import-via:" else "announce" s = "{action} {afi} {rules} {filter}".format( action=dic["action"], afi="afi {afi_list}".format( afi_list=" ".join([afi for afi in dic["afi"]]) ) if dic["afi"] else "", rules=" ".join([ "{via} {from_to} {peers}".format( from_to=from_to, via="{intermediate_as} {router}".format( intermediate_as=rule["via"]["intermediate_as"], router="{peer} {at} {local}".format( peer=rule["via"]["router"]["peer_router"]
def test_fn_in_fn(): """Test function declarations being impossible inside a function body.""" decl = emptyfn(emptyfn("")) with raises(FailedParse): parse_source(decl)
def _default(self, ast, *args, **kwargs): if not args: return ast typespec = args[0].split(BASE_CLASS_TOKEN) typename = typespec[0] bases = typespec[-1:0:-1] base = self.base_type for base_ in bases: base = self._get_constructor(base_, base) constructor = self._get_constructor(typename, base) try: if type(constructor) is type and issubclass(constructor, Node): return constructor(*args[1:], ast=ast, ctx=self.ctx, **kwargs) else: return constructor(ast, *args[1:], **kwargs) except Exception as e: raise SemanticError( 'Could not call constructor for %s: %s' % (typename, str(e)) )
if PY33: name = cls.__qualname__ else: name = cls.__name__ # Try to reference the class try: idents = name.split('.') _cls = getattr(module, idents[0]) for ident in idents[1:]: _cls = getattr(_cls, ident) assert _cls == cls except AttributeError: raise CodegenError("Couldn't find base type, it has to be importable") return modulename, name
def _get_full_name(cls): if not inspect.isclass(cls): raise CodegenError("Base type has to be a class") module = inspect.getmodule(cls) if not module: raise CodegenError("Base type has to be inside a module") modulename = module.__name__ if PY33: name = cls.__qualname__ else: name = cls.__name__ # Try to reference the class try: idents = name.split('.') _cls = getattr(module, idents[0]) for ident in idents[1:]: _cls = getattr(_cls, ident) assert _cls == cls except AttributeError:
def _get_full_name(cls): if not inspect.isclass(cls): raise CodegenError("Base type has to be a class") module = inspect.getmodule(cls) if not module: raise CodegenError("Base type has to be inside a module") modulename = module.__name__ if PY33: name = cls.__qualname__ else: name = cls.__name__ # Try to reference the class try: idents = name.split('.') _cls = getattr(module, idents[0]) for ident in idents[1:]: _cls = getattr(_cls, ident)
parseinfo = self.node.directives.get('parseinfo', True) namechars = repr(self.node.directives.get('namechars') or '') rules = '\n'.join([ self.get_renderer(rule).render() for rule in self.node.rules ]) version = str(tuple(int(n) for n in str(timestamp()).split('.'))) keywords = [str(k) for k in self.keywords] keywords = '\n'.join(" %s," % repr(k) for k in keywords) if keywords: keywords = '\n%s\n' % keywords fields.update(rules=indent(rules), start=self.node.rules[0].name, abstract_rules=abstract_rules, version=version, whitespace=whitespace, nameguard=nameguard, ignorecase=ignorecase, comments_re=comments_re, eol_comments_re=eol_comments_re, left_recursion=left_recursion, parseinfo=parseinfo, keywords=keywords, namechars=namechars, )
@tatsumasu() def _IDENTIFIER_(self): # noqa self._pattern('[\\w$](?:[\\w\\d]|\\\\u[\\dA-Fa-f]{4})*')
@tatsumasu() def _start_(self): self._expression_() self._check_eof()