本文整理汇总了Python中xmltodict.unparse方法的典型用法代码示例。如果您正苦于以下问题:Python xmltodict.unparse方法的具体用法?Python xmltodict.unparse怎么用?Python xmltodict.unparse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xmltodict
的用法示例。
在下文中一共展示了xmltodict.unparse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_cert_request
# 需要导入模块: import xmltodict [as 别名]
# 或者: from xmltodict import unparse [as 别名]
def send_cert_request(url, param):
# dict 2 xml
param = {'root': param}
xml = xmltodict.unparse(param)
'''
登录微信商户平台(pay.weixin.qq.com)-->账户设置-->API安全-->证书下载
下载apiclient_cert.p12
python无法使用双向证书,使用openssl导出:
openssl pkcs12 -clcerts -nokeys -in apiclient_cert.p12 -out apiclient_cert.pem
openssl pkcs12 -nocerts -in apiclient_cert.p12 -out apiclient_key.pem
导出apiclient_key.pem时需输入PEM phrase, 此后每次发起请求均要输入,可使用openssl解除:
openssl rsa -in apiclient_key.pem -out apiclient_key.pem.unsecure
'''
response = requests.post(url, data=xml.encode('utf-8'),
headers={'Content-Type': 'text/xml'},
cert=(WX_CERT_PATH, WX_KEY_PATH))
# xml 2 dict
msg = response.text
xmlmsg = xmltodict.parse(msg)
return xmlmsg
示例2: prepare_request
# 需要导入模块: import xmltodict [as 别名]
# 或者: from xmltodict import unparse [as 别名]
def prepare_request(self, method, path, params):
kwargs = {}
_params = self.get_base_params()
params.update(_params)
newparams, prestr = params_filter(params)
sign = build_mysign(prestr, self.partner_key)
# 将内容转化为unicode xmltodict 只支持unicode
newparams = params_encoding(newparams)
newparams['sign'] = sign
xml_dict = {'xml': newparams}
kwargs['data'] = smart_str(xmltodict.unparse(xml_dict))
url = self._full_url(path)
if self.mch_cert and self.mch_key:
kwargs['cert'] = (self.mch_cert, self.mch_key)
return method, url, kwargs
# 统一下单
# https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1
示例3: get_request_kwargs
# 需要导入模块: import xmltodict [as 别名]
# 或者: from xmltodict import unparse [as 别名]
def get_request_kwargs(self, api_params, *args, **kwargs):
# stores kwargs prefixed with 'xmltodict_unparse__' for use by xmltodict.unparse
self._xmltodict_unparse_kwargs = {k[len('xmltodict_unparse__'):]: kwargs.pop(k)
for k in kwargs.copy().keys()
if k.startswith('xmltodict_unparse__')}
# stores kwargs prefixed with 'xmltodict_parse__' for use by xmltodict.parse
self._xmltodict_parse_kwargs = {k[len('xmltodict_parse__'):]: kwargs.pop(k)
for k in kwargs.copy().keys()
if k.startswith('xmltodict_parse__')}
arguments = super(XMLAdapterMixin, self).get_request_kwargs(
api_params, *args, **kwargs)
if 'headers' not in arguments:
arguments['headers'] = {}
arguments['headers']['Content-Type'] = 'application/xml'
return arguments
示例4: test_xml_post_dict_passes_unparse_param
# 需要导入模块: import xmltodict [as 别名]
# 或者: from xmltodict import unparse [as 别名]
def test_xml_post_dict_passes_unparse_param(self):
responses.add(responses.POST, self.wrapper.test().data,
body='Any response', status=200, content_type='application/json')
data = OrderedDict([
('tag1', OrderedDict([
('@attr1', 'val1'), ('tag2', 'text1'), ('tag3', 'text2')
]))
])
self.wrapper.test().post(data=data, xmltodict_unparse__full_document=False)
request_body = responses.calls[0].request.body
self.assertEqual(request_body, xmltodict.unparse(
data, full_document=False).encode('utf-8'))
示例5: _prepare_blr_xml
# 需要导入模块: import xmltodict [as 别名]
# 或者: from xmltodict import unparse [as 别名]
def _prepare_blr_xml(self, restore_option):
request_json = self._prepare_blr_json(restore_option)
xml_string = xmltodict.unparse(request_json)
plans = Plans(self._commcell_object)
return (
"""<?xml version="1.0" encoding="UTF-8"?><EVGui_SetVMBlockLevelReplicationReq subclientId="{5}" opType="3">
<blockLevelReplicationTaskXML><![CDATA[{0}]]></blockLevelReplicationTaskXML>
<subClientProperties>
<subClientEntity clientId="{1}" applicationId="106" instanceId="{2}" backupsetId="{3}"/>
<planEntity planId="{4}"/>
</subClientProperties>
</EVGui_SetVMBlockLevelReplicationReq>
""".format(
xml_string,
self._client_object.client_id,
self._instance_object.instance_id,
self._backupset_object.backupset_id,
plans.all_plans[restore_option["plan_name"].lower()],
self._subclient_id))
示例6: change_video_settings
# 需要导入模块: import xmltodict [as 别名]
# 或者: from xmltodict import unparse [as 别名]
def change_video_settings(self, options):
tilt = int((900 * int(options["brightness"])) / 100)
pan = int((3600 * int(options["contrast"])) / 100)
zoom = int((40 * int(options["hue"])) / 100)
self.logger.info("Moving to %s:%s:%s", pan, tilt, zoom)
req = {
"PTZData": {
"@version": "2.0",
"@xmlns": "http://www.hikvision.com/ver20/XMLSchema",
"AbsoluteHigh": {
"absoluteZoom": str(zoom),
"azimuth": str(pan),
"elevation": str(tilt),
},
}
}
self.cam.PTZCtrl.channels[1].absolute(
method="put", data=xmltodict.unparse(req, pretty=True)
)
示例7: _generate_uvmpw_file
# 需要导入模块: import xmltodict [as 别名]
# 或者: from xmltodict import unparse [as 别名]
def _generate_uvmpw_file(self):
uvmpw_dic = xmltodict.parse(open(self.uvmpw_file, "rb"))
uvmpw_dic['ProjectWorkspace']['project'] = []
for project in self.workspace['projects']:
# We check how far is project from root and workspace. IF they dont match,
# get relpath for project and inject it into workspace
path_project = os.path.dirname(project['files']['uvproj'])
path_workspace = os.path.dirname(self.workspace['settings']['path'] + '\\')
destination = os.path.join(os.path.relpath(self.env_settings.root, path_project), project['files']['uvproj'])
if path_project != path_workspace:
destination = os.path.join(os.path.relpath(self.env_settings.root, path_workspace), project['files']['uvproj'])
uvmpw_dic['ProjectWorkspace']['project'].append({'PathAndName': destination})
# generate the file
uvmpw_xml = xmltodict.unparse(uvmpw_dic, pretty=True)
project_path, uvmpw = self.gen_file_raw(uvmpw_xml, '%s.uvmpw' % self.workspace['settings']['name'], self.workspace['settings']['path'])
return project_path, uvmpw
示例8: instruction_to_svg
# 需要导入模块: import xmltodict [as 别名]
# 或者: from xmltodict import unparse [as 别名]
def instruction_to_svg(self, instruction):
""":return: an SVG representing the instruction.
The SVG file is determined by the type attribute of the instruction.
An instruction of type ``"knit"`` is looked for in a file named
``"knit.svg"``.
Every element inside a group labeled ``"color"`` of mode ``"layer"``
that has a ``"fill"`` style gets this fill replaced by the color of
the instruction.
Example of a recangle that gets filled like the instruction:
.. code:: xml
<g inkscape:label="color" inkscape:groupmode="layer">
<rect style="fill:#ff0000;fill-opacity:1;fill-rule:nonzero"
id="rectangle1" width="10" height="10" x="0" y="0" />
</g>
If nothing was loaded to display this instruction, a default image is
be generated by :meth:`default_instruction_to_svg`.
"""
return xmltodict.unparse(self.instruction_to_svg_dict(instruction))
示例9: send_properties
# 需要导入模块: import xmltodict [as 别名]
# 或者: from xmltodict import unparse [as 别名]
def send_properties(self, **kwargs):
if not self._properties or 'ui_properties' not in self._properties:
return
# Decide the method to use.
if self._instance.game.game == 'tm':
method = 'Trackmania.UI.SetProperties'
else:
method = 'Shootmania.UI.SetProperties'
# Create XML document
try:
xml = xd.unparse(self._properties, full_document=False, short_empty_elements=True)
except Exception as e:
logger.warning('Can\'t convert UI Properties to XML document! Error: {}'.format(str(e)))
return
try:
await self._instance.gbx(method, xml, encode_json=False, response_id=False)
except Exception as e:
logger.warning('Can\'t send UI Properties! Error: {}'.format(str(e)))
return
示例10: assertXMLEqual
# 需要导入模块: import xmltodict [as 别名]
# 或者: from xmltodict import unparse [as 别名]
def assertXMLEqual(self, expected, xml):
expected = xmltodict.unparse(xmltodict.parse(expected))
xml = xmltodict.unparse(xmltodict.parse(xml))
self.assertEqual(expected, xml)
示例11: _output_convert
# 需要导入模块: import xmltodict [as 别名]
# 或者: from xmltodict import unparse [as 别名]
def _output_convert(output_type, data):
output_switch = {'dict': data,
'raw': data,
'json': json.dumps(data, indent=4),
'xml': xmltodict.unparse({'root': data})}
return output_switch.get(output_type, None)
示例12: _update_subscribe
# 需要导入模块: import xmltodict [as 别名]
# 或者: from xmltodict import unparse [as 别名]
def _update_subscribe(self, headers, raw_data):
subscribers_url = "".join([self.url,
"?oslc_cm.properties=rtc_cm:subscribers"])
self.put(subscribers_url,
verify=False,
proxies=self.rtc_obj.proxies,
headers=headers,
data=xmltodict.unparse(raw_data))
示例13: make_shape
# 需要导入模块: import xmltodict [as 别名]
# 或者: from xmltodict import unparse [as 别名]
def make_shape(name, points):
''' Make the STL and XML, and save both to the proper directories. '''
# Make the STL and XML
shape, size = build_stl(name, points)
xml_dict = build_xml(name, size)
# Make the directory to save files to if we have to
xml_dirname = worldgen_path('assets', 'xmls', 'shapes', name)
stl_dirname = worldgen_path('assets', 'stls', 'shapes', name)
os.makedirs(xml_dirname, exist_ok=True)
os.makedirs(stl_dirname, exist_ok=True)
# Save the STL and XML to our new directories
shape.save(os.path.join(stl_dirname, name + '.stl'))
with open(os.path.join(xml_dirname, 'main.xml'), 'w') as f:
f.write(xmltodict.unparse(xml_dict, pretty=True))
示例14: unparse_dict
# 需要导入模块: import xmltodict [as 别名]
# 或者: from xmltodict import unparse [as 别名]
def unparse_dict(xml_dict):
'''
Convert a normalized XML dictionary into a XML string. See stringify().
Note: this modifies xml_dict in place to have strings instead of values.
'''
stringify(xml_dict)
xml_doc_dict = OrderedDict(mujoco=xml_dict)
return xmltodict.unparse(xml_doc_dict, pretty=True)
示例15: send_xml_request
# 需要导入模块: import xmltodict [as 别名]
# 或者: from xmltodict import unparse [as 别名]
def send_xml_request(url, param):
# dict 2 xml
param = {'root': param}
xml = xmltodict.unparse(param)
response = requests.post(url, data=xml.encode('utf-8'), headers={'Content-Type': 'text/xml'})
# xml 2 dict
msg = response.text
xmlmsg = xmltodict.parse(msg)
return xmlmsg
# 统一下单