MCPcopy Index your code
hub / github.com/python/cpython / setup_testing_defaults

Function setup_testing_defaults

Lib/wsgiref/util.py:111–147  ·  view source on GitHub ↗

Update 'environ' with trivial defaults for testing purposes This adds various parameters required for WSGI, including HTTP_HOST, SERVER_NAME, SERVER_PORT, REQUEST_METHOD, SCRIPT_NAME, PATH_INFO, and all of the wsgi.* variables. It only supplies default values, and does not replace

(environ)

Source from the content-addressed store, hash-verified

109 return name
110
111def setup_testing_defaults(environ):
112 """Update 'environ' with trivial defaults for testing purposes
113
114 This adds various parameters required for WSGI, including HTTP_HOST,
115 SERVER_NAME, SERVER_PORT, REQUEST_METHOD, SCRIPT_NAME, PATH_INFO,
116 and all of the wsgi.* variables. It only supplies default values,
117 and does not replace any existing settings for these variables.
118
119 This routine is intended to make it easier for unit tests of WSGI
120 servers and applications to set up dummy environments. It should *not*
121 be used by actual WSGI servers or applications, since the data is fake!
122 """
123
124 environ.setdefault('SERVER_NAME','127.0.0.1')
125 environ.setdefault('SERVER_PROTOCOL','HTTP/1.0')
126
127 environ.setdefault('HTTP_HOST',environ['SERVER_NAME'])
128 environ.setdefault('REQUEST_METHOD','GET')
129
130 if 'SCRIPT_NAME' not in environ and 'PATH_INFO' not in environ:
131 environ.setdefault('SCRIPT_NAME','')
132 environ.setdefault('PATH_INFO','/')
133
134 environ.setdefault('wsgi.version', (1,0))
135 environ.setdefault('wsgi.run_once', 0)
136 environ.setdefault('wsgi.multithread', 0)
137 environ.setdefault('wsgi.multiprocess', 0)
138
139 from io import StringIO, BytesIO
140 environ.setdefault('wsgi.input', BytesIO())
141 environ.setdefault('wsgi.errors', StringIO())
142 environ.setdefault('wsgi.url_scheme',guess_scheme(environ))
143
144 if environ['wsgi.url_scheme']=='http':
145 environ.setdefault('SERVER_PORT', '80')
146 elif environ['wsgi.url_scheme']=='https':
147 environ.setdefault('SERVER_PORT', '443')
148
149
150

Callers 2

__init__Method · 0.90
testEnvironMethod · 0.90

Calls 4

BytesIOClass · 0.90
StringIOClass · 0.90
guess_schemeFunction · 0.85
setdefaultMethod · 0.45

Tested by 2

__init__Method · 0.72
testEnvironMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…