Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
new_recurse = True
else:
new_recurse = False
recurse_pathspec = recurse_spec.pathspec if recurse_spec is not None \
else None
el = self.entityref_to_record(newstep, schema,
pathspec=recurse_pathspec,
_visited_records=_memo,
_recurse=new_recurse)
prop_elements = []
if link.has_user_defined_properties():
if recurse_spec.pathspec is not None:
must_have_props = (
sn.Name('std.linkid'),
)
recurse_props = {propn: irast.PtrPathSpec(ptr_proto=link.pointers[propn])
for propn in must_have_props}
for ps in recurse_spec.pathspec:
if (isinstance(ps.ptr_proto, s_lprops.LinkProperty)
and not ps.ptr_proto.is_endpoint_pointer()):
recurse_props[ps.ptr_proto.normal_name()] = ps
else:
recurse_props = {pn: irast.PtrPathSpec(ptr_proto=p)
for pn, p in link.pointers.items()
if p.get_loading_behaviour() == s_pointers.PointerLoading.Eager
and not p.is_endpoint_pointer()}
proprec = irast.Record(elements=prop_elements, concept=root_link_proto)
context.current.namespaces.update(context.current.module_aliases)
if edgeql_tree.cges:
graph.cges = []
for cge in edgeql_tree.cges:
with context(ParseContext.SUBQUERY):
_cge = self._transform_select(context, cge.expr, arg_types)
context.current.cge_map[cge.alias] = _cge
graph.cges.append(
irast.CommonGraphExpr(expr=_cge, alias=cge.alias))
tgt = graph.optarget = self._process_select_where(
context, edgeql_tree.subject)
idname = sn.Name('std.id')
idref = irast.AtomicRefSimple(
name=idname, ref=tgt,
ptr_proto=tgt.concept.pointers[idname])
tgt.atomrefs.add(idref)
selexpr = irast.SelectorExpr(expr=idref, name=None)
graph.selector.append(selexpr)
with context():
context.current.location = 'optarget_shaper'
if edgeql_tree.targets:
graph.opselector = self._process_select_targets(
context, edgeql_tree.targets)
else:
graph.opselector = []
if edgeql_tree.pathspec:
def _get_schema_object(self, name, module=None):
ctx = self.context.current
if isinstance(name, qlast.ClassRef):
module = name.module
name = name.name
if module:
name = sn.Name(name=name, module=module)
return ctx.schema.get(name=name, module_aliases=ctx.namespaces)
target_set.concept)
target_set.users.add(context.current.location)
link = irast.EntityLink(source=path_tip,
target=target_set,
link_proto=link_proto,
direction=direction,
users={context.current.location})
target_set.rlink = link
atomref_id = irutils.LinearPath(path_tip.id)
atomref_id.add(link_proto, direction, target)
if not link_proto.singular():
ptr_name = sn.Name(
'std.target')
ptr_proto = link_proto.pointers[ptr_name]
atomref = irast.LinkPropRefSimple(
name=ptr_name, ref=link,
id=atomref_id, ptr_proto=ptr_proto)
link.proprefs.add(atomref)
path_tip.disjunction.update(link)
path_tip.disjunction.fixed = context.current.weak_path
else:
atomref = irast.AtomicRefSimple(
name=link_proto.normal_name(),
ref=path_tip, id=atomref_id,
rlink=link, ptr_proto=link_proto)
path_tip.atomrefs.add(atomref)
link.target = atomref
sn.Name('std::json'): 'jsonb',
}
base_type_name_map_r = {
'character varying': sn.Name('std::str'),
'character': sn.Name('std::str'),
'text': sn.Name('std::str'),
'numeric': sn.Name('std::decimal'),
'int4': sn.Name('std::int32'),
'integer': sn.Name('std::int32'),
'bigint': sn.Name('std::int64'),
'int8': sn.Name('std::int64'),
'int2': sn.Name('std::int16'),
'smallint': sn.Name('std::int16'),
'boolean': sn.Name('std::bool'),
'bool': sn.Name('std::bool'),
'double precision': sn.Name('std::float64'),
'float8': sn.Name('std::float64'),
'real': sn.Name('std::float32'),
'float4': sn.Name('std::float32'),
'uuid': sn.Name('std::uuid'),
'timestamp with time zone': sn.Name('std::datetime'),
'timestamptz': sn.Name('std::datetime'),
'date': sn.Name('std::date'),
'timetz': sn.Name('std::time'),
'time': sn.Name('std::time'),
'interval': sn.Name('std::timedelta'),
'bytea': sn.Name('std::bytes'),
'jsonb': sn.Name('std::json'),
}
expr=qlast.Path(steps=[
qlast.Ptr(
ptr=qlast.ClassRef(
name=pn.name,
module=pn.module
)
)
])
)
implicit_shape_els.append(shape_el)
shapespec = implicit_shape_els + list(shapespec)
elif source_expr.rptr is not None or rptr is not None:
target_prop = sn.Name('std::target')
target_el = qlast.ShapeElement(
expr=qlast.Path(steps=[
qlast.Ptr(
ptr=qlast.ClassRef(
name=target_prop.name,
module=target_prop.module
),
type='property'
)
])
)
precompiled_exprs[target_el] = source_expr
shapespec = [target_el] + list(shapespec)
for shape_el in shapespec:
with ctx.newfence() as elctx:
}
base_type_name_map_r = {
'character varying': sn.Name('std::str'),
'character': sn.Name('std::str'),
'text': sn.Name('std::str'),
'numeric': sn.Name('std::decimal'),
'int4': sn.Name('std::int32'),
'integer': sn.Name('std::int32'),
'bigint': sn.Name('std::int64'),
'int8': sn.Name('std::int64'),
'int2': sn.Name('std::int16'),
'smallint': sn.Name('std::int16'),
'boolean': sn.Name('std::bool'),
'bool': sn.Name('std::bool'),
'double precision': sn.Name('std::float64'),
'float8': sn.Name('std::float64'),
'real': sn.Name('std::float32'),
'float4': sn.Name('std::float32'),
'uuid': sn.Name('std::uuid'),
'timestamp with time zone': sn.Name('std::datetime'),
'timestamptz': sn.Name('std::datetime'),
'date': sn.Name('std::date'),
'timetz': sn.Name('std::time'),
'time': sn.Name('std::time'),
'interval': sn.Name('std::timedelta'),
'bytea': sn.Name('std::bytes'),
'jsonb': sn.Name('std::json'),
}
def get_scalar_base(schema, scalar):
class AtomicRefExpr(AtomicRef, BaseRefExpr):
def update_ref(self):
refs = set(ast.find_children(self.expr, lambda n: isinstance(n, EntitySet)))
assert(len(refs) == 1)
ast.AST.__setattr__(self, 'ref', next(iter(refs)))
self.ref.backrefs.add(self)
class LinkPropRef(BaseRef):
pass
class LinkPropRefSimple(LinkPropRef):
__fields = [('name', sn.Name, None)]
class LinkPropRefExpr(LinkPropRef, BaseRefExpr):
def update_ref(self):
refs = set(ast.find_children(self.expr, lambda n: isinstance(n, EntityLink)))
assert(len(refs) == 1)
ast.AST.__setattr__(self, 'ref', next(iter(refs)))
self.ref.backrefs.add(self)
class EntityLink(Base):
__fields = ['propfilter', 'source', 'target', 'link_class', ('proprefs', set),
('users', set), 'anchor', 'show_as_anchor',
'pathvar', 'direction', 'pathspec_trigger']
def replace_refs(self, old, new, deep=False, _memo=None):
self.apply_rewrites(expr.source)
if 'lang_rewrite' not in expr.rewrite_flags:
schema = self.context.current.proto_schema
localizable = schema.get('std.localizable', default=None)
link_proto = expr.link_proto
if localizable is not None and link_proto.issubclass(localizable):
cvars = self.context.current.context_vars
lang = irast.Constant(index='__context_lang',
type=schema.get('std.str'))
cvars['lang'] = 'en-US'
propn = sn.Name('std.lang')
for langprop in expr.proprefs:
if langprop.name == propn:
break
else:
lprop_proto = link_proto.pointers[propn]
langprop = irast.LinkPropRefSimple(name=propn, ref=expr,
ptr_proto=lprop_proto)
expr.proprefs.add(langprop)
eq_lang = irast.BinOp(left=langprop, right=lang, op=ast.ops.EQ)
lang_none = irast.NoneTest(expr=lang)
# Test for property emptiness is for LEFT JOIN cases
prop_none = irast.NoneTest(expr=langprop)
lang_prop_none = irast.BinOp(left=lang_none, right=prop_none, op=ast.ops.OR)
lang_test = irast.BinOp(left=lang_prop_none, right=eq_lang, op=ast.ops.OR,
sn.Name('std::int16'): 'smallint',
sn.Name('std::decimal'): 'numeric',
sn.Name('std::bool'): 'boolean',
sn.Name('std::float64'): 'float8',
sn.Name('std::float32'): 'float4',
sn.Name('std::uuid'): 'uuid',
sn.Name('std::datetime'): 'timestamptz',
sn.Name('std::date'): 'date',
sn.Name('std::time'): 'timetz',
sn.Name('std::timedelta'): 'interval',
sn.Name('std::bytes'): 'bytea',
sn.Name('std::json'): 'jsonb',
}
base_type_name_map_r = {
'character varying': sn.Name('std::str'),
'character': sn.Name('std::str'),
'text': sn.Name('std::str'),
'numeric': sn.Name('std::decimal'),
'int4': sn.Name('std::int32'),
'integer': sn.Name('std::int32'),
'bigint': sn.Name('std::int64'),
'int8': sn.Name('std::int64'),
'int2': sn.Name('std::int16'),
'smallint': sn.Name('std::int16'),
'boolean': sn.Name('std::bool'),
'bool': sn.Name('std::bool'),
'double precision': sn.Name('std::float64'),
'float8': sn.Name('std::float64'),
'real': sn.Name('std::float32'),
'float4': sn.Name('std::float32'),
'uuid': sn.Name('std::uuid'),