本文整理汇总了Python中wsgiref.util.application_uri函数的典型用法代码示例。如果您正苦于以下问题:Python application_uri函数的具体用法?Python application_uri怎么用?Python application_uri使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了application_uri函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: serve
def serve(environ, start_response):
root = root_url.lstrip('/')
tail, get = (util.request_uri(environ).split('?') + [''])[:2]
tail = tail[len(util.application_uri(environ)):]
result = []
content_type = 'text/plain'
status = '200 OK'
if tail.startswith(root):
tail = tail[len(root):]
get = parse_qs(get)
method = environ['REQUEST_METHOD']
text, post = '', {}
if method == 'POST':
text = environ['wsgi.input'].\
read(int(environ.get('CONTENT_LENGTH', 0)))
post = parse_qs(text)
response = server.process_request(
Request(tail, text, get, post, {}))
content_type = response.content_type
status = get_http_response_code(response)
result.append(response.text)
headers = [('Content-type', content_type)]
start_response(status, headers)
return result
开发者ID:gustavo-gomez,项目名称:freezing-tyrion,代码行数:35,代码来源:_wsgi.py
示例2: get_schema
def get_schema(self, lang):
## 0. memcache hit -> response
schema = self.cache_get(lang)
if schema:
return schema
url = self.format_url(lang)
## 1. mmemcache miss -> url fetch
try:
schema = jsonloads(urlopen(url).read())
app_uri = application_uri(self.request.environ)
img_fixes = self.img_fixes
for item in schema['result']['items']['item']:
if item['defindex'] in img_fixes:
item['image_url'] = app_uri + img_fixes[item['defindex']]
except (Exception, ), exc:
## 1a. fetch failure -> history lookup
storage = History.all().filter('url =', url).get()
if storage:
## this assumes that the schema has already been
## parsed and fixed at least one time.
schema = jsonloads(storage.payload)
self.cache_set(schema, lang)
else:
## 1b. total failure
schema = {}
开发者ID:natural,项目名称:tf2-api-proxy,代码行数:26,代码来源:proxyapp.py
示例3: handle_application_error
def handle_application_error(self, environ, start_response):
status = "500 Internal Server Error"
headers = Headers([])
# Package the exception info as into a special header and
# send it to the client
type, exc, tb = sys.exc_info()
tbfile = StringIO()
traceback.print_exc(file=tbfile)
headers['Content-Type'] = 'text/plain; charset=utf-8'
LOG.debug("Packing traceback context into debug header: %s",
self.debug_header)
debug_header = self.pack_header(Traceback(tb))
LOG.debug("Debug header (%d bytes): %s",
len(debug_header), debug_header)
headers[self.debug_header] = debug_header
app_uri = application_uri(environ)
headers["Location"] = app_uri[:-1] + self.debug_uri
start_response(status, headers.items())
return [tbfile.getvalue().encode('utf-8')]
开发者ID:te-je,项目名称:ohoh,代码行数:25,代码来源:middleware.py
示例4: serve
def serve(environ, start_response):
root = root_url.lstrip("/")
tail, get = (util.request_uri(environ).split("?") + [""])[:2]
tail = tail[len(util.application_uri(environ)) :]
result = []
content_type = "text/plain"
status = "200 OK"
if tail.lstrip("/").startswith(root):
tail = tail[len(root) :]
get = parse_qs(get)
method = environ["REQUEST_METHOD"]
text, post = "", {}
if method == "POST":
text = environ["wsgi.input"].read(int(environ.get("CONTENT_LENGTH", 0)))
post = parse_qs(text)
response = server.process_request(Request(tail, text, get, post, {}))
content_type = response.content_type
status = get_http_response_code(response)
result.append(response.text)
headers = [("Content-type", content_type)]
start_response(status, headers)
return result
开发者ID:Kjir,项目名称:pyws,代码行数:33,代码来源:_wsgi.py
示例5: __call__
def __call__(environ, start_response):
"""Handle a HTTP request."""
from wsgiref.util import application_uri, shift_path_info
from urlparse import urljoin
try:
import swat
except ImportError as e:
print("NO SWAT: %r" % e)
have_swat = False
else:
have_swat = True
orig_path = environ['PATH_INFO']
name = shift_path_info(environ)
if name == "":
if have_swat:
start_response('301 Redirect',
[('Location', urljoin(application_uri(environ), 'swat')),])
return []
else:
return render_placeholder(environ, start_response)
elif have_swat and name == "swat":
return swat.__call__(environ, start_response)
else:
status = '404 Not found'
response_headers = [('Content-type', 'text/html')]
start_response(status, response_headers)
return ["The path %s (%s) was not found" % (orig_path, name)]
开发者ID:sYnfo,项目名称:samba,代码行数:30,代码来源:__init__.py
示例6: __call__
def __call__(self, environ, start_response):
path = environ["PATH_INFO"]
qs = environ["QUERY_STRING"]
if path == "/":
# Step 1: Get a request token. This is a temporary token that is used for
# having the user authorize an access token and to sign the request to obtain
# said access token.
appuri = application_uri(environ)
if not appuri.endswith("/"):
appuri += "/"
oauth_callback = "%scallback" % appuri
url = "%s?%s" % (self.request_token_url, urllib.urlencode({"oauth_callback": oauth_callback}))
client = self.oauth.Client(self.consumer)
resp, content = client.request(url, "GET")
if resp["status"] != "200":
raise Exception("Invalid response %s." % resp["status"])
request_token = dict(parse_qsl(content))
if "oauth_callback_confirmed" not in request_token or request_token["oauth_callback_confirmed"] != "true":
raise Exception("Oauth callback must be confirmed.")
self.request_tokens[request_token["oauth_token"]] = request_token
# Step 2: Redirect to the provider.
redirect_url = "%s?oauth_token=%s" % (self.authorize_url, request_token["oauth_token"])
start_response("302 Found", [("Location", redirect_url)])
return []
elif path == "/callback":
qsdict = dict(parse_qsl(qs))
if qsdict["oauth_token"] not in self.request_tokens:
raise Exception("invalid token: %s" % self.request_tokens)
request_token = self.request_tokens[qsdict["oauth_token"]]
del self.request_tokens[qsdict["oauth_token"]]
token = self.oauth.Token(request_token["oauth_token"], request_token["oauth_token_secret"])
token.set_verifier(qsdict["oauth_verifier"])
client = self.oauth.Client(self.consumer, token)
resp, content = client.request(self.access_token_url, "POST")
if resp["status"] != "200":
raise Exception("Invalid response %s." % resp["status"])
access_token = dict(parse_qsl(content))
environ["oauth.access_token"] = access_token
return self.onsuccess(environ, start_response)
start_response("404 Not Found", [("Content-Type", "text/plain")])
return ["path not found: %s" % path]
开发者ID:toolness,项目名称:twitblob,代码行数:53,代码来源:twitter_client.py
示例7: checkAppURI
def checkAppURI(self,uri,**kw):
util.setup_testing_defaults(kw)
self.assertEqual(util.application_uri(kw),uri)
开发者ID:524777134,项目名称:cpython,代码行数:3,代码来源:test_wsgiref.py
示例8: form
def form(environ, start_response):
start_response("200 OK", [("Content-type", "text/html;charset=utf-8")])
url = application_uri(environ)
return [form_body.format(url=url).encode("utf-8")]
开发者ID:Machi427,项目名称:python,代码行数:4,代码来源:form_handling.py
示例9: shift_path_info
try:
import swat
except ImportError, e:
print "NO SWAT: %r" % e
have_swat = False
else:
have_swat = True
orig_path = environ['PATH_INFO']
name = shift_path_info(environ)
if name == "":
if have_swat:
start_response('301 Redirect',
[('Location', urljoin(application_uri(environ), 'swat')),])
return []
else:
return render_placeholder(environ, start_response)
elif have_swat and name == "swat":
return swat.__call__(environ, start_response)
else:
status = '404 Not found'
response_headers = [('Content-type', 'text/html')]
start_response(status, response_headers)
return ["The path %s (%s) was not found" % (orig_path, name)]
if __name__ == '__main__':
from wsgiref import simple_server
httpd = simple_server.make_server('localhost', 8090, __call__)
开发者ID:AIdrifter,项目名称:samba,代码行数:30,代码来源:__init__.py
示例10: __init__
def __init__(self, environ: Dict[str, Any], urlmapper: URLMapper) -> None:
self.environ = environ
self.urlmapper = urlmapper
self.application_uri = application_uri(environ)
开发者ID:aodag,项目名称:WebDispatch,代码行数:4,代码来源:urldispatcher.py
示例11: fake_app
def fake_app(req):
return util.application_uri(req.environ)
开发者ID:aishi1979,项目名称:studyKilo,代码行数:2,代码来源:test_http_proxy_to_wsgi.py
示例12: app_url
def app_url(self):
return application_uri(self.request.environ)
开发者ID:natural,项目名称:tf2-api-proxy,代码行数:2,代码来源:lib.py
示例13: send_podcast
def send_podcast(self, environ, podcast_name):
if podcast_name not in self.podcasts:
return self.send_not_found(environ)
baseurl = application_uri(environ) + podcast_name + "/"
podcast = self.podcasts[podcast_name]
return "200 OK", [], podcast.xml(baseurl)
开发者ID:wolever,项目名称:dir2podcast,代码行数:6,代码来源:dir2podcast.py
注:本文中的wsgiref.util.application_uri函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论