Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on the Pytz library #949

Merged
merged 12 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"