MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / check_environ

Function check_environ

tools/python-3.11.9-amd64/Lib/wsgiref/validate.py:298–361  ·  view source on GitHub ↗
(environ)

Source from the content-addressed store, hash-verified

296 "Iterator garbage collected without being closed")
297
298def check_environ(environ):
299 assert_(type(environ) is dict,
300 "Environment is not of the right type: %r (environment: %r)"
301 % (type(environ), environ))
302
303 for key in ['REQUEST_METHOD', 'SERVER_NAME', 'SERVER_PORT',
304 'wsgi.version', 'wsgi.input', 'wsgi.errors',
305 'wsgi.multithread', 'wsgi.multiprocess',
306 'wsgi.run_once']:
307 assert_(key in environ,
308 "Environment missing required key: %r" % (key,))
309
310 for key in ['HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH']:
311 assert_(key not in environ,
312 "Environment should not have the key: %s "
313 "(use %s instead)" % (key, key[5:]))
314
315 if 'QUERY_STRING' not in environ:
316 warnings.warn(
317 'QUERY_STRING is not in the WSGI environment; the cgi '
318 'module will use sys.argv when this variable is missing, '
319 'so application errors are more likely',
320 WSGIWarning)
321
322 for key in environ.keys():
323 if '.' in key:
324 # Extension, we don't care about its type
325 continue
326 assert_(type(environ[key]) is str,
327 "Environmental variable %s is not a string: %r (value: %r)"
328 % (key, type(environ[key]), environ[key]))
329
330 assert_(type(environ['wsgi.version']) is tuple,
331 "wsgi.version should be a tuple (%r)" % (environ['wsgi.version'],))
332 assert_(environ['wsgi.url_scheme'] in ('http', 'https'),
333 "wsgi.url_scheme unknown: %r" % environ['wsgi.url_scheme'])
334
335 check_input(environ['wsgi.input'])
336 check_errors(environ['wsgi.errors'])
337
338 # @@: these need filling out:
339 if environ['REQUEST_METHOD'] not in (
340 'GET', 'HEAD', 'POST', 'OPTIONS', 'PATCH', 'PUT', 'DELETE', 'TRACE'):
341 warnings.warn(
342 "Unknown REQUEST_METHOD: %r" % environ['REQUEST_METHOD'],
343 WSGIWarning)
344
345 assert_(not environ.get('SCRIPT_NAME')
346 or environ['SCRIPT_NAME'].startswith('/'),
347 "SCRIPT_NAME doesn't start with /: %r" % environ['SCRIPT_NAME'])
348 assert_(not environ.get('PATH_INFO')
349 or environ['PATH_INFO'].startswith('/'),
350 "PATH_INFO doesn't start with /: %r" % environ['PATH_INFO'])
351 if environ.get('CONTENT_LENGTH'):
352 assert_(int(environ['CONTENT_LENGTH']) >= 0,
353 "Invalid CONTENT_LENGTH: %r" % environ['CONTENT_LENGTH'])
354
355 if not environ.get('SCRIPT_NAME'):

Callers 1

lint_appFunction · 0.70

Calls 8

assert_Function · 0.85
check_inputFunction · 0.85
check_errorsFunction · 0.85
startswithMethod · 0.80
typeClass · 0.50
warnMethod · 0.45
keysMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected