本文整理汇总了Python中xml.dom.minidom.Document.toxml方法的典型用法代码示例。如果您正苦于以下问题:Python Document.toxml方法的具体用法?Python Document.toxml怎么用?Python Document.toxml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml.dom.minidom.Document
的用法示例。
在下文中一共展示了Document.toxml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: notifyHealers
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toxml [as 别名]
def notifyHealers(txn, errorDetails, pid, tid, extraData):
m = Document()
notification = m.appendChild(m.createElement('message'))
notification.setAttribute('kind', 'fault notification')
faultNode = m.createElement('faulty')
for k,v in tid:
faultNode.setAttribute(str(k), str(v))
error = m.createElement('errors')
for k,v in errorDetails:
error.setAttribute(str(k), str(v))
notification.appendChild(faultNode)
notification.appendChild(error)
'''We are sending the notification... But to whom??'''
healers = txn.runQuery('SELECT * FROM healing_group')
monitors = txn.runQuery('SELECT * FROM monitoring_group')
writer = BundleWriter('dtnhealing:')
for p in healers:
writer.write(m.toxml())
for p in monitors:
writer.write(m.toxml())
monitoringPlans[pid][tid].stop()
示例2: _build_request_xml
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toxml [as 别名]
def _build_request_xml(self, method_name, **kwargs):
"""
Builds the XML for a 'initial' transaction
"""
doc = Document()
req = self._create_element(doc, doc, "Request")
# Authentication
auth = self._create_element(doc, req, "Authentication")
self._create_element(doc, auth, "client", self._client)
self._create_element(doc, auth, "password", self._password)
# Transaction
txn = self._create_element(doc, req, "Transaction")
# CardTxn
if "card_number" in kwargs:
card_txn = self._create_element(doc, txn, "CardTxn")
self._create_element(doc, card_txn, "method", method_name)
card = self._create_element(doc, card_txn, "Card")
self._create_element(doc, card, "pan", kwargs["card_number"])
self._create_element(doc, card, "expirydate", kwargs["expiry_date"])
if "start_date" in kwargs:
self._create_element(doc, card, "startdate", kwargs["start_date"])
if "issue_number" in kwargs:
self._create_element(doc, card, "issuenumber", kwargs["issue_number"])
if "auth_code" in kwargs:
self._create_element(doc, card, "authcode", kwargs["auth_code"])
if self._cv2avs:
self._add_cv2avs_elements(doc, card, kwargs)
# HistoricTxn
if "txn_reference" in kwargs:
historic_txn = self._create_element(doc, txn, "HistoricTxn")
self._create_element(doc, historic_txn, "reference", kwargs["txn_reference"])
self._create_element(doc, historic_txn, "method", method_name)
if "auth_code" in kwargs:
self._create_element(doc, historic_txn, "authcode", kwargs["auth_code"])
# TxnDetails
if "amount" in kwargs:
txn_details = self._create_element(doc, txn, "TxnDetails")
if "merchant_reference" in kwargs:
self._create_element(doc, txn_details, "merchantreference", kwargs["merchant_reference"])
self._create_element(doc, txn_details, "amount", str(kwargs["amount"]), {"currency": kwargs["currency"]})
# Save XML for later retrieval
self._last_request_xml = doc.toxml()
return self.do_request(doc.toxml())
示例3: _build_request_xml
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toxml [as 别名]
def _build_request_xml(self, method_name, **kwargs):
"""
Builds the XML for a 'initial' transaction
"""
doc = Document()
req = self._create_element(doc, doc, 'Request')
# Authentication
auth = self._create_element(doc, req, 'Authentication')
self._create_element(doc, auth, 'client', self._client)
self._create_element(doc, auth, 'password', self._password)
# Transaction
txn = self._create_element(doc, req, 'Transaction')
# CardTxn
if 'card_number' in kwargs:
card_txn = self._create_element(doc, txn, 'CardTxn')
self._create_element(doc, card_txn, 'method', method_name)
card = self._create_element(doc, card_txn, 'Card')
self._create_element(doc, card, 'pan', kwargs['card_number'])
self._create_element(doc, card, 'expirydate', kwargs['expiry_date'])
if 'start_date' in kwargs:
self._create_element(doc, card, 'startdate', kwargs['start_date'])
if 'issue_number' in kwargs:
self._create_element(doc, card, 'issuenumber', kwargs['issue_number'])
if 'auth_code' in kwargs:
self._create_element(doc, card, 'authcode', kwargs['auth_code'])
if self._cv2avs:
self._add_cv2avs_elements(doc, card, kwargs)
# HistoricTxn
if 'txn_reference' in kwargs:
historic_txn = self._create_element(doc, txn, 'HistoricTxn')
self._create_element(doc, historic_txn, 'reference', kwargs['txn_reference'])
self._create_element(doc, historic_txn, 'method', method_name)
if 'auth_code' in kwargs:
self._create_element(doc, historic_txn, 'authcode', kwargs['auth_code'])
# TxnDetails
if 'amount' in kwargs:
txn_details = self._create_element(doc, txn, 'TxnDetails')
if 'merchant_reference' in kwargs:
self._create_element(doc, txn_details, 'merchantreference', kwargs['merchant_reference'])
self._create_element(doc, txn_details, 'amount', str(kwargs['amount']), {'currency': kwargs['currency']})
# Save XML for later retrieval
self._last_request_xml = doc.toxml()
return self.do_request(doc.toxml())
示例4: distributePlan
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toxml [as 别名]
def distributePlan(txn, targets, plan):
m = Document()
message = m.appendChild(m.createElement('message'))
message.setAttribute('kind', 'distribution')
targetNodes = message.appendChild(m.createElement('targets'))
planNode = message.appendChild(m.createElement('plan'))
for t in targets:
newTarget = m.createElement('target')
for k,v in t.itervalues():
newTarget.setAttribute(k,v)
targetNodes.appendChild(newTarget)
for k,v in plan.itervalues():
if k is 'plan':
continue
planNode.setAttribute(k,v)
planNode.appendChild(m.createTextNode(plan['plan']))
peers = txn.execute(
'SELECT peer FROM healing_group ORDER BY peer'
).fetchall()
writer = BundleWriter('dtnhealing:')
for p in peers:
writer.write(p['peer'], m.toxml())
return targets, plan
示例5: testTaxes7
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toxml [as 别名]
def testTaxes7(self):
doc = Document()
parent_node = doc.createElement('parent_node')
doc.appendChild(parent_node)
data = {
'default-tax-table': {
'tax-rules': [
{
'shipping-taxed': True,
'rate': 0.175,
'tax-area': {
'postal-area': [
{'country-code': 'DE'},
{'country-code': 'ES'},
{'country-code': 'GB'},
],
},
},
]
},
}
self.gc._taxes(doc, parent_node, data)
xml1 = "<parent_node><tax-tables>\
<default-tax-table><tax-rules><default-tax-rule>\
<shipping-taxed>true</shipping-taxed><rate>0.175</rate>\
<tax-areas><postal-area><country-code>DE</country-code>\
</postal-area><postal-area><country-code>ES</country-code>\
</postal-area><postal-area><country-code>GB</country-code>\
</postal-area></tax-areas></default-tax-rule></tax-rules>\
</default-tax-table></tax-tables></parent_node>"
doc_good = parseString(xml1)
self.assertEquals(doc.toxml(), doc_good.toxml())
示例6: testTaxes2
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toxml [as 别名]
def testTaxes2(self):
doc = Document()
parent_node = doc.createElement('parent_node')
doc.appendChild(parent_node)
data = {
'default-tax-table': {
'tax-rules': [
{
'shipping-taxed': True,
'rate': 0.06,
'tax-area': {
'us-state-area': ['CT'],
}
},
{
'rate': 0.05,
'tax-area': {
'us-state-area': ['MD'],
}
}
]
}
}
self.gc._taxes(doc, parent_node, data)
xml1 = "<parent_node><tax-tables><default-tax-table><tax-rules>\
<default-tax-rule><shipping-taxed>true</shipping-taxed><rate>0.06</rate>\
<tax-area><us-state-area><state>CT</state></us-state-area></tax-area>\
</default-tax-rule><default-tax-rule><shipping-taxed>false</shipping-taxed>\
<rate>0.05</rate><tax-area><us-state-area><state>MD</state></us-state-area>\
</tax-area></default-tax-rule></tax-rules></default-tax-table></tax-tables>\
</parent_node>"
doc_good = parseString(xml1)
self.assertEquals(doc.toxml(), doc_good.toxml())
示例7: createGeneralUnknownResponse
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toxml [as 别名]
def createGeneralUnknownResponse(self, message):
doc = Document()
root_response = doc.createElement('Response')
root_response.setAttribute("creationSuccessful", str(False))
root_response.setAttribute("reason", message)
doc.appendChild(root_response)
return doc.toxml(encoding='utf-8')
示例8: list_bucket
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toxml [as 别名]
def list_bucket(self):
dirL = self.user.list_bucket(self.bucketName, self.request.args)
doc = Document()
# Create the <wml> base element
xList = doc.createElement("ListBucketResult")
xList.setAttribute("xmlns", "http://doc.s3.amazonaws.com/2006-03-01")
doc.appendChild(xList)
# Create the main <card> element
xName = doc.createElement("Name")
xList.appendChild(xName)
xNameText = doc.createTextNode(str(self.bucketName))
xName.appendChild(xNameText)
xIsTruncated = doc.createElement("IsTruncated")
xList.appendChild(xIsTruncated)
xIsTText = doc.createTextNode('false')
xIsTruncated.appendChild(xIsTText)
for obj in dirL:
xObj = obj.create_xml_element(doc)
xList.appendChild(xObj)
x = doc.toxml();
self.send_xml(x)
self.finish(self.request)
示例9: encode
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toxml [as 别名]
def encode(self):
# Create the XML document
doc = Document()
signed_cred = doc.createElement("signed-credential")
# Declare namespaces
# Note that credential/policy.xsd are really the PG schemas
# in a PL namespace.
# Note that delegation of credentials between the 2 only really works
# cause those schemas are identical.
# Also note these PG schemas talk about PG tickets and CM policies.
signed_cred.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
signed_cred.setAttribute("xsi:noNamespaceSchemaLocation", "http://www.geni.net/resources/credential/2/credential.xsd")
signed_cred.setAttribute("xsi:schemaLocation", "http://www.planet-lab.org/resources/sfa/ext/policy/1 http://www.planet-lab.org/resources/sfa/ext/policy/1/policy.xsd")
# PG says for those last 2:
# signed_cred.setAttribute("xsi:noNamespaceSchemaLocation", "http://www.protogeni.net/resources/credential/credential.xsd")
# signed_cred.setAttribute("xsi:schemaLocation", "http://www.protogeni.net/resources/credential/ext/policy/1 http://www.protogeni.net/resources/credential/ext/policy/1/policy.xsd")
doc.appendChild(signed_cred)
# Fill in the <credential> bit
cred = doc.createElement("credential")
cred.setAttribute("xml:id", self.get_refid())
signed_cred.appendChild(cred)
append_sub(doc, cred, "type", "abac")
# Stub fields
append_sub(doc, cred, "serial", "8")
append_sub(doc, cred, "owner_gid", '')
append_sub(doc, cred, "owner_urn", '')
append_sub(doc, cred, "target_gid", '')
append_sub(doc, cred, "target_urn", '')
append_sub(doc, cred, "uuid", "")
if not self.expiration:
self.set_expiration(datetime.datetime.utcnow() + datetime.timedelta(seconds=DEFAULT_CREDENTIAL_LIFETIME))
self.expiration = self.expiration.replace(microsecond=0)
if self.expiration.tzinfo is not None and self.expiration.tzinfo.utcoffset(self.expiration) is not None:
# TZ aware. Make sure it is UTC
self.expiration = self.expiration.astimezone(tz.tzutc())
append_sub(doc, cred, "expires", self.expiration.strftime('%Y-%m-%dT%H:%M:%SZ')) # RFC3339
abac = doc.createElement("abac")
rt0 = doc.createElement("rt0")
abac.appendChild(rt0)
cred.appendChild(abac)
append_sub(doc, rt0, "version", "1.1")
head = self.createABACElement(doc, "head", self.get_head())
rt0.appendChild(head)
for tail in self.get_tails():
tailEle = self.createABACElement(doc, "tail", tail)
rt0.appendChild(tailEle)
# Create the <signatures> tag
signatures = doc.createElement("signatures")
signed_cred.appendChild(signatures)
# Get the finished product
self.xml = doc.toxml("utf-8")
示例10: xmlify
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toxml [as 别名]
def xmlify(self, aHost, encryptedMessage):
### xmlifies the current message, building an onion as it goes.
# open a file, write to it the xml-ified version of the query
# structure:
# <transmission>
# <next-hop> a hop </next-hop>
# <encrypted block>
# (encrypted block contains one of these same blocks)
# </encrypted block>
# </transmission>
# using xml.dom.minidom will autosanitize input!
PDSMessage = Document()
transmission = doc.createElement(TRANSMISSION)
PDSMessage.appendChild(transmission)
next_hop = doc.createElement(NEXT_HOP)
transmission.appendChild(next_hop)
nextHopText = doc.createTextElement(aHost)
next_hop.appendChild(nextHopText)
encrypted_block = doc.createElement(ENCRYPTED_BLOCK)
transmission.appendChild(encrypted_block)
encryptedText = doc.createTextElement(encryptedMessage)
encrypted_block.appendChild(encryptedText)
## TODO: this little bit is maybe not quite right -- I don't know if this syntax is correct.
return PDSMessage.toxml()
示例11: export_tar
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toxml [as 别名]
def export_tar(request):
data = _get_data(request)
arch_file = StringIO()
arch = tarfile.TarFile(fileobj=arch_file, mode="w")
for note in data:
doc = Document()
root = _note_to_xml(doc, note)
doc.appendChild(root)
note_data = doc.toxml(encoding='utf-8')
note_file = StringIO()
note_file.write(note_data)
note_file.seek(0)
note_info = tarfile.TarInfo("%s.note" % note["guid"])
note_info.size = len(note_data)
note_info.mtime = time.mktime(parse_iso_time(note["last-change-date"]).timetuple())
arch.addfile(
tarinfo=note_info,
fileobj=note_file
)
arch.close()
response = HttpResponse(arch_file.getvalue())
response["Content-Type"] = "application/x-tar"
response["Content-Disposition"] = "attachment; filename=snowy-%s-%s.tar" % (request.user, time.strftime("%Y-%m-%d"))
return response
示例12: object_to_xml
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toxml [as 别名]
def object_to_xml(obj_file, xml_file):
"""Gnerate an XML file."""
dic_obj = open(obj_file, "r")
if options.verbose:
print("Loading dictionary...")
dic_ip = pickle.load(dic_obj)
if options.verbose:
print("Creating XML file...")
doc = Document()
racine = doc.createElement("IP-Link")
doc.appendChild(racine)
for ip_src in dic_ip:
ipsrc = doc.createElement("ip_packet")
ipsrc.setAttribute("source_ip", ip_src)
racine.appendChild(ipsrc)
for ip_dst in dic_ip[ip_src]:
ipdst = doc.createElement("ip_packet")
ipdst.setAttribute("destination_ip", ip_dst)
ipdst.setAttribute("weight", str(dic_ip[ip_src][ip_dst]))
ipsrc.appendChild(ipdst)
# Elegant display of the XML object
#print doc.toprettyxml()
try:
file = open(xml_file, 'w')
file.write('%s' % doc.toxml().encode('utf-8'))
except IOError as e:
print("Writting error :", e)
finally:
file.close()
示例13: constructLogXml
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toxml [as 别名]
def constructLogXml(event, comment):
eventString = str(event)
commentString = str(comment)
doc = Document()
#Create root
root = doc.createElement('log_entry')
doc.appendChild(root)
#Add event
event = doc.createElement('event')
root.appendChild(event)
eventText = doc.createTextNode(eventString)
event.appendChild(eventText)
#Add timestamp
time = doc.createElement('time')
root.appendChild(time)
timeText = doc.createTextNode(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
time.appendChild(timeText)
#Add cell ID
cell = doc.createElement('cell_id')
root.appendChild(cell)
cellText = doc.createTextNode('4')
cell.appendChild(cellText)
#add comment
comment = doc.createElement('comment')
root.appendChild(comment)
commentText = doc.createTextNode(commentString)
comment.appendChild(commentText)
return doc.toxml(encoding="utf-8")
示例14: to_xml
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toxml [as 别名]
def to_xml(self):
doc = Document()
root = doc.createElement('patterns')
doc.appendChild(root)
for test in self.tests:
test_node = doc.createElement('test')
test_node.setAttribute('name', test.name)
options_node = doc.createElement('options')
for option in test.options:
option_node = doc.createElement('option')
option_node.setAttribute('name', option.name)
options_node.appendChild(option_node)
test_node.appendChild(options_node)
for pattern in test.patterns:
pattern_node = doc.createElement('pattern')
pattern_node.setAttribute('result', pattern.result)
pattern_node.setAttribute('probability', str(pattern.probability))
for k,v in pattern.options.iteritems():
option_node = doc.createElement('option')
option_node.setAttribute('name', k)
option_node.appendChild(doc.createTextNode(v))
pattern_node.appendChild(option_node)
test_node.appendChild(pattern_node)
root.appendChild(test_node)
return doc.toxml()
示例15: saveImageInfoByTitleId
# 需要导入模块: from xml.dom.minidom import Document [as 别名]
# 或者: from xml.dom.minidom.Document import toxml [as 别名]
def saveImageInfoByTitleId(site,request):
titleid=request.POST.get('titleid','')
if titleid:
titlequery=Title.objects.filter(site=site.get('id')).filter(pk=titleid)[:1]
title=None
if 1==len(titlequery):
title=titlequery[0]
if title and title.type in SWFUPLOAD_TITLE_TYPE:
from xml.dom.minidom import Document
xml=Document()
datas=xml.createElement('datas')
datas.setAttribute('userid',str(request.user.pk))
xml.appendChild(datas)
for i in range(0,int(request.POST.get('num'))):
id=request.POST.get('id'+str(i))
if id:
paperImage=PaperImage.objects.get(pk=id)
else:
paperImage=PaperImage()
paperImage.img=''
paperImage.imgmid=''
paperImage.imgsmall=''
paperImage.title=title
paperImage.content=request.POST.get('text'+str(i))
paperImage.index=int(request.POST.get('index'+str(i)))
paperImage.save()
data=xml.createElement('data')
data.setAttribute('imgid',str(paperImage.id))
data.setAttribute('imgindex',str(paperImage.index))
datas.appendChild(data)
return HttpResponse(xml.toxml('utf-8'))
return HttpResponse()