mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-12 00:44:19 -05:00
Fix warnings about not calling superclass constructor
Separate `SimpleCommand` from `Command`, so that things which don't want to use the `data` property don't have to, and thus fix the warnings PyCharm was giving me about not calling `__init__` in the base class.
This commit is contained in:
parent
6a519a0ca0
commit
c3e4b4edb2
@ -17,7 +17,7 @@
|
|||||||
The VALID_SERVER_COMMANDS and VALID_CLIENT_COMMANDS define which commands are
|
The VALID_SERVER_COMMANDS and VALID_CLIENT_COMMANDS define which commands are
|
||||||
allowed to be sent by which side.
|
allowed to be sent by which side.
|
||||||
"""
|
"""
|
||||||
|
import abc
|
||||||
import logging
|
import logging
|
||||||
import platform
|
import platform
|
||||||
from typing import Tuple, Type
|
from typing import Tuple, Type
|
||||||
@ -34,34 +34,29 @@ else:
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Command(object):
|
class Command(metaclass=abc.ABCMeta):
|
||||||
"""The base command class.
|
"""The base command class.
|
||||||
|
|
||||||
All subclasses must set the NAME variable which equates to the name of the
|
All subclasses must set the NAME variable which equates to the name of the
|
||||||
command on the wire.
|
command on the wire.
|
||||||
|
|
||||||
A full command line on the wire is constructed from `NAME + " " + to_line()`
|
A full command line on the wire is constructed from `NAME + " " + to_line()`
|
||||||
|
|
||||||
The default implementation creates a command of form `<NAME> <data>`
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
NAME = None # type: str
|
NAME = None # type: str
|
||||||
|
|
||||||
def __init__(self, data):
|
|
||||||
self.data = data
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@abc.abstractmethod
|
||||||
def from_line(cls, line):
|
def from_line(cls, line):
|
||||||
"""Deserialises a line from the wire into this command. `line` does not
|
"""Deserialises a line from the wire into this command. `line` does not
|
||||||
include the command.
|
include the command.
|
||||||
"""
|
"""
|
||||||
return cls(line)
|
|
||||||
|
|
||||||
def to_line(self):
|
@abc.abstractmethod
|
||||||
|
def to_line(self) -> str:
|
||||||
"""Serialises the comamnd for the wire. Does not include the command
|
"""Serialises the comamnd for the wire. Does not include the command
|
||||||
prefix.
|
prefix.
|
||||||
"""
|
"""
|
||||||
return self.data
|
|
||||||
|
|
||||||
def get_logcontext_id(self):
|
def get_logcontext_id(self):
|
||||||
"""Get a suitable string for the logcontext when processing this command"""
|
"""Get a suitable string for the logcontext when processing this command"""
|
||||||
@ -70,7 +65,21 @@ class Command(object):
|
|||||||
return self.NAME
|
return self.NAME
|
||||||
|
|
||||||
|
|
||||||
class ServerCommand(Command):
|
class _SimpleCommand(Command):
|
||||||
|
"""An implementation of Command whose argument is just a 'data' string."""
|
||||||
|
|
||||||
|
def __init__(self, data):
|
||||||
|
self.data = data
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_line(cls, line):
|
||||||
|
return cls(line)
|
||||||
|
|
||||||
|
def to_line(self) -> str:
|
||||||
|
return self.data
|
||||||
|
|
||||||
|
|
||||||
|
class ServerCommand(_SimpleCommand):
|
||||||
"""Sent by the server on new connection and includes the server_name.
|
"""Sent by the server on new connection and includes the server_name.
|
||||||
|
|
||||||
Format::
|
Format::
|
||||||
@ -155,7 +164,7 @@ class PositionCommand(Command):
|
|||||||
return " ".join((self.stream_name, str(self.token)))
|
return " ".join((self.stream_name, str(self.token)))
|
||||||
|
|
||||||
|
|
||||||
class ErrorCommand(Command):
|
class ErrorCommand(_SimpleCommand):
|
||||||
"""Sent by either side if there was an ERROR. The data is a string describing
|
"""Sent by either side if there was an ERROR. The data is a string describing
|
||||||
the error.
|
the error.
|
||||||
"""
|
"""
|
||||||
@ -163,14 +172,14 @@ class ErrorCommand(Command):
|
|||||||
NAME = "ERROR"
|
NAME = "ERROR"
|
||||||
|
|
||||||
|
|
||||||
class PingCommand(Command):
|
class PingCommand(_SimpleCommand):
|
||||||
"""Sent by either side as a keep alive. The data is arbitary (often timestamp)
|
"""Sent by either side as a keep alive. The data is arbitary (often timestamp)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
NAME = "PING"
|
NAME = "PING"
|
||||||
|
|
||||||
|
|
||||||
class NameCommand(Command):
|
class NameCommand(_SimpleCommand):
|
||||||
"""Sent by client to inform the server of the client's identity. The data
|
"""Sent by client to inform the server of the client's identity. The data
|
||||||
is the name
|
is the name
|
||||||
"""
|
"""
|
||||||
@ -387,7 +396,7 @@ class UserIpCommand(Command):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class RemoteServerUpCommand(Command):
|
class RemoteServerUpCommand(_SimpleCommand):
|
||||||
"""Sent when a worker has detected that a remote server is no longer
|
"""Sent when a worker has detected that a remote server is no longer
|
||||||
"down" and retry timings should be reset.
|
"down" and retry timings should be reset.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user