Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
err_add(ctx.errors, stmt.i_uses_pos, 'NEED_KEY_USES',
(stmt.pos))
else:
err_add(ctx.errors, stmt.pos, 'NEED_KEY', ())
stmt.i_key = []
if key is not None and key.arg is not None:
found = []
for x in key.arg.split():
if x == '':
continue
prefix, name = util.split_identifier(x)
if prefix is not None and prefix != stmt.i_module.i_prefix:
err_add(ctx.errors, key.pos, 'BAD_KEY', x)
return
ptr = util.attrsearch(name, 'arg', stmt.i_children)
if x in found:
err_add(ctx.errors, key.pos, 'DUPLICATE_KEY', x)
return
elif ptr is None or ptr.keyword != 'leaf':
err_add(ctx.errors, key.pos, 'BAD_KEY', x)
return
chk_status(ctx, ptr.parent, ptr)
type_ = ptr.search_one('type')
if stmt.i_module.i_version == '1':
if type_ is not None:
t = has_type(type_, ['empty'])
if t is not None:
err_add(ctx.errors, key.pos, 'BAD_TYPE_IN_KEY',
(t.arg, x))
return
default = ptr.search_one('default')
err_add(ctx.errors, stmt.pos, 'NEED_KEY', ())
stmt.i_key = []
if key is not None and key.arg is not None:
found = []
for x in key.arg.split():
if x == '':
continue
if x.find(":") == -1:
name = x
else:
[prefix, name] = x.split(':', 1)
if prefix != stmt.i_module.i_prefix:
err_add(ctx.errors, key.pos, 'BAD_KEY', x)
return
ptr = attrsearch(name, 'arg', stmt.i_children)
if x in found:
err_add(ctx.errors, key.pos, 'DUPLICATE_KEY', x)
return
elif ((ptr is None) or (ptr.keyword != 'leaf')):
err_add(ctx.errors, key.pos, 'BAD_KEY', x)
return
type_ = ptr.search_one('type')
if stmt.i_module.i_version == '1':
if type_ is not None:
t = has_type(type_, ['empty'])
if t is not None:
err_add(ctx.errors, key.pos, 'BAD_TYPE_IN_KEY',
(t.arg, x))
return
default = ptr.search_one('default')
if default is not None:
for expr in u.arg.split():
if expr == '':
continue
ptr = stmt
for x in expr.split('/'):
if x == '':
continue
if ptr.keyword not in ['container', 'list',
'choice', 'case']:
err_add(ctx.errors, u.pos, 'BAD_UNIQUE_PART', x)
return
prefix, name = util.split_identifier(x)
if prefix is not None and prefix != stmt.i_module.i_prefix:
err_add(ctx.errors, u.pos, 'BAD_UNIQUE_PART', x)
return
ptr = util.attrsearch(name, 'arg', ptr.i_children)
if ptr is None:
err_add(ctx.errors, u.pos, 'BAD_UNIQUE_PART', x)
return
if ptr.keyword == 'list':
err_add(ctx.errors, u.pos, 'BAD_UNIQUE_PART_LIST', x)
if ptr is None or ptr.keyword != 'leaf':
err_add(ctx.errors, u.pos, 'BAD_UNIQUE', expr)
return
if ptr in found:
err_add(ctx.errors, u.pos, 'DUPLICATE_UNIQUE', expr)
if hasattr(ptr, 'i_config'):
if uconfig is None:
uconfig = ptr.i_config
elif uconfig != ptr.i_config:
err_add(ctx.errors, u.pos, 'BAD_UNIQUE_CONFIG', expr)
return
def gen_new_typedef(module, new_type):
i = 0
name = "t" + str(i)
all_typedefs = module.search('typedef') + module.i_local_typedefs + \
module.i_gen_typedef
while util.attrsearch(name, 'arg', all_typedefs):
i = i + 1
name = "t" + str(i)
typedef = statements.Statement(module, module, new_type.pos,
'typedef', name)
typedef.substmts.append(new_type)
module.i_gen_typedef.append(typedef)
return name
def gen_name(name, name_list):
i = 0
tname = name + '_' + str(i)
while util.attrsearch(tname, 'i_xsd_name', name_list):
i = i + 1
tname = name + '_' + str(i)
return tname
def v_reference_choice(ctx, stmt):
"""Make sure that the default case exists"""
d = stmt.search_one('default')
if d is not None:
m = stmt.search_one('mandatory')
if m is not None and m.arg == 'true':
err_add(ctx.errors, stmt.pos, 'DEFAULT_AND_MANDATORY', ())
ptr = attrsearch(d.arg, 'arg', stmt.i_children)
if ptr is None:
err_add(ctx.errors, d.pos, 'DEFAULT_CASE_NOT_FOUND', d.arg)
else:
# make sure there are no mandatory nodes in the default case
def chk_no_defaults(s):
for c in s.i_children:
if c.keyword in ('leaf', 'choice'):
m = c.search_one('mandatory')
if m is not None and m.arg == 'true':
err_add(ctx.errors, c.pos,
'MANDATORY_NODE_IN_DEFAULT_CASE', ())
elif c.keyword in ('list', 'leaf-list'):
m = c.search_one('min-elements')
if m is not None and int(m.arg) > 0:
err_add(ctx.errors, c.pos,
'MANDATORY_NODE_IN_DEFAULT_CASE', ())