Skip to content

Commit

Permalink
Merge branch 'feature/timezone-deprecations'
Browse files Browse the repository at this point in the history
  • Loading branch information
leonhard-s committed Nov 4, 2024
2 parents 50220ce + d88a645 commit f915a6b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
Expand Down
12 changes: 7 additions & 5 deletions auraxium/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ def __init__(self, type_: Type[_Ps2ObjectT], query: Query,
self._data: List[_Ps2ObjectT]
self._index: int
self._lock = asyncio.Lock()
self._last_fetched = datetime.datetime.fromtimestamp(0, datetime.UTC)
max_age = datetime.datetime.now(datetime.UTC) - self._last_fetched
self._last_fetched = datetime.datetime.fromtimestamp(
0, datetime.timezone.utc)
max_age = datetime.datetime.now(
datetime.timezone.utc) - self._last_fetched
assert self._ttu < max_age.total_seconds()

async def _poll(self) -> None:
Expand All @@ -70,7 +72,7 @@ async def _poll(self) -> None:
payload = await self._client.request(self.query)
list_ = self._resolve_nested_payload(payload)
self._data = [self._type(d, client=self._client) for d in list_]
self._last_fetched = datetime.datetime.now(datetime.UTC)
self._last_fetched = datetime.datetime.now(datetime.timezone.utc)

def _resolve_nested_payload(self, payload: CensusData) -> List[CensusData]:
"""Resolve the object payload.
Expand Down Expand Up @@ -143,7 +145,7 @@ def __aiter__(self) -> 'SequenceProxy[_Ps2ObjectT]':
return self

async def __anext__(self) -> _Ps2ObjectT:
age = datetime.datetime.now(datetime.UTC) - self._last_fetched
age = datetime.datetime.now(datetime.timezone.utc) - self._last_fetched
if age.total_seconds() > self._ttu:
if self._index > -1:
warnings.warn('Data went stale during iteration, polling new')
Expand Down Expand Up @@ -181,7 +183,7 @@ async def resolve(self) -> Optional[_Ps2ObjectT]:
:return: The object, or :obj:`None` if no match was found.
"""
age = datetime.datetime.now(datetime.UTC) - self._last_fetched
age = datetime.datetime.now(datetime.timezone.utc) - self._last_fetched
if age.total_seconds() > self._ttu:
await self._poll()
try:
Expand Down
89 changes: 32 additions & 57 deletions auraxium/census/_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class SearchModifier(enum.Enum):
GREATER_THAN_OR_EQUAL: ']', STARTS_WITH: '^',
CONTAINS: '*', NOT_EQUAL: '!'
"""
# pylint: disable=invalid-name

EQUAL_TO = 0
LESS_THAN = 1
Expand All @@ -45,77 +44,53 @@ class SearchModifier(enum.Enum):
CONTAINS = 6
NOT_EQUAL = 7

@classmethod
@property
def EQ(cls) -> 'SearchModifier':
"""Alias for :class:`EQUAL_TO <SearchModifier>`.
EQ = EQUAL_TO
"""Alias for :class:`EQUAL_TO <SearchModifier>`.
.. versionadded:: 0.2
"""
return cls.EQUAL_TO
.. versionadded:: 0.2
"""

@classmethod
@property
def LT(cls) -> 'SearchModifier':
"""Alias for :class:`LESS_THAN <SearchModifier>`.
LT = LESS_THAN
"""Alias for :class:`LESS_THAN <SearchModifier>`.
.. versionadded:: 0.2
"""
return cls.LESS_THAN
.. versionadded:: 0.2
"""

@classmethod
@property
def LTE(cls) -> 'SearchModifier':
"""Alias for :class:`LESS_THAN_OR_EQUAL <SearchModifier>`.
LTE = LESS_THAN_OR_EQUAL
"""Alias for :class:`LESS_THAN_OR_EQUAL <SearchModifier>`.
.. versionadded:: 0.2
"""
return cls.LESS_THAN_OR_EQUAL
.. versionadded:: 0.2
"""

@classmethod
@property
def GT(cls) -> 'SearchModifier':
"""Alias for :class:`GREATER_THAN <SearchModifier>`.
GT = GREATER_THAN
"""Alias for :class:`GREATER_THAN <SearchModifier>`.
.. versionadded:: 0.2
"""
return cls.GREATER_THAN
.. versionadded:: 0.2
"""

@classmethod
@property
def GTE(cls) -> 'SearchModifier':
"""Alias for :class:`GREATER_THAN_OR_EQUAL <SearchModifier>`.
GTE = GREATER_THAN_OR_EQUAL
"""Alias for :class:`GREATER_THAN_OR_EQUAL <SearchModifier>`.
.. versionadded:: 0.2
"""
return cls.GREATER_THAN_OR_EQUAL
.. versionadded:: 0.2
"""

@classmethod
@property
def SW(cls) -> 'SearchModifier':
"""Alias for :class:`STARTS_WITH <SearchModifier>`.
SW = STARTS_WITH
"""Alias for :class:`STARTS_WITH <SearchModifier>`.
.. versionadded:: 0.2
"""
return cls.STARTS_WITH
.. versionadded:: 0.2
"""

@classmethod
@property
def IN(cls) -> 'SearchModifier':
"""Alias for :class:`CONTAINS <SearchModifier>`.
IN = CONTAINS
"""Alias for :class:`CONTAINS <SearchModifier>`.
.. versionadded:: 0.2
"""
return cls.CONTAINS
.. versionadded:: 0.2
"""

@classmethod
@property
def NE(cls) -> 'SearchModifier':
"""Alias for :class:`NOT_EQUAL <SearchModifier>`.
NE = NOT_EQUAL
"""Alias for :class:`NOT_EQUAL <SearchModifier>`.
.. versionadded:: 0.2
"""
return cls.NOT_EQUAL
.. versionadded:: 0.2
"""

@classmethod
def from_value(cls, value: CensusValue) -> 'SearchModifier':
Expand Down
2 changes: 1 addition & 1 deletion auraxium/event/_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ async def run(self, event: Event) -> None:
:param Event event: The event to pass to the trigger action.
"""
self.last_run = datetime.datetime.now(datetime.UTC)
self.last_run = datetime.datetime.now(datetime.timezone.utc)
if self.action is None: # pragma: no cover
warnings.warn(f'Trigger {self.name} run with no action specified')
return
Expand Down
4 changes: 2 additions & 2 deletions auraxium/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ def _utc_from_timestamp(cls, value: str,
) -> datetime.datetime:
"""Convert timestamps to UTC datetimes."""
_ = info
return datetime.datetime.fromtimestamp(int(value), datetime.UTC)
return datetime.datetime.fromtimestamp(int(value), datetime.timezone.utc)

@property
def age(self) -> float:
"""The age of the event in seconds."""
now = datetime.datetime.now(datetime.UTC)
now = datetime.datetime.now(datetime.timezone.utc)
return (now - self.timestamp).total_seconds()


Expand Down
3 changes: 2 additions & 1 deletion auraxium/ps2/_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,5 @@ async def status(self) -> Tuple[str, datetime.datetime]:
data = extract_single(payload, 'game_server_status')
status = str(data['last_reported_state'])
last_updated = int(str(data['last_reported_time']))
return status, datetime.datetime.utcfromtimestamp(last_updated)
return status, datetime.datetime.fromtimestamp(
last_updated, datetime.timezone.utc)
2 changes: 1 addition & 1 deletion tests/unit/trigger_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class TriggerTest(unittest.TestCase):
"""Test cases for the auraxium.event.Trigger class."""

time = datetime.datetime.utcnow()
time = datetime.datetime.now(datetime.timezone.utc)

@classmethod
def death_evt_factory(cls, attacker: int, victim: int, world: int,
Expand Down

0 comments on commit f915a6b

Please sign in to comment.