Skip to content

Commit

Permalink
UPD: use private classes where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
desty2k committed Oct 14, 2021
1 parent a91df48 commit 7dda0d4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions QtPyNetwork/client/QThreadedClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from qtpy.QtCore import QObject, QIODevice, Signal, QMetaObject, Slot, QThread, Qt


class SocketClient(QObject):
class _SocketClient(QObject):
closed = Signal()
connected = Signal(str, int)
message = Signal(bytes)
Expand All @@ -21,7 +21,7 @@ class SocketClient(QObject):
disconnect_signal = Signal()

def __init__(self, ip: str, port: int, loggerName=None):
super(SocketClient, self).__init__(None)
super(_SocketClient, self).__init__(None)
self.ip = ip
self.port = port
self.logger_name = loggerName
Expand Down Expand Up @@ -171,7 +171,7 @@ def start(self, ip: str, port: int):
self.__ip = ip
self.__port = port

self.__client = SocketClient(self.__ip, self.__port, loggerName=self.__logger_name)
self.__client = _SocketClient(self.__ip, self.__port, loggerName=self.__logger_name)
self.__client_thread = QThread()

self.__client_thread.started.connect(self.__client.start)
Expand Down
14 changes: 7 additions & 7 deletions QtPyNetwork/server/QBalancedServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from QtPyNetwork.server.BaseServer import QBaseServer


class SocketWorker(QObject):
"""SocketWorker manages sockets and handles messages.
class _SocketWorker(QObject):
"""_SocketWorker manages sockets and handles messages.
Outgoing signals:
- disconnected (device_id: int): Client disconnected.
Expand Down Expand Up @@ -44,7 +44,7 @@ class SocketWorker(QObject):
kick = Signal(int)

def __init__(self, parent=None):
super(SocketWorker, self).__init__(parent)
super(_SocketWorker, self).__init__(parent)

@Slot()
def start(self) -> None:
Expand Down Expand Up @@ -246,7 +246,7 @@ def close(self):
self.closed.emit()


class BalancedSocketHandler(QObject):
class _BalancedSocketHandler(QObject):
"""Creates socket handlers threads. New sockets
are passed to worker with least load.
Expand Down Expand Up @@ -280,7 +280,7 @@ class BalancedSocketHandler(QObject):
close_signal = Signal()

def __init__(self, cores=None):
super(BalancedSocketHandler, self).__init__(None)
super(_BalancedSocketHandler, self).__init__(None)
self.cores = cores

@Slot()
Expand Down Expand Up @@ -314,7 +314,7 @@ def start(self):
def create_worker(self):
"""Creates new socket worker in thread."""
thread = QThread()
worker = SocketWorker()
worker = _SocketWorker()
worker.moveToThread(thread)

worker.connected.connect(self.connected.emit) # noqa
Expand Down Expand Up @@ -419,4 +419,4 @@ class QBalancedServer(QBaseServer):

def __init__(self, *args, **kwargs):
super(QBalancedServer, self).__init__(*args, **kwargs)
self.set_handler_class(BalancedSocketHandler)
self.set_handler_class(_BalancedSocketHandler)
12 changes: 6 additions & 6 deletions QtPyNetwork/server/QThreadedServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from QtPyNetwork.server.BaseServer import QBaseServer


class SocketClient(QObject):
class _SocketClient(QObject):
"""Keeps socket in separate thread.
Outgoing signals:
Expand Down Expand Up @@ -35,7 +35,7 @@ class SocketClient(QObject):
write = Signal(bytes)

def __init__(self, socket_descriptor, client_id):
super(SocketClient, self).__init__(None)
super(_SocketClient, self).__init__(None)
self.socket_descriptor = socket_descriptor
self.id = int(client_id)

Expand Down Expand Up @@ -152,7 +152,7 @@ def close(self):
self.closed.emit()


class ThreadedSocketHandler(QObject):
class _ThreadedSocketHandler(QObject):
"""Creates and manages socket client threads.
Outgoing signals:
Expand Down Expand Up @@ -185,7 +185,7 @@ class ThreadedSocketHandler(QObject):
close_signal = Signal()

def __init__(self):
super(ThreadedSocketHandler, self).__init__(None)
super(_ThreadedSocketHandler, self).__init__(None)

@Slot()
def start(self):
Expand All @@ -212,7 +212,7 @@ def on_incoming_connection(self, socket_descriptor: int) -> None:

thread = QThread()
thread.setObjectName(str(client_id))
client = SocketClient(socket_descriptor, client_id)
client = _SocketClient(socket_descriptor, client_id)
client.moveToThread(thread)
thread.started.connect(client.run) # noqa

Expand Down Expand Up @@ -332,4 +332,4 @@ class QThreadedServer(QBaseServer):

def __init__(self, *args, **kwargs):
super(QThreadedServer, self).__init__(*args, **kwargs)
self.set_handler_class(ThreadedSocketHandler)
self.set_handler_class(_ThreadedSocketHandler)

0 comments on commit 7dda0d4

Please sign in to comment.