本文整理汇总了Python中webob.Request.remote_user方法的典型用法代码示例。如果您正苦于以下问题:Python Request.remote_user方法的具体用法?Python Request.remote_user怎么用?Python Request.remote_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webob.Request
的用法示例。
在下文中一共展示了Request.remote_user方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: simpleapp
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import remote_user [as 别名]
def simpleapp(environ, start_response):
status = '200 OK'
response_headers = [('Content-type','text/plain')]
start_response(status, response_headers)
request = Request(environ)
request.remote_user = 'bob'
return [
'Hello world!\n',
'The get is %r' % request.GET,
' and Val is %s\n' % request.GET.get('name'),
'The languages are: %s\n' % request.accept_language.best_matches('en-US'),
'The accepttypes is: %s\n' % request.accept.best_match(['application/xml', 'text/html']),
'post is %r\n' % request.POST,
'params is %r\n' % request.params,
'cookies is %r\n' % request.cookies,
'body: %r\n' % request.body,
'method: %s\n' % request.method,
'remote_user: %r\n' % request.environ['REMOTE_USER'],
'host_url: %r; application_url: %r; path_url: %r; url: %r\n' % (request.host_url, request.application_url, request.path_url, request.url),
'urlvars: %r\n' % request.urlvars,
'urlargs: %r\n' % (request.urlargs, ),
'is_xhr: %r\n' % request.is_xhr,
'if_modified_since: %r\n' % request.if_modified_since,
'user_agent: %r\n' % request.user_agent,
'if_none_match: %r\n' % request.if_none_match,
]
示例2: simpleapp
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import remote_user [as 别名]
def simpleapp(environ, start_response):
status = "200 OK"
response_headers = [("Content-type", "text/plain")]
start_response(status, response_headers)
request = Request(environ)
request.remote_user = "bob"
return [
"Hello world!\n",
"The get is %r" % request.GET,
" and Val is %s\n" % request.GET.get("name"),
"The languages are: %s\n" % request.accept_language.best_matches("en-US"),
"The accepttypes is: %s\n" % request.accept.best_match(["text/html", "application/xml"]),
"post is %r\n" % request.POST,
"params is %r\n" % request.params,
"cookies is %r\n" % request.cookies,
"body: %r\n" % request.body,
"method: %s\n" % request.method,
"remote_user: %r\n" % request.environ["REMOTE_USER"],
"host_url: %r; application_url: %r; path_url: %r; url: %r\n"
% (request.host_url, request.application_url, request.path_url, request.url),
"urlvars: %r\n" % request.urlvars,
"urlargs: %r\n" % (request.urlargs,),
"is_xhr: %r\n" % request.is_xhr,
"if_modified_since: %r\n" % request.if_modified_since,
"user_agent: %r\n" % request.user_agent,
"if_none_match: %r\n" % request.if_none_match,
]
示例3: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import remote_user [as 别名]
def __call__(self, environ, start_response):
req = Request(environ)
step = req.path_info.strip('/')
try:
if step in [i[0] for i in self.steps]:
# determine which step we are on
index = [i[0] for i in self.steps].index(step)
else:
# delegate to Trac
environ['trac.env_parent_dir'] = self.directory
environ['trac.env_index_template'] = self.index
# data for index template
if req.remote_user and self.remote_user_name:
# XXX fails if unicode
req.remote_user = str(self.remote_user_name(req.remote_user))
data = { 'remote_user': req.remote_user or '',
'auth': self.auth and 'yes' or ''
}
environ['trac.template_vars'] = ','.join(["%s=%s" % (key, value) for key, value in data.items()])
return dispatch_request(environ, start_response)
# if self.auth, enforce remote_user to be set
if self.auth and not req.remote_user:
return exc.HTTPUnauthorized()(environ, start_response)
# if POST-ing, validate the request and store needed information
errors = []
name, step = self.steps[index]
base_url = req.url.rsplit(step.name, 1)[0]
project = req.params.get('project')
if req.method == 'POST':
# check for project existence
if not project and index:
res = exc.HTTPSeeOther("No session found", location="create-project")
return res(environ, start_response)
if index:
if project not in self.projects:
errors.append('Project not found')
project_data = self.projects.get(project)
errors = step.errors(project_data, req.POST)
if not index:
project_data = self.projects[project] = {}
# set *after* error check so that `create-project` doesn't find itself
project_data['base_url'] = base_url
if not errors: # success
step.transition(project_data, req.POST)
# find the next step and redirect to it
while True:
index += 1
if index == len(self.steps):
destination = self.done % self.projects[project]['vars']
time.sleep(1) # XXX needed?
self.projects.pop(project) # successful project creation
break
else:
name, step = self.steps[index]
if step.display(project_data):
destination = '%s?project=%s' % (self.steps[index][0], project)
break
else:
step.transition(project_data, {})
res = exc.HTTPSeeOther(destination, location=destination)
return res(environ, start_response)
else: # GET
project_data = self.projects.get(project, {})
project_data['base_url'] = base_url
if index and project not in self.projects:
res = exc.HTTPSeeOther("No session found", location="create-project")
return res(environ, start_response)
# render the template and return the response
data = step.data(project_data)
data['req'] = req
data['errors'] = errors
template = self.loader.load(step.template)
html = template.generate(**data).render('html', doctype='html')
res = Response(content_type='text/html', body=html)
return res(environ, start_response)
except:
# error handling
exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
buffer = StringIO()
traceback.print_exception(exceptionType, exceptionValue, exceptionTraceback,
limit=20, file=buffer)
res = exc.HTTPServerError(buffer.getvalue())
return res(environ, start_response)