Example #1
0
def emit_yin(ctx, module, fd):
    fd.write('<?xml version="1.0" encoding="UTF-8"?>\n')
    fd.write('<%s name="%s"\n' % (module.keyword, module.arg))
    fd.write(' ' * len(module.keyword) + '  xmlns="%s"' % yin_namespace)

    prefix = module.search_one('prefix')
    if prefix is not None:
        namespace = module.search_one('namespace')
        fd.write('\n')
        fd.write(' ' * len(module.keyword))
        fd.write('  xmlns:' + prefix.arg + '=' + quoteattr(namespace.arg))
    for imp in module.search('import'):
        prefix = imp.search_one('prefix')
        if prefix is not None:
            rev = None
            r = imp.search_one('revision-date')
            if r is not None:
                rev = r.arg
            mod = statements.modulename_to_module(module, imp.arg, rev)
            if mod is not None:
                ns = mod.search_one('namespace')
                if ns is not None:
                    fd.write('\n')
                    fd.write(' ' * len(module.keyword))
                    fd.write('  xmlns:' + prefix.arg + '=' + quoteattr(ns.arg))
    fd.write('>\n')
    if ctx.opts.yin_canonical:
        substmts = grammar.sort_canonical(module.keyword, module.substmts)
    else:
        substmts = module.substmts
    for s in substmts:
        emit_stmt(ctx, module, s, fd, '  ', '  ')
    fd.write('</%s>\n' % module.keyword)
Example #2
0
def emit_yin(ctx, module, fd):
    fd.write('<?xml version="1.0" encoding="UTF-8"?>\n')
    fd.write('<%s name="%s"\n' % (module.keyword, module.arg))
    fd.write(' ' * len(module.keyword) + '  xmlns="%s"' % yin_namespace)

    prefix = module.search_one('prefix')
    if prefix is not None:
        namespace = module.search_one('namespace')
        fd.write('\n')
        fd.write(' ' * len(module.keyword))
        fd.write('  xmlns:' + prefix.arg + '=' +
                 quoteattr(namespace.arg))
    for imp in module.search('import'):
        prefix = imp.search_one('prefix')
        if prefix is not None:
            rev = None
            r = imp.search_one('revision-date')
            if r is not None:
                rev = r.arg
            mod = statements.modulename_to_module(module, imp.arg, rev)
            if mod is not None:
                ns = mod.search_one('namespace')
                if ns is not None:
                    fd.write('\n')
                    fd.write(' ' * len(module.keyword))
                    fd.write('  xmlns:' + prefix.arg + '=' +
                             quoteattr(ns.arg))
    fd.write('>\n')
    if ctx.opts.yin_canonical:
        substmts = grammar.sort_canonical(module.keyword, module.substmts)
    else:
        substmts = module.substmts
    for s in substmts:
        emit_stmt(ctx, module, s, fd, '  ', '  ')
    fd.write('</%s>\n' % module.keyword)
Example #3
0
def _get_module_nsmap(module_statement):
    nsmap = {}

    prefixes = module_statement.i_prefixes
    for prefix, (module_name, revision) in prefixes.items():
        imported_module_statement = statements.modulename_to_module(
            module_statement, module_name, revision)
        namespace = imported_module_statement.search_one('namespace').arg
        nsmap[prefix] = namespace

    return nsmap
