本文整理汇总了Python中webob.Request.path_info方法的典型用法代码示例。如果您正苦于以下问题:Python Request.path_info方法的具体用法?Python Request.path_info怎么用?Python Request.path_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webob.Request
的用法示例。
在下文中一共展示了Request.path_info方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wsgi_app
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info [as 别名]
def wsgi_app(self, environ, start_response):
self.host_framework.start_request(environ)
environ['paste.registry'].register(tw.framework, self.host_framework)
#XXX Do we really need to stuff these in environ?
environ['toscawidgets.prefix'] = self.prefix
environ.setdefault('toscawidgets.framework', self.host_framework)
environ.setdefault('toscawidgets.javascript.require_once', self.require_once)
req = Request(environ)
try:
tw.framework.script_name = req.script_name
if self.serve_resources and req.path_info.startswith(self.prefix):
# Intercept request to possibly serve a static resource
req.path_info = req.path_info[len(self.prefix):]
req.script_name += self.prefix
resources_app = resources.registry
if req.path_info.startswith(resources_app.prefix):
req.path_info = req.path_info[len(resources_app.prefix):]
req.script_name += resources_app.prefix
resp = req.get_response(resources_app)
return resp(environ, start_response)
else:
# Pass request downstream
resp = req.get_response(self.application)
return resp(environ, start_response)
finally:
self.host_framework.end_request(environ)
示例2: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info [as 别名]
def __call__(self, environ, start_response):
request = Request(environ)
if request.path == '/':
request.path_info = '/index.html'
app = static
elif request.path.startswith('/static/'):
request.path_info = request.path_info[8:]
app = static
else:
app = self.traverse(request)
return app(environ, start_response)
示例3: publish
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info [as 别名]
def publish(self, environ, bind=None):
"""Return response for request given by ``environ``."""
request = Request(environ)
path = request.path_info
controller = self.match(path)
if controller is None:
if path.endswith('/'):
path = path.rstrip('/')
else:
path = path + '/'
controller = self.match(path)
if controller is not None:
request.path_info = path
response = HTTPMovedPermanently(location=request.url)
else:
response = HTTPNotFound("Page not found.")
else:
if bind is not None:
controller = types.MethodType(controller, bind)
try:
response = controller(request)
except HTTPError as e:
response = e
except HTTPException as e: # pragma no cover
response = e.wsgi_response
return response
示例4: application
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info [as 别名]
def application(environ, start_response):
req = Request(environ)
if req.path_info == "/redirect":
req.path_info = "/path"
resp = exc.HTTPFound(location=req.path)
else:
resp = Response()
resp.body = '<html><body><a href="%s">link</a></body></html>' % req.path
return resp(environ, start_response)
示例5: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info [as 别名]
def __call__(self, environ, start_response):
assert not environ["wsgi.multiprocess"], "Dozer middleware is not usable in a " "multi-process environment"
req = Request(environ)
req.base_path = req.application_url + self.path
if req.path_info.startswith(self.path + "/") or req.path_info == self.path:
req.script_name += self.path
req.path_info = req.path_info[len(self.path) :]
return self.dowse(req)(environ, start_response)
else:
return self.app(environ, start_response)
示例6: application
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info [as 别名]
def application(environ, start_response):
req = Request(environ)
if req.path_info == '/redirect':
req.path_info = '/path'
resp = Response()
resp.status = '302 Found'
resp.location = req.path
else:
resp = Response()
resp.body = to_bytes('<html><body><a href="%s">link</a></body></html>' % req.path)
return resp(environ, start_response)
示例7: scan
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info [as 别名]
def scan(req, path):
files = []
for file in os.listdir(path):
_file = file
file = req.path_info.rstrip('/') + '/' + file
data = {'url': file}
filepath = os.path.join(path, _file)
if os.path.isdir(filepath):
_req = Request(req.environ.copy())
_req.path_info = file
subfiles = scan(_req, filepath)
data['children'] = subfiles
files.append(data)
return files
示例8: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info [as 别名]
def __call__(self, environ, start_response):
assert not environ['wsgi.multiprocess'], (
"Leak middleware is not usable in a "
"multi-process environment")
if self.inupy_config['ipfilter'] and not check_ipfilter(environ,
self.inupy_config['ipfilter']):
# then we want to filter on ip and this one failed
return self.app(environ, start_response)
else:
req = Request(environ)
req.base_path = req.application_url + self.path
if (req.path_info.startswith(self.path+'/')
or req.path_info == self.path):
req.script_name += self.path
req.path_info = req.path_info[len(self.path):]
return self.dowse(req)(environ, start_response)
else:
return self.app(environ, start_response)
示例9: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info [as 别名]
def __call__(self, environ, start_response):
"""
This method is called for each request. It looks for a user-supplied
CSRF token in the GET/POST parameters, and compares it to the token
attached to ``environ['repoze.who.identity']['_csrf_token']``. If it
does not match, or if a token is not provided, it will remove the
user from the ``environ``, based on the ``clear_env`` setting.
"""
request = Request(environ)
log.debug("CSRFProtectionMiddleware(%s)" % request.path)
token = environ.get('repoze.who.identity', {}).get(self.csrf_token_id)
csrf_token = environ.get(self.token_env)
if token and csrf_token and token == csrf_token:
log.debug("User supplied CSRF token matches environ!")
else:
if not environ.get(self.auth_state):
log.debug("Clearing identity")
CSRFMetadataProvider.clean_environ(environ, self.clear_env)
if csrf_token:
log.warning("Invalid CSRF token. User supplied (%s) "
"does not match what's in our environ (%s)"
% (csrf_token, token))
if not environ.get(self.auth_state):
log.debug("Logging the user out")
request.path_info = '/logout_handler'
response = request.get_response(self.application)
response.status = '401'
return response(environ, start_response)
response = request.get_response(self.application)
if environ.get(self.auth_state):
log.debug("CSRF_AUTH_STATE; rewriting headers")
token = environ.get('repoze.who.identity', {}).get(self.csrf_token_id)
loc = update_qs(response.location, {self.csrf_token_id: str(token)})
response.location = loc
log.debug("response.location = %s" % response.location)
environ[self.auth_state] = None
return response(environ, start_response)
示例10: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info [as 别名]
def __call__(self, environ, start_response):
'''
Searches through available routes to see if any of them match the current
request, if so, passes the request off to the controller.
Returns:
framework.Response response -- The response from the controller
'''
self.debug('\nNew Request ----------')
request = Request(environ)
self.debug('Remote addr: %s' % request.remote_addr)
# Try to find /some/ sort of request path
if (request.path_info == ""):
request.path_info = request.environ['REQUEST_URI']
for route, controller in self.routes:
match = route.match(request.path_info)
if (match):
self.debug('Route matched to %s' % request.path_info)
if (type(controller) == type):
self.debug('Controller was an Application.')
# Test to see if it's an Application (has a handle method)
controller = controller(environ, start_response)
return controller.handle(match.groupdict())
else:
self.debug('Controller was a function.')
# Alternatively, fall back on the assumption that this is a function
return controller(environ, start_response, **match.groupdict())
else:
self.debug('No route matched to %s' % request.path_info)
# If there is no route, 404
return exc.HTTPNotFound()(environ, start_response)
示例11: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info [as 别名]
def __call__(self, environ, start_response):
request = Request(environ)
request.path_info = request.path_info.rstrip('/')
res = self.handle_request(request)
return res(environ, start_response)