Python wsgiref.validate.validator() Examples
The following are 30
code examples of wsgiref.validate.validator().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
wsgiref.validate
, or try the search function
.
Example #1
Source File: helper.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def get_app(self, app=None): """Obtain a new (decorated) WSGI app to hook into the origin server.""" if app is None: app = cherrypy.tree if self.validate: try: from wsgiref import validate except ImportError: warnings.warn( 'Error importing wsgiref. The validator will not run.') else: # wraps the app in the validator app = validate.validator(app) return app
Example #2
Source File: test_wsgiref.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_cp1252_url(self): def app(e, s): s("200 OK", [ ("Content-Type", "text/plain"), ("Date", "Wed, 24 Dec 2008 13:29:32 GMT"), ]) # PEP3333 says environ variables are decoded as latin1. # Encode as latin1 to get original bytes return [e["PATH_INFO"].encode("latin1")] out, err = run_amock( validator(app), data=b"GET /\x80%80 HTTP/1.0") self.assertEqual( [ b"HTTP/1.0 200 OK", mock.ANY, b"Content-Type: text/plain", b"Date: Wed, 24 Dec 2008 13:29:32 GMT", b"", b"/\x80\x80", ], out.splitlines())
Example #3
Source File: test_wsgiref.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_bytes_validation(self): def app(e, s): s("200 OK", [ ("Content-Type", "text/plain; charset=utf-8"), ("Date", "Wed, 24 Dec 2008 13:29:32 GMT"), ]) return [b"data"] out, err = run_amock(validator(app)) self.assertTrue(err.endswith('"GET / HTTP/1.0" 200 4\n')) ver = sys.version.split()[0].encode('ascii') py = python_implementation().encode('ascii') pyver = py + b"/" + ver self.assertEqual( b"HTTP/1.0 200 OK\r\n" b"Server: WSGIServer/0.2 "+ pyver + b"\r\n" b"Content-Type: text/plain; charset=utf-8\r\n" b"Date: Wed, 24 Dec 2008 13:29:32 GMT\r\n" b"\r\n" b"data", out)
Example #4
Source File: wsgi_test.py From teleport with Apache License 2.0 | 6 votes |
def get_app(self): class HelloHandler(RequestHandler): def get(self): self.write("Hello world!") class PathQuotingHandler(RequestHandler): def get(self, path): self.write(path) # It would be better to run the wsgiref server implementation in # another thread instead of using our own WSGIContainer, but this # fits better in our async testing framework and the wsgiref # validator should keep us honest with ignore_deprecation(): return WSGIContainer(validator(WSGIAdapter( Application([ ("/", HelloHandler), ("/path/(.*)", PathQuotingHandler), ("/typecheck", TypeCheckHandler), ]))))
Example #5
Source File: ch13_e1_ex3.py From Mastering-Object-Oriented-Python-Second-Edition with MIT License | 6 votes |
def roulette_server_3(count: int = 1) -> None: from wsgiref.simple_server import make_server from wsgiref.validate import validator wheel = American(seed=1) roulette = Roulette(wheel) debug = validator(roulette) httpd = make_server("", 8080, debug) if count is None: httpd.serve_forever() else: for c in range(count): httpd.handle_request() # Client
Example #6
Source File: ch13_e1_ex4.py From Mastering-Object-Oriented-Python-Second-Edition with MIT License | 6 votes |
def roulette_server_4(count: int = 1): from wsgiref.simple_server import make_server from wsgiref.validate import validator wheel = American() roulette = Roulette(wheel) debug = validator(roulette) httpd = make_server("", 8080, debug) if count is None: httpd.serve_forever() else: for c in range(count): httpd.handle_request() # Client
Example #7
Source File: ch13_e1_ex4.py From Mastering-Object-Oriented-Python-Second-Edition with MIT License | 6 votes |
def auth_server(count: int = 1) -> None: from wsgiref.simple_server import make_server from wsgiref.validate import validator secure_app = Some_App() authenticated_app = Authenticate(users, secure_app) debug = validator(authenticated_app) httpd = make_server("", 8080, debug) if count is None: httpd.serve_forever() else: for c in range(count): httpd.handle_request() # Demo
Example #8
Source File: wsgi_test.py From viewfinder with Apache License 2.0 | 6 votes |
def get_app(self): class HelloHandler(RequestHandler): def get(self): self.write("Hello world!") class PathQuotingHandler(RequestHandler): def get(self, path): self.write(path) # It would be better to run the wsgiref server implementation in # another thread instead of using our own WSGIContainer, but this # fits better in our async testing framework and the wsgiref # validator should keep us honest return WSGIContainer(validator(WSGIApplication([ ("/", HelloHandler), ("/path/(.*)", PathQuotingHandler), ("/typecheck", TypeCheckHandler), ])))
Example #9
Source File: test_wsgiref.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_bytes_validation(self): def app(e, s): s("200 OK", [ ("Content-Type", "text/plain; charset=utf-8"), ("Date", "Wed, 24 Dec 2008 13:29:32 GMT"), ]) return [b"data"] out, err = run_amock(validator(app)) self.assertTrue(err.endswith('"GET / HTTP/1.0" 200 4\n')) ver = sys.version.split()[0].encode('ascii') py = python_implementation().encode('ascii') pyver = py + b"/" + ver self.assertEqual( b"HTTP/1.0 200 OK\r\n" b"Server: WSGIServer/0.2 "+ pyver + b"\r\n" b"Content-Type: text/plain; charset=utf-8\r\n" b"Date: Wed, 24 Dec 2008 13:29:32 GMT\r\n" b"\r\n" b"data", out)
Example #10
Source File: test_wsgiref.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_bytes_validation(self): def app(e, s): s("200 OK", [ ("Content-Type", "text/plain; charset=utf-8"), ("Date", "Wed, 24 Dec 2008 13:29:32 GMT"), ]) return [b"data"] out, err = run_amock(validator(app)) self.assertTrue(err.endswith('"GET / HTTP/1.0" 200 4\n')) ver = sys.version.split()[0].encode('ascii') py = python_implementation().encode('ascii') pyver = py + b"/" + ver self.assertEqual( b"HTTP/1.0 200 OK\r\n" b"Server: WSGIServer/0.2 "+ pyver + b"\r\n" b"Content-Type: text/plain; charset=utf-8\r\n" b"Date: Wed, 24 Dec 2008 13:29:32 GMT\r\n" b"\r\n" b"data", out)
Example #11
Source File: helper.py From bazarr with GNU General Public License v3.0 | 6 votes |
def get_app(self, app=None): """Obtain a new (decorated) WSGI app to hook into the origin server.""" if app is None: app = cherrypy.tree if self.validate: try: from wsgiref import validate except ImportError: warnings.warn( 'Error importing wsgiref. The validator will not run.') else: # wraps the app in the validator app = validate.validator(app) return app
Example #12
Source File: helper.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
def get_app(self, app=None): """Obtain a new (decorated) WSGI app to hook into the origin server.""" if app is None: app = cherrypy.tree if self.conquer: try: import wsgiconq except ImportError: warnings.warn("Error importing wsgiconq. pyconquer will not run.") else: app = wsgiconq.WSGILogger(app, c_calls=True) if self.validate: try: from wsgiref import validate except ImportError: warnings.warn("Error importing wsgiref. The validator will not run.") else: #wraps the app in the validator app = validate.validator(app) return app
Example #13
Source File: wsgi_test.py From pySINDy with MIT License | 6 votes |
def get_app(self): class HelloHandler(RequestHandler): def get(self): self.write("Hello world!") class PathQuotingHandler(RequestHandler): def get(self, path): self.write(path) # It would be better to run the wsgiref server implementation in # another thread instead of using our own WSGIContainer, but this # fits better in our async testing framework and the wsgiref # validator should keep us honest with ignore_deprecation(): return WSGIContainer(validator(WSGIAdapter( Application([ ("/", HelloHandler), ("/path/(.*)", PathQuotingHandler), ("/typecheck", TypeCheckHandler), ]))))
Example #14
Source File: wsgi_test.py From EventGhost with GNU General Public License v2.0 | 6 votes |
def get_app(self): class HelloHandler(RequestHandler): def get(self): self.write("Hello world!") class PathQuotingHandler(RequestHandler): def get(self, path): self.write(path) # It would be better to run the wsgiref server implementation in # another thread instead of using our own WSGIContainer, but this # fits better in our async testing framework and the wsgiref # validator should keep us honest return WSGIContainer(validator(WSGIApplication([ ("/", HelloHandler), ("/path/(.*)", PathQuotingHandler), ("/typecheck", TypeCheckHandler), ])))
Example #15
Source File: helper.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def get_app(self, app=None): """Obtain a new (decorated) WSGI app to hook into the origin server.""" if app is None: app = cherrypy.tree if self.validate: try: from wsgiref import validate except ImportError: warnings.warn( 'Error importing wsgiref. The validator will not run.') else: # wraps the app in the validator app = validate.validator(app) return app
Example #16
Source File: wsgi_test.py From pySINDy with MIT License | 6 votes |
def wrap_web_tests_application(): result = {} for cls in web_test.wsgi_safe_tests: def class_factory(): class WSGIApplicationWrappedTest(cls): # type: ignore def setUp(self): self.warning_catcher = ignore_deprecation() self.warning_catcher.__enter__() super(WSGIApplicationWrappedTest, self).setUp() def tearDown(self): super(WSGIApplicationWrappedTest, self).tearDown() self.warning_catcher.__exit__(None, None, None) def get_app(self): self.app = WSGIApplication(self.get_handlers(), **self.get_app_kwargs()) return WSGIContainer(validator(self.app)) result["WSGIApplication_" + cls.__name__] = class_factory() return result
Example #17
Source File: wsgi_test.py From tornado-zh with MIT License | 6 votes |
def get_app(self): class HelloHandler(RequestHandler): def get(self): self.write("Hello world!") class PathQuotingHandler(RequestHandler): def get(self, path): self.write(path) # It would be better to run the wsgiref server implementation in # another thread instead of using our own WSGIContainer, but this # fits better in our async testing framework and the wsgiref # validator should keep us honest return WSGIContainer(validator(WSGIApplication([ ("/", HelloHandler), ("/path/(.*)", PathQuotingHandler), ("/typecheck", TypeCheckHandler), ])))
Example #18
Source File: wsgi_test.py From teleport with Apache License 2.0 | 6 votes |
def wrap_web_tests_application(): result = {} for cls in web_test.wsgi_safe_tests: def class_factory(): class WSGIApplicationWrappedTest(cls): # type: ignore def setUp(self): self.warning_catcher = ignore_deprecation() self.warning_catcher.__enter__() super(WSGIApplicationWrappedTest, self).setUp() def tearDown(self): super(WSGIApplicationWrappedTest, self).tearDown() self.warning_catcher.__exit__(None, None, None) def get_app(self): self.app = WSGIApplication(self.get_handlers(), **self.get_app_kwargs()) return WSGIContainer(validator(self.app)) result["WSGIApplication_" + cls.__name__] = class_factory() return result
Example #19
Source File: wsgi_test.py From honeything with GNU General Public License v3.0 | 6 votes |
def get_app(self): class HelloHandler(RequestHandler): def get(self): self.write("Hello world!") class PathQuotingHandler(RequestHandler): def get(self, path): self.write(path) # It would be better to run the wsgiref server implementation in # another thread instead of using our own WSGIContainer, but this # fits better in our async testing framework and the wsgiref # validator should keep us honest return WSGIContainer(validator(WSGIApplication([ ("/", HelloHandler), ("/path/(.*)", PathQuotingHandler), ("/typecheck", TypeCheckHandler), ])))
Example #20
Source File: wsgi_test.py From tornado-zh with MIT License | 6 votes |
def get_app(self): class HelloHandler(RequestHandler): def get(self): self.write("Hello world!") class PathQuotingHandler(RequestHandler): def get(self, path): self.write(path) # It would be better to run the wsgiref server implementation in # another thread instead of using our own WSGIContainer, but this # fits better in our async testing framework and the wsgiref # validator should keep us honest return WSGIContainer(validator(WSGIApplication([ ("/", HelloHandler), ("/path/(.*)", PathQuotingHandler), ("/typecheck", TypeCheckHandler), ])))
Example #21
Source File: wsgi_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def wrap_web_tests_adapter(): result = {} for cls in web_test.wsgi_safe_tests: class WSGIAdapterWrappedTest(cls): def get_app(self): self.app = Application(self.get_handlers(), **self.get_app_kwargs()) return WSGIContainer(validator(WSGIAdapter(self.app))) result["WSGIAdapter_" + cls.__name__] = WSGIAdapterWrappedTest return result
Example #22
Source File: test_wsgiref.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_simple_validation_error(self): def bad_app(environ,start_response): start_response("200 OK", ('Content-Type','text/plain')) return ["Hello, world!"] out, err = run_amock(validator(bad_app)) self.assertTrue(out.endswith( b"A server error occurred. Please contact the administrator." )) self.assertEqual( err.splitlines()[-2], "AssertionError: Headers (('Content-Type', 'text/plain')) must" " be of type list: <class 'tuple'>" )
Example #23
Source File: wsgi_test.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def wrap_web_tests_application(): result = {} for cls in web_test.wsgi_safe_tests: class WSGIApplicationWrappedTest(cls): def get_app(self): self.app = WSGIApplication(self.get_handlers(), **self.get_app_kwargs()) return WSGIContainer(validator(self.app)) result["WSGIApplication_" + cls.__name__] = WSGIApplicationWrappedTest return result
Example #24
Source File: test_wsgiref.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_validated_hello(self): out, err = run_amock(validator(hello_app)) # the middleware doesn't support len(), so content-length isn't there self.check_hello(out, has_length=False)
Example #25
Source File: test_wsgiref.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_validated_hello(self): out, err = run_amock(validator(hello_app)) # the middleware doesn't support len(), so content-length isn't there self.check_hello(out, has_length=False)
Example #26
Source File: test_wsgiref.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_simple_validation_error(self): def bad_app(environ,start_response): start_response("200 OK", ('Content-Type','text/plain')) return ["Hello, world!"] out, err = run_amock(validator(bad_app)) self.assertTrue(out.endswith( "A server error occurred. Please contact the administrator." )) self.assertEqual( err.splitlines()[-2], "AssertionError: Headers (('Content-Type', 'text/plain')) must" " be of type list: <type 'tuple'>" )
Example #27
Source File: test_wsgiref.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_validated_hello(self): out, err = run_amock(validator(hello_app)) # the middleware doesn't support len(), so content-length isn't there self.check_hello(out, has_length=False)
Example #28
Source File: test_wsgiref.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_wsgi_input(self): def bad_app(e,s): e["wsgi.input"].read() s("200 OK", [("Content-Type", "text/plain; charset=utf-8")]) return [b"data"] out, err = run_amock(validator(bad_app)) self.assertTrue(out.endswith( b"A server error occurred. Please contact the administrator." )) self.assertEqual( err.splitlines()[-2], "AssertionError" )
Example #29
Source File: test_wsgiref.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_simple_validation_error(self): def bad_app(environ,start_response): start_response("200 OK", ('Content-Type','text/plain')) return ["Hello, world!"] out, err = run_amock(validator(bad_app)) self.assertTrue(out.endswith( b"A server error occurred. Please contact the administrator." )) self.assertEqual( err.splitlines()[-2], "AssertionError: Headers (('Content-Type', 'text/plain')) must" " be of type list: <class 'tuple'>" )
Example #30
Source File: wsgi_test.py From pySINDy with MIT License | 5 votes |
def get_app(self): with ignore_deprecation(): return WSGIContainer(validator(WSGIAdapter(Application(self.get_handlers()))))