本文整理汇总了Python中http.HTTP.to方法的典型用法代码示例。如果您正苦于以下问题:Python HTTP.to方法的具体用法?Python HTTP.to怎么用?Python HTTP.to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http.HTTP
的用法示例。
在下文中一共展示了HTTP.to方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fakeWSGIERRApp
# 需要导入模块: from http import HTTP [as 别名]
# 或者: from http.HTTP import to [as 别名]
def fakeWSGIERRApp(envir, responder):
codedict = envir.get('CODE_DICT', {})
body = envir.get('PATH_INFO')
code = codedict.get(envir.get('PATH_INFO'), 200)
if envir.get('PATH_INFO') not in codedict:
body = bodydict.get(envir.get('PATH_INFO'))
else:
body = 'Complete Utter Failure'
response = HTTP(code, body)
retval = response.to(responder)
return retval
示例2: dict
# 需要导入模块: from http import HTTP [as 别名]
# 或者: from http.HTTP import to [as 别名]
% dict(ticket=ticket),
web2py_error='ticket %s' % ticket)
finally:
if response and hasattr(response, 'session_file') \
and response.session_file:
response.session_file.close()
session._unlock(response)
http_response, new_environ = try_rewrite_on_error(
http_response, request, environ, ticket)
if not http_response:
return wsgibase(new_environ, responder)
if global_settings.web2py_crontype == 'soft':
newcron.softcron(global_settings.applications_parent).start()
return http_response.to(responder, env=env)
def save_password(password, port):
"""
used by main() to save the password in the parameters_port.py file.
"""
password_file = abspath('parameters_%i.py' % port)
if password == '<random>':
# make up a new password
chars = string.letters + string.digits
password = ''.join([random.choice(chars) for i in range(8)])
cpassword = CRYPT()(password)[0]
print '******************* IMPORTANT!!! ************************'
print 'your admin password is "%s"' % password
示例3: handle_errors
# 需要导入模块: from http import HTTP [as 别名]
# 或者: from http.HTTP import to [as 别名]
def handle_errors(envir, responder, error_list):
class responder_wrapper:
def __init__(self, responder):
self.theRealSlimShady = responder
self.status = None
self.headers = None
def storeValues(self, status, headers):
self.status = status
self.headers = headers
def sendIt(self):
self.theRealSlimShady(self.status, self.headers)
error_map = dict([(x[0], x) for x in error_list])
error_list = list(error_list)
pre_translated_path = envir['PATH_INFO']
respond_wrap = responder_wrapper(responder)
routed_environ = filter_in(envir)
app = routed_environ['PATH_INFO'].strip('/').split('/')
if len(app) > 0:
app = app[0]
else:
app = 'init' # ## THIS NEEDS FIX
data = wsgibase(routed_environ, respond_wrap.storeValues)
http_status = int(respond_wrap.status.split()[0])
body = data
if http_status >= 400:
query = regex_iter.search(envir.get('query_string', ''))
if query:
query = query.groupdict()
else:
query = {}
code = query.get('code')
ticket = dict(respond_wrap.headers).get('web2py_error',
'None None')
if 'ticket' in ticket:
ticket = ticket.split()[1]
else:
ticket = 'None'
redir = []
for handler in ['%s/%s' % (app, http_status), '%s/*' % app,
'*/%s' % http_status, '*/*', None]:
if handler and handler in error_map:
error_redir = error_map[handler]
if error_redir[1] == '!':
redir = []
break
else:
redir.append(error_redir)
redir.sort(lambda x, y: error_list.index(x)\
- error_list.index(y))
if redir and not pre_translated_path.startswith(redir[0][1])\
and http_status != code:
redir = redir[0][1]
elif len(redir) > 1:
redir = redir[1][1]
else:
redir = None
if redir:
if '?' in redir:
url = redir + '&'
else:
url = redir + '?'
url += 'code=%s&ticket=%s'
url %= (http_status, ticket)
response = HTTP(303,
'You are being redirected <a href="%s">here</a>.'
% url, Location=url)
return response.to(responder)
respond_wrap.sendIt()
return body
示例4: fakeWSGIOutApp
# 需要导入模块: from http import HTTP [as 别名]
# 或者: from http.HTTP import to [as 别名]
def fakeWSGIOutApp(envir, responder):
args = envir.get('PATH_INFO').split('/')
response = HTTP(envir.get('ERROR_CODE', 200), URL(a=args[1],
c=args[2], f=args[3], args=args[4:]))
retval = response.to(responder)
return retval
示例5: fakeWSGIInApp
# 需要导入模块: from http import HTTP [as 别名]
# 或者: from http.HTTP import to [as 别名]
def fakeWSGIInApp(envir, responder):
response = HTTP(envir.get('ERROR_CODE', 200),
bodydict.get(envir.get('PATH_INFO'), "404'd"))
retval = response.to(responder)
return retval