Skip to content

Commit

Permalink
add StrEnum and async sock recv compat for python < 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
etene committed Jan 15, 2025
1 parent 10cb2eb commit 14cdae0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
14 changes: 14 additions & 0 deletions pyroute2/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'''Compatibility with older but supported Python versions'''

try:
from enum import StrEnum
except ImportError:
# StrEnum appeared in python 3.11

from enum import Enum

class StrEnum(str, Enum):
'''Same as enum, but members are also strings.'''


__all__ = ('StrEnum',)
2 changes: 1 addition & 1 deletion pyroute2/dhcp/dhcp4socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async def get(self) -> dhcp4msg:
only MAC/IPv4/UDP headers are stripped out, and the
rest is interpreted as DHCP.
'''
data, _ = await self.aio_loop.sock_recvfrom(self, 4096)
data = await self.aio_loop.sock_recv(self, 4096)
eth = ethmsg(buf=data).decode()
ip4 = ip4msg(buf=data, offset=eth.offset).decode()
udp = udpmsg(buf=data, offset=ip4.offset).decode()
Expand Down
4 changes: 3 additions & 1 deletion pyroute2/dhcp/fsm.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'''DHCP client state machine helpers.'''

from enum import StrEnum, auto
from enum import auto
from logging import getLogger
from typing import TYPE_CHECKING, Final

from pyroute2.compat import StrEnum

if TYPE_CHECKING:
from .client import AsyncDHCPClient

Expand Down

0 comments on commit 14cdae0

Please sign in to comment.