Remove the TZ*Values and rely on datetime.datetime directly.

This commit is contained in:
Mike Auty
2018-04-12 15:43:02 +01:00
parent 6402c94078
commit 90641befd2
2 changed files with 6 additions and 23 deletions
+3 -11
View File
@@ -2,11 +2,12 @@
or in some other form. This module defines both the output format (:class:`TreeGrid`) and the renderer interface
which can interact with a TreeGrid to produce suitable output."""
import collections
import datetime
import typing
from abc import abstractmethod, ABCMeta
import collections
from volatility.framework import validity
Column = collections.namedtuple('Column', ['index', 'name', 'type'])
@@ -81,22 +82,13 @@ class BaseAbsentValue(object):
# We don't class these off a shared base, because the SimpleTypes must only
# contain the types that the validator will accept (which would not include the base)
class TZAwareValue(datetime.datetime):
"""Class for TZ-aware datetimes"""
class TZNaiveValue(datetime.datetime):
"""Class for TZ-aware datetimes"""
_Type = typing.TypeVar("_Type")
ColumnsType = typing.List[typing.Tuple[str, typing.Type]]
SimpleTypes = typing.Union[typing.Type[int],
typing.Type[str],
typing.Type[float],
typing.Type[bytes],
typing.Type[TZAwareValue],
typing.Type[TZNaiveValue],
typing.Type[datetime.datetime],
typing.Type[BaseAbsentValue]]
VisitorSignature = typing.Callable[[TreeNode, _Type], _Type]
+3 -12
View File
@@ -61,18 +61,9 @@ class TreeNode(interfaces.renderers.TreeNode):
column.name,
type(val),
column.type))
if isinstance(val, (interfaces.renderers.TZAwareValue, interfaces.renderers.TZNaiveValue)):
tznaive = val.tzinfo is None or val.tzinfo.utcoffset(val) is None
if isinstance(val, interfaces.renderers.TZAwareValue) and tznaive:
raise TypeError(
"Values item with index {} is not a timezone aware datetime object as required by column {}".format(
index,
column.name))
elif isinstance(val, interfaces.renderers.TZNaiveValue) and not tznaive:
raise TypeError(
"Values item with index {} is not a timezone naive datetime object as required by column {}".format(
index,
column.name))
# TODO: Consider how to deal with timezone naive/aware datetimes (and alert plugin uses to be precise)
# if isinstance(val, datetime.datetime):
# tznaive = val.tzinfo is None or val.tzinfo.utcoffset(val) is None
@property
def values(self) -> typing.Iterable[interfaces.renderers.SimpleTypes]: