Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if i.arg == "identityref":
subtypes.append(i.search_one("base"))
else:
subtypes.append(i)
elif base_t.arg == "identityref":
subtypes = [base_t.search_one("base")]
else:
subtypes = [base_t]
any_unknown = False
for i in subtypes:
# Resolve this typedef to the module that it
# was defined by
if ":" in i.arg:
defining_module = util.prefix_to_module(
defnd[t].i_module, i.arg.split(":")[0], defnd[t].pos, ctx.errors
)
else:
defining_module = defnd[t].i_module
belongs_to = defining_module.search_one("belongs-to")
if belongs_to is not None:
for mod in ctx.modules:
if mod[0] == belongs_to.arg:
defining_module = ctx.modules[mod]
real_pfx = defining_module.search_one("prefix").arg
if ":" in i.arg:
tn = "%s:%s" % (real_pfx, i.arg.split(":")[1])
elif i.arg not in base_types:
tid.add_prefix(prefix)
self.add_identity(tid)
if defining_module in mod_ref_prefixes:
for i in mod_ref_prefixes[defining_module]:
tid.add_prefix(i)
else:
# Determine what the name of the base and the prefix for
# the base should be
if ":" in base.arg:
base_pfx, base_name = base.arg.split(":")
else:
base_pfx, base_name = prefix, base.arg
parent_module = util.prefix_to_module(defmod, base_pfx,
base.pos, ctx.errors)
# Find whether we have the base in the store
base_id = self.find_identity_by_source_name(parent_module.arg, base_name)
if base_id is None:
# and if not, then push this identity back onto the stack
unresolved_identities.append(this_id)
unresolved_identity_count[this_id] += 1
else:
# Check we don't already have this identity defined
if self.find_identity_by_source_name(defining_module, iddef.arg) is None:
# otherwise, create a new identity that reflects this one
tid = Identity(iddef.arg)
tid.source_module = defining_module
tid.source_namespace = namespace
def v_xpath(ctx, stmt):
try:
toks = xpath.tokens(stmt.arg)
for (tokname, s) in toks:
if tokname == 'name' or tokname == 'prefix-match':
i = s.find(':')
if i != -1:
prefix = s[:i]
prefix_to_module(stmt.i_module, prefix, stmt.pos,
ctx.errors)
elif tokname == 'literal':
# kind of hack to detect qnames, and mark the prefixes
# as being used in order to avoid warnings.
if s[0] == s[-1] and s[0] in ("'", '"'):
s = s[1:-1]
i = s.find(':')
# make sure there is just one : present
if i != -1 and s[i+1:].find(':') == -1:
prefix = s[:i]
# we don't want to report an error; just mark the
# prefix as being used.
my_errors = []
prefix_to_module(stmt.i_module, prefix, stmt.pos,
my_errors)
for (pos, code, arg) in my_errors:
def has_feature(name):
# raises Abort if the feature is not defined
# returns True if we compile with the feature
# returns False if we compile without the feature
found = None
prefix, name = util.split_identifier(name)
if prefix is None or stmt.i_module.i_prefix == prefix:
# check local features
pmodule = stmt.i_module
else:
# this is a prefixed name, check the imported modules
pmodule = util.prefix_to_module(
stmt.i_module, prefix, stmt.pos, ctx.errors)
if pmodule is None:
raise Abort
if name in pmodule.i_features:
f = pmodule.i_features[name]
if prefix is None and not is_submodule_included(stmt, f):
pass
else:
found = pmodule.i_features[name]
chk_status(ctx, stmt.parent, found)
v_type_feature(ctx, found)
if pmodule.i_modulename in ctx.features:
if name not in ctx.features[pmodule.i_modulename]:
return False
if found is None and no_error_report is False:
preds = head[3]
node1 = None
if axis == 'self':
pass
elif axis == 'child' and nodetest[0] == 'name':
prefix = nodetest[1]
name = nodetest[2]
if prefix is None:
if initial is None:
pmodule = None
elif initial.keyword == 'module':
pmodule = initial
else:
pmodule = initial.i_module
else:
pmodule = prefix_to_module(mod, prefix, pos, ctx.errors)
# if node and initial are None, it means we're checking an XPath
# expression when it is defined in a grouping or augment, i.e.,
# when the full tree is not expanded. in this case we can't check
# the paths
if pmodule is not None and node is not None and initial is not None:
if node == 'root':
children = pmodule.i_children
else:
children = getattr(node, 'i_children', None) or []
child = search_data_node(children, pmodule.i_modulename, name)
if child is None and node == 'root':
err_add(ctx.errors, pos, 'XPATH_NODE_NOT_FOUND2',
(pmodule.i_modulename, name, pmodule.arg))
elif child is None and node.i_module is not None:
err_add(ctx.errors, pos, 'XPATH_NODE_NOT_FOUND1',
(pmodule.i_modulename, name,
s = get_nontypedefstring(node)
if s != "":
t = node.search_one('type')
# chase typedef
type_namespace = None
i_type_name = None
prefix, name = util.split_identifier(t.arg)
if prefix is None or t.i_module.i_prefix == prefix:
# check local typedefs
pmodule = node.i_module
typedef = statements.search_typedef(t, name)
else:
# this is a prefixed name, check the imported modules
err = []
pmodule = util.prefix_to_module(t.i_module, prefix, t.pos, err)
if pmodule is None:
return
typedef = statements.search_typedef(pmodule, name)
if typedef is not None:
s = s + get_nontypedefstring(typedef)
return s
def find_target_node(ctx, stmt, is_augment=False):
if (hasattr(stmt, 'is_grammatically_valid') and
stmt.is_grammatically_valid == False):
return None
if stmt.arg.startswith("/"):
is_absolute = True
arg = stmt.arg
else:
is_absolute = False
arg = "/" + stmt.arg # to make node_id_part below work
# parse the path into a list of two-tuples of (prefix,identifier)
path = [(m[1], m[2]) for m in syntax.re_schema_node_id_part.findall(arg)]
# find the module of the first node in the path
(prefix, identifier) = path[0]
module = prefix_to_module(stmt.i_module, prefix, stmt.pos, ctx.errors)
if module is None:
# error is reported by prefix_to_module
return None
if (stmt.parent.keyword in ('module', 'submodule') or
is_absolute):
# find the first node
node = search_child(module.i_children, module.i_modulename, identifier)
if not is_submodule_included(stmt, node):
node = None
if node is None:
err_add(ctx.errors, stmt.pos, 'NODE_NOT_FOUND',
(module.i_modulename, identifier))
return None
else:
chs = [c for c in stmt.parent.parent.i_children \
def find_refine_node(refinement):
# parse the path into a list of two-tuples of (prefix,identifier)
pstr = '/' + refinement.arg
path = [(m[1], m[2]) \
for m in syntax.re_schema_node_id_part.findall(pstr)]
node = stmt.parent
# recurse down the path
for prefix, identifier in path:
module = util.prefix_to_module(
stmt.i_module, prefix, refinement.pos, ctx.errors)
if hasattr(node, 'i_children'):
if module is None:
return None
child = search_child(node.i_children, module.i_modulename,
identifier)
if child is None:
err_add(ctx.errors, refinement.pos, 'NODE_NOT_FOUND',
(module.i_modulename, identifier))
return None
node = child
else:
err_add(ctx.errors, refinement.pos, 'BAD_NODE_IN_REFINE',
(module.i_modulename, identifier))
return None
return node
elif c.keyword in _singleton_keywords:
if t.search_one(c.keyword) is not None:
err_add(ctx.errors, c.pos, 'BAD_DEVIATE_ADD',
(c.keyword, t.i_module.arg, t.arg))
elif t.keyword not in _valid_deviations[c.keyword]:
err_add(ctx.errors, c.pos, 'BAD_DEVIATE_TYPE',
c.keyword)
else:
t.substmts.append(c)
else:
# multi-valued keyword; just add the statement if it is valid
if c.keyword not in _valid_deviations:
if util.is_prefixed(c.keyword):
(prefix, name) = c.keyword
pmodule = util.prefix_to_module(
c.i_module, prefix, c.pos, [])
if (pmodule is not None and
pmodule.modulename in grammar.extension_modules):
err_add(ctx.errors, c.pos, 'BAD_DEVIATE_TYPE',
c.keyword)
else:
# unknown module, let's assume the extension can
# be deviated
t.substmts.append(c)
else:
err_add(ctx.errors, c.pos, 'BAD_DEVIATE_TYPE',
c.keyword)
elif t.keyword not in _valid_deviations[c.keyword]:
err_add(ctx.errors, c.pos, 'BAD_DEVIATE_TYPE',
c.keyword)