diff --git a/aiosmtpd/docs/proxyprotocol.rst b/aiosmtpd/docs/proxyprotocol.rst index eac41b0a..d5a3b650 100644 --- a/aiosmtpd/docs/proxyprotocol.rst +++ b/aiosmtpd/docs/proxyprotocol.rst @@ -203,7 +203,7 @@ Enums Valid only for address family of :attr:`AF.INET` or :attr:`AF.INET6` .. py:attribute:: rest - :type: ByteString + :type: bytearray The contents depend on the version of the PROXY header *and* (for version 2) the address family. @@ -374,7 +374,7 @@ Enums .. py:classmethod:: from_raw(raw) -> Optional[ProxyTLV] :param raw: The raw bytes containing the TLV Vectors - :type raw: ByteString + :type raw: bytearray :return: A new instance of ProxyTLV, or ``None`` if parsing failed This triggers the parsing of raw bytes/bytearray into a ProxyTLV instance. @@ -387,7 +387,7 @@ Enums .. py:classmethod:: parse(chunk, partial_ok=True) -> Dict[str, Any] :param chunk: The bytes to parse into TLV Vectors - :type chunk: ByteString + :type chunk: bytearray :param partial_ok: If ``True``, return partially-parsed TLV Vectors as is. If ``False``, (re)raise ``MalformedTLV`` :type partial_ok: bool diff --git a/aiosmtpd/proxy_protocol.py b/aiosmtpd/proxy_protocol.py index b5be17cb..3395b35b 100644 --- a/aiosmtpd/proxy_protocol.py +++ b/aiosmtpd/proxy_protocol.py @@ -9,7 +9,7 @@ from enum import IntEnum from functools import partial from ipaddress import IPv4Address, IPv6Address, ip_address -from typing import Any, ByteString, Dict, Optional, Protocol, Tuple, Union +from typing import Any, Dict, Optional, Protocol, Tuple, Union import attr from public import public @@ -165,7 +165,7 @@ def same_attribs(self, _raises: bool = False, **kwargs) -> bool: @classmethod def parse( cls, - data: ByteString, + data: bytearray, partial_ok: bool = True, strict: bool = False, ) -> Tuple[Dict[str, Any], Dict[str, int]]: @@ -179,7 +179,7 @@ def parse( rslt: Dict[str, Any] = {} tlv_loc: Dict[str, int] = {} - def _pars(chunk: ByteString, *, offset: int) -> None: + def _pars(chunk: bytearray, *, offset: int) -> None: i = 0 while i < len(chunk): typ = chunk[i] @@ -218,7 +218,7 @@ def _pars(chunk: ByteString, *, offset: int) -> None: @classmethod def from_raw( - cls, raw: ByteString, strict: bool = False + cls, raw: bytearray, strict: bool = False ) -> Optional["ProxyTLV"]: """ Parses raw bytes for TLV Vectors, decode them and giving them human-readable @@ -265,7 +265,7 @@ class ProxyData: dst_addr: Optional[EndpointAddress] = _anoinit(default=None) src_port: Optional[int] = _anoinit(default=None) dst_port: Optional[int] = _anoinit(default=None) - rest: ByteString = _anoinit(default=b"") + rest: bytearray = _anoinit(default=b"") """ Rest of PROXY Protocol data following UNKNOWN (v1) or UNSPEC (v2), or containing undecoded TLV (v2). If the latter, you can use the ProxyTLV class to parse the @@ -340,7 +340,7 @@ def __bool__(self) -> bool: # Reference: https://github.com/haproxy/haproxy/blob/v2.3.0/doc/proxy-protocol.txt -async def _get_v1(reader: AsyncReader, initial: ByteString = b"") -> ProxyData: +async def _get_v1(reader: AsyncReader, initial: bytearray = b"") -> ProxyData: proxy_data = ProxyData(version=1) proxy_data.whole_raw = bytearray(initial) @@ -424,7 +424,7 @@ async def get_ap(matcher: "re.Pattern[str]") -> str: return proxy_data -async def _get_v2(reader: AsyncReader, initial: ByteString = b"") -> ProxyData: +async def _get_v2(reader: AsyncReader, initial: bytearray = b"") -> ProxyData: proxy_data = ProxyData(version=2) whole_raw = bytearray()