How to use the pyang.error.EmitError function in pyang

To help you get started, we’ve selected a few pyang examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mbj4668 / pyang / pyang / plugins / sample-xml-skeleton.py View on Github external
sample XML document.
        """
        if ctx.opts.sample_path is not None:
            path = ctx.opts.sample_path.split('/')
            if path[0] == '':
                path = path[1:]
        else:
            path = []

        for (epos, etag, eargs) in ctx.errors:
            if error.is_error(error.err_level(etag)):
                raise error.EmitError(
                    "sample-xml-skeleton plugin needs a valid module")
        self.doctype = ctx.opts.doctype
        if self.doctype not in ("config", "data"):
            raise error.EmitError("Unsupported document type: %s" %
                                  self.doctype)
        self.annots = ctx.opts.sample_annots
        self.defaults = ctx.opts.sample_defaults
        self.node_handler = {
            "container": self.container,
            "leaf": self.leaf,
            "anyxml": self.anyxml,
            "choice": self.process_children,
            "case": self.process_children,
            "list": self.list,
            "leaf-list": self.leaf_list
        }
        self.ns_uri = {}
        for yam in modules:
            if yam.keyword == 'module':
                self.ns_uri[yam] = yam.search_one("namespace").arg
github mbj4668 / pyang / pyang / plugins / jsonxsl.py View on Github external
def emit(self, ctx, modules, fd):
        """Main control function.

        Set up the top-level parts of the stylesheet, then process
        recursively all nodes in all data trees, and finally emit the
        serialized stylesheet.
        """
        for (epos, etag, eargs) in ctx.errors:
            if error.is_error(error.err_level(etag)):
                raise error.EmitError("JSONXSL plugin needs a valid module")
        self.real_prefix = unique_prefixes(ctx)
        self.top_names = []
        for m in modules:
            self.top_names.extend([c.arg for c in m.i_children if
                                   c.keyword not in ("rpc", "notification")])
        tree = ET.ElementTree(ss)
        ET.SubElement(ss, "output", method="text")
        xsltdir = os.environ.get("PYANG_XSLT_DIR",
                                 "/usr/local/share/yang/xslt")
        ET.SubElement(ss, "include", href=xsltdir + "/jsonxsl-templates.xsl")
        ET.SubElement(ss, "strip-space", elements="*")
        nsmap = ET.SubElement(ss, "template", name="nsuri-to-module")
        ET.SubElement(nsmap, "param", name="uri")
        choo = ET.SubElement(nsmap, "choose")
        for module in self.real_prefix.keys():
            ns_uri = module.search_one("namespace").arg
github ansible-network / yang / lookup_plugins / yang_spec.py View on Github external
def emit(self, ctx, modules, fd):
        """Main control function.
        """
        for (epos, etag, eargs) in ctx.errors:
            if error.is_error(error.err_level(etag)):
                raise error.EmitError("sample-json-skeleton plugin needs a valid module")
        tree = {}
        self.defaults = ctx.opts.sample_defaults
        self.doctype = ctx.opts.doctype
        if self.doctype not in ("config", "data"):
            raise error.EmitError("Unsupported document type: %s" %
                                  self.doctype)

        for module in modules:
            self.process_children(module, tree, None)
        json.dump(tree, fd, indent=4)
github mbj4668 / pyang / pyang / translators / xsd.py View on Github external
def emit(self, ctx, modules, fd):
        module = modules[0]
        # cannot do XSD unless everything is ok for our module
        for (epos, etag, eargs) in ctx.errors:
            if (epos.top == module and
                error.is_error(error.err_level(etag))):
                raise error.EmitError("XSD translation needs a valid module")
        # we also need to have all other modules found
        for pre in module.i_prefixes:
            (modname, revision) = module.i_prefixes[pre]
            mod = statements.modulename_to_module(module, modname, revision)
            if mod == None:
                raise error.EmitError("cannot find module %s, needed by XSD"
                                      " translation" % modname)
            
        emit_xsd(ctx, module, fd)
github mbj4668 / pyang / pyang / plugins / depend.py View on Github external
def emit(self, ctx, modules, fd):
        # cannot do this unless everything is ok for our module
        modulenames = [m.arg for m in modules]
        for (epos, etag, eargs) in ctx.errors:
            if ((epos.top is None or epos.top.arg in modulenames) and
                error.is_error(error.err_level(etag))):
                raise error.EmitError("%s contains errors" % epos.top.arg)
        emit_depend(ctx, modules, fd)
github mbj4668 / pyang / pyang / translators / dsdl.py View on Github external
def yang_version_stmt(self, stmt, p_elem, pset):
        if float(stmt.arg) > self.YANG_version:
            raise error.EmitError("Unsupported YANG version: %s" % stmt.arg)
github mbj4668 / pyang / pyang / translators / dsdl.py View on Github external
arguments as this method. They should create the output schema
        fragment corresponding to `stmt`, apply all patches from
        `pset` belonging to `stmt`, insert the fragment under `p_elem`
        and perform all side effects as necessary.
        """
        if self.debug > 0:
            sys.stderr.write("Handling '%s %s'\n" %
                             (util.keyword_to_str(stmt.raw_keyword), stmt.arg))
        try:
            method = self.stmt_handler[stmt.keyword]
        except KeyError:
            if isinstance(stmt.keyword, tuple): # extension
                self.handle_extension(stmt, p_elem)
                return
            else:
                raise error.EmitError(
                    "Unknown keyword %s - this should not happen.\n"
                    % stmt.keyword)

        method(stmt, p_elem, pset)
