Skip to content

Commit e3a084b

Browse files
committed
WMS 1.3.0: support any boolean for queryable layers (#993)
1 parent 65a6bf9 commit e3a084b

File tree

3 files changed

+56
-16
lines changed

3 files changed

+56
-16
lines changed

owslib/map/wms130.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
# =============================================================================
33
# Copyright (c) 2004, 2006 Sean C. Gillies
44
# Copyright (c) 2005 Nuxeo SARL <http://nuxeo.com>
5+
# Copyright (c) 2025 Tom Kralidis
56
#
67
# Authors : Sean Gillies <sgillies@frii.com>
78
# Julien Anguenot <ja@nuxeo.com>
9+
# Tom Kralidis <tomkralidis@gmail.com>
810
#
911
# Contact email: sgillies@frii.com
1012
# =============================================================================
@@ -20,7 +22,7 @@
2022
from owslib.etree import etree
2123
from owslib.util import (openURL, ServiceException, testXMLValue,
2224
extract_xml_list, xmltag_split, OrderedDict, nspath,
23-
nspath_eval, bind_url, Authentication)
25+
nspath_eval, bind_url, Authentication, str2bool)
2426
from owslib.fgdc import Metadata
2527
from owslib.iso import MD_Metadata
2628
from owslib.iso3 import MD_Metadata as MD_Metadata3 # ISO 19115 Part 3 XML
@@ -446,7 +448,7 @@ def __init__(self, elem, parent=None, children=None, index=0, parse_remote_metad
446448
self.id = self.name = testXMLValue(elem.find(nspath('Name', WMS_NAMESPACE)))
447449

448450
# layer attributes
449-
self.queryable = int(elem.attrib.get('queryable', 0))
451+
self.queryable = int(str2bool(elem.attrib.get('queryable'), '0'))
450452
self.cascaded = int(elem.attrib.get('cascaded', 0))
451453
self.opaque = int(elem.attrib.get('opaque', 0))
452454
self.noSubsets = int(elem.attrib.get('noSubsets', 0))

owslib/util.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
# -*- coding: ISO-8859-15 -*-
22
# =============================================================================
3-
# Copyright (c) 2024 Tom Kralidis
3+
# Copyright (c) 2025 Tom Kralidis
44
#
55
# Authors : Tom Kralidis <tomkralidis@gmail.com>
66
#
77
# Contact email: tomkralidis@gmail.com
88
# =============================================================================
99

10-
import os
11-
import sys
10+
import codecs
1211
from collections import OrderedDict
13-
from dateutil import parser
14-
from datetime import datetime, timedelta, timezone
15-
from owslib.etree import etree, ParseError
16-
from owslib.namespaces import Namespaces
17-
from urllib.parse import urlsplit, urlencode, urlparse, parse_qs, urlunparse, parse_qsl
1812
import copy
19-
13+
from copy import deepcopy
14+
from datetime import datetime, timedelta, timezone
2015
from io import StringIO, BytesIO
21-
16+
import os
2217
import re
23-
from copy import deepcopy
18+
import sys
19+
from typing import Union
20+
from urllib.parse import urlsplit, urlencode, urlparse, parse_qs, urlunparse, parse_qsl
2421
import warnings
22+
23+
from dateutil import parser
2524
import requests
2625
from requests.auth import AuthBase
27-
import codecs
26+
27+
from owslib.etree import etree, ParseError
28+
from owslib.namespaces import Namespaces
2829

2930
"""
3031
Utility functions and classes
@@ -1047,3 +1048,23 @@ def __repr__(self, *args, **kwargs):
10471048
return '<{} shared={} username={} password={} cert={} verify={} auth_delegate={}>'.format(
10481049
self.__class__.__name__, self.shared, self.username, self.password, self.cert, self.verify,
10491050
self.auth_delegate)
1051+
1052+
1053+
def str2bool(value: Union[bool, str]) -> bool:
1054+
"""
1055+
helper function to return Python boolean
1056+
type (source: https://stackoverflow.com/a/715468)
1057+
1058+
:param value: value to be evaluated
1059+
1060+
:returns: `bool` of whether the value is boolean-ish
1061+
"""
1062+
1063+
value2 = False
1064+
1065+
if isinstance(value, bool):
1066+
value2 = value
1067+
else:
1068+
value2 = value.lower() in ('yes', 'true', 't', '1', 'on')
1069+
1070+
return value2

tests/test_util.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
# -*- coding: UTF-8 -*-
2+
# =============================================================================
3+
# Copyright (c) 2025 Tom Kralidis
4+
#
5+
# Authors : Tom Kralidis <tomkralidis@gmail.com>
6+
#
7+
# Contact email: tomkralidis@gmail.com
8+
# =============================================================================
9+
10+
211
import codecs
12+
from datetime import datetime, timezone
313
from unittest import mock
14+
415
import pytest
5-
from owslib.util import clean_ows_url, build_get_url, strip_bom, extract_time, ResponseWrapper, getXMLTree
616
from owslib.etree import etree
7-
from datetime import datetime, timezone
17+
from owslib.util import clean_ows_url, build_get_url, strip_bom, extract_time, ResponseWrapper, getXMLTree, str2bool
818

919

1020
def test_strip_bom():
@@ -127,3 +137,10 @@ def test_extract_time():
127137
assert start.isoformat()[-6:] == "+00:00"
128138
stop = extract_time(etree.fromstring(indefinite_sample))
129139
assert stop.isoformat()[-6:] == "+00:00"
140+
141+
142+
def test_str2bool():
143+
assert str2bool('1')
144+
assert not str2bool('0')
145+
assert int(str2bool('true')) == 1
146+
assert int(str2bool('false')) == 0

0 commit comments

Comments
 (0)