Browse Source

add dunders to classes

pull/43/head
Alex Nørgaard 2 years ago
parent
commit
e162c7b72e
No known key found for this signature in database GPG Key ID: 94D54F6A3604E97
  1. 14
      a2s/a2s_async.py
  2. 10
      a2s/a2s_fragment.py
  3. 7
      a2s/a2s_sync.py
  4. 13
      a2s/byteio.py

14
a2s/a2s_async.py

@ -148,6 +148,14 @@ async def request_async_impl(
class A2SProtocol(asyncio.DatagramProtocol):
__slots__ = (
"recv_queue",
"error_event",
"error",
"fragment_buf",
"transport",
)
def __init__(self):
self.recv_queue: asyncio.Queue[bytes] = asyncio.Queue()
self.error_event: asyncio.Event = asyncio.Event()
@ -192,6 +200,12 @@ class A2SProtocol(asyncio.DatagramProtocol):
class A2SStreamAsync:
__slots__ = (
"transport",
"protocol",
"timeout",
)
def __init__(self, transport: asyncio.DatagramTransport, protocol: A2SProtocol, timeout: float) -> None:
self.transport = transport
self.protocol = protocol

10
a2s/a2s_fragment.py

@ -29,6 +29,16 @@ from a2s.byteio import ByteReader
class A2SFragment:
__slots__ = (
"message_id",
"fragment_count",
"fragment_id",
"mtu",
"decompressed_size",
"crc",
"payload",
)
def __init__(
self,
message_id: int,

7
a2s/a2s_sync.py

@ -48,8 +48,6 @@ logger: logging.Logger = logging.getLogger("a2s")
T = TypeVar("T", InfoProtocol, RulesProtocol, PlayersProtocol)
__all__ = ("A2SStream",)
@overload
def request_sync(
@ -139,6 +137,11 @@ def request_sync_impl(
class A2SStream:
__slots__ = (
"address",
"_socket",
)
def __init__(self, address: Tuple[str, int], timeout: float) -> None:
self.address: Tuple[str, int] = address
self._socket: socket.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

13
a2s/byteio.py

@ -32,7 +32,6 @@ from a2s.exceptions import BufferExhaustedError
from .defaults import DEFAULT_ENCODING
if TYPE_CHECKING:
from typing_extensions import Literal
@ -42,6 +41,12 @@ STRUCT_OPTIONS = Literal[
class ByteReader:
__slots__ = (
"stream",
"endian",
"encoding",
)
def __init__(self, stream: io.BytesIO, endian: str = "=", encoding: Optional[str] = None) -> None:
self.stream: io.BytesIO = stream
self.endian: str = endian
@ -126,6 +131,12 @@ class ByteReader:
class ByteWriter:
__slots__ = (
"stream",
"endian",
"encoding",
)
def __init__(self, stream: io.BytesIO, endian: str = "=", encoding: Optional[str] = None) -> None:
self.stream: io.BytesIO = stream
self.endian: str = endian

Loading…
Cancel
Save