本文整理汇总了Python中xmltodict.unparse函数的典型用法代码示例。如果您正苦于以下问题:Python unparse函数的具体用法?Python unparse怎么用?Python unparse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unparse函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_generator
def test_generator(self):
obj = {'a': {'b': ['1', '2', '3']}}
def lazy_obj():
return {'a': {'b': (i for i in ('1', '2', '3'))}}
self.assertEqual(obj, parse(unparse(lazy_obj())))
self.assertEqual(unparse(lazy_obj()),
unparse(parse(unparse(lazy_obj()))))
开发者ID:zhanglei002,项目名称:xmltodict,代码行数:7,代码来源:test_dicttoxml.py
示例2: write
def write(path, doc, unix=False):
# Convert items to list
doc['anime-list']['anime'] = doc['anime-list']['anime'].values()
# Encode document
buf = StringIO()
unparse(
doc,
output=buf,
indent=' ',
newl='\n',
pretty=True,
short_empty_elements=True
)
# Convert to string
data = buf.getvalue() + '\n'
if unix:
data = data.replace('\n', '\r\n')
# Write data to path
with open(path, 'w') as fp:
fp.write(data)
开发者ID:fuzeman,项目名称:anime-lists,代码行数:26,代码来源:utils.py
示例3: test_multiple_roots_nofulldoc
def test_multiple_roots_nofulldoc(self):
obj = OrderedDict((('a', 1), ('b', 2)))
xml = unparse(obj, full_document=False)
self.assertEqual(xml, '<a>1</a><b>2</b>')
obj = {'a': [1, 2]}
xml = unparse(obj, full_document=False)
self.assertEqual(xml, '<a>1</a><a>2</a>')
开发者ID:zhanglei002,项目名称:xmltodict,代码行数:7,代码来源:test_dicttoxml.py
示例4: make_qbxml
def make_qbxml(self, query=None, payload=None):
"""
Outputs a valid QBXML
if there is a payload it will be included in the output
:param query is the full name of the object like CustomerAddRq
:param payload is the optional payload , it is required when adding items.
"""
if payload:
qb_request = payload
else:
qb_request = None
qbxml_query = {
'QBXML': {
'QBXMLMsgsRq':
{
'@onError': "stopOnError",
query: qb_request
}
}
}
data_xml = self.xml_soap(xmltodict.unparse(qbxml_query, full_document=False))
data_xml = xmltodict.unparse(qbxml_query, full_document=False)
res = self.xml_prefix + data_xml
return res
开发者ID:royendgel,项目名称:quickbooks,代码行数:31,代码来源:old_code.py
示例5: export_project
def export_project(self):
output = copy.deepcopy(self.generated_project)
expanded_dic = self.workspace.copy()
# data for .vcxproj
expanded_dic['vcxproj'] = {}
expanded_dic['vcxproj'] = self._set_vcxproj(expanded_dic['name'])
# data for debugger for pyOCD
expanded_dic['vcxproj_user'] = {}
# TODO: localhost and gdb should be misc for VS ! Add misc options
vcxproj_user_dic = self._set_vcxproj_user('localhost:3333', 'arm-none-eabi-gdb',
os.path.join(expanded_dic['build_dir'], expanded_dic['name']), os.path.join(os.getcwd(), expanded_dic['output_dir']['path']))
self._set_groups(expanded_dic)
# Project files
project_path, output = self._generate_vcxproj_files(expanded_dic,
expanded_dic['name'], expanded_dic['output_dir']['path'], vcxproj_user_dic)
# NMake and debugger assets
# TODO: not sure about base class having NMake and debugger. We might want to disable that by default?
self.gen_file_raw(xmltodict.unparse(self.linux_nmake_xaml, pretty=True), 'linux_nmake.xaml', expanded_dic['output_dir']['path'])
self.gen_file_raw(xmltodict.unparse(self.linux_debugger_xaml, pretty=True), 'LocalDebugger.xaml', expanded_dic['output_dir']['path'])
return output
开发者ID:0xc0170,项目名称:project_generator,代码行数:26,代码来源:visual_studio.py
示例6: StaticDiscovery
def StaticDiscovery():
"""
"""
p = Associate()
for obisInfo in OBISList:
a = obisInfo['code'][0]
b = obisInfo['code'][1]
c = obisInfo['code'][2]
d = obisInfo['code'][3]
e = obisInfo['code'][4]
f = obisInfo['code'][5]
ic = int(obisInfo['ic'])
hexCode = '%02x%02x%02x%02x%02x%02x'%(a,b,c,d,e,f)
print('------- getting %s ic=%d --------'%(hexCode,ic))
if ic == 3:
rq = DLMSPlayground.CreateGetRequest(ic,hexCode,3)
elif ic == 4:
rq = DLMSPlayground.CreateGetRequest(ic,hexCode,4)
elif ic == 5:
rq = DLMSPlayground.CreateGetRequest(ic,hexCode,4)
elif ic == 8:
rq = DLMSPlayground.CreateGetRequest(ic,hexCode,3)
elif ic == 1:
rq = DLMSPlayground.CreateGetRequest(ic,hexCode,3)
else:
print('oops...')
pass
print(rq)
DLMSPlayground.SendHDLCToMeter(p, rq )
time.sleep(0.5)
rsp = DLMSPlayground.GetResponseFromMeter(p)
print(rsp)
print( DLMS.HDLCToDict(rsp) )
if rsp != None:
xmlAttr3 = xmltodict.unparse(DLMS.HDLCToDict(rsp))
rq = DLMSPlayground.CreateGetRequest(ic,hexCode,2)
print(rq)
DLMSPlayground.SendHDLCToMeter(p, rq )
time.sleep(0.5)
rsp = DLMSPlayground.GetResponseFromMeter(p)
print(rsp)
print( DLMS.HDLCToDict(rsp) )
if rsp != None:
xmlAttr2 = xmltodict.unparse(DLMS.HDLCToDict(rsp))
combinedXML = '<Object><OBIS value="%s" /><ClassID Value="%d" /><Attribute2Read>%s</Attribute2Read>\n<Attribute3Read>%s</Attribute3Read></Object>'%(hexCode,ic,xmlAttr2,xmlAttr3)
combinedXML = re.sub(r'<\?.*\?>','',combinedXML)
open('Objects/%s.xml'%(hexCode),'w+').write(combinedXML)
开发者ID:BlockWorksCo,项目名称:Playground,代码行数:57,代码来源:StaticDiscovery.py
示例7: write_config_xml
def write_config_xml(xmlfile, dict):
try:
with open(xmlfile, "wt") as fo:
xmltodict.unparse(dict, fo, pretty=True)
except IOError as e:
print "Error writing XML file: ", e
return False
return True
开发者ID:modmypi,项目名称:PiModules,代码行数:9,代码来源:configuration.py
示例8: check_notify
def check_notify(self, xml_notify, handle):
self._logResp(xml_notify, 'Wechat pay notify')
content = self._check_error(xml_notify)
result, fail_msg = handle(**content)
if result:
return unparse(dict(xml={'return_code': 'SUCCESS'}))
else:
self.log.error('Wechat pay notify fail: {}'.format(fail_msg))
return unparse(dict(xml={'return_code': 'FAIL', 'return_msg': fail_msg}))
开发者ID:Ginhing,项目名称:wechat,代码行数:9,代码来源:wechatpay.py
示例9: test_encoding
def test_encoding(self):
try:
value = unichr(39321)
except NameError:
value = chr(39321)
obj = {'a': value}
utf8doc = unparse(obj, encoding='utf-8')
latin1doc = unparse(obj, encoding='iso-8859-1')
self.assertEqual(parse(utf8doc), parse(latin1doc))
self.assertEqual(parse(utf8doc), obj)
开发者ID:zhanglei002,项目名称:xmltodict,代码行数:10,代码来源:test_dicttoxml.py
示例10: _api_out_as
def _api_out_as(self, out):
""" Formats the response to the desired output """
if self._api_cmd == "docs_md":
return out["response"]["data"]
elif self._api_cmd == "download_log":
return
elif self._api_cmd == "pms_image_proxy":
cherrypy.response.headers["Content-Type"] = "image/jpeg"
return out["response"]["data"]
if self._api_out_type == "json":
cherrypy.response.headers["Content-Type"] = "application/json;charset=UTF-8"
try:
if self._api_debug:
out = json.dumps(out, indent=4, sort_keys=True)
else:
out = json.dumps(out)
if self._api_callback is not None:
cherrypy.response.headers["Content-Type"] = "application/javascript"
# wrap with JSONP call if requested
out = self._api_callback + "(" + out + ");"
# if we fail to generate the output fake an error
except Exception as e:
logger.info(u"PlexPy APIv2 :: " + traceback.format_exc())
out["message"] = traceback.format_exc()
out["result"] = "error"
elif self._api_out_type == "xml":
cherrypy.response.headers["Content-Type"] = "application/xml"
try:
out = xmltodict.unparse(out, pretty=True)
except Exception as e:
logger.error(u"PlexPy APIv2 :: Failed to parse xml result")
try:
out["message"] = e
out["result"] = "error"
out = xmltodict.unparse(out, pretty=True)
except Exception as e:
logger.error(u"PlexPy APIv2 :: Failed to parse xml result error message %s" % e)
out = (
"""<?xml version="1.0" encoding="utf-8"?>
<response>
<message>%s</message>
<data></data>
<result>error</result>
</response>
"""
% e
)
return out
开发者ID:MikeDawg,项目名称:plexpy,代码行数:54,代码来源:api2.py
示例11: test_multiple_roots
def test_multiple_roots(self):
try:
unparse({'a': '1', 'b': '2'})
self.fail()
except ValueError:
pass
try:
unparse({'a': ['1', '2', '3']})
self.fail()
except ValueError:
pass
开发者ID:dpla,项目名称:xmltodict,代码行数:11,代码来源:test_dicttoxml.py
示例12: convert
def convert(self, path, data):
if isinstance(data, list):
data = {'items': {str(k): v for k, v in enumerate(data)}}
try:
with open(path, 'w') as outfile:
xmltodict.unparse(data, outfile, pretty=True)
except Exception:
logger.exception(u'File `{}` can not be parsed in xml'.format(path))
os.remove(path)
raise
return path
开发者ID:AlexLisovoy,项目名称:binary_studio,代码行数:12,代码来源:file_processor.py
示例13: _api_out_as
def _api_out_as(self, out):
""" Formats the response to the desired output """
if self._api_cmd == 'docs_md':
return out['response']['data']
elif self._api_cmd == 'download_log':
return
elif self._api_cmd == 'pms_image_proxy':
cherrypy.response.headers['Content-Type'] = 'image/jpeg'
return out['response']['data']
if self._api_out_type == 'json':
cherrypy.response.headers['Content-Type'] = 'application/json;charset=UTF-8'
try:
if self._api_debug:
out = json.dumps(out, indent=4, sort_keys=True)
else:
out = json.dumps(out)
if self._api_callback is not None:
cherrypy.response.headers['Content-Type'] = 'application/javascript'
# wrap with JSONP call if requested
out = self._api_callback + '(' + out + ');'
# if we fail to generate the output fake an error
except Exception as e:
logger.info(u'PlexPy APIv2 :: ' + traceback.format_exc())
out['message'] = traceback.format_exc()
out['result'] = 'error'
elif self._api_out_type == 'xml':
cherrypy.response.headers['Content-Type'] = 'application/xml'
try:
out = xmltodict.unparse(out, pretty=True)
except Exception as e:
logger.error(u'PlexPy APIv2 :: Failed to parse xml result')
try:
out['message'] = e
out['result'] = 'error'
out = xmltodict.unparse(out, pretty=True)
except Exception as e:
logger.error(u'PlexPy APIv2 :: Failed to parse xml result error message %s' % e)
out = '''<?xml version="1.0" encoding="utf-8"?>
<response>
<message>%s</message>
<data></data>
<result>error</result>
</response>
''' % e
return out
开发者ID:hsojekok,项目名称:plexpy,代码行数:52,代码来源:api2.py
示例14: __call__
def __call__(self, text):
soap_version = None
try:
data = xmltodict.parse(text, process_namespaces=True,
namespaces=self.parse_ns)
if "s11:Envelope" in data:
soap_version = SOAP11
body = data["s11:Envelope"]["s11:Body"]
elif "s12:Envelope" in data:
soap_version = SOAP12
body = data["s12:Envelope"]["s12:Body"]
else:
if self.ctx:
self.ctx.exc_info = None
self.ctx.error = True
return "Missing SOAP Envelope"
res = self.app(body)
out = OrderedDict([
("env:Envelope", OrderedDict([
("@xmlns:env", soap_version),
("env:Body", res),
])),
])
# Add namespace attributes, preferably to the inner top-level element
# but fallback to putting them on the Envelope
root = out["env:Envelope"]
try:
keys = res.keys()
if len(keys) == 1:
root = res[keys[0]]
except AttributeError:
pass
for (k, v) in self.namespaces.iteritems():
root["@xmlns:"+v] = k
# Add canned attributes, typically for adding encodingStyle
# (Note: SOAP 1.1 allows this to be anywhere including on the
# envelope, but SOAP 1.2 is more restrictive)
if self.reply_attrs:
root.update(self.reply_attrs)
return xmltodict.unparse(out, **self.unparse_options)
except Exception:
if not self.trap_exception: raise
exc_info = sys.exc_info()
if self.ctx:
# This allows the exception to be logged elsewhere,
# and for a HTTP connector to return a 500 status code
self.ctx.exc_info = exc_info
self.ctx.error = True
return xmltodict.unparse(self.fault(exc_info, soap_version),
**self.unparse_options)
开发者ID:candlerb,项目名称:pato,代码行数:51,代码来源:soap.py
示例15: test_nested
def test_nested(self):
obj = {"a": {"b": "1", "c": "2"}}
self.assertEqual(obj, parse(unparse(obj)))
self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
obj = {"a": {"b": {"c": {"@a": "x", "#text": "y"}}}}
self.assertEqual(obj, parse(unparse(obj)))
self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
开发者ID:Mondego,项目名称:pyreco,代码行数:7,代码来源:allPythonContent.py
示例16: inputsToBaclava
def inputsToBaclava(self):
""" Returns an XML in baclava format corresponding to previously specified input ports and values. """
if len(self.inputsDic)==0:
return None;
try:
enclosingDicMap = {}
enclosingDicMap['@xmlns:b']='http://org.embl.ebi.escience/baclava/0.1alpha'
baclavaDic = { 'b:dataThingMap': enclosingDicMap}
baseDoc = xmltodict.unparse(baclavaDic, pretty=True)
fullDataThingStringList = ""
for port in self.inputsDic.keys():
if self.inputsDic[port]!=None:
mimeTypesDict = { 's:mimeTypes' : {'s:mimeType' : 'text/plain'}}
mimeTypesDict['@xmlns:s'] = 'http://org.embl.ebi.escience/xscufl/0.1alpha'
metadataDict = { 's:metadata' : mimeTypesDict}
metadataDict[ '@lsid'] =''
metadataDict[ '@syntactictype']="'text/plain'"
if len(self.inputsDic[port])==1:
dataElementDataDict = { 'b:dataElementData': base64.b64encode(self.inputsDic[port][0])}
dataElementDataDict [ '@lsid'] =''
metadataDict[ 'b:dataElement'] = dataElementDataDict
else:
relationEmptyDict = [{ '@parent': "0", '@child': "1" }]
for i in range(2,len(self.inputsDic[port])):
relationEmptyDict.append({ '@parent': str(i-1), '@child': str(i) })
relationDict = { 'b:relation' : relationEmptyDict }
relationListDict = { 'b:relationList': relationDict , '@lsid': "" , '@type': "list"}
dataElementDataDict = []
for i in range(len(self.inputsDic[port])):
dataElementDataDict.append( { 'b:dataElementData': base64.b64encode(self.inputsDic[port][i]), '@lsid': "", '@index': str(i)} )
dataElementDict = { 'b:dataElement': dataElementDataDict}
relationListDict['b:itemList'] = dataElementDict
metadataDict[ 'b:partialOrder'] = relationListDict
myGridDataDocumentDict = { 'b:myGridDataDocument': metadataDict, '@key': port}
dataThingDic = {'b:dataThing': myGridDataDocumentDict}
dataThingDicString = xmltodict.unparse(dataThingDic, pretty=True)
dataThingDicString = dataThingDicString[ dataThingDicString.find('\n') + 1 : ]
fullDataThingStringList = fullDataThingStringList + dataThingDicString
if fullDataThingStringList!="":
baseDoc = baseDoc.replace("</b:dataThingMap>" , "\n" + fullDataThingStringList + "\n")
baseDoc = baseDoc + "</b:dataThingMap>"
return baseDoc
except Exception as e:
raise Exception('Error while generating Baclava string: ' + e.message)
开发者ID:VPH-Share,项目名称:portal,代码行数:49,代码来源:Taverna2WorkflowIO.py
示例17: reportCreation
def reportCreation():
error = None
if 'token' in session:
concur = ConcurClient()
token = session['token']
username = session['username']
if request.method == 'POST':
today = datetime.date.today()
new_xml_update = {}
new_xml_update['Report'] = {}
#new_xml_update['Report']['ID'] = dict_resp_report['Report']['ID']
new_xml_update['Report']['Name'] = request.form['Name']
new_xml_update['Report']['Comment'] = request.form['Comment']
xml_post = xmltodict.unparse(new_xml_update)
content_type, resp_post = concur.validate_response(concur.api('v3.0/expense/reports', method='POST', params={'access_token': token},
headers={'content-type': 'application/xml', 'accept':'*'}, data=xml_post))
#print resp_post['Response']['ID']
#print resp_post['Response']['URI']
return render_template('reportCreationSuccess.html', username=username, reportURL=resp_post['Response']['URI'], reportID=resp_post['Response']['ID'], error=error)
return render_template('reportCreation.html', username=username, error=error)
else:
return 'Invalid Token - Please Login /login'
开发者ID:lordillusions,项目名称:docker-flask,代码行数:28,代码来源:welcome.py
示例18: update_URDF_from_config
def update_URDF_from_config(urdf_path, config_path):
with open(urdf_path) as f:
urdf = xmltodict.parse(f.read())
with open(config_path) as f:
conf = json.load(f)
confmotors = conf['motors']
joints = urdf['robot']['joint']
links = urdf['robot']['link']
# Update joint properties
wrong_motors=[]
for j in joints:
name = j['@name']
dxl = confmotors[name]['type']
ll, ul = confmotors[name]['angle_limit']
j['limit']['@lower'] = str(deg2rad(ll))
j['limit']['@upper'] = str(deg2rad(ul))
j['limit']['@effort'] = str(DXL2EFFORT[dxl])
j['limit']['@velocity'] = str(DXL2VEL[dxl])
# Update motors rotation
if name not in good_motors:
list = j['axis']['@xyz'].split()
new_list=[ '1' if i=='-1' else '-1' if i=='1' else i for i in list]
j['axis']['@xyz']=' '.join(new_list)
wrong_motors.append(name)
# Update link properties
for l in links:
name = l['@name']
mesh = l['visual']['geometry']['mesh']['@filename']
if '_visual' not in mesh:
pos = mesh.find('.')
l['visual']['geometry']['mesh']['@filename'] = mesh[0:10]+mesh[24:pos]+'_visual.STL'
mesh = l['collision']['geometry']['mesh']['@filename']
if '_respondable' not in mesh:
pos = mesh.find('.')
l['collision']['geometry']['mesh']['@filename'] = mesh[0:10]+mesh[24:pos]+'_respondable.STL'
l['visual']['material']['color']['@rgba'] = COLOR
#l['mass'] = MASS[name]
new_urdf = xmltodict.unparse(urdf, pretty=True)
pos = urdf_path.find('.U')
urdf_path_new = urdf_path[0:pos]+'_vrep.URDF'
with open(urdf_path_new, 'w') as f:
f.write(new_urdf)
return wrong_motors
开发者ID:quan-vu,项目名称:Heol-humanoid,代码行数:60,代码来源:update_URDF.py
示例19: generate_flow_xml
def generate_flow_xml(classifier):
import sklearn
flow_dict = OrderedDict()
flow_dict['oml:flow'] = OrderedDict()
flow_dict['oml:flow']['@xmlns:oml'] = 'http://openml.org/openml'
flow_dict['oml:flow']['oml:name'] = classifier.__module__ +"."+ classifier.__class__.__name__
flow_dict['oml:flow']['oml:external_version'] = 'Tsklearn_'+sklearn.__version__
flow_dict['oml:flow']['oml:description'] = 'Flow generated by openml_run'
clf_params = classifier.get_params()
flow_parameters = []
for k, v in clf_params.items():
# data_type, default_value, description, recommendedRange
# type = v.__class__.__name__ Not using this because it doesn't conform standards
# eg. int instead of integer
param_dict = {'oml:name':k}
flow_parameters.append(param_dict)
flow_dict['oml:flow']['oml:parameter'] = flow_parameters
flow_xml = xmltodict.unparse(flow_dict, pretty=True)
# A flow may not be uploaded with the encoding specification..
flow_xml = flow_xml.split('\n', 1)[-1]
return flow_xml
开发者ID:brylie,项目名称:openml-python,代码行数:25,代码来源:autorun.py
示例20: replace_spreadsheet_row_values
def replace_spreadsheet_row_values( cellsfeed_url, row_number, column_values, use_raw_values=False ):
from collections import OrderedDict
import xmltodict
for index, column in enumerate(column_values, start=1):
cell = 'R' + str(row_number) + 'C' + str(index)
cell_url = cellsfeed_url + '/' + cell
value = str(column)
if not use_raw_values:
value = "'" + value
entry = OrderedDict()
entry['@xmlns'] = 'http://www.w3.org/2005/Atom'
entry['@xmlns:gs'] = "http://schemas.google.com/spreadsheets/2006"
entry['id'] = cell_url
entry['link'] = OrderedDict()
entry['link']['@rel'] = 'edit'
entry['link']['@type'] = 'application/atom+xml'
entry['link']['@href'] = cell_url
entry['gs:cell'] = OrderedDict()
entry['gs:cell']['@row'] = str(row_number)
entry['gs:cell']['@col'] = str(index)
entry['gs:cell']['@inputValue'] = unicode( value )
entry_dict = OrderedDict([ ( 'entry', entry ) ] )
entry_xml = xmltodict.unparse( entry_dict ).encode('utf-8')
make_authorized_request( cell_url, None, 'PUT', entry_xml, { 'If-None-Match' : 'replace' } )
开发者ID:amv,项目名称:gapier,代码行数:28,代码来源:handlers.py
注:本文中的xmltodict.unparse函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论