|
1 | 1 | # -*- coding: ISO-8859-15 -*- |
2 | 2 | # ============================================================================= |
3 | | -# Copyright (c) 2024 Tom Kralidis |
| 3 | +# Copyright (c) 2025 Tom Kralidis |
4 | 4 | # |
5 | 5 | # Authors : Tom Kralidis <tomkralidis@gmail.com> |
6 | 6 | # |
7 | 7 | # Contact email: tomkralidis@gmail.com |
8 | 8 | # ============================================================================= |
9 | 9 |
|
10 | | -import os |
11 | | -import sys |
| 10 | +import codecs |
12 | 11 | 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 |
18 | 12 | import copy |
19 | | - |
| 13 | +from copy import deepcopy |
| 14 | +from datetime import datetime, timedelta, timezone |
20 | 15 | from io import StringIO, BytesIO |
21 | | - |
| 16 | +import os |
22 | 17 | 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 |
24 | 21 | import warnings |
| 22 | + |
| 23 | +from dateutil import parser |
25 | 24 | import requests |
26 | 25 | from requests.auth import AuthBase |
27 | | -import codecs |
| 26 | + |
| 27 | +from owslib.etree import etree, ParseError |
| 28 | +from owslib.namespaces import Namespaces |
28 | 29 |
|
29 | 30 | """ |
30 | 31 | Utility functions and classes |
@@ -1047,3 +1048,23 @@ def __repr__(self, *args, **kwargs): |
1047 | 1048 | return '<{} shared={} username={} password={} cert={} verify={} auth_delegate={}>'.format( |
1048 | 1049 | self.__class__.__name__, self.shared, self.username, self.password, self.cert, self.verify, |
1049 | 1050 | 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 |
0 commit comments