本文整理匯總了Python中xmlbuilder.XMLBuilder類的典型用法代碼示例。如果您正苦於以下問題:Python XMLBuilder類的具體用法?Python XMLBuilder怎麽用?Python XMLBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了XMLBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: makeXML
def makeXML(cls, name, memory, vcpu, *devices):
if cls.domain_type is None:
raise libvirt.libvirtError("%r can't be instanciated - no domain type" \
% cls)
cfg = DomainConfig(name, memory, vcpu, devices)
root = XMLBuilder('domain', type=cls.domain_type)
cls.commonFields(root, cfg)
with root.os:
cls.generateOS(root, cfg)
root.clock(sync='localtime')
cls.powerFeatures(root, cfg)
with root.devices:
cls.emulator(root, cfg)
for dev in devices:
dev.toxml(root)
cls.commonDevices(root, cfg)
return root
示例2: pipeline_to_xml
def pipeline_to_xml(p):
""" Convert a Pipeline to XML
:type p: Pipeline
:param p:
:return:
"""
root = XMLBuilder(Constants.WORKFLOW_TEMPLATE_ROOT, id=p.idx)
with getattr(root, Constants.ENTRY_POINTS):
for eid, bid in p.entry_bindings:
_d = {"id": eid, "in": bid}
getattr(root, Constants.ENTRY_POINT)(**_d)
with getattr(root, Constants.BINDINGS):
for bout, bin_ in p.bindings:
_d = {"out": bout, "in": bin_}
getattr(root, Constants.BINDING)(**_d)
# Engine level Options
# for completeness write this element
getattr(root, "options")
# Task Options
with getattr(root, "task-options"):
for key, value in p.task_options.iteritems():
_d = {"id": key}
with getattr(root, 'option')(**_d):
root.value(str(value))
return root
示例3: _generate_xml
def _generate_xml(self, exception,message = ""):
_,_,trace = sys.exc_info()
xml = XMLBuilder()
tb_dict = {}
tb = traceback.extract_tb(trace)
with xml.notice(version = 2.0):
xml << ('api-key', self.environment.api_key)
with xml.notifier:
xml << ('name', self.environment.name)
xml << ('version', self.environment.version)
xml << ('url', self.environment.url)
with xml('server-environment'):
xml << ('environment-name', self.environment.environment_name)
with xml.error:
xml << ('class', exception.__class__.__name__)
if message == "":
xml << ('message', str(exception))
else:
xml << ('message', str(exception) + '\n\n' + message)
with xml.backtrace:
for trace in tb:
tb_dict['filename'] = trace[0]
tb_dict['line_number'] = trace[1]
tb_dict['function_name'] = trace[2]
xml << ('line', {
'file':tb_dict.get('filename', 'unknown'),
'number':tb_dict.get('line_number', 'unknown'),
'method':tb_dict.get('function_name', 'unknown')
})
return str(xml)
示例4: to_xml
def to_xml(self):
"""Return an XML instance of the suite"""
x = XMLBuilder('testsuite', name=self.name, tests=str(self.ntests), errors=str(self.nerrors), failures=str(self.nfailure), skip=str(self.nskipped))
for test_case in self.tests:
classname = test_case.classname
# sanitize for XML
text = "" if test_case.text is None else test_case.text
etype = "" if test_case.etype is None else test_case.etype
with x.testcase(classname=classname, name=test_case.name,
result=test_case.result, etype=etype,
text=text):
if test_case.result == 'failures':
x.error(type=test_case.etype, message=test_case.message)
elif test_case.result == 'failure':
x.failure(type=test_case.etype, message=test_case.message)
elif test_case.result == 'skipped':
x.skipped(type=test_case.etype, message=test_case.message)
elif test_case.result == 'error':
x.error(type=test_case.etype, message=test_case.message)
else:
# Successful testcase
pass
return x
示例5: checkstyle_xml
def checkstyle_xml(diags_set):
def converted_severity(fauxpas_severity):
# checkstyle severities: ignore, info, warning, error
if (9 <= fauxpas_severity):
return 'error'
elif (5 <= fauxpas_severity):
return 'warning'
return 'info'
x = XMLBuilder('checkstyle')
diags_by_file = diags_set.grouped_diagnostics(by_property='file')
for filepath, diags in diags_by_file.items():
with x.file(name=filepath or diags_set.pbxproj_path):
for diag in diags:
message = diag.info
if 0 < len(message):
message += ' '
message += '(%s - %s)' % (diag.ruleName, diag.ruleDescription)
x.error(severity=converted_severity(diag.severity),
source=diag.ruleShortName,
message=message,
line=str(diag.extent.start.line),
column=str(diag.extent.start.utf16Column)
)
return str(x)
示例6: testWith
def testWith(self):
xml = XMLBuilder()
with xml.root(lenght = 12):
pass
self.assertEqual(str(xml),'<root lenght="12" />')
xml = XMLBuilder()
with xml.root():
xml << "text1" << "text2" << ('some_node',)
self.assertEqual(str(xml),"<root>text1text2<some_node /></root>")
示例7: build_snapshot_xml
def build_snapshot_xml(self, name=None, description=None):
"""
:rtype : String
:type name: String
:type description: String
"""
xml_builder = XMLBuilder('domainsnapshot')
if not (name is None):
xml_builder.name(name)
if not (description is None):
xml_builder.description(description)
return str(xml_builder)
示例8: tree_to_xml
def tree_to_xml(root):
xml = XMLBuilder('map', version='0.9.0')
def rec_tree(tree, xnode):
if tree == {}:
return
xnode['folded'] = 'true'
for key, subtree in tree.iteritems():
rec_tree(subtree, xnode.node(text=key))
xroot = xml.node(text='Categories')
rec_tree(root, xroot)
xroot['folded'] = 'false'
return str(xml)
示例9: testFormat
def testFormat(self):
x = XMLBuilder('utf-8',format = True)
with x.root():
x << ('array',)
with x.array(len = 10):
with x.el(val = 0):
pass
with x.el('xyz',val = 1):
pass
x << ("el","abc",{'val':2}) << ('el',dict(val=3))
x << ('el',dict(val=4)) << ('el',dict(val='5'))
with x('sup-el',val = 23):
x << "test "
self.assertEqual(str(x),result1)
示例10: schema_options_to_xml
def schema_options_to_xml(option_type_name, schema_options_d):
"""Option type name is the task-option or option"""
x = XMLBuilder(Constants.WORKFLOW_TEMPLATE_PRESET_ROOT)
# Need to do this getattr to get around how the API works
with getattr(x, option_type_name):
for option_id, schema in schema_options_d.iteritems():
default_value = schema["properties"][option_id]["default"]
if default_value is not None:
with x.option(id=option_id):
default_value = schema["properties"][option_id]["default"]
x.value(str(default_value))
return x
示例11: toxml
def toxml(self, hrn = None):
xml = XMLBuilder(format = True, tab_step = " ")
with xml.RSpec(type="VINI"):
if hrn:
element = xml.network(name="Public_VINI", slice=hrn)
else:
element = xml.network(name="Public_VINI")
with element:
for site in self.getSites():
site.toxml(xml, hrn, self.nodes)
for link in self.sitelinks:
link.toxml(xml)
header = '<?xml version="1.0"?>\n'
return header + str(xml)
示例12: toxml
def toxml(self):
xml = XMLBuilder(format = True, tab_step = " ")
with xml.RSpec(type=self.type):
if self.slice:
element = xml.network(name=self.api.hrn, slice=self.slice.hrn)
else:
element = xml.network(name=self.api.hrn)
with element:
if self.slice:
self.slice.toxml(xml)
for site in self.getSites():
site.toxml(xml)
for link in self.sitelinks:
link.toxml(xml)
header = '<?xml version="1.0"?>\n'
return header + str(xml)
示例13: toxml
def toxml(self):
"""
Produce XML directly from the topology specification.
"""
xml = XMLBuilder(format = True, tab_step = " ")
with xml.RSpec(type=self.type):
if self.slice:
element = xml.network(name=self.api.hrn, slice=self.slice.hrn)
else:
element = xml.network(name=self.api.hrn)
with element:
if self.slice:
self.slice.toxml(xml)
for site in self.getSites():
site.toxml(xml)
header = '<?xml version="1.0"?>\n'
return header + str(xml)
示例14: export_to_xml
def export_to_xml(people, questions_to_export, user_id, can_view_email):
response = HttpResponse(content_type = "application/xml")
response['Content-Disposition'] = 'attachment; filename="sc4g-people.xml"'
xml = XMLBuilder('volunteers')
for person in people:
with xml.volunteer:
xml.firstName(person.user.first_name)
xml.lastName(person.user.last_name)
if (can_view_email):
xml.email(person.user.email)
with xml.form_responses:
for key, value in get_card_fields_with_icons_together(person, user_id).items():
xml.form_response(value, question=key)
response.content = str(xml)
return response
示例15: create_snapshot
def create_snapshot(self, domain, snapshot_name, \
snapshot_description):
"""Create VM snapshot
connection: object with a connection to the Hypervisor
domain: VM name
snapshot_name
snapshot_description
"""
try:
libvirt_domain = self.libvirt_connection.lookupByName(domain)
xml_base = XMLBuilder('domainsnapshot')
xml_base.name(snapshot_name)
xml_base.description(snapshot_description)
xml = str(xml_base)
libvirt_domain.snapshotCreateXML(xml)
except:
print 'Unable to create snapshot'
sys.exit(1)
print 'Snapshot has been created successfully.'