Archived documentation version rendered and hosted by DevNetExpertTraining.com
Skip to content

Module scrapli_netconf.helper

scrapli_netconf.helper

Expand source code
        
"""scrapli_netconf.helper"""
import re
from logging import getLogger

from lxml import objectify
from lxml.etree import Element

LOG = getLogger("scrapli_netconf.helper")


def remove_namespaces(tree: Element) -> Element:
    """
    Remove all namespace tags from Element object

    Replace element tags like: {http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-bgp-oper}connection-state
    With: connection-state

    Args:
        tree: lxml Element

    Returns:
        Element: lxml Element with namespaces stripped out

    Raises:
        N/A

    """
    for el in tree.getiterator():
        if not hasattr(el.tag, "find"):
            continue
        el.tag = re.sub(r"^{.*}", "", el.tag)
    objectify.deannotate(tree, cleanup_namespaces=True)
    return tree
        
    

Functions

remove_namespaces

remove_namespaces(tree: <cyfunction Element at 0x7fecff06c120>) ‑> <cyfunction Element at 0x7fecff06c120>

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
Remove all namespace tags from Element object

Replace element tags like: {http://cisco.com/ns/yang/Cisco-IOS-XR-ipv4-bgp-oper}connection-state
With: connection-state

Args:
    tree: lxml Element

Returns:
    Element: lxml Element with namespaces stripped out

Raises:
    N/A