Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# This pyang plugin generates a random XML instance document adhering
# to a YANG module.
from pyang import plugin
from pyang import types
from pyang import statements
import sys
from random import randint, random
def pyang_plugin_init():
plugin.register_plugin(YANGXMLPlugin())
class YANGXMLPlugin(plugin.PyangPlugin):
def add_output_format(self, fmts):
fmts['xml'] = self
def emit(self, ctx, modules, writef):
module = modules[0]
emit_xml(module, writef)
def emit_xml(module, fd):
# pick one top-level child
if len(module.i_children) == 0:
return
c = pick(module.i_children)
attrs = ' xmlns="%s"' % module.search_one('namespace').arg
if c.keyword == 'choice':
sys.stderr.write("Cannot handle choice on top-level")
sys.exit(1)
emit_stmt(c, fd, '', attrs, 1)
from pyang import plugin
from pyang import statements
def pyang_plugin_init():
plugin.register_plugin(AddFoo())
class AddFoo(plugin.PyangPlugin):
def add_transform(self, xforms):
xforms['add-foo'] = self
def transform(self, ctx, modules):
for module in modules:
for stmt in module.substmts:
if stmt.keyword == 'container':
foo = stmt.search_one('foo')
if not foo:
foo = add_leaf(stmt, 'foo', 'string')
def add_leaf(parent, name, type_name):
leaf = statements.new_statement(parent.top, parent, parent.pos,
'leaf', name)
parent.substmts.append(leaf)
def pyang_plugin_init():
plugin.register_plugin(YANGXMLPlugin())
def pyang_plugin_init():
plugin.register_plugin(YANGPlugin())
def pyang_plugin_init():
plugin.register_plugin(SidPlugin())
__docformat__ = "reStructuredText"
import sys
import optparse
import time
import pyang
from pyang import plugin, error, xpath, util, statements, types
from schemanode import SchemaNode
def pyang_plugin_init():
plugin.register_plugin(DSDLPlugin())
class DSDLPlugin(plugin.PyangPlugin):
def add_output_format(self, fmts):
self.multiple_modules = True
fmts['dsdl'] = self
def add_opts(self, optparser):
optlist = [
optparse.make_option("--dsdl-no-documentation",
dest="dsdl_no_documentation",
action="store_true",
default=False,
help="No output of DTD compatibility"
" documentation annotations"),
optparse.make_option("--dsdl-no-dublin-core",
dest="dsdl_no_dublin_core",
action="store_true",
default=False,
help="No output of Dublin Core"
def pyang_plugin_init():
plugin.register_plugin(ProtobufPlugin())
def pyang_plugin_init():
plugin.register_plugin(JSTreePlugin())
def __init__(self):
plugin.PyangPlugin.__init__(self, "flatten")