Skip to content

Commit

Permalink
fix(aiohttp): use app var instead of inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Jun 29, 2023
1 parent f7fad26 commit a0c7e64
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
16 changes: 9 additions & 7 deletions python/src/wslink/backends/aiohttp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ def _fix_path(path):
# -----------------------------------------------------------------------------


class WebAppServer(AbstractWebApp, aiohttp_web.Application):
class WebAppServer(AbstractWebApp):
def __init__(self, server_config):
AbstractWebApp.__init__(self, server_config)
aiohttp_web.Application.__init__(self)
self.set_app(aiohttp_web.Application())
self._ws_handlers = []
self._site = None
self._runner = None
Expand All @@ -52,7 +52,7 @@ def __init__(self, server_config):
aiohttp_web.get(_fix_path(route), protocol_handler.handleWsRequest)
)

self.add_routes(routes)
self.app.add_routes(routes)

if "static" in server_config:
static_routes = server_config["static"]
Expand All @@ -68,10 +68,10 @@ def __init__(self, server_config):
)

# Resolve / => index.html
self.router.add_route("GET", "/", _root_handler)
self.add_routes(routes)
self.app.router.add_route("GET", "/", _root_handler)
self.app.add_routes(routes)

self["state"] = {}
self.app["state"] = {}

# -------------------------------------------------------------------------
# Server status
Expand All @@ -94,7 +94,9 @@ def get_port(self):
# -------------------------------------------------------------------------

async def start(self, port_callback=None):
self._runner = aiohttp_web.AppRunner(self, handle_signals=self.handle_signals)
self._runner = aiohttp_web.AppRunner(
self.app, handle_signals=self.handle_signals
)

logging.info("awaiting runner setup")
await self._runner.setup()
Expand Down
26 changes: 15 additions & 11 deletions python/src/wslink/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self, server_config):
self._config = server_config
self._shutdown_task = None
self._completion = asyncio.get_event_loop().create_future()
self._app = None

# -------------------------------------------------------------------------
# Config helper
Expand Down Expand Up @@ -58,11 +59,22 @@ def last_active_client_id(self, value):
self._last_active_client_id = value

# -------------------------------------------------------------------------
# Legacy / deprecated
# Implementation server class
# -------------------------------------------------------------------------

def set_app(self, *args):
print("DEPRECATED: set_app()")
def set_app(self, app):
self._app = app

def get_app(self):
return self._app

@property
def app(self):
return self._app

# -------------------------------------------------------------------------
# Legacy / deprecated
# -------------------------------------------------------------------------

def get_config(self):
print("DEPRECATED: get_config() use property instead")
Expand All @@ -71,14 +83,6 @@ def get_config(self):
def set_config(self, config):
print("DEPRECATED: set_config() use constructor instead")

def get_app(self):
print("DEPRECATED: get_app()")
return self

@property
def app(self):
print("DEPRECATED: .app.")

def get_last_active_client_id(self):
print(
"DEPRECATED: get_last_active_client_id() should be replaced by last_active_client_id"
Expand Down

0 comments on commit a0c7e64

Please sign in to comment.