Python werkzeug.exceptions.ClientDisconnected() Examples

The following are 26 code examples of werkzeug.exceptions.ClientDisconnected(). 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.exceptions , or try the search function .
Example #1
Source File: wsgi.py    From arithmancer with Apache License 2.0 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #2
Source File: wsgi.py    From Flask with Apache License 2.0 5 votes vote down vote up
def test_limited_stream_disconnection(self):
        io = BytesIO(b'A bit of content')

        # disconnect detection on out of bytes
        stream = wsgi.LimitedStream(io, 255)
        with self.assert_raises(ClientDisconnected):
            stream.read()

        # disconnect detection because file close
        io = BytesIO(b'x' * 255)
        io.close()
        stream = wsgi.LimitedStream(io, 255)
        with self.assert_raises(ClientDisconnected):
            stream.read() 
Example #3
Source File: wsgi.py    From Flask with Apache License 2.0 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #4
Source File: wsgi.py    From Flask with Apache License 2.0 5 votes vote down vote up
def test_limited_stream_disconnection(self):
        io = BytesIO(b'A bit of content')

        # disconnect detection on out of bytes
        stream = wsgi.LimitedStream(io, 255)
        with self.assert_raises(ClientDisconnected):
            stream.read()

        # disconnect detection because file close
        io = BytesIO(b'x' * 255)
        io.close()
        stream = wsgi.LimitedStream(io, 255)
        with self.assert_raises(ClientDisconnected):
            stream.read() 
Example #5
Source File: wsgi.py    From Flask with Apache License 2.0 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #6
Source File: wsgi.py    From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #7
Source File: wsgi.py    From android_universal with MIT License 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #8
Source File: wsgi.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #9
Source File: wsgi.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #10
Source File: wsgi.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #11
Source File: wsgi.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #12
Source File: wsgi.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #13
Source File: wsgi.py    From appengine-try-python-flask with Apache License 2.0 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #14
Source File: wsgi.py    From jbox with MIT License 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #15
Source File: wsgi.py    From syntheticmass with Apache License 2.0 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #16
Source File: wsgi.py    From cloud-playground with Apache License 2.0 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #17
Source File: nameko_sentry.py    From nameko-sentry with Apache License 2.0 5 votes vote down vote up
def http_context(self, worker_ctx):
        """ Attempt to extract HTTP context if an HTTP entrypoint was used.
        """
        http = {}
        if isinstance(worker_ctx.entrypoint, HttpRequestHandler):
            try:
                request = worker_ctx.args[0]
                try:
                    if request.mimetype == 'application/json':
                        data = request.data
                    else:
                        data = request.form
                except ClientDisconnected:
                    data = {}

                urlparts = urlsplit(request.url)
                http.update({
                    'url': '{}://{}{}'.format(
                        urlparts.scheme, urlparts.netloc, urlparts.path
                    ),
                    'query_string': urlparts.query,
                    'method': request.method,
                    'data': data,
                    'headers': dict(get_headers(request.environ)),
                    'env': dict(get_environ(request.environ)),
                })
            except:
                pass  # probably not a compatible entrypoint

        self.client.http_context(http) 
Example #18
Source File: test_nameko_sentry.py    From nameko-sentry with Apache License 2.0 5 votes vote down vote up
def test_client_disconnect(
        self, container_factory, config, web_session
    ):
        class Service(object):
            name = "service"

            sentry = SentryReporter()

            @http('POST', '/resource')
            def resource(self, request):
                raise CustomException()

        container = container_factory(Service, config)
        container.start()

        request = Mock(
            method="GET",
            url="http://example.com",
            mimetype='application/json',
            environ={}
        )
        type(request).data = PropertyMock(side_effect=ClientDisconnected)

        with entrypoint_hook(container, 'resource') as hook:
            with pytest.raises(CustomException):
                hook(request)

        sentry = get_extension(container, SentryReporter)

        assert sentry.client.send.call_count == 1
        _, kwargs = sentry.client.send.call_args

        assert kwargs['request']['data'] == {} 
Example #19
Source File: wsgi.py    From PhonePi_SampleServer with MIT License 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #20
Source File: wsgi.py    From pyRevit with GNU General Public License v3.0 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #21
Source File: utils.py    From apm-agent-python with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_data_from_request(request, config, event_type):
    result = {
        "env": dict(get_environ(request.environ)),
        "method": request.method,
        "socket": {"remote_address": request.environ.get("REMOTE_ADDR"), "encrypted": request.is_secure},
        "cookies": request.cookies,
    }
    if config.capture_headers:
        result["headers"] = dict(get_headers(request.environ))
    if request.method in constants.HTTP_WITH_BODY:
        if config.capture_body not in ("all", event_type):
            result["body"] = "[REDACTED]"
        else:
            body = None
            if request.content_type == "application/x-www-form-urlencoded":
                body = compat.multidict_to_dict(request.form)
            elif request.content_type and request.content_type.startswith("multipart/form-data"):
                body = compat.multidict_to_dict(request.form)
                if request.files:
                    body["_files"] = {
                        field: val[0].filename if len(val) == 1 else [f.filename for f in val]
                        for field, val in compat.iterlists(request.files)
                    }
            else:
                try:
                    body = request.get_data(as_text=True)
                except ClientDisconnected:
                    pass

            if body is not None:
                result["body"] = body

    result["url"] = get_url_dict(request.url)
    return result 
Example #22
Source File: wsgi.py    From planespotter with MIT License 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #23
Source File: wsgi.py    From Flask-P2P with MIT License 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #24
Source File: wsgi.py    From Financial-Portfolio-Flask with MIT License 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #25
Source File: wsgi.py    From RSSNewsGAE with Apache License 2.0 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected() 
Example #26
Source File: wsgi.py    From lambda-packs with MIT License 5 votes vote down vote up
def on_disconnect(self):
        """What should happen if a disconnect is detected?  The return
        value of this function is returned from read functions in case
        the client went away.  By default a
        :exc:`~werkzeug.exceptions.ClientDisconnected` exception is raised.
        """
        from werkzeug.exceptions import ClientDisconnected
        raise ClientDisconnected()