/
wsgi.py
97 lines (74 loc) · 2.93 KB
/
wsgi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def response_handler(environ, start_response):
"""The WSGI Application Server.
Arguments:
environ {dict} -- The WSGI environ dictionary
start_response {WSGI callable}
Returns:
WSGI Response
"""
from wsgi import container
"""Add Environ To Service Container
Add the environ to the service container. The environ is generated by the
the WSGI server above and used by a service provider to manipulate the
incoming requests
"""
container.bind("Environ", environ)
"""Execute All Service Providers That Require The WSGI Server
Run all service provider boot methods if the wsgi attribute is true.
"""
try:
for provider in container.make("WSGIProviders"):
container.resolve(provider.boot)
except Exception as e:
container.make("ExceptionHandler").load_exception(e)
"""We Are Ready For Launch
If we have a solid response and not redirecting then we need to return
a 200 status code along with the data. If we don't, then we'll have
to return a 302 redirection to where ever the user would like go
to next.
"""
from masonite.response import Response
response = container.make(Response)
start_response(response.get_status_code(), response.get_and_reset_headers())
"""Final Step
This will take the data variable from the Service Container and return
it to the WSGI server.
"""
return iter([response.get_response_content()])
def package_response_handler(environ, start_response):
"""The WSGI Application Server.
Arguments:
environ {dict} -- The WSGI environ dictionary
start_response {WSGI callable}
Returns:
WSGI Response
"""
from wsgi import container
"""Add Environ To Service Container
Add the environ to the service container. The environ is generated by the
the WSGI server above and used by a service provider to manipulate the
incoming requests
"""
container.bind("Environ", environ)
"""Execute All Service Providers That Require The WSGI Server
Run all service provider boot methods if the wsgi attribute is true.
"""
try:
for provider in container.make("WSGIProviders"):
container.resolve(provider.boot)
except Exception as e:
container.make("ExceptionHandler").load_exception(e)
"""We Are Ready For Launch
If we have a solid response and not redirecting then we need to return
a 200 status code along with the data. If we don't, then we'll have
to return a 302 redirection to where ever the user would like go
to next.
"""
from src.masonite.response import Response
response = container.make(Response)
start_response(response.get_status_code(), response.get_and_reset_headers())
"""Final Step
This will take the data variable from the Service Container and return
it to the WSGI server.
"""
return iter([response.get_response_content()])