Skip to content

Commit

Permalink
Fix 3.12 ET and datetime deprecation warnings (#842)
Browse files Browse the repository at this point in the history
  • Loading branch information
JSCU-CNI committed Sep 6, 2024
1 parent 85082d4 commit ce1e994
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
5 changes: 4 additions & 1 deletion dissect/target/plugins/os/windows/adpolicy.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def _xmltasks(self, policy_dir):
xml = task_file.read_text()
tree = ElementTree.fromstring(xml)
for task in tree.findall(".//{*}Task"):
properties = task.find("Properties") or task
# https://github.com/python/cpython/issues/83122
if (properties := task.find("Properties")) is None:
properties = task

task_data = ElementTree.tostring(task)
yield ADPolicyRecord(
last_modification_time=task_file_stat.st_mtime,
Expand Down
4 changes: 2 additions & 2 deletions dissect/target/plugins/os/windows/regf/shimcache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import binascii
from datetime import datetime
from enum import IntEnum, auto
from enum import IntEnum
from io import BytesIO
from typing import Callable, Generator, Optional, Tuple, Union

Expand Down Expand Up @@ -116,7 +116,7 @@ class SHIMCACHE_WIN_TYPE(IntEnum):
VERSION_NT61 = 0x0601
VERSION_NT52 = 0x0502

VERSION_WIN81_NO_HEADER = auto()
VERSION_WIN81_NO_HEADER = 0x1002 # auto()


def win_10_path(ed: Structure) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def get_raw(self, xml_path: Optional[str] = None) -> str:
bytes: The raw XML data as string of the element if found, otherwise None.
"""
data = self.task_element.find(xml_path) if xml_path else self.task_element
if data:
if data is not None:
return ElementTree.tostring(data, encoding="utf-8").strip()

def get_triggers(self) -> Iterator[GroupedRecord]:
Expand Down
4 changes: 2 additions & 2 deletions dissect/target/tools/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import pathlib
import sys
from datetime import datetime
from datetime import datetime, timezone
from typing import Callable

from flow.record import RecordPrinter, RecordStreamWriter, RecordWriter
Expand Down Expand Up @@ -390,7 +390,7 @@ def main():
log.debug("", exc_info=e)
parser.exit(1)

timestamp = datetime.utcnow()
timestamp = datetime.now(tz=timezone.utc)

execution_report.set_plugin_stats(PLUGINS)
log.debug("%s", execution_report.get_formatted_report())
Expand Down
7 changes: 4 additions & 3 deletions tests/plugins/apps/ssh/test_putty.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ def test_putty_plugin_saved_sessions_unix(target_unix_users: Target, fs_unix: Vi

assert len(records) == 1

assert records[0].ts == datetime.utcfromtimestamp(
stat(absolute_path("_data/plugins/apps/ssh/putty/sessions/example-saved-session")).st_mtime
).replace(tzinfo=timezone.utc)
assert records[0].ts == datetime.fromtimestamp(
stat(absolute_path("_data/plugins/apps/ssh/putty/sessions/example-saved-session")).st_mtime,
tz=timezone.utc,
)
assert records[0].session_name == "example-saved-session"
assert records[0].protocol == "ssh"
assert records[0].host == "192.168.123.130"
Expand Down
4 changes: 2 additions & 2 deletions tests/plugins/os/unix/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
def test_unix_generic_activity(target_unix, fs_unix):
fs_unix.map_file("/var/log/some.log", absolute_path("_data/plugins/os/unix/log/empty.log"))
target_unix.add_plugin(GenericPlugin)
assert target_unix.activity == datetime.utcfromtimestamp(log_mtime).replace(tzinfo=timezone.utc)
assert target_unix.activity == datetime.fromtimestamp(log_mtime, tz=timezone.utc)


def test_unix_generic_install_date(target_unix, fs_unix):
fs_unix.map_file("/var/log/installer/syslog", absolute_path("_data/plugins/os/unix/log/empty.log"))
target_unix.add_plugin(GenericPlugin)
assert target_unix.install_date == datetime.utcfromtimestamp(log_mtime).replace(tzinfo=timezone.utc)
assert target_unix.install_date == datetime.fromtimestamp(log_mtime, tz=timezone.utc)

0 comments on commit ce1e994

Please sign in to comment.