本文整理汇总了Python中wsgiref.util.request_uri方法的典型用法代码示例。如果您正苦于以下问题:Python util.request_uri方法的具体用法?Python util.request_uri怎么用?Python util.request_uri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wsgiref.util
的用法示例。
在下文中一共展示了util.request_uri方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkReqURI
# 需要导入模块: from wsgiref import util [as 别名]
# 或者: from wsgiref.util import request_uri [as 别名]
def checkReqURI(self,uri,query=1,**kw):
util.setup_testing_defaults(kw)
self.assertEqual(util.request_uri(kw,query),uri)
示例2: collect_request_attributes
# 需要导入模块: from wsgiref import util [as 别名]
# 或者: from wsgiref.util import request_uri [as 别名]
def collect_request_attributes(environ):
"""Collects HTTP request attributes from the PEP3333-conforming
WSGI environ and returns a dictionary to be used as span creation attributes."""
result = {
"component": "http",
"http.method": environ.get("REQUEST_METHOD"),
"http.server_name": environ.get("SERVER_NAME"),
"http.scheme": environ.get("wsgi.url_scheme"),
}
host_port = environ.get("SERVER_PORT")
if host_port is not None:
result.update({"host.port": int(host_port)})
setifnotnone(result, "http.host", environ.get("HTTP_HOST"))
target = environ.get("RAW_URI")
if target is None: # Note: `"" or None is None`
target = environ.get("REQUEST_URI")
if target is not None:
result["http.target"] = target
else:
result["http.url"] = wsgiref_util.request_uri(environ)
remote_addr = environ.get("REMOTE_ADDR")
if remote_addr:
result["net.peer.ip"] = remote_addr
remote_host = environ.get("REMOTE_HOST")
if remote_host and remote_host != remote_addr:
result["net.peer.name"] = remote_host
setifnotnone(result, "net.peer.port", environ.get("REMOTE_PORT"))
flavor = environ.get("SERVER_PROTOCOL", "")
if flavor.upper().startswith(_HTTP_VERSION_PREFIX):
flavor = flavor[len(_HTTP_VERSION_PREFIX) :]
if flavor:
result["http.flavor"] = flavor
return result
示例3: __call__
# 需要导入模块: from wsgiref import util [as 别名]
# 或者: from wsgiref.util import request_uri [as 别名]
def __call__(self, environ, start_response):
path = environ["PATH_INFO"]
url = util.request_uri(environ)
try:
request_body_size = int(environ.get('CONTENT_LENGTH', 0))
except (ValueError):
request_body_size = 0
request_body = environ['wsgi.input'].read(request_body_size)
request = _HTTPRequest(url)
request.setMethod(environ["REQUEST_METHOD"])
request.setBody(request_body)
request.setHeader("Content-Type", environ["CONTENT_TYPE"])
request.setHeader("Content-Length", request_body_size)
for key in environ:
if key.startswith("HTTP_"):
request.setHeader(key[5:], environ[key])
response = _HTTPResponse()
with self.lock:
servlet = self.servlets.get(path, None)
if servlet is None:
start_response("404 Not Found", [("Content-Type", "text/plain")])
yield "404 Not Found (%r)" % path
return
self.runtime.events.put((self.call_servlet, (servlet, request, response), {}))
try:
self.runtime.acquire()
while not response._responded:
self.runtime.wait(60)
finally:
self.runtime.release()
for chunk in servlet.respond(environ, start_response, request, response):
yield chunk