本文整理汇总了Python中pyramid.response.Response.headerlist方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headerlist方法的具体用法?Python Response.headerlist怎么用?Python Response.headerlist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.response.Response
的用法示例。
在下文中一共展示了Response.headerlist方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: export
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headerlist [as 别名]
def export(self):
exch = Exchange(Base.metadata,
ignlist=['cpu_types', 'machine_types', 'nic_types'])
fp = StringIO.StringIO()
exch.export_xml()
exch.write_xml(fp)
resp = Response()
resp.headerlist=[('Content-Type', 'text/html; charset=UTF-8'),]
resp.text=fp.getvalue()
resp.content_disposition = 'attachment; filename="qtubes_export.xml"'
resp.charset='utf-8'
return resp
示例2: createResponse
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import headerlist [as 别名]
def createResponse(
status,
code,
result,
serialize,
request,
format='json',
header=None,
):
""" Create and format a response
Available formats: JSON ('json'), XML ('xml')
"""
format = format.lower()
# set status
if status == False:
status = 'failure'
else:
status = 'success'
if serialize:
output = [i.serialize for i in result]
else:
output = result
res = Response('')
# set header
if format == 'xml':
res.content_type = 'application/xml'
else:
# default - format = "json"
format = 'json'
res.content_type = 'application/json'
if header != None:
res.headerlist = header
if format == 'xml':
response = \
XMLDict.convert_dict_to_xml({'response': {'status': status,
'code': code, 'data': output}})
else:
# default - format = "json":
response = json.dumps({'status': status, 'code': code,
'data': output})
callback = request.params.get('callback', None)
if callback:
response = callback + '(' + response + ')'
res.text = response
else:
res.body = response
return res