MCPcopy Create free account
hub / github.com/Pylons/webtest / check_environ

Function check_environ

webtest/lint.py:313–397  ·  view source on GitHub ↗
(environ)

Source from the content-addressed store, hash-verified

311
312
313def check_environ(environ):
314 if type(environ) is not dict:
315 raise AssertionError(
316 "Environment is not of the right type: %r (environment: %r)"
317 % (type(environ), environ)
318 )
319
320 for key in ['REQUEST_METHOD', 'SERVER_NAME', 'SERVER_PORT',
321 'wsgi.version', 'wsgi.input', 'wsgi.errors',
322 'wsgi.multithread', 'wsgi.multiprocess',
323 'wsgi.run_once']:
324 if key not in environ:
325 raise AssertionError("Environment missing required key: %r" % key)
326
327 for key in ['HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH']:
328 if key in environ:
329 raise AssertionError(
330 "Environment should not have the key: %s "
331 "(use %s instead)" % (key, key[5:])
332 )
333
334 if 'QUERY_STRING' not in environ:
335 warnings.warn(
336 'QUERY_STRING is not in the WSGI environment; the cgi '
337 'module will use sys.argv when this variable is missing, '
338 'so application errors are more likely',
339 WSGIWarning)
340
341 for key in environ:
342 if '.' in key:
343 # Extension, we don't care about its type
344 continue
345 if type(environ[key]) not in METADATA_TYPE:
346 raise AssertionError(
347 "Environmental variable %s is not a string: %r (value: %r)"
348 % (key, type(environ[key]), environ[key])
349 )
350
351 if type(environ['wsgi.version']) is not tuple:
352 raise AssertionError(
353 "wsgi.version should be a tuple (%r)" % environ['wsgi.version']
354 )
355
356 if environ['wsgi.url_scheme'] not in ('http', 'https'):
357 raise AssertionError(
358 "wsgi.url_scheme unknown: %r" % environ['wsgi.url_scheme']
359 )
360
361 check_input(environ['wsgi.input'])
362 check_errors(environ['wsgi.errors'])
363
364 # @@: these need filling out:
365 if environ['REQUEST_METHOD'] not in valid_methods:
366 warnings.warn(
367 "Unknown REQUEST_METHOD: %r" % environ['REQUEST_METHOD'],
368 WSGIWarning)
369
370 if environ.get('SCRIPT_NAME') and not environ['SCRIPT_NAME'].startswith(SLASH):

Callers 4

test_no_query_stringMethod · 0.90
test_no_valid_requestMethod · 0.90
lint_appFunction · 0.85

Calls 3

check_inputFunction · 0.85
check_errorsFunction · 0.85
getMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…