本文整理汇总了Python中werkzeug.exceptions.ClientDisconnected方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.ClientDisconnected方法的具体用法?Python exceptions.ClientDisconnected怎么用?Python exceptions.ClientDisconnected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.exceptions
的用法示例。
在下文中一共展示了exceptions.ClientDisconnected方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_disconnect
# 需要导入模块: from werkzeug import exceptions [as 别名]
# 或者: from werkzeug.exceptions import ClientDisconnected [as 别名]
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()
示例2: get_data_from_request
# 需要导入模块: from werkzeug import exceptions [as 别名]
# 或者: from werkzeug.exceptions import ClientDisconnected [as 别名]
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
示例3: test_client_disconnect
# 需要导入模块: from werkzeug import exceptions [as 别名]
# 或者: from werkzeug.exceptions import ClientDisconnected [as 别名]
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'] == {}
示例4: http_context
# 需要导入模块: from werkzeug import exceptions [as 别名]
# 或者: from werkzeug.exceptions import ClientDisconnected [as 别名]
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)
示例5: test_limited_stream_disconnection
# 需要导入模块: from werkzeug import exceptions [as 别名]
# 或者: from werkzeug.exceptions import ClientDisconnected [as 别名]
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()