我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用werkzeug.exceptions.ClientDisconnected()。
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()
def get_http_info_with_retriever(self, retriever=None): """ Exact method for getting http_info but with form data work around. """ if retriever is None: retriever = self.get_form_data url_parts = urlparse.urlsplit(request.url) try: data = retriever() except ClientDisconnected: data = {} headers = dict(get_headers(request.environ)) if self.data_blacklist: data = apply_blacklist(data, self.data_blacklist) if self.headers_blacklist: headers = apply_blacklist(headers, self.headers_blacklist) return { 'url': '%s://%s%s' % (url_parts.scheme, url_parts.netloc, url_parts.path), 'query_string': url_parts.query, 'method': request.method, 'data': data, 'headers': headers, 'env': dict(get_environ(request.environ)), }
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()