本文整理匯總了Python中wsgiref.handlers.SimpleHandler.finish_response方法的典型用法代碼示例。如果您正苦於以下問題:Python SimpleHandler.finish_response方法的具體用法?Python SimpleHandler.finish_response怎麽用?Python SimpleHandler.finish_response使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wsgiref.handlers.SimpleHandler
的用法示例。
在下文中一共展示了SimpleHandler.finish_response方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: finish_response
# 需要導入模塊: from wsgiref.handlers import SimpleHandler [as 別名]
# 或者: from wsgiref.handlers.SimpleHandler import finish_response [as 別名]
def finish_response(self):
"""
Completes the response and performs the following tasks:
- Remove the `'ws4py.socket'` and `'ws4py.websocket'`
environ keys.
- Attach the returned websocket, if any, to the WSGI server
using its ``link_websocket_to_server`` method.
"""
# force execution of the result iterator until first actual content
rest = iter(self.result)
first = list(itertools.islice(rest, 1))
self.result = itertools.chain(first, rest)
# now it's safe to look if environ was modified
ws = None
if self.environ:
self.environ.pop('ws4py.socket', None)
ws = self.environ.pop('ws4py.websocket', None)
try:
SimpleHandler.finish_response(self)
except:
if ws:
ws.close(1011, reason='Something broke')
raise
else:
if ws:
self.request_handler.server.link_websocket_to_server(ws)
示例2: finish_response
# 需要導入模塊: from wsgiref.handlers import SimpleHandler [as 別名]
# 或者: from wsgiref.handlers.SimpleHandler import finish_response [as 別名]
def finish_response(self):
"""
Completes the response and performs the following tasks:
- Remove the `'ws4py.socket'` and `'ws4py.websocket'`
environ keys.
- Attach the returned websocket, if any, to the WSGI server
using its ``link_websocket_to_server`` method.
"""
ws = None
if self.environ:
self.environ.pop('ws4py.socket', None)
ws = self.environ.pop('ws4py.websocket', None)
try:
SimpleHandler.finish_response(self)
except:
if ws:
ws.close(1011, reason='Something broke')
raise
else:
if ws:
self.request_handler.server.link_websocket_to_server(ws)