本文整理汇总了Python中comoonics.XmlTools.toPrettyXML方法的典型用法代码示例。如果您正苦于以下问题:Python XmlTools.toPrettyXML方法的具体用法?Python XmlTools.toPrettyXML怎么用?Python XmlTools.toPrettyXML使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类comoonics.XmlTools
的用法示例。
在下文中一共展示了XmlTools.toPrettyXML方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __test_overwrite_element_with_xpaths
# 需要导入模块: from comoonics import XmlTools [as 别名]
# 或者: from comoonics.XmlTools import toPrettyXML [as 别名]
def __test_overwrite_element_with_xpaths(self):
for doc in self.docs:
if len(doc) > 1:
(doc, xpathtest)=doc
(xpath, expectedresult, newvalue) = xpathtest
xml2=XmlTools.overwrite_element_with_xpaths(doc.documentElement, { xpath: newvalue })
buf=XmlTools.toPrettyXML(doc)
self.assertEquals(buf.replace("\n", "").replace(" ", ""), XmlTools.toPrettyXML(doc).replace("\n", "").replace(" ", ""))
示例2: test_overwrite_attributes_with_xpaths
# 需要导入模块: from comoonics import XmlTools [as 别名]
# 或者: from comoonics.XmlTools import toPrettyXML [as 别名]
def test_overwrite_attributes_with_xpaths(self):
for doc in self.docs:
if len(doc) > 1:
(doc, xpathtest)=doc
(xpath, expectedresult, newvalue) = xpathtest
xml2=XmlTools.overwrite_attributes_with_xpaths(doc.documentElement, { xpath: newvalue })
buf=XmlTools.toPrettyXML(xml2)
self.assertEquals(buf.replace("\n", "").replace(" ", "").replace('<?xmlversion="1.0"?>', ""),
XmlTools.toPrettyXML(doc).replace("\n", "").replace(" ", "").replace('<?xmlversion="1.0"?>', "").replace("lilr629", "myname").replace("/dev/sda1", "mydisk"))
示例3: testClusterRepositoryEXT3
# 需要导入模块: from comoonics import XmlTools [as 别名]
# 或者: from comoonics.XmlTools import toPrettyXML [as 别名]
def testClusterRepositoryEXT3(self):
from comoonics import XmlTools
result="""<cluster config_version="1" name="testcluster">
<clusternodes>
<clusternode name="name0" nodeid="1" votes="1">
<com_info>
<eth master="bond0" name="eth0" slave="yes"/>
<eth master="bond0" name="eth1" slave="yes"/>
<eth bondingopts="miimon=100,mode=passive" name="bond0"/>
<eth gateway="10.0.0.2" ip="10.0.0.1" name="bond0.100" netmask="255.255.255.0"/>
<rootvolume fstype="ext3" name="/dev/vg_testcluster_sr/lv_sharedroot"/>
</com_info>
<fence>
<method name="1"/>
</fence>
</clusternode>
</clusternodes>
<fencedevices/>
<cman expected_votes="1" two_node="0"/>
<rm>
<resources/>
<failoverdomains/>
</rm>
</cluster>
"""
self.numnodes=1
osrcluster=OSRCluster(self.clustername, self.numnodes)
for i in range(self.numnodes):
_node=OSRClusterNode(osrcluster, "name%u" %i, self.rootvolume)
_node.rootvol=self.rootvolume
_node.rootfstype="ext3"
_netdev=OSRClusterNodeNetdev(_node, "eth0")
_netdev.master="bond0"
_netdev.slave="yes"
_node.addNetdev(_netdev)
_netdev=OSRClusterNodeNetdev(_node, "eth1")
_netdev.master="bond0"
_netdev.slave="yes"
_node.addNetdev(_netdev)
_netdev=OSRClusterNodeNetdev(_node, "bond0")
_netdev.bondingopts="miimon=100,mode=passive"
_node.addNetdev(_netdev)
_netdev=OSRClusterNodeNetdev(_node, "bond0.100")
_netdev.ip="10.0.0.1"
_netdev.netmask="255.255.255.0"
_netdev.gateway="10.0.0.2"
_node.addNetdev(_netdev)
osrcluster.addNode(_node)
log.debug("Cluster: %s" %osrcluster)
log.debug("Cluster as hash: %s" %osrcluster.toHash())
from comoonics.cluster import getClusterRepository
hash=osrcluster.toHash()
tmp=getClusterRepository(None,None,hash,self.defaults)
print XmlTools.toPrettyXML(tmp.getElement())
tmp=XmlTools.toPrettyXML(tmp.getElement())
self.assertEquals(result.replace(" ", "").replace("\n", ""), tmp.replace("\t", "").replace(" ", "").replace("\n", ""))
示例4: test_removePrettyTextNodes
# 需要导入模块: from comoonics import XmlTools [as 别名]
# 或者: from comoonics.XmlTools import toPrettyXML [as 别名]
def test_removePrettyTextNodes(self):
docstring="""<?xml version="1.0" ?>
<x>
<y>
abcdef
</y>
</x>
"""
doc=XmlTools.parseXMLString(docstring)
XmlTools.removePrettyTextNodes(doc)
result=XmlTools.toPrettyXML(doc, " ", "\n")
self.assertEquals(docstring.replace("\n", "").replace(" ", ""), result.replace("\n", "").replace(" ", ""))
示例5: test_overwrite_attributes_with_xpaths2
# 需要导入模块: from comoonics import XmlTools [as 别名]
# 或者: from comoonics.XmlTools import toPrettyXML [as 别名]
def test_overwrite_attributes_with_xpaths2(self):
doc="""<a>
<b name="hallo"/>
<b name="hallo2"/>
<c name="hallo3"/>
<c name2="hallo4"/>
<c name="hallo5"/>
</a>
"""
edoc="""<a>
<b name="marc"/>
<b name="marc"/>
<c name="marc"/>
<c name2="hallo4"/>
<c name="marc"/>
</a>
"""
rdoc=XmlTools.overwrite_attributes_with_xpaths(XmlTools.parseXMLString(doc), {"//b/@name": "marc", "/a/c/@name": "marc"})
self.failUnlessEqual(XmlTools.toPrettyXML(rdoc).replace("\n", "").replace(" ", "").replace("\t", "").replace('<?xmlversion="1.0"?>', ""), edoc.replace("\n", "").replace(" ", "").replace("\t", ""))
示例6: testClusterRepositoryGFS
# 需要导入模块: from comoonics import XmlTools [as 别名]
# 或者: from comoonics.XmlTools import toPrettyXML [as 别名]
def testClusterRepositoryGFS(self):
from comoonics import XmlTools
self.numnodes=5
result="""<cluster config_version="1" name="testcluster">
<clusternodes>
<clusternode name="name0" nodeid="1" votes="1">
<com_info>
<eth ip="dhcp" mac="00:00:00:xx:00" name="eth0"/>
<rootvolume fstype="gfs" name="/dev/vg_testcluster_sr/lv_sharedroot"/>
<filesystems>
<filesystem dest="/var/run" fstype="bind" mountopts="defaults" source="/.cluster/cdsl/%(param0)s/var/run"/>
</filesystems>
</com_info>
<fence>
<method name="1"/>
</fence>
</clusternode>
<clusternode name="name1" nodeid="2" votes="1">
<com_info>
<eth ip="dhcp" mac="00:00:00:xx:01" name="eth0"/>
<rootvolume fstype="gfs" name="/dev/vg_testcluster_sr/lv_sharedroot"/>
<filesystems>
<filesystem dest="/var/run" fstype="bind" mountopts="defaults" source="/.cluster/cdsl/%(param0)s/var/run"/>
</filesystems>
</com_info>
<fence>
<method name="1"/>
</fence>
</clusternode>
<clusternode name="name2" nodeid="3" votes="1">
<com_info>
<eth ip="dhcp" mac="00:00:00:xx:02" name="eth0"/>
<rootvolume fstype="gfs" name="/dev/vg_testcluster_sr/lv_sharedroot"/>
<filesystems>
<filesystem dest="/var/run" fstype="bind" mountopts="defaults" source="/.cluster/cdsl/%(param0)s/var/run"/>
</filesystems>
</com_info>
<fence>
<method name="1"/>
</fence>
</clusternode>
<clusternode name="name3" nodeid="4" votes="1">
<com_info>
<eth ip="dhcp" mac="00:00:00:xx:03" name="eth0"/>
<rootvolume fstype="gfs" name="/dev/vg_testcluster_sr/lv_sharedroot"/>
<filesystems>
<filesystem dest="/var/run" fstype="bind" mountopts="defaults" source="/.cluster/cdsl/%(param0)s/var/run"/>
</filesystems>
</com_info>
<fence>
<method name="1"/>
</fence>
</clusternode>
<clusternode name="name4" nodeid="5" votes="1">
<com_info>
<eth ip="dhcp" mac="00:00:00:xx:04" name="eth0"/>
<rootvolume fstype="gfs" name="/dev/vg_testcluster_sr/lv_sharedroot"/>
<filesystems>
<filesystem dest="/var/run" fstype="bind" mountopts="defaults" source="/.cluster/cdsl/%(param0)s/var/run"/>
</filesystems>
</com_info>
<fence>
<method name="1"/>
</fence>
</clusternode>
</clusternodes>
<fencedevices/>
<cman expected_votes="1" two_node="0"/>
<rm>
<resources/>
<failoverdomains/>
</rm>
</cluster>
"""
log.debug("Setting up cluster %s" %self.clustername)
osrcluster=OSRCluster(self.clustername, self.numnodes)
for i in range(self.numnodes):
_node=OSRClusterNode(osrcluster, "name%u" %i, self.rootvolume)
_node.rootvol=self.rootvolume
_node.rootfstype="gfs"
_node.addNetdev(OSRClusterNodeNetdev(_node, self.netdev))
_node.getNetdev(self.netdev).mac="00:00:00:xx:0%u" %i
_node.getNetdev(self.netdev).ip="dhcp"
_node.addFilesystem(OSRClusterNodeFilesystem(_node, "bind", "/.cluster/cdsl/%(param0)s/var/run", "/var/run"))
osrcluster.addNode(_node)
log.debug("Cluster: %s" %osrcluster)
log.debug("Cluster as hash: %s" %osrcluster.toHash())
from comoonics.cluster import getClusterRepository
tmp=getClusterRepository(None,None,osrcluster.toHash(),self.defaults)
print XmlTools.toPrettyXML(tmp.getElement())
tmp=XmlTools.toPrettyXML(tmp.getElement())
self.assertEquals(result.replace(" ", "").replace("\n", ""), tmp.replace("\t", "").replace(" ", "").replace("\n", ""))
示例7: test_toPrettyXml
# 需要导入模块: from comoonics import XmlTools [as 别名]
# 或者: from comoonics.XmlTools import toPrettyXML [as 别名]
def test_toPrettyXml(self):
docstring="""<?xml version="1.0" ?>
\t<x>
\t <y>
\t abc
\t </y>
\t</x>
"""
doc=XmlTools.parseXMLString(docstring)
self.assertEquals(docstring.replace("\n", "").replace("\t", "").replace(" ", ""), XmlTools.toPrettyXML(doc).replace("\n", "").replace("\t", "").replace(" ", ""))
示例8: testCloneNode
# 需要导入模块: from comoonics import XmlTools [as 别名]
# 或者: from comoonics.XmlTools import toPrettyXML [as 别名]
def testCloneNode(self):
for doc in self.docs:
doc=doc[0]
buf1=XmlTools.toPrettyXML(doc.documentElement)
buf2=XmlTools.toPrettyXML(XmlTools.clone_node(doc.documentElement))
self.assertEquals(buf1, buf2)