|
1 | 1 | from abc import ABCMeta, abstractmethod |
2 | | -from datetime import datetime, tzinfo |
| 2 | +from datetime import datetime |
3 | 3 | from pathlib import Path |
4 | 4 | from sys import stderr |
5 | 5 | from types import TracebackType |
6 | 6 | from typing import IO, Iterator, List, Match, Optional, Tuple, Type, Union |
7 | 7 |
|
8 | | -import dateutil.tz |
9 | 8 | from clp_ffi_py.ir import FourByteEncoder |
10 | 9 | from zstandard import ZstdDecompressionReader, ZstdDecompressor |
11 | 10 |
|
|
31 | 30 | VAR_COMPACT_ENCODING, |
32 | 31 | ) |
33 | 32 |
|
| 33 | +try: |
| 34 | + from zoneinfo import ZoneInfo # type: ignore[import-not-found, unused-ignore] |
| 35 | +except ImportError: |
| 36 | + from backports.zoneinfo import ( # type: ignore[import-not-found, no-redef, unused-ignore] |
| 37 | + ZoneInfo, |
| 38 | + ) |
| 39 | + |
34 | 40 |
|
35 | 41 | class Log: |
36 | 42 | """ |
@@ -61,7 +67,7 @@ def __init__(self) -> None: |
61 | 67 | def __str__(self) -> str: |
62 | 68 | return self.formatted_msg |
63 | 69 |
|
64 | | - def _decode(self, timestamp_format: Optional[str], timezone: Optional[tzinfo]) -> int: |
| 70 | + def _decode(self, timestamp_format: Optional[str], timezone: Optional[ZoneInfo]) -> int: |
65 | 71 | """ |
66 | 72 | Populate the `variables`, `msg`, and `formatted_msg` fields by decoding |
67 | 73 | the encoded `encoded_logtype and `encoded_variables`. |
@@ -148,7 +154,7 @@ def __init__(self, timestamp_format: Optional[str], chunk_size: int) -> None: |
148 | 154 | self.metadata: Optional[Metadata] = None |
149 | 155 | self.last_timestamp_ms: int |
150 | 156 | self.timestamp_format: Optional[str] = timestamp_format |
151 | | - self.timezone: Optional[tzinfo] |
| 157 | + self.timezone: Optional[ZoneInfo] |
152 | 158 | self.pos: int |
153 | 159 |
|
154 | 160 | def read_preamble(self) -> int: |
@@ -186,7 +192,7 @@ def read_preamble(self) -> int: |
186 | 192 | # We do not use the timestamp pattern from the preamble as it may |
187 | 193 | # be from other languages and therefore incompatible. |
188 | 194 | # self.timestamp_format = self.metadata[METADATA_TIMESTAMP_PATTERN_KEY] |
189 | | - self.timezone = dateutil.tz.gettz(self.metadata[METADATA_TZ_ID_KEY]) |
| 195 | + self.timezone = ZoneInfo(self.metadata[METADATA_TZ_ID_KEY]) |
190 | 196 | return self.pos |
191 | 197 |
|
192 | 198 | @abstractmethod |
|
0 commit comments