Fix Flake8 error and use UTC as default timezone

stix2.1
clenk 2017-04-17 13:16:14 -04:00
parent b4f116a33f
commit 40810646fb
2 changed files with 4 additions and 10 deletions

View File

@ -1,6 +1,6 @@
import re
import uuid
from six import PY2
from six import text_type
import datetime as dt
import pytz
from dateutil import parser
@ -134,10 +134,7 @@ class ListProperty(Property):
class StringProperty(Property):
def __init__(self, **kwargs):
if PY2:
self.string_type = unicode
else:
self.string_type = str
self.string_type = text_type
super(StringProperty, self).__init__(**kwargs)
def clean(self, value):
@ -224,7 +221,6 @@ class TimestampProperty(Property):
return parsed.astimezone(pytz.utc)
else:
# Doesn't have timezone info in the string; assume UTC
# TODO Should we default to system local timezone instead?
return pytz.utc.localize(parsed)

View File

@ -1,7 +1,6 @@
"""Utility functions and classes for the stix2 library."""
import datetime as dt
import time
import pytz
# Sentinel value for fields that should be set to the current time.
@ -24,9 +23,8 @@ def format_datetime(dttm):
try:
zoned = dttm.astimezone(pytz.utc)
except ValueError:
# dttm is timezone-naive
tz_name = time.tzname[time.localtime().tm_isdst]
zoned = pytz.timezone(tz_name).localize(dttm).astimezone(pytz.utc)
# dttm is timezone-naive; assume UTC
pytz.utc.localize(dttm)
ts = zoned.strftime("%Y-%m-%dT%H:%M:%S")
if zoned.microsecond > 0:
ms = zoned.strftime("%f")