Revision dd8b8dd7 ncclient/xml_.py

b/ncclient/xml_.py
13 13
# limitations under the License.
14 14

  
15 15

  
16
"""The :mod:`xml` module provides methods for creating XML documents, parsing
17
XML, and converting between different XML representations. It uses
18
:mod:`~xml.etree.ElementTree` internally.
19
"""
16
"""The :mod:`xml_` module provides methods for creating, parsing, and dealing
17
with XML. It uses :mod:`~xml.etree.ElementTree`."""
20 18

  
21 19
from cStringIO import StringIO
22 20
from xml.etree import cElementTree as ET
......
30 28

  
31 29
#: Base NETCONF namespace
32 30
BASE_NS_1_0 = 'urn:ietf:params:xml:ns:netconf:base:1.0'
33
#: namespace for Tail-f data model
31
#: Namespace for Tail-f core data model
34 32
TAILF_AAA_1_1 = 'http://tail-f.com/ns/aaa/1.1'
35
#: namespace for Tail-f data model
33
#: Namespace for Tail-f execd data model
36 34
TAILF_EXECD_1_1 = 'http://tail-f.com/ns/execd/1.1'
37
#: namespace for Cisco data model
35
#: Namespace for Cisco data model
38 36
CISCO_CPI_1_0 = 'http://www.cisco.com/cpi_10/schema'
39
#: namespace for Flowmon data model
37
#: Namespace for Flowmon data model
40 38
FLOWMON_1_0 = 'http://www.liberouter.org/ns/netopeer/flowmon/1.0'
41 39

  
42 40
try:
......
63 61
#unqualify = lambda tag: tag[tag.rfind('}')+1:]
64 62

  
65 63
def to_xml(ele, encoding="UTF-8"):
66
    """Element -> XML
64
    """Convert an :class:`~xml.etree.ElementTree.Element` to XML.
67 65
    
68
    :type spec: :class:`~xml.etree.ElementTree.Element`
66
    :arg ele: the :class:`~xml.etree.ElementTree.Element`
69 67
    :arg encoding: character encoding
70 68
    :rtype: :obj:`string`
71 69
    """
......
73 71
    return xml if xml.startswith('<?xml') else '<?xml version="1.0" encoding="%s"?>%s' % (encoding, xml)
74 72

  
75 73
def to_ele(x):
76
    """XML -> Element
74
    """Convert XML to :class:`~xml.etree.ElementTree.Element`.
77 75
    
78 76
    :type xml: :obj:`string`
79 77
    :rtype: :class:`~xml.etree.ElementTree.Element`
......
86 84
    """Efficiently parses the root element of an XML document.
87 85

  
88 86
    :arg raw: XML document
89
    :type raw: string
90
    :returns: a tuple of `(tag, attributes)`, where `tag` is the (qualified) name of the element and `attributes` is a dictionary of its attributes.
87
    :returns: a tuple of `(tag, attrib)`, where *tag* is the (qualified)
88
    name of the element and *attrib* is a dictionary of its attributes.
91 89
    :rtype: `tuple`
92 90
    """
93 91
    fp = StringIO(raw)
......
95 93
        return (element.tag, element.attrib)
96 94

  
97 95
def validated_element(x, tags=None, attrs=None):
98
    """Checks if the root element meets the supplied criteria. Returns a
99
    :class:`~xml.etree.ElementTree.Element` instance if so, otherwise raises
100
    :exc:`ContentError`.
101

  
96
    """Checks if the root element of an XML document or
97
    :class:`~xml.etree.ElementTree.Element` meets the supplied criteria. Raises
98
    :exc:`XMLError` if it is not met.
99
    
100
    :arg x: the XML document or :class:`~xml.etree.ElementTree.Element` to validate
102 101
    :arg tags: tag name or a sequence of allowable tag names
103 102
    :arg attrs: sequence of required attribute names, each item may be a list of allowable alternatives
104
    :arg text: textual content to match
105
    :type rep: :class:`~xml.etree.ElementTree.Element`
103
    :returns: validated element
104
    :rtype: :class:`~xml.etree.ElementTree.Element`
106 105
    """
107 106
    ele = to_ele(x)
108 107
    if tags:

Also available in: Unified diff