diff --git a/etc/RPM/python-owslib.spec b/etc/RPM/python-owslib.spec index 96f8599de..8dfad75df 100644 --- a/etc/RPM/python-owslib.spec +++ b/etc/RPM/python-owslib.spec @@ -25,7 +25,7 @@ BuildRequires: python-devel BuildRequires: python-setuptools BuildRequires: fdupes Requires: python -Requires: python-dateutil python-pytz +Requires: python-dateutil %description OWSLib is a Python package for client programming with Open Geospatial Consortium (OGC) web service (hence OWS) interface standards, and their related content models. diff --git a/owslib/util.py b/owslib/util.py index dfc16b32e..779b444cb 100644 --- a/owslib/util.py +++ b/owslib/util.py @@ -11,8 +11,7 @@ import sys from collections import OrderedDict from dateutil import parser -from datetime import datetime, timedelta -import pytz +from datetime import datetime, timedelta, timezone from owslib.etree import etree, ParseError from owslib.namespaces import Namespaces from urllib.parse import urlsplit, urlencode, urlparse, parse_qs, urlunparse, parse_qsl @@ -648,8 +647,7 @@ def extract_time(element): except Exception: att = testXMLValue(element.attrib.get('indeterminatePosition'), True) if att and att == 'now': - dt = datetime.utcnow() - dt.replace(tzinfo=pytz.utc) + dt = datetime.utcnow().replace(tzinfo=timezone.utc) else: dt = None return dt diff --git a/requirements.txt b/requirements.txt index 864dc07c9..f4d789801 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ lxml python-dateutil -pytz pyyaml requests diff --git a/tests/doctests/sml_52n_network.txt b/tests/doctests/sml_52n_network.txt index 010fbb6b5..94add7ddc 100644 --- a/tests/doctests/sml_52n_network.txt +++ b/tests/doctests/sml_52n_network.txt @@ -3,7 +3,6 @@ Imports >>> from tests.utils import resource_file >>> from owslib.swe.sensor.sml import SensorML >>> from dateutil import parser - >>> import pytz Initialize diff --git a/tests/doctests/sml_ndbc_station.txt b/tests/doctests/sml_ndbc_station.txt index bd2ecf3af..4a25902c7 100644 --- a/tests/doctests/sml_ndbc_station.txt +++ b/tests/doctests/sml_ndbc_station.txt @@ -3,7 +3,7 @@ Imports >>> from tests.utils import resource_file >>> from owslib.swe.sensor.sml import SensorML >>> from dateutil import parser - >>> import pytz + >>> from datetime import timezone Initialize @@ -104,7 +104,7 @@ History 2 >>> event = his[0] - >>> parser.parse(event.date).replace(tzinfo=pytz.utc).isoformat() + >>> parser.parse(event.date).replace(tzinfo=timezone.utc).isoformat() '2010-01-12T00:00:00+00:00' >>> event.description 'Deployment start event' diff --git a/tests/test_util.py b/tests/test_util.py index 70a9148d6..06508699a 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -1,6 +1,8 @@ # -*- coding: UTF-8 -*- import codecs -from owslib.util import clean_ows_url, build_get_url, strip_bom +from owslib.util import clean_ows_url, build_get_url, strip_bom, extract_time +from owslib.etree import etree +from datetime import datetime, timezone def test_strip_bom(): @@ -28,7 +30,8 @@ def test_clean_ows_url(): def test_build_get_url(): assert build_get_url("http://example.org/wps", {'service': 'WPS'}) == 'http://example.org/wps?service=WPS' assert build_get_url("http://example.org/wms", {'SERVICE': 'wms'}) == 'http://example.org/wms?SERVICE=wms' - 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' + 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' assert build_get_url("http://example.org/wps?service=WPS", {'request': 'GetCapabilities'}) == \ 'http://example.org/wps?service=WPS&request=GetCapabilities' assert build_get_url("http://example.org/wps?service=WPS", {'request': 'GetCapabilities'}) == \ @@ -40,10 +43,10 @@ def test_build_get_url(): assert build_get_url("http://example.org/ows?SERVICE=WPS", {'service': 'WMS'}) == \ 'http://example.org/ows?SERVICE=WPS&service=WMS' # Test with trailing ampersand and doseq False (default) - assert build_get_url("http://example.org/ows?SERVICE=WFS&", {'typename': 'test', 'keys': [1,2]}, doseq=False) == \ + assert build_get_url("http://example.org/ows?SERVICE=WFS&", {'typename': 'test', 'keys': [1, 2]}, doseq=False) == \ 'http://example.org/ows?SERVICE=WFS&typename=test&keys=%5B1%2C+2%5D' # Test with trailing ampersand and doseq True - assert build_get_url("http://example.org/ows?SERVICE=WFS&", {'typename': 'test', 'keys': [1,2]}, doseq=True) == \ + assert build_get_url("http://example.org/ows?SERVICE=WFS&", {'typename': 'test', 'keys': [1, 2]}, doseq=True) == \ 'http://example.org/ows?SERVICE=WFS&typename=test&keys=1&keys=2' @@ -51,3 +54,18 @@ def test_build_get_url_overwrite(): # Use overwrite flag assert build_get_url("http://example.org/ows?SERVICE=WPS", {'SERVICE': 'WMS'}, overwrite=True) == \ 'http://example.org/ows?SERVICE=WMS' + + +def test_time_zone_utc(): + now = datetime.utcnow() + as_utc = now.replace(tzinfo=timezone.utc) + assert as_utc.isoformat()[-6:] == "+00:00" + + +def test_extract_time(): + definite_sample = "2006-07-27T21:10:00Z" + indefinite_sample = "" + start = extract_time(etree.fromstring(definite_sample)) + assert start.isoformat()[-6:] == "+00:00" + stop = extract_time(etree.fromstring(indefinite_sample)) + assert stop.isoformat()[-6:] == "+00:00"