|
|
@ -5436,15 +5436,18 @@ class Config:
|
|
|
|
class WebSocketsWrapper():
|
|
|
|
class WebSocketsWrapper():
|
|
|
|
"""Wraps websockets module to use in non-async scopes"""
|
|
|
|
"""Wraps websockets module to use in non-async scopes"""
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, url, headers=None):
|
|
|
|
def __init__(self, url, headers=None, connect=True):
|
|
|
|
self.loop = asyncio.events.new_event_loop()
|
|
|
|
self.loop = asyncio.events.new_event_loop()
|
|
|
|
self.conn = compat_websockets.connect(
|
|
|
|
self.conn = compat_websockets.connect(
|
|
|
|
url, extra_headers=headers, ping_interval=None,
|
|
|
|
url, extra_headers=headers, ping_interval=None,
|
|
|
|
close_timeout=float('inf'), loop=self.loop, ping_timeout=float('inf'))
|
|
|
|
close_timeout=float('inf'), loop=self.loop, ping_timeout=float('inf'))
|
|
|
|
|
|
|
|
if connect:
|
|
|
|
|
|
|
|
self.__enter__()
|
|
|
|
atexit.register(self.__exit__, None, None, None)
|
|
|
|
atexit.register(self.__exit__, None, None, None)
|
|
|
|
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
def __enter__(self):
|
|
|
|
self.pool = self.run_with_loop(self.conn.__aenter__(), self.loop)
|
|
|
|
if not self.pool:
|
|
|
|
|
|
|
|
self.pool = self.run_with_loop(self.conn.__aenter__(), self.loop)
|
|
|
|
return self
|
|
|
|
return self
|
|
|
|
|
|
|
|
|
|
|
|
def send(self, *args):
|
|
|
|
def send(self, *args):
|
|
|
|