Skip to content

Commit 1058b0b

Browse files
committed
Replaced stub TimeZone_UTC() class with the standard datetime.timezone.utc. This drops support for Python 3.8 and earlier, but OWSLib now targets 3.10 and later.
1 parent bcc4b20 commit 1058b0b

File tree

3 files changed

+6
-21
lines changed

3 files changed

+6
-21
lines changed

owslib/util.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import sys
1212
from collections import OrderedDict
1313
from dateutil import parser
14-
from datetime import datetime, timedelta, tzinfo
14+
from datetime import datetime, timezone
1515
from owslib.etree import etree, ParseError
1616
from owslib.namespaces import Namespaces
1717
from urllib.parse import urlsplit, urlencode, urlparse, parse_qs, urlunparse, parse_qsl
@@ -36,21 +36,6 @@ class ServiceException(Exception):
3636
pass
3737

3838

39-
# Allows marking timestamps as UTC without pulling in all of Pytz
40-
class TimeZone_UTC(tzinfo):
41-
def tzname(self, dt):
42-
return "UTC"
43-
44-
def utcoffset(self, dt):
45-
return timedelta(0)
46-
47-
def dst(self, dt):
48-
return timedelta(0)
49-
50-
51-
tz_utc = TimeZone_UTC()
52-
53-
5439
# http://stackoverflow.com/questions/6256183/combine-two-dictionaries-of-dictionaries-python
5540
def dict_union(d1, d2):
5641
return dict((x, (dict_union(d1.get(x, {}), d2[x]) if isinstance(d2.get(x), dict) else d2.get(x, d1.get(x))))
@@ -662,7 +647,7 @@ def extract_time(element):
662647
except Exception:
663648
att = testXMLValue(element.attrib.get('indeterminatePosition'), True)
664649
if att and att == 'now':
665-
dt = datetime.utcnow().replace(tzinfo=tz_utc)
650+
dt = datetime.utcnow().replace(tzinfo=timezone.utc)
666651
else:
667652
dt = None
668653
return dt

tests/doctests/sml_ndbc_station.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Imports
33
>>> from tests.utils import resource_file
44
>>> from owslib.swe.sensor.sml import SensorML
55
>>> from dateutil import parser
6-
>>> from owslib.util import TimeZone_UTC
6+
>>> from datetime import timezone
77

88
Initialize
99

@@ -104,7 +104,7 @@ History
104104
2
105105

106106
>>> event = his[0]
107-
>>> parser.parse(event.date).replace(tzinfo=TimeZone_UTC()).isoformat()
107+
>>> parser.parse(event.date).replace(tzinfo=timezone.utc).isoformat()
108108
'2010-01-12T00:00:00+00:00'
109109
>>> event.description
110110
'Deployment start event'

tests/test_util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: UTF-8 -*-
22
import codecs
3-
from owslib.util import clean_ows_url, build_get_url, strip_bom, extract_time, tz_utc
3+
from owslib.util import clean_ows_url, build_get_url, strip_bom, extract_time
44
from owslib.etree import etree
55
from datetime import datetime, timezone
66

@@ -57,7 +57,7 @@ def test_build_get_url_overwrite():
5757

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

6363

0 commit comments

Comments
 (0)