本文整理汇总了Python中webob.Request.path_info_peek方法的典型用法代码示例。如果您正苦于以下问题:Python Request.path_info_peek方法的具体用法?Python Request.path_info_peek怎么用?Python Request.path_info_peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webob.Request
的用法示例。
在下文中一共展示了Request.path_info_peek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info_peek [as 别名]
def __call__(self, environ, start_response):
req = Request(environ)
if "deliv_notheme" in req.GET:
return self.app(environ, start_response)
req.environ["deliverance.base_url"] = req.application_url
## FIXME: copy_get?:
orig_req = Request(environ.copy())
if "deliverance.log" in req.environ:
log = req.environ["deliverance.log"]
else:
log = self.log_factory(req, self, **self.log_factory_kw)
## FIXME: should this be put in both the orig_req and this req?
req.environ["deliverance.log"] = log
def resource_fetcher(url, retry_inner_if_not_200=False):
"""
Return the Response object for the given URL
"""
return self.get_resource(url, orig_req, log, retry_inner_if_not_200)
if req.path_info_peek() == ".deliverance":
req.path_info_pop()
resp = self.internal_app(req, resource_fetcher)
return resp(environ, start_response)
rule_set = self.rule_getter(resource_fetcher, self.app, orig_req)
clientside = rule_set.check_clientside(req, log)
if clientside and req.url in self.known_html:
if req.cookies.get("jsEnabled"):
log.debug(self, "Responding to %s with a clientside theme" % req.url)
return self.clientside_response(req, rule_set, resource_fetcher, log)(environ, start_response)
else:
log.debug(self, "Not doing clientside theming because jsEnabled cookie not set")
resp = req.get_response(self.app)
## FIXME: also XHTML?
if resp.content_type != "text/html":
## FIXME: remove from known_html?
return resp(environ, start_response)
# XXX: Not clear why such responses would have a content type, but
# they sometimes do (from Zope/Plone, at least) and that then breaks
# when trying to apply a theme.
if resp.status_int in (301, 302, 304):
return resp(environ, start_response)
if resp.content_length == 0:
return resp(environ, start_response)
if clientside and req.url not in self.known_html:
log.debug(
self, "%s would have been a clientside check; in future will be since we know it is HTML" % req.url
)
self.known_titles[req.url] = self._get_title(resp.body)
self.known_html.add(req.url)
resp = rule_set.apply_rules(req, resp, resource_fetcher, log, default_theme=self.default_theme)
if clientside:
resp.decode_content()
resp.body = self._substitute_jsenable(resp.body)
resp = log.finish_request(req, resp)
return resp(environ, start_response)
示例2: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info_peek [as 别名]
def __call__(self, environ, start_response):
req = Request(environ)
if req.path_info_peek() == '.media':
req.path_info_pop()
app = StaticURLParser(os.path.join(os.path.dirname(__file__), 'media'))
return app(environ, start_response)
if self.base_dir:
filename = os.path.join(self.base_dir, req.path_info.lstrip('/'))
assert filename.startswith(self.base_dir)
else:
filename = self.filename
if req.method not in ('GET', 'POST'):
resp = exc.HTTPMethodNotAllowed('Bad method: %s' % req.method,
allow='GET,POST')
elif os.path.isdir(filename):
if req.method == 'POST':
resp = self.save_create(req, filename)
else:
if not req.path.endswith('/'):
resp = exc.HTTPMovedPermanently(add_slash=True)
else:
resp = self.view_dir(req, filename)
else:
if req.method == 'POST':
resp = self.save_file(req, filename)
elif req.method == 'GET':
resp = self.edit_file(req, filename)
return resp(environ, start_response)
示例3: application
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info_peek [as 别名]
def application(environ, start_response):
"""Determine the user's country based on their IP address."""
request = Request(environ)
response = Response(
status=200,
cache_control=('no-store, no-cache, must-revalidate, post-check=0, '
'pre-check=0, max-age=0'),
pragma='no-cache',
expires='02 Jan 2010 00:00:00 GMT',
)
client_ip = request.headers.get('HTTP_X_CLUSTER_CLIENT_IP',
request.client_addr)
geo_data = {
'country_code': geoip.country_code_by_addr(client_ip),
'country_name': geoip.country_name_by_addr(client_ip),
}
# Users can request either a JavaScript file or a JSON file for the output.
path = request.path_info_peek()
if path == 'country.js':
response.content_type = 'text/javascript'
response.body = """
function geoip_country_code() {{ return '{country_code}'; }}
function geoip_country_name() {{ return '{country_name}'; }}
""".format(**geo_data)
elif path == 'country.json':
response.content_type = 'application/json'
response.body = json.dumps(geo_data)
else:
response.status = 404
response.content_type = 'application/json'
response.body = json.dumps({'error': 'Function not supported.'})
return response(environ, start_response)
示例4: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info_peek [as 别名]
def __call__(self, environ, start_response):
req = Request(environ)
path = req.path_info_peek()
if path == "theme.html":
return self.theme(environ, start_response)
if path == "login":
return self.login(environ, start_response)
if path == "logout":
if '__ac' in req.cookies:
res = Response()
res.status = 304
res.location = "/"
res.delete_cookie("__ac")
return res(environ, start_response)
if path == "projects":
req.path_info_pop()
project = req.path_info_pop()
path = req.path_info_peek()
if path == "info.xml":
return Response("""
<info>
<policy>medium_policy</policy>
<featurelets>
<featurelet>blog</featurelet>
<featurelet>wikis</featurelet>
<featurelet>tasks</featurelet>
<featurelet>listen</featurelet>
</featurelets>
</info>""", content_type="application/xml")(environ, start_response)
if path == "members.xml":
return Response("""
<members>
<member>
<id>ejucovy</id>
<role>ProjectAdmin</role>
</member>
</members>""", content_type="application/xml")(environ, start_response)
return Response(req.path_info_peek(), content_type='text/plain')(environ, start_response)
示例5: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info_peek [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 + '/_profiler'
if req.path_info_peek() == '_profiler':
return self.profiler(req)(environ, start_response)
for regex in self.ignored_paths:
if regex.match(environ['PATH_INFO']) is not None:
return self.app(environ, start_response)
return self.run_profile(environ, start_response)
示例6: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info_peek [as 别名]
def __call__(self, environ, start_response):
req = Request(environ)
if req.GET.get('__pdbid__'):
id = int(req.GET['__pdbid__'])
response = self.states[id]['response']
return response(environ, start_response)
if req.path_info_peek() == '.pdbcapture':
req.path_info_pop()
if req.path_info_peek() == 'static':
req.path_info_pop()
return self.static_app(environ, start_response)
if req.path_info_peek() == 'media':
req.path_info_pop()
return self.media_app(environ, start_response)
resp = self.internal_request(req)
return resp(environ, start_response)
id = self.counter.next()
state = dict(id=id,
event=threading.Event(),
base_url=req.application_url,
stdout=[],
stdin=[],
stdin_event=threading.Event())
t = threading.Thread(target=self.call_app, args=(req, state))
t.setDaemon(True)
t.start()
state['event'].wait()
if 'response' in state:
# Normal request, nothing happened
resp = state['response']
return resp(environ, start_response)
if 'exc_info' in state:
raise state['exc_info'][0], \
state['exc_info'][1], state['exc_info'][2]
self.states[id] = state
tmpl = self.get_template('pdbcapture_response.html')
body = tmpl.substitute(req=req, state=state, id=id)
resp = Response(body)
return resp(environ, start_response)
示例7: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info_peek [as 别名]
def __call__(self, environ, start_response):
## FIXME: print better error message (maybe fall back on
## normal middleware, plus an error message)
assert not environ['wsgi.multiprocess'], (
"The EvalException middleware is not usable in a "
"multi-process environment")
# XXX: Legacy support for Paste restorer
environ['weberror.evalexception'] = environ['paste.evalexception'] = \
self
req = Request(environ)
if req.path_info_peek() == '_debug':
return self.debug(req)(environ, start_response)
else:
return self.respond(environ, start_response)
示例8: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info_peek [as 别名]
def __call__(self, environ, start_response):
"""
This will be called when the application is being run. This can be
either:
- a request to the __profiler__ framework to display profiled
information, or
- a normal request that will be profiled.
Returns the WSGI application.
"""
# If we're not accessing the profiler, profile the request.
req = Request(environ)
self.profiling_enabled = os.path.exists(ENABLED_FLAG_FILE)
if req.path_info_peek() != self.profiler_path.strip('/'):
if not self.profiling_enabled:
return self.app(environ, start_response)
_locals = locals()
prof = Profile()
start_timestamp = datetime.now()
prof.runctx(
"app = self.app(environ, start_response)", globals(), _locals)
stats = prof.getstats()
session = ProfilingSession(stats, environ, start_timestamp)
self._backend.add(session)
return _locals['app']
req.path_info_pop()
# We could import `routes` and use something like that here, but since
# not all frameworks use this, it might become an external dependency
# that isn't needed. So parse the URL manually using :class:`webob`.
query_param = req.path_info_pop()
if not query_param:
wsgi_app = self.list_profiles(req)
elif query_param == "graph":
wsgi_app = self.render_graph(req)
elif query_param == "media":
wsgi_app = self.media(req)
elif query_param == "profiles":
wsgi_app = self.show_profile(req)
elif query_param == "delete":
wsgi_app = self.delete_profile(req)
else:
wsgi_app = HTTPNotFound()
return wsgi_app(environ, start_response)
示例9: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info_peek [as 别名]
def __call__(self, environ, start_response):
req = Request(environ)
if req.path_info_peek() == '.comments':
return self.process_comment(req)(environ, start_response)
# This is the base path of *this* middleware:
base_url = req.application_url
resp = req.get_response(self.app)
if resp.content_type != 'text/html' or resp.status_int != 200:
# Not an HTML response, we don't want to
# do anything to it
return resp(environ, start_response)
# Make sure the content isn't gzipped:
resp.decode_content()
comments = self.get_data(req.url)
body = resp.body
body = self.add_to_end(body, self.format_comments(comments))
body = self.add_to_end(body, self.submit_form(base_url, req))
resp.body = body
return resp(environ, start_response)
示例10: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info_peek [as 别名]
def __call__(self, environ, start_response):
assert not environ['wsgi.multiprocess'], (
"Inupy 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 + '/_profiler'
if req.path_info_peek() == '_profiler':
return self.profiler(req)(environ, start_response)
for regex in self.ignored_paths:
if regex.match(environ['PATH_INFO']) is not None:
return self.app(environ, start_response)
return self.run_profile(environ, start_response)
示例11: application
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info_peek [as 别名]
def application(environ, start_response):
"""Determine the user's country based on their IP address."""
request = Request(environ)
response = Response(
status=200,
cache_control=('no-store, no-cache, must-revalidate, post-check=0, '
'pre-check=0, max-age=0'),
pragma='no-cache',
expires='02 Jan 2010 00:00:00 GMT',
)
if getattr(settings, 'ALLOW_POST', False) and request.method == 'POST':
if 'ip' in request.POST:
client_ip = request.POST['ip']
else:
response = error(response, 400, '`ip` required in POST body.')
return response(environ, start_response)
else:
client_ip = request.headers.get('X-Cluster-Client-IP',
request.client_addr)
geo_data = {
'country_code': geoip.country_code_by_addr(client_ip),
'country_name': geoip.country_name_by_addr(client_ip),
}
# Users can request either a JavaScript file or a JSON file for the output.
path = request.path_info_peek()
if path == 'country.js':
response.content_type = 'text/javascript'
response.body = """
function geoip_country_code() {{ return '{country_code}'; }}
function geoip_country_name() {{ return '{country_name}'; }}
""".format(**geo_data)
elif path == 'country.json':
response.content_type = 'application/json'
response.body = json.dumps(geo_data)
else:
response = error(response, 404, 'Function not supported.')
return response(environ, start_response)
示例12: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info_peek [as 别名]
def __call__(self, environ, start_response):
from webob import Request
req = Request(environ)
if req.path_info_peek() == ".comments":
return self.process_comment(req)(environ, start_response)
# URL without PATH_INFO:
base_url = req.application_url
resp = req.get_response(self.app)
if resp.content_type != "text/html" or resp.status_int != 200:
# Not an HTML response, we don't want to
# do anything to it
return resp(environ, start_response)
# Make sure the content isn't gzipped:
resp.decode_content()
comments = self.get_data(req.url)
body = resp.body
body = self.add_to_end(body, self.format_comments(comments))
body = self.add_to_end(body, self.submit_form(base_url, req))
resp.body = body
return resp(environ, start_response)
示例13: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info_peek [as 别名]
def __call__(self, environ, start_response):
req = Request(environ)
if self.notheme_request(req):
return self.app(environ, start_response)
req.environ['deliverance.base_url'] = req.application_url
## FIXME: copy_get?:
orig_req = Request(environ.copy())
if 'deliverance.log' in req.environ:
log = req.environ['deliverance.log']
else:
log = self.log_factory(req, self, **self.log_factory_kw)
## FIXME: should this be put in both the orig_req and this req?
req.environ['deliverance.log'] = log
def resource_fetcher(url, retry_inner_if_not_200=False):
"""
Return the Response object for the given URL
"""
return self.get_resource(url, orig_req, log, retry_inner_if_not_200)
if req.path_info_peek() == '.deliverance':
req.path_info_pop()
resp = self.internal_app(req, resource_fetcher)
return resp(environ, start_response)
rule_set = self.rule_getter(resource_fetcher, self.app, orig_req)
clientside = rule_set.check_clientside(req, log)
if clientside and req.url in self.known_html:
if req.cookies.get('jsEnabled'):
log.debug(self, 'Responding to %s with a clientside theme' % req.url)
return self.clientside_response(req, rule_set, resource_fetcher, log)(environ, start_response)
else:
log.debug(self, 'Not doing clientside theming because jsEnabled cookie not set')
head_response = None
if req.method == "HEAD":
# We need to copy the request instead of reusing it,
# in case the downstream app modifies req.environ in-place
head_req = req.copy()
head_response = head_req.get_response(self.app)
req.method = "GET"
resp = req.get_response(self.app)
## FIXME: also XHTML?
if resp.content_type != 'text/html':
## FIXME: remove from known_html?
return resp(environ, start_response)
# XXX: Not clear why such responses would have a content type, but
# they sometimes do (from Zope/Plone, at least) and that then breaks
# when trying to apply a theme.
if resp.status_int in (301, 302, 304):
return resp(environ, start_response)
if resp.content_length == 0:
return resp(environ, start_response)
if resp.body == '':
return resp(environ, start_response)
if clientside and req.url not in self.known_html:
log.debug(self, '%s would have been a clientside check; in future will be since we know it is HTML'
% req.url)
self.known_titles[req.url] = self._get_title(resp.body)
self.known_html.add(req.url)
resp = rule_set.apply_rules(req, resp, resource_fetcher, log,
default_theme=self.default_theme(environ))
if clientside:
resp.decode_content()
resp.body = self._substitute_jsenable(resp.body)
resp = log.finish_request(req, resp)
if head_response:
head_response.headers = resp.headers
resp = head_response
return resp(environ, start_response)
示例14: __call__
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info_peek [as 别名]
def __call__(self, environ, start_response):
req = Request(environ)
if req.path_info_peek() == "stop":
log.info("Received a /stop HTTP request, stopping the runner.")
self.running = False
self.runner.running = False
start_response("200 OK", [("Content-type", "text/plain")])
return "Stopping server"
if not self.runner.running:
start_response("500 Internal Server Error",
[("Content-type", "text/plain")])
return "Error: The Runner is not running"
if not self.runner.ua_string:
self.runner.ua_string = req.user_agent
if (not self.runner.options.nouacheck and
self.runner.ua_string and
self.runner.ua_string != req.user_agent):
start_response("500 Internal Server Error",
[("Content-type", "text/plain")])
return (("The server received a request from a different user "
"agent.\n Original ua: %s\n This ua: %s\n"
"You should restart the server or use the original "
"user agent.") %
(self.runner.ua_string, req.user_agent))
if req.path_info_peek() == "imagestore":
return self._handle_image_store(req, start_response)
if req.path_info_peek() == "report":
return self._create_report(environ, start_response)
if (req.path_info == "/" or
req.path_info == "/favicon.ico" or
req.path_info == ("/browsertest.js") or
req.path_info == ("/browsertest.css") or
req.path_info.startswith("/testrunner") or
# For Mochitests:
req.path_info.startswith("/MochiKit") or
req.path_info.startswith("/tests/SimpleTest/")):
return self.resourcesapp(environ, start_response)
if req.path_info_peek() == "rpc":
return self.rpcapp(environ, start_response)
if req.path_info.endswith(".py") and self.tests_path:
script = req.path_info.lstrip("/")
cgiapp = PythonCGIApplication({}, script=script, path=[self.tests_path])
return cgiapp(environ, start_response)
if self.localtests_app:
return self.localtests_app(environ, start_response)
if self.remotetests_app:
return self.remotetests_app(environ, start_response)
# Default response
start_response("404 Not found", [("Content-type", "text/plain")])
return "Not found"
示例15: pprint
# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import path_info_peek [as 别名]
#pprint(req.environ)
# 'GET'
req_method=req.method
#pprint(req.method)
#
req_dir=dir(req)
# req
# <Request at 0x27cd9e8 (invalid WSGI environ)>
req=Request.blank('/article?id=1&id=2')
pprint(req.environ)
# demo for request body
req.body='This is a request body'
req.path_info_peek()
req.path_info_pop()
req.script_name
# Headers
req.headers['Content-Type'] = 'application/x-www-urlencoded'
req.headers.items()
req.environ['CONTENT_TYPE']
# Query & POST
req = Request.blank('/test?check=a&check=b&name=Bob')
req.GET
req.GET['check']
req.GET.getall('check')
req.GET.items()
req.GET.values()