summaryrefslogtreecommitdiff
path: root/ncserver/util.py
blob: 209d4d9bafa3fd1aead8dca3d25e567a8482fd2b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
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
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)
    if nodens not in (mod.M_PREFIX for mod in MODMAN._augments_for_ns(xmlns)):
        raise error.UnknownNamespaceAppError(rpc, node, None)