def _start(self, term, **global_opt_args): token = self.next_token self.next_token += 1 # Construct query query = p.Query() query.type = p.Query.START query.token = token # Set global opt args # The 'db' option will default to this connection's default # if not otherwise specified. if 'db' in global_opt_args: global_opt_args['db'] = DB(global_opt_args['db']) else: if self.db: global_opt_args['db'] = DB(self.db) for k,v in global_opt_args.iteritems(): pair = query.global_optargs.add() pair.key = k expr(v).build(pair.val) # Compile query to protobuf term.build(query.query) return self._send_query(query, term, global_opt_args)
def _start(self, term, **global_opt_args): token = self.next_token self.next_token += 1 # Construct query query = p.Query() query.type = p.Query.START query.token = token # Set global opt args # The 'db' option will default to this connection's default # if not otherwise specified. if 'db' in global_opt_args: global_opt_args['db'] = DB(global_opt_args['db']) else: if self.db: global_opt_args['db'] = DB(self.db) for k,v in global_opt_args.iteritems(): pair = query.global_optargs.add() pair.key = k expr(v).build(pair.val) noreply = False if 'noreply' in global_opt_args: noreply = global_opt_args['noreply'] # Compile query to protobuf term.build(query.query) return self._send_query(query, term, noreply)
def test_invalid_sum(self): pos = dict(lineno=2, col_offset=3) m = ast.Module([ast.Expr(ast.expr(**pos), **pos)]) with self.assertRaises(TypeError) as cm: compile(m, "<test>", "exec") if support.check_impl_detail(): self.assertIn("but got <_ast.expr", str(cm.exception))
def tokenRawValue(idx): tokType = tokens[idx]['type'] tokVal = tokens[idx]['value'] if tokType == T_Word: return ast.expr(ast.Name(id=tokVal, ctx=ast.Load())) elif tokType == T_Num: ast.Num(n = tokVal)
def test_invalid_sum(self): pos = dict(lineno=2, col_offset=3) m = ast.Module([ast.Expr(ast.expr(**pos), **pos)]) try: compile(m, "<test>", "exec") except TypeError as exc: self.assertIn("but got <_ast.expr", str(exc)) else: self.fail("needed TypeError")
def match(value, *patterns: Iterator[Tuple[str, AST]], locals_=None): if locals_ is None: import inspect locals_ = inspect.currentframe().f_back.f_locals from enum import Enum if isinstance(value, Enum): enums_in_pattern = { getattribute(p[0], locals_=locals_) for p in patterns } all_enums = {*iter(value.__class__)} sub = all_enums.difference(enums_in_pattern) if not any(p[0] == "_" for p in patterns) and len(sub) != 0: raise TypeError( f"Not exaustive match on Enum class {value.__class__.__name__} not handling {sub} for example" ) for m, expr in patterns: if m == "_": return expr() union = unify(value, m, locals_=locals_) if union is not None: if callable(expr): expr = expr(**union) elif isinstance(expr, str): expr = lazy(repr(expr)) elif hasattr(expr, "eval"): union = { k: lazy(repr(v)) if not isinstance(k, AST) else v for k, v in union.items() } expr = expr.eval(**{**locals_, **union}) return expr return None