Skip to content

Commit

Permalink
Merge pull request #949 from spillner/remove-pytz
Browse files Browse the repository at this point in the history
Remove dependency on the Pytz library
  • Loading branch information
geographika authored Oct 14, 2024
2 parents 852fe6d + 54c1287 commit 40b9fe0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion etc/RPM/python-owslib.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions owslib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
lxml
python-dateutil
pytz
pyyaml
requests
1 change: 0 additions & 1 deletion tests/doctests/sml_52n_network.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

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
>>> import pytz
>>> from datetime import timezone

Initialize

Expand Down Expand Up @@ -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'
Expand Down
26 changes: 22 additions & 4 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down Expand Up @@ -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'}) == \
Expand All @@ -40,14 +43,29 @@ 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'


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 = "<beginPosition>2006-07-27T21:10:00Z</beginPosition>"
indefinite_sample = "<endPosition indeterminatePosition=\"now\"></endPosition>"
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"

0 comments on commit 40b9fe0

Please sign in to comment.