MCPcopy Index your code
hub / github.com/webpy/webpy / load

Method load

web/application.py:424–477  ·  view source on GitHub ↗

Initializes ctx using env.

(self, env)

Source from the content-addressed store, hash-verified

422 return wsgiref.handlers.CGIHandler().run(wsgiapp)
423
424 def load(self, env):
425 """Initializes ctx using env."""
426 ctx = web.ctx
427 ctx.clear()
428 ctx.status = "200 OK"
429 ctx.headers = []
430 ctx.output = ""
431 ctx.environ = ctx.env = env
432 ctx.host = env.get("HTTP_HOST")
433
434 if env.get("wsgi.url_scheme") in ["http", "https"]:
435 ctx.protocol = env["wsgi.url_scheme"]
436 elif env.get("HTTPS", "").lower() in ["on", "true", "1"]:
437 ctx.protocol = "https"
438 else:
439 ctx.protocol = "http"
440 ctx.homedomain = ctx.protocol + "://" + env.get("HTTP_HOST", "[unknown]")
441 ctx.homepath = os.environ.get("REAL_SCRIPT_NAME", env.get("SCRIPT_NAME", ""))
442 ctx.home = ctx.homedomain + ctx.homepath
443 # @@ home is changed when the request is handled to a sub-application.
444 # @@ but the real home is required for doing absolute redirects.
445 ctx.realhome = ctx.home
446 ctx.ip = env.get("REMOTE_ADDR")
447 ctx.method = env.get("REQUEST_METHOD")
448 try:
449 ctx.path = bytes(env.get("PATH_INFO"), "latin1").decode("utf8")
450 except UnicodeDecodeError: # If there are Unicode characters...
451 ctx.path = env.get("PATH_INFO")
452
453 # http://trac.lighttpd.net/trac/ticket/406 requires:
454 if env.get("SERVER_SOFTWARE", "").startswith(("lighttpd/", "nginx/")):
455 ctx.path = lstrips(env.get("REQUEST_URI").split("?")[0], ctx.homepath)
456 # Apache and CherryPy webservers unquote urls but lighttpd and nginx do not.
457 # Unquote explicitly for lighttpd and nginx to make ctx.path uniform across
458 # all servers.
459 ctx.path = unquote(ctx.path)
460
461 if env.get("QUERY_STRING"):
462 ctx.query = "?" + env.get("QUERY_STRING", "")
463 else:
464 ctx.query = ""
465
466 ctx.fullpath = ctx.path + ctx.query
467
468 for k, v in iteritems(ctx):
469 # convert all string values to unicode values and replace
470 # malformed data with a suitable replacement marker.
471 if isinstance(v, bytes):
472 ctx[k] = v.decode("utf-8", "replace")
473
474 # status must always be str
475 ctx.status = "200 OK"
476
477 ctx.app_stack = []
478
479 def _delegate(self, f, fvars, args=[]):
480 def handle_class(cls):

Callers 3

wsgiMethod · 0.95
parse_cookiesFunction · 0.80
__getattr__Method · 0.80

Calls 5

bytesClass · 0.85
lstripsFunction · 0.85
clearMethod · 0.80
decodeMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected