本文整理匯總了Python中httplib.FOUND屬性的典型用法代碼示例。如果您正苦於以下問題:Python httplib.FOUND屬性的具體用法?Python httplib.FOUND怎麽用?Python httplib.FOUND使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類httplib
的用法示例。
在下文中一共展示了httplib.FOUND屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ParseStatusRewriter
# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import FOUND [as 別名]
def ParseStatusRewriter(response):
"""Parse status header, if it exists.
Handles the server-side 'status' header, which instructs the server to change
the HTTP response code accordingly. Handles the 'location' header, which
issues an HTTP 302 redirect to the client. Also corrects the 'content-length'
header to reflect actual content length in case extra information has been
appended to the response body.
If the 'status' header supplied by the client is invalid, this method will
set the response to a 500 with an error message as content.
"""
location_value = response.headers.getheader('location')
status_value = response.headers.getheader('status')
if status_value:
response_status = status_value
del response.headers['status']
elif location_value:
response_status = '%d Redirecting' % httplib.FOUND
else:
return response
status_parts = response_status.split(' ', 1)
response.status_code, response.status_message = (status_parts + [''])[:2]
try:
response.status_code = int(response.status_code)
except ValueError:
response.status_code = 500
response.body = cStringIO.StringIO(
'Error: Invalid "status" header value returned.')
示例2: _redirect_302_path_info
# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import FOUND [as 別名]
def _redirect_302_path_info(self, updated_path_info, environ, start_response):
"""Redirect to an updated path.
Respond to the current request with a 302 Found status with an updated path
but preserving the rest of the request.
Notes:
- WSGI does not make the fragment available so we are not able to preserve
it. Luckily prod does not preserve the fragment so it works out.
Args:
updated_path_info: the new HTTP path to redirect to.
environ: WSGI environ object.
start_response: WSGI start response callable.
Returns:
WSGI-compatible iterable object representing the body of the response.
"""
correct_url = urlparse.urlunsplit(
(environ['wsgi.url_scheme'],
environ['HTTP_HOST'],
urllib.quote(updated_path_info),
self._quote_querystring(environ['QUERY_STRING']),
None))
content_type = 'text/html; charset=utf-8'
output = _REDIRECT_HTML % {
'content-type': content_type,
'status': httplib.FOUND,
'correct-url': correct_url
}
start_response('%d %s' % (httplib.FOUND, httplib.responses[httplib.FOUND]),
[('Content-Type', content_type),
('Location', correct_url),
('Content-Length', str(len(output)))])
return output