Example #4
0
def emit_yin(ctx, module, fd):
    fd.write('<?xml version="1.0" encoding="UTF-8"?>' + new_line)
    fd.write(('<%s name="%s"' + new_line) % (module.keyword, module.arg))
    fd.write(ns_indent_space * len(module.keyword) + ns_indent_space +
             ' xmlns="%s"' % yin_namespace)

    prefix = module.search_one('prefix')
    if prefix is not None:
        namespace = module.search_one('namespace')
        fd.write('' + new_line)
        fd.write(ns_indent_space * len(module.keyword))
        fd.write(ns_indent_space + ' xmlns:' + prefix.arg + '=' +
                 quoteattr(namespace.arg))
    else:
        belongs_to = module.search_one('belongs-to')
        if belongs_to is not None:
            prefix = belongs_to.search_one('prefix')
            if prefix is not None:
                # read the parent module in order to find the namespace uri
                res = ctx.read_module(belongs_to.arg,
                                      extra={'no_include': True})
                if res is not None:
                    namespace = res.search_one('namespace')
                    if namespace is None or namespace.arg is None:
                        pass
                    else:
                        # success - namespace found
                        fd.write('' + new_line)
                        fd.write(sonic - acl.yin * len(module.keyword))
                        fd.write(sonic - acl.yin + ' xmlns:' + prefix.arg +
                                 '=' + quoteattr(namespace.arg))

    for imp in module.search('import'):
        prefix = imp.search_one('prefix')
        if prefix is not None:
            rev = None
            r = imp.search_one('revision-date')
            if r is not None:
                rev = r.arg
            mod = statements.modulename_to_module(module, imp.arg, rev)
            if mod is not None:
                ns = mod.search_one('namespace')
                if ns is not None:
                    fd.write('' + new_line)
                    fd.write(ns_indent_space * len(module.keyword))
                    fd.write(ns_indent_space + ' xmlns:' + prefix.arg + '=' +
                             quoteattr(ns.arg))
    fd.write('>' + new_line)

    substmts = module.substmts
    for s in substmts:
        emit_stmt(ctx, module, s, fd, indent_space, indent_space)
    fd.write(('</%s>' + new_line) % module.keyword)
def emit_yin(ctx, module, fd):
    fd.write('<?xml version="1.0" encoding="UTF-8"?>\n')
    fd.write('<%s name="%s"\n' % (module.keyword, module.arg))
    fd.write(' ' * len(module.keyword) + '  xmlns="%s"' % yin_namespace)

    prefix = module.search_one('prefix')
    if prefix is not None:
        namespace = module.search_one('namespace')
        fd.write('\n')
        fd.write(' ' * len(module.keyword))
        fd.write('  xmlns:' + prefix.arg + '=' +
                 quoteattr(namespace.arg))
    else:
        belongs_to = module.search_one('belongs-to')
        if belongs_to is not None:
            prefix = belongs_to.search_one('prefix')
            if prefix is not None:
                # read the parent module in order to find the namespace uri
                res = ctx.read_module(belongs_to.arg, extra={'no_include':True})
                if res is not None:
                    namespace = res.search_one('namespace')
                    if namespace is None or namespace.arg is None:
                        pass
                    else:
                        # success - namespace found
                        fd.write('\n')
                        fd.write(' ' * len(module.keyword))
                        fd.write('  xmlns:' + prefix.arg + '=' +
                                 quoteattr(namespace.arg))
            
    for imp in module.search('import'):
        prefix = imp.search_one('prefix')
        if prefix is not None:
            rev = None
            r = imp.search_one('revision-date')
            if r is not None:
                rev = r.arg
            mod = statements.modulename_to_module(module, imp.arg, rev)
            if mod is not None:
                ns = mod.search_one('namespace')
                if ns is not None:
                    fd.write('\n')
                    fd.write(' ' * len(module.keyword))
                    fd.write('  xmlns:' + prefix.arg + '=' +
                             quoteattr(ns.arg))
    fd.write('>\n')
    if ctx.opts.yin_canonical:
        substmts = grammar.sort_canonical(module.keyword, module.substmts)
    else:
        substmts = module.substmts
    for s in substmts:
        emit_stmt(ctx, module, s, fd, '  ', '  ')
    fd.write('</%s>\n' % module.keyword)
Example #6
0
 def rng_annotation(self, stmt, p_elem):
     """Append YIN representation of extension statement `stmt`."""
     ext = stmt.i_extension
     prf, extkw = stmt.raw_keyword
     (modname, rev) = stmt.i_module.i_prefixes[prf]
     prefix = self.add_namespace(statements.modulename_to_module(self.module, modname, rev))
     eel = SchemaNode(prefix + ":" + extkw, p_elem)
     argst = ext.search_one("argument")
     if argst:
         if argst.search_one("yin-element", "true"):
             SchemaNode(prefix + ":" + argst.arg, eel, stmt.arg)
         else:
             eel.attr[argst.arg] = stmt.arg
     self.handle_substmts(stmt, eel)
