Some client improvements and some improvements to testing classes for non-rf testing.
This commit is contained in:
@@ -7,6 +7,7 @@ from typing import Union, Self, Optional
|
||||
import os.path
|
||||
import logging
|
||||
import ax25
|
||||
from shutil import rmtree
|
||||
|
||||
class DummyPacketServerConnection(PacketServerConnection):
|
||||
|
||||
@@ -90,9 +91,17 @@ class DirectoryTestServerConnection(PacketServerConnection):
|
||||
file_path = os.path.join(self._directory, file_name)
|
||||
return file_path
|
||||
|
||||
def close(self):
|
||||
self.closing = True
|
||||
self._state = ConnectionState.DISCONNECTED
|
||||
if os.path.exists(self._directory):
|
||||
rmtree(self._directory)
|
||||
|
||||
def check_closed(self):
|
||||
if self.closing:
|
||||
self._state = ConnectionState.DISCONNECTED
|
||||
if os.path.exists(self._directory):
|
||||
rmtree(self._directory)
|
||||
if self._state is not ConnectionState.CONNECTED:
|
||||
return True
|
||||
if not os.path.isdir(self._directory):
|
||||
@@ -256,6 +265,7 @@ class SimpleDirectoryConnection:
|
||||
"""Monitors connection directory for data."""
|
||||
if self.closing:
|
||||
self._state = ConnectionState.DISCONNECTED
|
||||
logging.debug(f"Connection {self} closed.")
|
||||
if self.check_closed():
|
||||
return False
|
||||
if os.path.isfile(self.remote_file_path):
|
||||
|
||||
@@ -7,6 +7,8 @@ import os.path
|
||||
from io import BytesIO, BufferedReader
|
||||
import random
|
||||
import string
|
||||
from persistent.mapping import PersistentMapping
|
||||
from persistent.list import PersistentList
|
||||
|
||||
def email_valid(email: str) -> bool:
|
||||
"""Taken from https://www.geeksforgeeks.org/check-if-email-address-valid-or-not-in-python/"""
|
||||
@@ -149,3 +151,25 @@ class TarFileExtractor(object):
|
||||
name = str(name)
|
||||
self._count = self._count + 1
|
||||
return os.path.basename(name), self.tar_file.extractfile(member)
|
||||
|
||||
def convert_to_persistent(data: Union[list,dict]):
|
||||
if isinstance(data, dict):
|
||||
persistent_dict = PersistentMapping()
|
||||
for key, value in data.items():
|
||||
persistent_dict[key] = convert_to_persistent(value)
|
||||
return persistent_dict
|
||||
elif isinstance(data, list):
|
||||
return PersistentList([convert_to_persistent(item) for item in data])
|
||||
else:
|
||||
return data
|
||||
|
||||
def convert_from_persistent(data):
|
||||
if isinstance(data, PersistentMapping):
|
||||
nonpersistent_dict = {}
|
||||
for key, value in data.items():
|
||||
nonpersistent_dict[key] = convert_from_persistent(value)
|
||||
return nonpersistent_dict
|
||||
elif isinstance(data, PersistentList):
|
||||
return [convert_from_persistent(item) for item in data]
|
||||
else:
|
||||
return data
|
||||
Reference in New Issue
Block a user