Python werkzeug.wrappers.BaseResponse() Examples
The following are 30
code examples of werkzeug.wrappers.BaseResponse().
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
werkzeug.wrappers
, or try the search function
.
Example #1
Source File: testapp.py From planespotter with MIT License | 6 votes |
def test_app(environ, start_response): """Simple test application that dumps the environment. You can use it to check if Werkzeug is working properly: .. sourcecode:: pycon >>> from werkzeug.serving import run_simple >>> from werkzeug.testapp import test_app >>> run_simple('localhost', 3000, test_app) * Running on http://localhost:3000/ The application displays important information from the WSGI environment, the Python interpreter and the installed libraries. """ req = Request(environ, populate_request=False) if req.args.get('resource') == 'logo': response = logo else: response = Response(render_testapp(req), mimetype='text/html') return response(environ, start_response)
Example #2
Source File: test_flask_example.py From opentelemetry-python with Apache License 2.0 | 6 votes |
def test_full_path(self): trace_id = trace_sdk.generate_trace_id() # We need to use the Werkzeug test app because # The headers are injected at the wsgi layer. # The flask test app will not include these, and # result in the values not propagated. client = Client(self.app.wsgi_app, BaseResponse) # emulate b3 headers client.get( "/", headers={ "traceparent": "00-{:032x}-{:016x}-{:02x}".format( trace_id, trace_sdk.generate_span_id(), trace.TraceFlags.SAMPLED, ) }, ) # assert the http request header was propagated through. prepared_request = self.send.call_args[0][1] headers = prepared_request.headers self.assertRegex( headers["traceparent"], r"00-{:032x}-[0-9a-f]{{16}}-01".format(trace_id), )
Example #3
Source File: testapp.py From lambda-packs with MIT License | 6 votes |
def test_app(environ, start_response): """Simple test application that dumps the environment. You can use it to check if Werkzeug is working properly: .. sourcecode:: pycon >>> from werkzeug.serving import run_simple >>> from werkzeug.testapp import test_app >>> run_simple('localhost', 3000, test_app) * Running on http://localhost:3000/ The application displays important information from the WSGI environment, the Python interpreter and the installed libraries. """ req = Request(environ, populate_request=False) if req.args.get('resource') == 'logo': response = logo else: response = Response(render_testapp(req), mimetype='text/html') return response(environ, start_response)
Example #4
Source File: assembly.py From assembly with MIT License | 6 votes |
def _error_handler__(cls, fn, e): """ Error handler callback. adding _error_handler() or _error_$code()/_error_404(), will trigger this method to return the response The method must accept one arg, which is the error object 'self' can still be used in your class :param fn: the method invoked :param e: the error object """ resp = fn(cls, e) if isinstance(resp, Response) or isinstance(resp, BaseResponse): return resp if isinstance(resp, dict) or isinstance(resp, tuple) or resp is None: data, status, headers = utils.prepare_view_response(resp) # create template from the error name, without the leading _, # ie: _error_handler -> error_handler.html, _error_404 -> error_404.html # template can be changed using @respone.template('app/class/action.html') if "__template__" not in data: data["__template__"] = _make_template_path(cls, fn.__name__.lstrip("_")) return cls.render(**resp), e.code, headers return resp # ------------------------------------------------------------------------------
Example #5
Source File: test_automatic.py From opentelemetry-python with Apache License 2.0 | 6 votes |
def test_uninstrument(self): # pylint: disable=access-member-before-definition resp = self.client.get("/hello/123") self.assertEqual(200, resp.status_code) self.assertEqual([b"Hello: 123"], list(resp.response)) span_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(span_list), 1) FlaskInstrumentor().uninstrument() self.app = flask.Flask(__name__) self.app.route("/hello/<int:helloid>")(self._hello_endpoint) # pylint: disable=attribute-defined-outside-init self.client = Client(self.app, BaseResponse) resp = self.client.get("/hello/123") self.assertEqual(200, resp.status_code) self.assertEqual([b"Hello: 123"], list(resp.response)) span_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(span_list), 1)
Example #6
Source File: pyramid_base_test.py From opentelemetry-python with Apache License 2.0 | 6 votes |
def _common_initialization(self, config): # pylint: disable=unused-argument def excluded_endpoint(request): return Response("excluded") # pylint: disable=unused-argument def excluded2_endpoint(request): return Response("excluded2") config.add_route("hello", "/hello/{helloid}") config.add_view(self._hello_endpoint, route_name="hello") config.add_route("excluded_arg", "/excluded/{helloid}") config.add_view(self._hello_endpoint, route_name="excluded_arg") config.add_route("excluded", "/excluded_noarg") config.add_view(excluded_endpoint, route_name="excluded") config.add_route("excluded2", "/excluded_noarg2") config.add_view(excluded2_endpoint, route_name="excluded2") # pylint: disable=attribute-defined-outside-init self.client = Client(config.make_wsgi_app(), BaseResponse)
Example #7
Source File: testapp.py From RSSNewsGAE with Apache License 2.0 | 6 votes |
def test_app(environ, start_response): """Simple test application that dumps the environment. You can use it to check if Werkzeug is working properly: .. sourcecode:: pycon >>> from werkzeug.serving import run_simple >>> from werkzeug.testapp import test_app >>> run_simple('localhost', 3000, test_app) * Running on http://localhost:3000/ The application displays important information from the WSGI environment, the Python interpreter and the installed libraries. """ req = Request(environ, populate_request=False) if req.args.get('resource') == 'logo': response = logo else: response = Response(render_testapp(req), mimetype='text/html') return response(environ, start_response)
Example #8
Source File: wrappers.py From RSSNewsGAE with Apache License 2.0 | 6 votes |
def application(cls, f): """Decorate a function as responder that accepts the request as first argument. This works like the :func:`responder` decorator but the function is passed the request object as first argument and the request object will be closed automatically:: @Request.application def my_wsgi_app(request): return Response('Hello World!') :param f: the WSGI callable to decorate :return: a new WSGI callable """ #: return a callable that wraps the -2nd argument with the request #: and calls the function with all the arguments up to that one and #: the request. The return value is then called with the latest #: two arguments. This makes it possible to use this decorator for #: both methods and standalone WSGI functions. def application(*args): request = cls(args[-2]) with request: return f(*args[:-2] + (request,))(*args[-2:]) return update_wrapper(application, f)
Example #9
Source File: test_wsgi_flow.py From SATOSA with Apache License 2.0 | 6 votes |
def test_flow(self, satosa_config_dict): """ Performs the test. """ test_client = Client(make_app(SATOSAConfig(satosa_config_dict)), BaseResponse) # Make request to frontend resp = test_client.get('/{}/{}/request'.format("backend", "frontend")) assert resp.status == '200 OK' headers = dict(resp.headers) assert headers["Set-Cookie"] # Fake response coming in to backend resp = test_client.get('/{}/response'.format("backend"), headers=[("Cookie", headers["Set-Cookie"])]) assert resp.status == '200 OK' assert resp.data.decode('utf-8') == "Auth response received, passed to test frontend"
Example #10
Source File: wrappers.py From pyRevit with GNU General Public License v3.0 | 6 votes |
def application(cls, f): """Decorate a function as responder that accepts the request as first argument. This works like the :func:`responder` decorator but the function is passed the request object as first argument and the request object will be closed automatically:: @Request.application def my_wsgi_app(request): return Response('Hello World!') :param f: the WSGI callable to decorate :return: a new WSGI callable """ #: return a callable that wraps the -2nd argument with the request #: and calls the function with all the arguments up to that one and #: the request. The return value is then called with the latest #: two arguments. This makes it possible to use this decorator for #: both methods and standalone WSGI functions. def application(*args): request = cls(args[-2]) with request: return f(*args[:-2] + (request,))(*args[-2:]) return update_wrapper(application, f)
Example #11
Source File: testapp.py From jbox with MIT License | 6 votes |
def test_app(environ, start_response): """Simple test application that dumps the environment. You can use it to check if Werkzeug is working properly: .. sourcecode:: pycon >>> from werkzeug.serving import run_simple >>> from werkzeug.testapp import test_app >>> run_simple('localhost', 3000, test_app) * Running on http://localhost:3000/ The application displays important information from the WSGI environment, the Python interpreter and the installed libraries. """ req = Request(environ, populate_request=False) if req.args.get('resource') == 'logo': response = logo else: response = Response(render_testapp(req), mimetype='text/html') return response(environ, start_response)
Example #12
Source File: wrappers.py From jbox with MIT License | 6 votes |
def application(cls, f): """Decorate a function as responder that accepts the request as first argument. This works like the :func:`responder` decorator but the function is passed the request object as first argument and the request object will be closed automatically:: @Request.application def my_wsgi_app(request): return Response('Hello World!') :param f: the WSGI callable to decorate :return: a new WSGI callable """ #: return a callable that wraps the -2nd argument with the request #: and calls the function with all the arguments up to that one and #: the request. The return value is then called with the latest #: two arguments. This makes it possible to use this decorator for #: both methods and standalone WSGI functions. def application(*args): request = cls(args[-2]) with request: return f(*args[:-2] + (request,))(*args[-2:]) return update_wrapper(application, f)
Example #13
Source File: testapp.py From Flask-P2P with MIT License | 6 votes |
def test_app(environ, start_response): """Simple test application that dumps the environment. You can use it to check if Werkzeug is working properly: .. sourcecode:: pycon >>> from werkzeug.serving import run_simple >>> from werkzeug.testapp import test_app >>> run_simple('localhost', 3000, test_app) * Running on http://localhost:3000/ The application displays important information from the WSGI environment, the Python interpreter and the installed libraries. """ req = Request(environ, populate_request=False) if req.args.get('resource') == 'logo': response = logo else: response = Response(render_testapp(req), mimetype='text/html') return response(environ, start_response)
Example #14
Source File: testapp.py From pyRevit with GNU General Public License v3.0 | 6 votes |
def test_app(environ, start_response): """Simple test application that dumps the environment. You can use it to check if Werkzeug is working properly: .. sourcecode:: pycon >>> from werkzeug.serving import run_simple >>> from werkzeug.testapp import test_app >>> run_simple('localhost', 3000, test_app) * Running on http://localhost:3000/ The application displays important information from the WSGI environment, the Python interpreter and the installed libraries. """ req = Request(environ, populate_request=False) if req.args.get('resource') == 'logo': response = logo else: response = Response(render_testapp(req), mimetype='text/html') return response(environ, start_response)
Example #15
Source File: testapp.py From Financial-Portfolio-Flask with MIT License | 6 votes |
def test_app(environ, start_response): """Simple test application that dumps the environment. You can use it to check if Werkzeug is working properly: .. sourcecode:: pycon >>> from werkzeug.serving import run_simple >>> from werkzeug.testapp import test_app >>> run_simple('localhost', 3000, test_app) * Running on http://localhost:3000/ The application displays important information from the WSGI environment, the Python interpreter and the installed libraries. """ req = Request(environ, populate_request=False) if req.args.get('resource') == 'logo': response = logo else: response = Response(render_testapp(req), mimetype='text/html') return response(environ, start_response)
Example #16
Source File: wrappers.py From Financial-Portfolio-Flask with MIT License | 6 votes |
def application(cls, f): """Decorate a function as responder that accepts the request as first argument. This works like the :func:`responder` decorator but the function is passed the request object as first argument and the request object will be closed automatically:: @Request.application def my_wsgi_app(request): return Response('Hello World!') :param f: the WSGI callable to decorate :return: a new WSGI callable """ #: return a callable that wraps the -2nd argument with the request #: and calls the function with all the arguments up to that one and #: the request. The return value is then called with the latest #: two arguments. This makes it possible to use this decorator for #: both methods and standalone WSGI functions. def application(*args): request = cls(args[-2]) with request: return f(*args[:-2] + (request,))(*args[-2:]) return update_wrapper(application, f)
Example #17
Source File: __init__.py From planespotter with MIT License | 5 votes |
def execute_command(self, request, command, frame): """Execute a command in a console.""" return Response(frame.console.eval(command), mimetype='text/html')
Example #18
Source File: plugin_test.py From fairness-indicators with Apache License 2.0 | 5 votes |
def setUp(self): super(PluginTest, self).setUp() # Log dir to save temp events into. self._log_dir = self.get_temp_dir() self._eval_result_output_dir = os.path.join(self.get_temp_dir(), "eval_result") if not os.path.isdir(self._eval_result_output_dir): os.mkdir(self._eval_result_output_dir) writer = tf.summary.create_file_writer(self._log_dir) with writer.as_default(): summary_v2.FairnessIndicators(self._eval_result_output_dir, step=1) writer.close() # Start a server that will receive requests. self._multiplexer = event_multiplexer.EventMultiplexer({ ".": self._log_dir, }) self._context = base_plugin.TBContext( logdir=self._log_dir, multiplexer=self._multiplexer) self._plugin = plugin.FairnessIndicatorsPlugin(self._context) self._multiplexer.Reload() wsgi_app = application.TensorBoardWSGI([self._plugin]) self._server = werkzeug_test.Client(wsgi_app, wrappers.BaseResponse) self._routes = self._plugin.get_plugin_apps()
Example #19
Source File: __init__.py From Flask-P2P with MIT License | 5 votes |
def get_source(self, request, frame): """Render the source viewer.""" return Response(frame.render_source(), mimetype='text/html')
Example #20
Source File: __init__.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def paste_traceback(self, request, traceback): """Paste the traceback and return a JSON response.""" rv = traceback.paste() return Response(json.dumps(rv), mimetype='application/json')
Example #21
Source File: __init__.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def get_resource(self, request, filename): """Return a static resource from the shared folder.""" filename = join(dirname(__file__), 'shared', basename(filename)) if isfile(filename): mimetype = mimetypes.guess_type(filename)[0] \ or 'application/octet-stream' f = open(filename, 'rb') try: return Response(f.read(), mimetype=mimetype) finally: f.close() return Response('Not Found', status=404)
Example #22
Source File: wrappers.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def _wrap_response(self, start, length): """Wrap existing Response in case of Range Request context.""" if self.status_code == 206: self.response = _RangeWrapper(self.response, start, length)
Example #23
Source File: atom.py From Flask-P2P with MIT License | 5 votes |
def get_response(self): """Return a response object for the feed.""" return BaseResponse(self.to_string(), mimetype='application/atom+xml')
Example #24
Source File: __init__.py From Flask-P2P with MIT License | 5 votes |
def get_resource(self, request, filename): """Return a static resource from the shared folder.""" filename = join(dirname(__file__), 'shared', basename(filename)) if isfile(filename): mimetype = mimetypes.guess_type(filename)[0] \ or 'application/octet-stream' f = open(filename, 'rb') try: return Response(f.read(), mimetype=mimetype) finally: f.close() return Response('Not Found', status=404)
Example #25
Source File: wrappers.py From planespotter with MIT License | 5 votes |
def application(cls, f): """Decorate a function as responder that accepts the request as first argument. This works like the :func:`responder` decorator but the function is passed the request object as first argument and the request object will be closed automatically:: @Request.application def my_wsgi_app(request): return Response('Hello World!') As of Werkzeug 0.14 HTTP exceptions are automatically caught and converted to responses instead of failing. :param f: the WSGI callable to decorate :return: a new WSGI callable """ #: return a callable that wraps the -2nd argument with the request #: and calls the function with all the arguments up to that one and #: the request. The return value is then called with the latest #: two arguments. This makes it possible to use this decorator for #: both methods and standalone WSGI functions. from werkzeug.exceptions import HTTPException def application(*args): request = cls(args[-2]) with request: try: resp = f(*args[:-2] + (request,)) except HTTPException as e: resp = e.get_response(args[-2]) return resp(*args[-2:]) return update_wrapper(application, f)
Example #26
Source File: __init__.py From Flask-P2P with MIT License | 5 votes |
def paste_traceback(self, request, traceback): """Paste the traceback and return a JSON response.""" rv = traceback.paste() return Response(json.dumps(rv), mimetype='application/json')
Example #27
Source File: __init__.py From Flask-P2P with MIT License | 5 votes |
def display_console(self, request): """Display a standalone shell.""" if 0 not in self.frames: self.frames[0] = _ConsoleFrame(self.console_init_func()) return Response(render_console_html(secret=self.secret), mimetype='text/html')
Example #28
Source File: __init__.py From Flask-P2P with MIT License | 5 votes |
def execute_command(self, request, command, frame): """Execute a command in a console.""" return Response(frame.console.eval(command), mimetype='text/html')
Example #29
Source File: atom.py From Financial-Portfolio-Flask with MIT License | 5 votes |
def get_response(self): """Return a response object for the feed.""" return BaseResponse(self.to_string(), mimetype='application/atom+xml')
Example #30
Source File: __init__.py From Financial-Portfolio-Flask with MIT License | 5 votes |
def get_resource(self, request, filename): """Return a static resource from the shared folder.""" filename = join(dirname(__file__), 'shared', basename(filename)) if isfile(filename): mimetype = mimetypes.guess_type(filename)[0] \ or 'application/octet-stream' f = open(filename, 'rb') try: return Response(f.read(), mimetype=mimetype) finally: f.close() return Response('Not Found', status=404)