Example #7
0
 def rng_annotation(self, stmt, p_elem):
     """Append YIN representation of extension statement `stmt`."""
     ext = stmt.i_extension
     prf, extkw = stmt.raw_keyword
     (modname,rev)=stmt.i_module.i_prefixes[prf]
     prefix = self.add_namespace(
         statements.modulename_to_module(self.module,modname,rev))
     eel = SchemaNode(prefix + ":" + extkw, p_elem)
     argst = ext.search_one("argument")
     if argst:
         if argst.search_one("yin-element", "true"):
             SchemaNode(prefix + ":" + argst.arg, eel, stmt.arg)
         else:
             eel.attr[argst.arg] = stmt.arg
     self.handle_substmts(stmt, eel)
Example #8
0
    def emit(self, ctx, module, fd):
        # cannot do XSD unless everything is ok for our module
        for (epos, etag, eargs) in ctx.errors:
            if (epos.top_name == module.arg
                    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)
Example #9
0
 def emit(self, ctx, module, fd):
     # cannot do XSD unless everything is ok for our module
     for (epos, etag, eargs) in ctx.errors:
         if (epos.top_name == module.arg 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)
Example #10
0
def wyin_init_prefix(ctx, module):
    global wyin_prefix, wyin_namespace, wyin_nsprefixes
    prefix = module.search_one('prefix')
    if prefix is not None:
        namespace = module.search_one('namespace')
        wyin_prefix = prefix.arg
        wyin_namespace = namespace.arg
        wyin_nsprefixes[prefix.arg] = namespace.arg
    else:
        belongs_to = module.search_one('belongs-to')
        if belongs_to is not None:
            prefix = belongs_to.search_one('prefix')
            if prefix is not None:
                # read the parent module in order to find the namespace uri
                res = ctx.read_module(belongs_to.arg,
                                      extra={'no_include': True})
                if res is not None:
                    namespace = res.search_one('namespace')
                    if namespace is None or namespace.arg is None:
                        pass
                    else:
                        # success - namespace found
                        wyin_namespace = namespace.arg
                        wyin_nsprefixes[prefix.arg] = namespace.arg
                wyin_prefix = prefix.arg
    for imp in module.search('import'):
        prefix = imp.search_one('prefix')
        if prefix is not None:
            rev = None
            r = imp.search_one('revision-date')
            if r is not None:
                rev = r.arg
            mod = statements.modulename_to_module(module, imp.arg, rev)
            if mod is not None:
                ns = mod.search_one('namespace')
                if ns is not None:
                    wyin_nsprefixes[prefix.arg] = ns.arg
Example #11
0
def wyin_init_prefix(ctx, module):
    global wyin_prefix, wyin_namespace, wyin_nsprefixes
    prefix = module.search_one('prefix')
    if prefix is not None:
        namespace = module.search_one('namespace')
        wyin_prefix = prefix.arg
        wyin_namespace = namespace.arg
        wyin_nsprefixes[prefix.arg] = namespace.arg
    else:
        belongs_to = module.search_one('belongs-to')
        if belongs_to is not None:
            prefix = belongs_to.search_one('prefix')
            if prefix is not None:
                # read the parent module in order to find the namespace uri
                res = ctx.read_module(belongs_to.arg, extra={'no_include':True})
                if res is not None:
                    namespace = res.search_one('namespace')
                    if namespace is None or namespace.arg is None:
                        pass
                    else:
                        # success - namespace found
                        wyin_namespace = namespace.arg
                        wyin_nsprefixes[prefix.arg] = namespace.arg
                wyin_prefix = prefix.arg
    for imp in module.search('import'):
        prefix = imp.search_one('prefix')
        if prefix is not None:
            rev = None
            r = imp.search_one('revision-date')
            if r is not None:
                rev = r.arg
            mod = statements.modulename_to_module(module, imp.arg, rev)
            if mod is not None:
                ns = mod.search_one('namespace')
                if ns is not None:
                    wyin_nsprefixes[prefix.arg] = ns.arg