summaryrefslogblamecommitdiff
path: root/ncserver/util.py
blob: bf47f561ead00ded0132c94f696560382c97f95f (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13












                                                                            
                                                     



















                                                                            
                           

                                                                              
"""
NETCONF for APK Distributions server:
    Higher-level utility functions.

Copyright © 2020 Adélie Software in the Public Benefit, Inc.

Released under the terms of the NCSA license.  See the LICENSE file included
with this source distribution for more information.

SPDX-License-Identifier: NCSA
"""


from lxml.etree import QName  # pylint: disable=E0611
from netconf import error

from ncserver.base.modman import MODMAN


def maybe_raise_on_invalid_node(xmlns, rpc, node):
    """Determine if this node should cause the module in namespace to raise.

    :param str xmlns:
        The xmlns of the current module.

    :param rpc:
        The RPC causing this lookup to happen.

    :param node:
        The node in question.
    """
    nodens = QName(node).namespace
    if nodens == xmlns:
        raise error.UnknownElementAppError(rpc, node)
    # pylint: disable=W0212
    if nodens not in (mod.M_PREFIX for mod in MODMAN._augments_for_ns(xmlns)):
        raise error.UnknownNamespaceAppError(rpc, node, None)