github CiscoDevNet / ydk-gen / ydkgen / printer / meta_data_util.py View on Github external
meta_info_data.ptype = 'Decimal64'
            lower = str(type_spec.min.s)
            if type_spec.max is not None:
                upper = str(type_spec.max.s)
            else:
                upper = lower
            meta_info_data.prange.append(
                ('%s' % lower, '%s' % upper))
            meta_info_data.doc_link += get_primitive_type_tag('Decimal64', language)
        elif isinstance(type_spec, EmptyTypeSpec):
            meta_info_data.ptype = 'Empty'
            meta_info_data.doc_link += get_primitive_type_tag('Empty', language)
        elif isinstance(prop.property_type, Enum):
            raise EmitError('Illegal Code path')
        elif isinstance(type_spec, IdentityrefTypeSpec):
            raise EmitError('Illegal Code path')
        elif isinstance(type_spec, IntTypeSpec):
            meta_info_data.ptype = 'int'
            meta_info_data.doc_link += meta_info_data.ptype
            lower = str(type_spec.min)
            if type_spec.max is not None:
                upper = str(type_spec.max)
            else:
                upper = lower
            meta_info_data.prange.append((lower, upper))
        elif isinstance(type_spec, LengthTypeSpec):
            meta_info_data.ptype = 'str'
            meta_info_data.doc_link += get_primitive_type_tag('str', language)
            meta_info_data.prange = get_length_limits(type_spec)

        elif isinstance(type_spec, PathTypeSpec):
            raise EmitError('Illegal Code path')
github CiscoDevNet / ydk-gen / ydkgen / printer / meta_data_util.py View on Github external
def get_range_base_type_name(range_type):
    base_type = get_range_base_type_spec(range_type)
    if isinstance(base_type, IntTypeSpec):
        ptype = 'int'
    elif isinstance(base_type, Decimal64TypeSpec):
        ptype = 'Decimal64'
    else:
        raise EmitError('Unknown range type')
    return ptype
github mbj4668 / pyang / pyang / translators / dsdl.py View on Github external
def emit_dsdl(ctx, modules, fd):
    for (epos, etag, eargs) in ctx.errors:
        if error.is_error(error.err_level(etag)):
            raise error.EmitError("DSDL translation needs a valid module")
    schema = HybridDSDLSchema().from_modules(modules,
                                  ctx.opts.dsdl_no_dublin_core,
                                  ctx.opts.dsdl_no_documentation,
                                  ctx.opts.dsdl_record_defs,
                                  ctx.opts.dsdl_lax_yang_version,
                                  debug=0)
    fd.write(schema.serialize())