Skip to content

Commit 40b9fe0

Browse files
authored
Merge pull request #949 from spillner/remove-pytz
Remove dependency on the Pytz library
2 parents 852fe6d + 54c1287 commit 40b9fe0

File tree

6 files changed

+27
-13
lines changed

6 files changed

+27
-13
lines changed

etc/RPM/python-owslib.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ BuildRequires: python-devel
2525
BuildRequires: python-setuptools
2626
BuildRequires: fdupes
2727
Requires: python
28-
Requires: python-dateutil python-pytz
28+
Requires: python-dateutil
2929

3030
%description
3131
OWSLib is a Python package for client programming with Open Geospatial Consortium (OGC) web service (hence OWS) interface standards, and their related content models.

owslib/util.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
import sys
1212
from collections import OrderedDict
1313
from dateutil import parser
14-
from datetime import datetime, timedelta
15-
import pytz
14+
from datetime import datetime, timedelta, timezone
1615
from owslib.etree import etree, ParseError
1716
from owslib.namespaces import Namespaces
1817
from urllib.parse import urlsplit, urlencode, urlparse, parse_qs, urlunparse, parse_qsl
@@ -648,8 +647,7 @@ def extract_time(element):
648647
except Exception:
649648
att = testXMLValue(element.attrib.get('indeterminatePosition'), True)
650649
if att and att == 'now':
651-
dt = datetime.utcnow()
652-
dt.replace(tzinfo=pytz.utc)
650+
dt = datetime.utcnow().replace(tzinfo=timezone.utc)
653651
else:
654652
dt = None
655653
return dt

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
lxml
22
python-dateutil
3-
pytz
43
pyyaml
54
requests

tests/doctests/sml_52n_network.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Imports
33
>>> from tests.utils import resource_file
44
>>> from owslib.swe.sensor.sml import SensorML
55
>>> from dateutil import parser
6-
>>> import pytz
76

87
Initialize
98

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-
>>> import pytz
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=pytz.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: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# -*- coding: UTF-8 -*-
22
import codecs
3-
from owslib.util import clean_ows_url, build_get_url, strip_bom
3+
from owslib.util import clean_ows_url, build_get_url, strip_bom, extract_time
4+
from owslib.etree import etree
5+
from datetime import datetime, timezone
46

57

68
def test_strip_bom():
@@ -28,7 +30,8 @@ def test_clean_ows_url():
2830
def test_build_get_url():
2931
assert build_get_url("http://example.org/wps", {'service': 'WPS'}) == 'http://example.org/wps?service=WPS'
3032
assert build_get_url("http://example.org/wms", {'SERVICE': 'wms'}) == 'http://example.org/wms?SERVICE=wms'
31-
assert build_get_url("http://example.org/wms?map=/path/to/foo.map&", {'SERVICE': 'wms'}) == 'http://example.org/wms?map=%2Fpath%2Fto%2Ffoo.map&SERVICE=wms'
33+
assert build_get_url("http://example.org/wms?map=/path/to/foo.map&", {'SERVICE': 'wms'}) == \
34+
'http://example.org/wms?map=%2Fpath%2Fto%2Ffoo.map&SERVICE=wms'
3235
assert build_get_url("http://example.org/wps?service=WPS", {'request': 'GetCapabilities'}) == \
3336
'http://example.org/wps?service=WPS&request=GetCapabilities'
3437
assert build_get_url("http://example.org/wps?service=WPS", {'request': 'GetCapabilities'}) == \
@@ -40,14 +43,29 @@ def test_build_get_url():
4043
assert build_get_url("http://example.org/ows?SERVICE=WPS", {'service': 'WMS'}) == \
4144
'http://example.org/ows?SERVICE=WPS&service=WMS'
4245
# Test with trailing ampersand and doseq False (default)
43-
assert build_get_url("http://example.org/ows?SERVICE=WFS&", {'typename': 'test', 'keys': [1,2]}, doseq=False) == \
46+
assert build_get_url("http://example.org/ows?SERVICE=WFS&", {'typename': 'test', 'keys': [1, 2]}, doseq=False) == \
4447
'http://example.org/ows?SERVICE=WFS&typename=test&keys=%5B1%2C+2%5D'
4548
# Test with trailing ampersand and doseq True
46-
assert build_get_url("http://example.org/ows?SERVICE=WFS&", {'typename': 'test', 'keys': [1,2]}, doseq=True) == \
49+
assert build_get_url("http://example.org/ows?SERVICE=WFS&", {'typename': 'test', 'keys': [1, 2]}, doseq=True) == \
4750
'http://example.org/ows?SERVICE=WFS&typename=test&keys=1&keys=2'
4851

4952

5053
def test_build_get_url_overwrite():
5154
# Use overwrite flag
5255
assert build_get_url("http://example.org/ows?SERVICE=WPS", {'SERVICE': 'WMS'}, overwrite=True) == \
5356
'http://example.org/ows?SERVICE=WMS'
57+
58+
59+
def test_time_zone_utc():
60+
now = datetime.utcnow()
61+
as_utc = now.replace(tzinfo=timezone.utc)
62+
assert as_utc.isoformat()[-6:] == "+00:00"
63+
64+
65+
def test_extract_time():
66+
definite_sample = "<beginPosition>2006-07-27T21:10:00Z</beginPosition>"
67+
indefinite_sample = "<endPosition indeterminatePosition=\"now\"></endPosition>"
68+
start = extract_time(etree.fromstring(definite_sample))
69+
assert start.isoformat()[-6:] == "+00:00"
70+
stop = extract_time(etree.fromstring(indefinite_sample))
71+
assert stop.isoformat()[-6:] == "+00:00"

0 commit comments

Comments
 (0)