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