blob: 3af31bd14f0c3edb15cce1fda1e21f515cfb8e0a [file] [log] [blame]
Khen Nursimuluc9ef7c12017-01-04 20:40:53 -05001#!/usr/bin/env python
2#
3# Copyright 2017 the original author or authors.
4#
5# Code adapted from https://github.com/choppsv1/netconf
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19from netconf.constants import Constants as C
20from lxml import etree
21
22ns_map = C.NS_MAP
23
24def qmap(key):
25 if ns_map.has_key(key):
26 return ''.join(['{', ns_map[key], '}'])
27
28def ns(key):
29 if ns_map.has_key(key):
30 return ns_map[key]
31
32def qname(tag):
33 try:
34 return etree.QName(tag)
35 except ValueError:
36 prefix, base = tag.split(":")
37 return etree.QName(ns(prefix), base)
38
39def elm(tag, attrib=None, **extra):
40 if attrib is None:
41 attrib = dict()
42 return etree.Element(qname(tag), attrib, **extra)
43