aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Touhey <thomas@touhey.fr>2022-09-10 17:08:39 +0200
committerThomas Touhey <thomas@touhey.fr>2022-09-10 17:08:39 +0200
commit7d96a34e2ab4a187159577440e69b866a4d13e2a (patch)
treeb06cf69818e0155d97dad6affd615a268357abdd
parent7aa4d6da423b4ac8cde845dc4a555e88eb48d26e (diff)
Added slots to all objectsHEADmaster
-rw-r--r--pyfingerd/binds.py6
-rwxr-xr-xpyfingerd/cli.py1
-rwxr-xr-xpyfingerd/core.py6
-rwxr-xr-xpyfingerd/errors.py12
-rwxr-xr-xpyfingerd/fiction.py41
-rwxr-xr-xpyfingerd/native.py2
-rwxr-xr-xpyfingerd/posix.py2
7 files changed, 60 insertions, 10 deletions
diff --git a/pyfingerd/binds.py b/pyfingerd/binds.py
index 0de3bc6..230517e 100644
--- a/pyfingerd/binds.py
+++ b/pyfingerd/binds.py
@@ -28,6 +28,8 @@ class FingerBind:
class FingerTCPv4Bind(FingerBind):
"""IPv4 TCP Address."""
+ __slots__ = ('_addr', '_port')
+
def __init__(self, address: str, port: int):
self._addr = _socket.inet_pton(_socket.AF_INET, address)
self._port = port
@@ -45,6 +47,8 @@ class FingerTCPv4Bind(FingerBind):
class FingerTCPv6Bind(FingerBind):
"""IPv6 TCP Address."""
+ __slots__ = ('_addr', '_port')
+
def __init__(self, address: str, port: int):
self._addr = _socket.inet_pton(_socket.AF_INET6, address)
self._port = port
@@ -62,6 +66,8 @@ class FingerTCPv6Bind(FingerBind):
class FingerBindsDecoder:
"""Binds decoder for pyfingerd."""
+ __port__ = ('_proto',)
+
def __init__(self, proto: str = 'finger'):
proto = proto.casefold()
if proto not in ('finger',):
diff --git a/pyfingerd/cli.py b/pyfingerd/cli.py
index 56b001d..6d33e4b 100755
--- a/pyfingerd/cli.py
+++ b/pyfingerd/cli.py
@@ -10,7 +10,6 @@ from platform import (
python_implementation as _python_impl,
python_version as _python_version,
)
-from sys import stderr as _stderr
import click as _click
diff --git a/pyfingerd/core.py b/pyfingerd/core.py
index 36b8b0e..c802c49 100755
--- a/pyfingerd/core.py
+++ b/pyfingerd/core.py
@@ -442,6 +442,8 @@ class FingerFormatter:
:param tzinfo: Timezone used for formatting dates and times.
"""
+ __slots__ = ('_tzinfo',)
+
def __init__(self, tzinfo: _t.Optional[_tzinfo] = None):
if tzinfo is None:
tzinfo = _dt.now().astimezone().tzinfo
@@ -699,6 +701,8 @@ class FingerInterface:
By default, it behaves like a dummy interface.
"""
+ __slots__ = ()
+
def __repr__(self):
return f'{self.__class__.__name__}()'
@@ -823,6 +827,8 @@ class FingerServer:
answers sent to clients.
"""
+ __slots__ = ('_host', '_interface', '_formatter', '_binds', '_p')
+
_p: _t.Optional[_multip.Process] = None
"""Process running the pyfingerd server."""
diff --git a/pyfingerd/errors.py b/pyfingerd/errors.py
index 796325c..2af5e39 100755
--- a/pyfingerd/errors.py
+++ b/pyfingerd/errors.py
@@ -18,12 +18,14 @@ __all__ = [
class ConfigurationError(Exception):
"""Raised when an invalid configuration option is set."""
- pass
+ __slots__ = ()
class HostnameError(ConfigurationError):
"""Raised when a host name is invalid."""
+ __slots__ = ()
+
def __init__(self, hostname):
super().__init__(f'Invalid host name {hostname!r}.')
@@ -31,6 +33,8 @@ class HostnameError(ConfigurationError):
class BindError(ConfigurationError):
"""Raised when an error has occurred with the provided binds."""
+ __slots__ = ('original_message',)
+
def __init__(self, msg):
self.original_message = msg
super().__init__(
@@ -41,6 +45,8 @@ class BindError(ConfigurationError):
class NoBindsError(BindError):
"""Raised when no binds were provided."""
+ __slots__ = ()
+
def __init__(self):
super().__init__('No valid bind')
@@ -48,6 +54,8 @@ class NoBindsError(BindError):
class InvalidBindError(BindError):
"""Raised when one of the provided binds came out erroneous."""
+ __slots__ = ('original_message',)
+
def __init__(self, bind, msg=None):
super().__init__(
f'One of the provided bind ({bind!r}) '
@@ -61,6 +69,8 @@ class InvalidBindError(BindError):
class MalformedQueryError(Exception):
"""Raised when a malformed query is received."""
+ __slots__ = ('query', 'msg')
+
def __init__(self, query, msg=None):
self.query = query
self.msg = msg
diff --git a/pyfingerd/fiction.py b/pyfingerd/fiction.py
index 8e70681..7583164 100755
--- a/pyfingerd/fiction.py
+++ b/pyfingerd/fiction.py
@@ -53,7 +53,7 @@ class FictionalFingerUser(_FingerUser):
For now, there are no modifications from the base class.
"""
- pass
+ __slots__ = ()
class FictionalFingerSession(_FingerSession):
@@ -153,6 +153,8 @@ class FictionalFingerSession(_FingerSession):
class UnchangedType:
+ __slots__ = ()
+
def __new__(mcls, *args, **kwargs):
# We want the same instance to be returned always when required.
try:
@@ -176,7 +178,7 @@ Unchanged = UnchangedType()
class FingerAction:
"""Base class for actions in a fiction."""
- pass
+ __slots__ = ()
class FingerUserCreationAction(FingerAction):
@@ -192,6 +194,8 @@ class FingerUserCreationAction(FingerAction):
:param plan: The initial value for :py:attr:`FictionalFingerUser.plan`.
"""
+ __slots__ = ('_login', '_name', '_home', '_shell', '_office', '_plan')
+
def __init__(
self,
login: str,
@@ -263,6 +267,8 @@ class FingerUserEditionAction(FingerAction):
:py:data:`Unchanged` if the property is unchanged.
"""
+ __slots__ = ('_login', '_name', '_home', '_shell', '_office', '_plan')
+
def __init__(
self,
login: str,
@@ -339,12 +345,14 @@ class FingerUserDeletionAction(FingerAction):
:param login: The login of the user to delete.
"""
+ __slots__ = ('_login',)
+
def __init__(self, login: str):
super().__init__()
self._login = login
def __repr__(self):
- p = (f'{x}={getattr(self, x)!r}' for x in ('login'))
+ p = (f'{x}={getattr(self, x)!r}' for x in ('login',))
return f"{self.__class__.__name__}({', '.join(p)})"
@property
@@ -362,6 +370,8 @@ class FingerUserLoginAction(FingerAction):
:param host: The new value for :py:attr:`FictionalFingerSession.host`.
"""
+ __slots__ = ('_login', '_session', '_line', '_host')
+
def __init__(
self,
login: str,
@@ -413,6 +423,8 @@ class FingerUserSessionChangeAction(FingerAction):
:py:data:`Unchanged` if the property is unchanged.
"""
+ __slots__ = ('_login', '_session', '_idle')
+
def __init__(
self,
login: str,
@@ -457,6 +469,8 @@ class FingerUserLogoutAction(FingerAction):
:param session_name: The name of the session to delete.
"""
+ __slots__ = ('_login', '_session')
+
def __init__(
self,
login: str,
@@ -504,6 +518,8 @@ class FingerFictionInterface(_FingerInterface):
a live source.
"""
+ __slots__ = ('_users', '_lasttime')
+
def __init__(self):
super().__init__()
@@ -692,6 +708,8 @@ class FingerScenario:
on repeat.
"""
+ __slots__ = ('_end_type', '_end_time', '_actions')
+
class EndingType(_Enum):
"""Ending type, i.e. what happens when the scenario comes to an end.
@@ -713,13 +731,10 @@ class FingerScenario:
STOP = 1
REPEAT = 2
- def __init__(self):
- self._end_type = None
- self._end_time = None
- self._actions = []
+ _end_type: _t.Optional[EndingType]
@property
- def ending_type(self) -> EndingType:
+ def ending_type(self) -> _t.Optional[EndingType]:
"""Get the ending type of the scenario."""
return self._end_type
@@ -769,6 +784,11 @@ class FingerScenario:
self._end_time = _make_delta(value)
+ def __init__(self):
+ self._end_type = None
+ self._end_time = None
+ self._actions = []
+
def verify(self) -> None:
"""Verify that the current scenario is valid.
@@ -1097,6 +1117,8 @@ class FingerScenarioInterface(FingerFictionInterface):
have started; by default, the current time is used.
"""
+ __slots__ = ('_scenario', '_start', '_laststart', '_lastdelta')
+
def __init__(
self,
scenario: FingerScenario,
@@ -1148,6 +1170,9 @@ class FingerScenarioInterface(FingerFictionInterface):
# Check if we have reached an ending.
if now > start + self._scenario.duration:
ending_type = self._scenario.ending_type
+ if ending_type is None:
+ raise AssertionError("Ending type shouldn't be None here!")
+
if ending_type == FingerScenario.EndingType.STOP:
_logger.debug('Stop ending has been reached.')
exit()
diff --git a/pyfingerd/native.py b/pyfingerd/native.py
index 3a4c175..bcfdf15 100755
--- a/pyfingerd/native.py
+++ b/pyfingerd/native.py
@@ -17,6 +17,8 @@ FingerNativeInterface: _t.Type[_FingerInterface]
class _FingerNoNativeFoundInterface(_FingerInterface):
"""Placeholder that doesn't initiate."""
+ __slots__ = ()
+
def __init__(self, *args, **kwargs):
raise NotImplementedError(
'Could not find a suitable native interface.',
diff --git a/pyfingerd/posix.py b/pyfingerd/posix.py
index daa556b..27941a9 100755
--- a/pyfingerd/posix.py
+++ b/pyfingerd/posix.py
@@ -36,6 +36,8 @@ class FingerPOSIXInterface(_FingerInterface):
will result in an ``ImportError``.
"""
+ __slots__ = ('_data', '_lastrefreshtime', '_lock')
+
def __init__(self):
self._data = []
self._lastrefreshtime = None