本文整理匯總了Python中tornado.websocket.WebSocketHandler方法的典型用法代碼示例。如果您正苦於以下問題:Python websocket.WebSocketHandler方法的具體用法?Python websocket.WebSocketHandler怎麽用?Python websocket.WebSocketHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tornado.websocket
的用法示例。
在下文中一共展示了websocket.WebSocketHandler方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from tornado import websocket [as 別名]
# 或者: from tornado.websocket import WebSocketHandler [as 別名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# since my parent doesn't keep calling the super() constructor,
# I need to do it myself
bases = inspect.getmro(type(self))
assert WebSocketHandlerMixin in bases
meindex = bases.index(WebSocketHandlerMixin)
try:
nextparent = bases[meindex + 1]
except IndexError:
raise Exception("WebSocketHandlerMixin should be followed "
"by another parent to make sense")
# undisallow methods --- t.ws.WebSocketHandler disallows methods,
# we need to re-enable these methods
def wrapper(method):
def undisallow(*args2, **kwargs2):
getattr(nextparent, method)(self, *args2, **kwargs2)
return undisallow
for method in ["write", "redirect", "set_header", "set_cookie",
"set_status", "flush", "finish"]:
setattr(self, method, wrapper(method))
nextparent.__init__(self, *args, **kwargs)
示例2: write_message
# 需要導入模塊: from tornado import websocket [as 別名]
# 或者: from tornado.websocket import WebSocketHandler [as 別名]
def write_message(self, message, binary=False):
super(WebSocketHandler, self).write_message(message, binary)
示例3: __init__
# 需要導入模塊: from tornado import websocket [as 別名]
# 或者: from tornado.websocket import WebSocketHandler [as 別名]
def __init__(self, *args, **kwargs):
super(WebSocketHandler, self).__init__(*args, **kwargs)
self._init_handler()
示例4: check_origin
# 需要導入模塊: from tornado import websocket [as 別名]
# 或者: from tornado.websocket import WebSocketHandler [as 別名]
def check_origin(self, origin):
"""
Overridden function from WebSocketHandler for CORS policy.
This ensures that websocket connection can be made from any
origin.
"""
return True
示例5: open
# 需要導入模塊: from tornado import websocket [as 別名]
# 或者: from tornado.websocket import WebSocketHandler [as 別名]
def open(self):
"""
A new websocket connection is opened.
Overridden function from WebSocketHandler
This method resets the global connection variables.
"""
self.__reset_connection()
示例6: on_message
# 需要導入模塊: from tornado import websocket [as 別名]
# 或者: from tornado.websocket import WebSocketHandler [as 別名]
def on_message(self, message):
"""
Got a messege from the websocket connection.
Overridden method from WebSocketHandler.
This method recieves the message from the websocket connection and
validates the message. If the message is validated it extracts the
data from the message and pass it as an argument to the function
registered corresponding to the users socket-id. The returned value
from the function is sent back to user as a response.
Args:
message: message from the websocket connection. \
This message is what we got from the websocket, first we need \
to validate it and then extract the required matter from it \
which will then be used by the registered function.
"""
data = self._validate_message(message)
if data:
out_msg = self.active_connection["func"](
*self.active_connection["arguments"], message=data)
try:
# Send the out_msg returned from the function.
if isinstance(out_msg, dict):
json_resp = json.dumps(out_msg)
self.write_message(json_resp)
elif utils.check_if_string(out_msg):
self.write_message(out_msg)
# self._origmai_send_data(
# "ws_data", out_msg, socketId=self.connection_id)
else:
print(
"A persistent connection can only return a python dict \
or string")
except Exception:
pass
示例7: __init__
# 需要導入模塊: from tornado import websocket [as 別名]
# 或者: from tornado.websocket import WebSocketHandler [as 別名]
def __init__(self, *args, **kwargs):
websocket.WebSocketHandler.__init__(self, *args, **kwargs)
handlers.IPythonHandler.__init__(self, *args, **kwargs)
ca_certs = None
if self.request.protocol == 'https':
ca_certs = self.config.get('NotebookApp', {}).get('certfile')
if not ca_certs:
raise ValueError('HTTPS requires the NotebookApp.certfile setting to '
'be present.')
self.ca_certs = ca_certs
示例8: __init__
# 需要導入模塊: from tornado import websocket [as 別名]
# 或者: from tornado.websocket import WebSocketHandler [as 別名]
def __init__(self, application, request, **kwargs):
super(WebSocketHandler, self).__init__(application, request, **kwargs)
self.remote_ip = request.headers.get(
'X-Forwarded-For',
request.headers.get(
'X-Real-Ip',
request.remote_ip))
application.log('INFO', 'CONNECTION_OPEN', self.remote_ip )
self.trade_client = None
self.user_response = None
self.last_message_datetime = [datetime.now()]
self.open_orders = {}
self.md_subscriptions = {}
self.sec_status_subscriptions = {}
self.honey_pot_connection = False
if self.application.is_tor_node( self.remote_ip ):
self.honey_pot_connection = True
application.log('INFO', 'BLOCKED_TOR_NODE', self.remote_ip )
return
self.trade_client = TradeClient(
self.application.zmq_context,
self.application.trade_in_socket,
self.application.options.trade_pub)
示例9: close
# 需要導入模塊: from tornado import websocket [as 別名]
# 或者: from tornado.websocket import WebSocketHandler [as 別名]
def close(self, code=None, reason=None):
self.application.log('DEBUG', self.remote_ip, 'WebSocketHandler.close() invoked' )
super(WebSocketHandler, self).close()