本文整理汇总了Python中webob.Response.headerlist方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headerlist方法的具体用法?Python Response.headerlist怎么用?Python Response.headerlist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webob.Response
的用法示例。
在下文中一共展示了Response.headerlist方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_set_headerlist
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headerlist [as 别名]
def test_set_headerlist():
res = Response()
# looks like a list
res.headerlist = (('Content-Type', 'text/html; charset=UTF-8'),)
eq_(res.headerlist, [('Content-Type', 'text/html; charset=UTF-8')])
# has items
res.headerlist = {'Content-Type': 'text/html; charset=UTF-8'}
eq_(res.headerlist, [('Content-Type', 'text/html; charset=UTF-8')])
del res.headerlist
eq_(res.headerlist, [])
示例2: __call__
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headerlist [as 别名]
def __call__(self, env, start_response):
"""
"""
req = Request(env)
self.loc.reload()
if self.loc.age == 0:
self.logger.warn('dispatcher relay rule is invalid, using old rules now.')
if not self.is_keystone_proxy_path(req):
return self.app(env, start_response)
try:
(loc_prefix, api_type) = self.location_api_check(req)
except Exception:
return HTTPPreconditionFailed(body='invalid PATH')(env, start_response)
ks_port = self.keystone_auth_port \
if api_type == self.keystone_proxy_auth_path \
else self.keystone_admin_port
(succ_resps, fail_resps) = self.request_to_ks(req, self.loc.swift_of(loc_prefix), ks_port)
if len(succ_resps) == 0:
resp = fail_resps[0]
if isinstance(resp, HTTPException):
return resp(env, start_response)
start_response('%s %s' % (resp.status, resp.reason), resp.getheaders())
return resp.read()
if self.loc.is_merged(loc_prefix):
try:
(body, header) = self.ks_merge_response(succ_resps, loc_prefix)
except Exception, err:
return HTTPServerError(body=err)(env, start_response)
res = Response(status='200 OK')
res.headerlist = header
res.body = body
return res(env, start_response)
示例3: application
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headerlist [as 别名]
def application(environ, start_response):
req = Request(environ)
res = Response()
res.status = 200
res.headerlist = [('Content-Type','text/html')]
res.body = "<h1>Hello World!<h1>"
return res(environ, start_response)
示例4: __call__
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headerlist [as 别名]
def __call__(self, env, start_response):
""" """
req = Request(env)
real_path = '/' + '/'.join(req.path.split('/')[2:])
#print real_path
if not self.is_keystone_req(req):
self.logger.info('pass through')
return self.app(env, start_response)
if self.is_keystone_auth_token_req(req):
self.logger.info('return auth response that merged one and other')
mbody, mheaders = self.relay_keystone_auth_req(req, real_path)
#print 'mbody in keystone_merge: %s' % mbody
if mbody:
merged_resp = Response(request=req,
body=mbody,
headers=mheaders)
start_response(merged_resp.status, merged_resp.headerlist)
return json.dumps(merged_resp.body)
else:
return self.app(env, start_response)
self.logger.info('normal keystone request to one')
result = self.relay_keystone_ordinary_req(req)
resp = Response(status='%s %s' % (result.status, result.reason));
resp.headerlist = result.getheaders()
resp.body = result.read()
start_response(resp.status, resp.headerlist)
return resp.body
示例5: export_notes
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headerlist [as 别名]
def export_notes(self, request, suffix=''):
""" Return an pdf export of user and public notes
Returns:
response
"""
res = Response()
student = self.__get_current_user()
try:
timecoded_data_set = self.__list_notes()
timecoded_data_array = []
for timecoded_data in timecoded_data_set:
timecoded_data_array.append([timecoded_data.seconds, Paragraph(timecoded_data.content.replace('\n','<br />'), ParagraphStyle("Page"))])
res.headerlist = [('Content-type', 'application/pdf'), ('Content-Disposition', 'attachment; filename=%s' % str(self.scope_ids.user_id)+".pdf")]
p = canvas.Canvas(res)
if (len(timecoded_data_array)>0):
table = Table(timecoded_data_array, colWidths=[20, 500])
table.setStyle(TableStyle([('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black),
('BOX', (0, 0), (-1, -1), 0.25, colors.black)]))
table.wrapOn(p, 700, 700)
table.drawOn(p, 50, 700)
p.showPage()
p.save()
return res
except KNoteList.DoesNotExist:
res.status = 404
return res
示例6: get_merged_containers_with_marker_resp
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headerlist [as 别名]
def get_merged_containers_with_marker_resp(self, req, location, marker):
""" """
if marker.find(self.combinater_char) == -1:
return HTTPNotFound(request=req)
marker_prefix = self._get_container_prefix(marker)
if not self.loc.servers_by_container_prefix_of(location, marker_prefix):
return HTTPNotFound(request=req)
real_marker = marker.split(marker_prefix + ':')[1]
swift_svrs = self.loc.servers_by_container_prefix_of(location, marker_prefix)
swift_server_subscript = self._get_servers_subscript_by_prefix(location, marker_prefix)
each_tokens = self._get_each_tokens(req)
query = parse_qs(urlparse(req.url).query)
query['marker'] = real_marker
real_path = '/' + '/'.join(self._get_real_path(req))
url = self._combinate_url(req, swift_svrs[0], real_path, query)
req.headers['x-auth-token'] = each_tokens[swift_server_subscript]
resp = self.relay_req(req, url,
self._get_real_path(req),
swift_svrs,
self.loc.webcache_of(location))
m_headers = self._merge_headers([resp], location)
m_body = ''
if req.method == 'GET':
if self._has_header('content-type', [resp]):
content_type = [v for k,v in m_headers if k == 'content-type'][0]
m_body = self._merge_container_lists(content_type, [resp.body], [marker_prefix])
resp = Response(status='200 OK')
resp.headerlist = m_headers
resp.body = m_body
return resp
示例7: challenge
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headerlist [as 别名]
def challenge(self, environ, status, app_headers, forget_headers):
'''
The challenger.
'''
res = Response()
res.headerlist = [('Content-type', 'application/json')]
res.charset = 'utf8'
res.unicode_body = u"{error:'wrong credentials'}"
res.status = 403
return res
示例8: app
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headerlist [as 别名]
def app(environ, start_response):
try:
request = Request(environ)
response = Response()
if len(request.body) == 0:
try:
request.body = sys.argv[1]
except:
response.status = 400 # Bad Request
response.headerlist = [('Content-Type', 'application/xml; charset=UTF-8'),]
response.body = str(NoApplicableCode('No query string found.'))
return response(environ, start_response)
wps = pywps.Pywps(request.method)
if wps.parseRequest(request.body):
# pywps.debug(wps.inputs)
response_msg = wps.performRequest()
# request performed, write the response back
if response_msg:
response.status = 200 # OK
response.headerlist = [('Content-Type', wps.request.contentType),]
response.body = response_msg
# pywps.response.response(wps.response,
# sys.stdout, wps.parser.soapVersion, wps.parser.isSoap,
# wps.parser.isSoapExecute, wps.request.contentType)
except WPSException as e:
traceback.print_exc(file=pywps.logFile)
response.status = 400 # Bad Request
response.headerlist = [('Content-Type', 'application/xml; charset=UTF-8'),]
response.body = str(e)
# pywps.response.response(e, sys.stdout, wps.parser.soapVersion,
# wps.parser.isSoap,
# wps.parser.isSoapExecute)
except Exception as e:
traceback.print_exc(file=pywps.logFile)
response.status = 500 # Internal Server Error
response.headerlist = [('Content-Type', 'application/xml; charset=UTF-8'),]
response.body = str(NoApplicableCode(e.message))
return response(environ, start_response)
示例9: index
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headerlist [as 别名]
def index(self,req):
data = {}
try:
rule_file = open('/var/tmp/rules_list.dat','r')
data['rules'] = pickle.load(rule_file)
except:
data['rules'] = None
rules_xml = self.show_template('rules.mako',data)
resp = Response()
resp.headerlist = [('Content-type', 'text/xml; charset=UTF-8')]
resp.body = rules_xml
return resp
示例10: GET
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headerlist [as 别名]
def GET(self, req):
print 'In GET()'
resp_headers = {'user-name': 'junaid',
'Content-type': 'text/html'}
df = Diskfile(req.path_info)
print 'path_info: ', req.path_info
if df.error:
res = Response(request=req, headers=resp_headers)
res.status = '500 File not found'
elif df.is_dir:
res = Response(request=req, headers=resp_headers)
res.status = '400 Download failed'
else:
res = Response(request=req, headers=resp_headers, app_iter=df)
res.status = '200 OK'
res.headerlist = [('Content-type', 'application/octet-stream')]
return res
示例11: respond
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headerlist [as 别名]
def respond(self, request):
address_parts = dict(scheme=self.scheme,
host=self.host,
port=self.port,
path=request.path,
)
address = "{scheme}://{host}:{port!s}{path}".format(**address_parts)
# TODO Use HTTP cache-control headers.
# Request the information from our proxy
resp, content = self.http.request(address)
status = int(resp['status'])
del resp['status']
response = Response()
response.status_int = status
response.headerlist = resp.items()
response.body = content
return response
示例12: get_merged_auth_resp
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headerlist [as 别名]
def get_merged_auth_resp(self, req, location):
""" """
resps = []
for swift in self.loc.swift_of(location):
resps.append(self.relay_req(req, req.url,
self._get_real_path(req),
swift,
self.loc.webcache_of(location)))
error_resp = self.check_error_resp(resps)
if error_resp:
return error_resp
ok_resps = []
for resp in resps:
if resp.status_int == 200:
ok_resps.append(resp)
resp = Response(status='200 OK')
resp.headerlist = self._merge_headers(ok_resps, location)
resp.body = self._merge_storage_url_body([r.body for r in ok_resps], location)
return resp
示例13: __call__
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headerlist [as 别名]
def __call__(self, context, request):
subpath = '/'.join(request.subpath)
caught = []
def catch_start_response(status, headers, exc_info=None):
caught[:] = (status, headers, exc_info)
ecopy = request.environ.copy()
# Fix up PATH_INFO to get rid of everything but the "subpath"
# (the actual path to the file relative to the root dir).
# Zero out SCRIPT_NAME for good measure.
ecopy['PATH_INFO'] = '/' + subpath
ecopy['SCRIPT_NAME'] = ''
body = self.app(ecopy, catch_start_response)
if caught:
status, headers, exc_info = caught
response = Response()
response.app_iter = body
response.status = status
response.headerlist = headers
return response
else:
raise RuntimeError('WSGI start_response not called')
示例14: get_merged_containers_resp
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headerlist [as 别名]
def get_merged_containers_resp(self, req, location):
""" """
each_tokens = self._get_each_tokens(req)
if not each_tokens:
return HTTPUnauthorized(request=req)
cont_prefix_ls = []
real_path = '/' + '/'.join(self._get_real_path(req))
each_swift_cluster = self.loc.swift_of(location)
query = parse_qs(urlparse(req.url).query)
each_urls = [self._combinate_url(req, s[0], real_path, query) for s in each_swift_cluster]
resps = []
for each_url, each_token, each_swift_svrs in zip(each_urls, each_tokens, each_swift_cluster):
req.headers['x-auth-token'] = each_token
resp = self.relay_req(req, each_url,
self._get_real_path(req),
each_swift_svrs,
self.loc.webcache_of(location))
resps.append((each_url, resp))
error_resp = self.check_error_resp([r for u, r in resps])
if error_resp:
return error_resp
ok_resps = []
ok_cont_prefix = []
for url, resp in resps:
if resp.status_int >= 200 and resp.status_int <= 299:
ok_resps.append(resp)
ok_cont_prefix.append(self.loc.container_prefix_of(location, url))
m_body = ''
m_headers = self._merge_headers(ok_resps, location)
if req.method == 'GET':
if self._has_header('content-type', ok_resps):
content_type = [v for k,v in m_headers if k == 'content-type'][0]
m_body = self._merge_container_lists(content_type,
[r.body for r in ok_resps],
ok_cont_prefix)
resp = Response(status='200 OK')
resp.headerlist = m_headers
resp.body = m_body
return resp
示例15: application
# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import headerlist [as 别名]
def application(request):
resp = Response()
resp.headerlist = [('Content-type', 'application/json')]
if request.method == 'POST':
if request.path == '/client/add':
r,b = client_request(request,'add')
resp.status = r['status']
resp.body = b
elif request.path == '/client/mod':
pass
elif request.path == '/client/del':
pass
elif request.path == '/client/check':
r,b = client_request(request,'check')
resp.status = r['status']
resp.body = b
else:
resp.status = 404
else:
resp.status = 404
return resp