Skip to content

Commit

Permalink
Replaced stub TimeZone_UTC() class with the standard datetime.timezon…
Browse files Browse the repository at this point in the history
…e.utc. This drops support for Python 3.8 and earlier, but OWSLib now targets 3.10 and later.
  • Loading branch information
spillner committed Oct 10, 2024
1 parent bcc4b20 commit 1058b0b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
19 changes: 2 additions & 17 deletions owslib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import sys
from collections import OrderedDict
from dateutil import parser
from datetime import datetime, timedelta, tzinfo
from datetime import datetime, timezone
from owslib.etree import etree, ParseError
from owslib.namespaces import Namespaces
from urllib.parse import urlsplit, urlencode, urlparse, parse_qs, urlunparse, parse_qsl
Expand All @@ -36,21 +36,6 @@ class ServiceException(Exception):
pass


# Allows marking timestamps as UTC without pulling in all of Pytz
class TimeZone_UTC(tzinfo):
def tzname(self, dt):
return "UTC"

def utcoffset(self, dt):
return timedelta(0)

def dst(self, dt):
return timedelta(0)


tz_utc = TimeZone_UTC()


# http://stackoverflow.com/questions/6256183/combine-two-dictionaries-of-dictionaries-python
def dict_union(d1, d2):
return dict((x, (dict_union(d1.get(x, {}), d2[x]) if isinstance(d2.get(x), dict) else d2.get(x, d1.get(x))))
Expand Down Expand Up @@ -662,7 +647,7 @@ def extract_time(element):
except Exception:
att = testXMLValue(element.attrib.get('indeterminatePosition'), True)
if att and att == 'now':
dt = datetime.utcnow().replace(tzinfo=tz_utc)
dt = datetime.utcnow().replace(tzinfo=timezone.utc)
else:
dt = None
return dt
Expand Down
4 changes: 2 additions & 2 deletions tests/doctests/sml_ndbc_station.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Imports
>>> from tests.utils import resource_file
>>> from owslib.swe.sensor.sml import SensorML
>>> from dateutil import parser
>>> from owslib.util import TimeZone_UTC
>>> from datetime import timezone

Initialize

Expand Down Expand Up @@ -104,7 +104,7 @@ History
2

>>> event = his[0]
>>> parser.parse(event.date).replace(tzinfo=TimeZone_UTC()).isoformat()
>>> parser.parse(event.date).replace(tzinfo=timezone.utc).isoformat()
'2010-01-12T00:00:00+00:00'
>>> event.description
'Deployment start event'
Expand Down
4 changes: 2 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: UTF-8 -*-
import codecs
from owslib.util import clean_ows_url, build_get_url, strip_bom, extract_time, tz_utc
from owslib.util import clean_ows_url, build_get_url, strip_bom, extract_time
from owslib.etree import etree
from datetime import datetime, timezone

Expand Down Expand Up @@ -57,7 +57,7 @@ def test_build_get_url_overwrite():

def test_time_zone_utc():
now = datetime.utcnow()
as_utc = now.replace(tzinfo=tz_utc)
as_utc = now.replace(tzinfo=timezone.utc)
assert(as_utc.isoformat()[-6:] == "+00:00")


Expand Down

0 comments on commit 1058b0b

Please sign in to comment.