Compare commits

..

1 Commits

Author SHA1 Message Date
Josiah Baldwin
564d466ff9 Fixed listening to raw not removing its listener correctly 2025-01-08 13:57:28 -08:00
4 changed files with 9 additions and 28 deletions

View File

@@ -2,9 +2,7 @@ class MeshCtrlError(Exception):
""" """
Base class for Meshctrl errors Base class for Meshctrl errors
""" """
def __init__(self, message, *args, **kwargs): pass
self.message = message
super().__init__(message, *args, **kwargs)
class ServerError(MeshCtrlError): class ServerError(MeshCtrlError):
""" """
@@ -27,7 +25,6 @@ class FileTransferError(MeshCtrlError):
""" """
def __init__(self, message, stats): def __init__(self, message, stats):
self.stats = stats self.stats = stats
super().__init__(message)
class FileTransferCancelled(FileTransferError): class FileTransferCancelled(FileTransferError):
""" """

View File

@@ -533,7 +533,7 @@ class Session(object):
data = await event_queue.get() data = await event_queue.get()
yield data yield data
finally: finally:
self._eventer.off("server_event", _) self._eventer.off("raw", _)
async def events(self, filter=None): async def events(self, filter=None):
''' '''

View File

@@ -140,20 +140,17 @@ def compare_dict(dict1, dict2):
return False return False
def _check_socket(f): def _check_socket(f):
async def _check_errs(self): @functools.wraps(f)
async def wrapper(self, *args, **kwargs):
try:
async with asyncio.TaskGroup() as tg:
tg.create_task(asyncio.wait_for(self.initialized.wait(), 10))
tg.create_task(asyncio.wait_for(self._socket_open.wait(), 10))
finally:
if not self.alive and self._main_loop_error is not None: if not self.alive and self._main_loop_error is not None:
raise self._main_loop_error raise self._main_loop_error
elif not self.alive and self.initialized.is_set(): elif not self.alive and self.initialized.is_set():
raise exceptions.SocketError("Socket Closed") raise exceptions.SocketError("Socket Closed")
@functools.wraps(f)
async def wrapper(self, *args, **kwargs):
try:
await asyncio.wait_for(self.initialized.wait(), 10)
await _check_errs(self)
await asyncio.wait_for(self._socket_open.wait(), 10)
finally:
await _check_errs(self)
return await f(self, *args, **kwargs) return await f(self, *args, **kwargs)
return wrapper return wrapper

View File

@@ -5,8 +5,6 @@ import meshctrl
import requests import requests
import random import random
import io import io
import traceback
import time
thisdir = os.path.dirname(os.path.realpath(__file__)) thisdir = os.path.dirname(os.path.realpath(__file__))
async def test_admin(env): async def test_admin(env):
@@ -79,17 +77,6 @@ async def test_users(env):
pass pass
else: else:
raise Exception("Connected with no password") raise Exception("Connected with no password")
start = time.time()
try:
async with meshctrl.Session(env.mcurl, user="admin", password="The wrong password", ignore_ssl=True) as admin_session:
pass
except* meshctrl.exceptions.ServerError as eg:
assert str(eg.exceptions[0]) == "Invalid Auth" or eg.exceptions[0].message == "Invalid Auth", "Didn't get invalid auth message"
assert time.time() - start < 10, "Invalid auth wasn't raised until after timeout"
pass
else:
raise Exception("Connected with bad password")
async with meshctrl.Session(env.mcurl+"/", user="admin", password=env.users["admin"], ignore_ssl=True) as admin_session,\ async with meshctrl.Session(env.mcurl+"/", user="admin", password=env.users["admin"], ignore_ssl=True) as admin_session,\
meshctrl.Session(env.mcurl, user="privileged", password=env.users["privileged"], ignore_ssl=True) as privileged_session,\ meshctrl.Session(env.mcurl, user="privileged", password=env.users["privileged"], ignore_ssl=True) as privileged_session,\
meshctrl.Session(env.mcurl, user="unprivileged", password=env.users["unprivileged"], ignore_ssl=True) as unprivileged_session: meshctrl.Session(env.mcurl, user="unprivileged", password=env.users["unprivileged"], ignore_ssl=True) as unprivileged_session: