本文整理匯總了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