Exemplo n.º 1
0
 def test_load_xml(self):
     """check code used for merge nodes"""
     original = "<a>a</a>"
     fake_file = mock.mock_open(read_data="<a>a</a>")
     with mock.patch('__builtin__.open', fake_file):
         xml = utils.load_xml("a.a")
         self.assertEqual(etree.tostring(xml), original)
 def test_load_xml(self):
     """check code used for merge nodes"""
     original = "<a>a</a>"
     fake_file = mock.mock_open(read_data="<a>a</a>")
     with mock.patch(
         '__builtin__.open', fake_file
     ):
         xml = utils.load_xml("a.a")
         self.assertEqual(etree.tostring(xml), original)
Exemplo n.º 3
0
        <turing:transition-function/>
      </turing:turing-machine>
    </filter>
    <source>
      <running/>
    </source>
  </get>
</rpc>
-------------------
"""
if __name__ == "__main__":
    if len(sys.argv) < 2 and len(sys.argv) > 4:
        print(help_message)
    else:
        xmlns = utils.default_xmlns()
        xml_node = utils.load_xml(sys.argv[1])
        rng = None
        if len(sys.argv) > 2:
            rng = utils.load_xml(sys.argv[2])
        if rng is not None:
            relaxng = etree.RelaxNG(rng)
            if not relaxng.validate(xml_node):
                print("You have issues with relaxng")
        sch = None
        if len(sys.argv) > 3:
            sch = utils.load_xml(sys.argv[3])
        if sch is not None:
            schematron = isoschematron.Schematron(sch)
            if not schematron.validate(xml_node):
                print("You have issues with Schematron")
        xml_dict = {}
        <turing:transition-function/>
      </turing:turing-machine>
    </filter>
    <source>
      <running/>
    </source>
  </get>
</rpc>
-------------------
"""
if __name__ == "__main__":
    if len(sys.argv) < 2 and len(sys.argv) > 4:
        print(help_message)
    else:
        xmlns = utils.default_xmlns()
        xml_node = utils.load_xml(sys.argv[1])
        rng = None
        if len(sys.argv) > 2:
            rng = utils.load_xml(sys.argv[2])
        if rng is not None:
            relaxng = etree.RelaxNG(rng)
            if not relaxng.validate(xml_node):
                print ("You have issues with relaxng")
        sch = None
        if len(sys.argv) > 3:
            sch = utils.load_xml(sys.argv[3])
        if sch is not None:
            schematron = isoschematron.Schematron(sch)
            if not schematron.validate(xml_node):
                print ("You have issues with Schematron")
        xml_dict = {}
  <get>
    <filter type="subtree">
      <turing:turing-machine>
        <turing:transition-function/>
      </turing:turing-machine>
    </filter>
    <source>
      <running/>
    </source>
  </get>
</rpc>
-------------------
"""
if __name__ == "__main__":
    if len(sys.argv) != 2:
        print(help_message)
    else:
        xmlns = utils.default_xmlns()
        xml_node = utils.load_xml(sys.argv[1])
        rng = None
        xml_dict = {}
        utils.generate_dict_node(
            xml_dict, xml_node,
            xmlns
        )
        result = {
            'payload': xml_dict,
            'ns': xmlns
        }
        print(yaml.dump(result))
usage: python netconfxml2yaml.py rpc.xml

In rpc.xml:
-------------------
<?xml version='1.0' encoding='UTF-8'?>
<rpc xmlns:turing="http://example.net/turing-machine"
    xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="some_id">
  <get>
    <filter type="subtree">
      <turing:turing-machine>
        <turing:transition-function/>
      </turing:turing-machine>
    </filter>
    <source>
      <running/>
    </source>
  </get>
</rpc>
-------------------
"""
if __name__ == "__main__":
    if len(sys.argv) != 2:
        print(help_message)
    else:
        xmlns = utils.default_xmlns()
        xml_node = utils.load_xml(sys.argv[1])
        rng = None
        xml_dict = utils.generate_dict_node(xml_node, xmlns)
        result = {'payload': xml_dict, 'ns': xmlns}
        print(yaml.dump(result))