hdx-python-utilities 4.2.5__py3-none-any.whl → 4.2.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hdx/utilities/__init__.py +0 -0
- hdx/utilities/_version.py +2 -2
- hdx/utilities/base_downloader.py +7 -1
- hdx/utilities/compare.py +2 -2
- hdx/utilities/dateparse.py +6 -4
- hdx/utilities/dictandlist.py +1 -1
- hdx/utilities/downloader.py +24 -11
- hdx/utilities/easy_logging.py +0 -0
- hdx/utilities/email.py +3 -3
- hdx/utilities/encoding.py +0 -0
- hdx/utilities/error_handler.py +12 -6
- hdx/utilities/file_hashing.py +1 -1
- hdx/utilities/frictionless_wrapper.py +19 -1
- hdx/utilities/html.py +0 -0
- hdx/utilities/loader.py +0 -0
- hdx/utilities/matching.py +2 -2
- hdx/utilities/path.py +11 -13
- hdx/utilities/retriever.py +8 -8
- hdx/utilities/session.py +0 -0
- hdx/utilities/state.py +9 -3
- hdx/utilities/text.py +1 -1
- hdx/utilities/useragent.py +0 -0
- hdx/utilities/uuid.py +1 -1
- {hdx_python_utilities-4.2.5.dist-info → hdx_python_utilities-4.2.7.dist-info}/METADATA +1 -1
- hdx_python_utilities-4.2.7.dist-info/RECORD +31 -0
- {hdx_python_utilities-4.2.5.dist-info → hdx_python_utilities-4.2.7.dist-info}/WHEEL +1 -1
- hdx_python_utilities-4.2.5.dist-info/RECORD +0 -31
- {hdx_python_utilities-4.2.5.dist-info → hdx_python_utilities-4.2.7.dist-info}/licenses/LICENSE +0 -0
hdx/utilities/__init__.py
CHANGED
|
File without changes
|
hdx/utilities/_version.py
CHANGED
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '4.2.
|
|
22
|
-
__version_tuple__ = version_tuple = (4, 2,
|
|
21
|
+
__version__ = version = '4.2.7'
|
|
22
|
+
__version_tuple__ = version_tuple = (4, 2, 7)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
hdx/utilities/base_downloader.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
2
|
from collections.abc import Iterator, Sequence
|
|
3
3
|
from pathlib import Path
|
|
4
|
+
from types import TracebackType
|
|
4
5
|
from typing import Any, Self
|
|
5
6
|
|
|
6
7
|
|
|
@@ -20,7 +21,12 @@ class BaseDownload(ABC):
|
|
|
20
21
|
"""
|
|
21
22
|
return self
|
|
22
23
|
|
|
23
|
-
def __exit__(
|
|
24
|
+
def __exit__(
|
|
25
|
+
self,
|
|
26
|
+
exc_type: type[BaseException] | None,
|
|
27
|
+
exc_value: BaseException | None,
|
|
28
|
+
traceback: TracebackType | None,
|
|
29
|
+
) -> None:
|
|
24
30
|
"""Subclasses should define this to allow with usage.
|
|
25
31
|
|
|
26
32
|
Args:
|
hdx/utilities/compare.py
CHANGED
|
@@ -23,8 +23,8 @@ def compare_files(
|
|
|
23
23
|
Delta between the two files
|
|
24
24
|
"""
|
|
25
25
|
diff = ndiff(
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
Path(path1).read_text(encoding=encoding).splitlines(),
|
|
27
|
+
Path(path2).read_text(encoding=encoding).splitlines(),
|
|
28
28
|
)
|
|
29
29
|
return [x for x in diff if x[0] in ["-", "+", "?"]]
|
|
30
30
|
|
hdx/utilities/dateparse.py
CHANGED
|
@@ -517,7 +517,7 @@ class DateParser(dateutil.parser.parser): # pragma: no cover
|
|
|
517
517
|
yearfirst = info.yearfirst
|
|
518
518
|
|
|
519
519
|
res = self._result()
|
|
520
|
-
l = _timelex.split(timestr)
|
|
520
|
+
l = _timelex.split(timestr)
|
|
521
521
|
|
|
522
522
|
skipped_idxs = []
|
|
523
523
|
|
|
@@ -944,7 +944,7 @@ def parse_date_range(
|
|
|
944
944
|
endday -= 1
|
|
945
945
|
if endday == 0:
|
|
946
946
|
raise ParserError(
|
|
947
|
-
f"No end day of month found for {
|
|
947
|
+
f"No end day of month found for {enddate!s}!"
|
|
948
948
|
) from e
|
|
949
949
|
if not any(str in date_format for str in ["%b", "%B", "%m", "%j"]):
|
|
950
950
|
startdate = startdate.replace(month=default_date.month)
|
|
@@ -1098,18 +1098,20 @@ def get_timestamp_from_datetime(date: datetime) -> float:
|
|
|
1098
1098
|
def get_datetime_from_timestamp(
|
|
1099
1099
|
timestamp: float,
|
|
1100
1100
|
timezone: datetime.tzinfo = UTC,
|
|
1101
|
-
today: datetime =
|
|
1101
|
+
today: datetime | None = None,
|
|
1102
1102
|
) -> datetime:
|
|
1103
1103
|
"""Convert timestamp to datetime.
|
|
1104
1104
|
|
|
1105
1105
|
Args:
|
|
1106
1106
|
timestamp: Timestamp to convert
|
|
1107
1107
|
timezone: Timezone to use
|
|
1108
|
-
today: Today's date. Defaults to now_utc.
|
|
1108
|
+
today: Today's date. Defaults to now_utc().
|
|
1109
1109
|
|
|
1110
1110
|
Returns:
|
|
1111
1111
|
Date of timestamp
|
|
1112
1112
|
"""
|
|
1113
|
+
if today is None:
|
|
1114
|
+
today = now_utc()
|
|
1113
1115
|
if timestamp > get_timestamp_from_datetime(today):
|
|
1114
1116
|
timestamp = timestamp / 1000
|
|
1115
1117
|
return datetime.fromtimestamp(timestamp, tz=timezone)
|
hdx/utilities/dictandlist.py
CHANGED
|
@@ -220,7 +220,7 @@ def list_distribute_contents(
|
|
|
220
220
|
def riffle_shuffle(piles_list):
|
|
221
221
|
def grouper(n, iterable, fillvalue=None):
|
|
222
222
|
args = [iter(iterable)] * n
|
|
223
|
-
return itertools.zip_longest(fillvalue=fillvalue
|
|
223
|
+
return itertools.zip_longest(*args, fillvalue=fillvalue)
|
|
224
224
|
|
|
225
225
|
if not piles_list:
|
|
226
226
|
return []
|
hdx/utilities/downloader.py
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
import hashlib
|
|
4
4
|
import logging
|
|
5
5
|
from collections.abc import Callable, Iterator, Sequence
|
|
6
|
+
from contextlib import suppress
|
|
6
7
|
from copy import deepcopy
|
|
7
8
|
from os.path import exists, isfile
|
|
8
9
|
from pathlib import Path
|
|
9
|
-
from
|
|
10
|
+
from types import TracebackType
|
|
11
|
+
from typing import Any, ClassVar
|
|
10
12
|
from urllib.parse import urlsplit, urlunsplit
|
|
11
13
|
|
|
12
14
|
import requests
|
|
@@ -59,7 +61,7 @@ class Download(BaseDownload):
|
|
|
59
61
|
allowed_methods (iterable): HTTP methods for which to force retry. Defaults t0 frozenset(['GET']).
|
|
60
62
|
"""
|
|
61
63
|
|
|
62
|
-
downloaders = {}
|
|
64
|
+
downloaders: ClassVar[dict[str, "Download"]] = {}
|
|
63
65
|
|
|
64
66
|
def __init__(
|
|
65
67
|
self,
|
|
@@ -102,10 +104,8 @@ class Download(BaseDownload):
|
|
|
102
104
|
None
|
|
103
105
|
"""
|
|
104
106
|
if self.response:
|
|
105
|
-
|
|
107
|
+
with suppress(Exception):
|
|
106
108
|
self.response.close()
|
|
107
|
-
except Exception:
|
|
108
|
-
pass
|
|
109
109
|
|
|
110
110
|
def close(self) -> None:
|
|
111
111
|
"""Close response and session.
|
|
@@ -116,7 +116,12 @@ class Download(BaseDownload):
|
|
|
116
116
|
self.close_response()
|
|
117
117
|
self.session.close()
|
|
118
118
|
|
|
119
|
-
def __exit__(
|
|
119
|
+
def __exit__(
|
|
120
|
+
self,
|
|
121
|
+
exc_type: type[BaseException] | None,
|
|
122
|
+
exc_value: BaseException | None,
|
|
123
|
+
traceback: TracebackType | None,
|
|
124
|
+
) -> None:
|
|
120
125
|
"""Allow usage of with.
|
|
121
126
|
|
|
122
127
|
Args:
|
|
@@ -245,10 +250,10 @@ class Download(BaseDownload):
|
|
|
245
250
|
if chunk: # filter out keep-alive new chunks
|
|
246
251
|
md5hash.update(chunk)
|
|
247
252
|
return md5hash.hexdigest()
|
|
248
|
-
except Exception:
|
|
253
|
+
except Exception as e:
|
|
249
254
|
raise DownloadError(
|
|
250
|
-
f"Download of {url} failed in retrieval of stream!"
|
|
251
|
-
)
|
|
255
|
+
f"Download of {url} failed in retrieval of stream!"
|
|
256
|
+
) from e
|
|
252
257
|
|
|
253
258
|
def stream_path(
|
|
254
259
|
self, path: Path | str, errormsg: str, append: bool = False
|
|
@@ -587,6 +592,7 @@ class Download(BaseDownload):
|
|
|
587
592
|
default_type (str | None): Default field type if infer_types False. Defaults to string.
|
|
588
593
|
float_numbers (bool): Use float not Decimal if infer_types True. Defaults to True.
|
|
589
594
|
null_values (list[Any]): Values that will return None. Defaults to [""].
|
|
595
|
+
normalise_headers (bool): Convert newlines in headers to spaces and strip them. Ignored if dialect supplied. Defaults to True.
|
|
590
596
|
dialect (Dialect): This can be set to override the above. See Frictionless docs.
|
|
591
597
|
detector (Detector): This can be set to override the above. See Frictionless docs.
|
|
592
598
|
layout (Layout): This can be set to override the above. See Frictionless docs.
|
|
@@ -655,6 +661,7 @@ class Download(BaseDownload):
|
|
|
655
661
|
default_type (str | None): Default field type if infer_types False. Defaults to string.
|
|
656
662
|
float_numbers (bool): Use float not Decimal if infer_types True. Defaults to True.
|
|
657
663
|
null_values (list[Any]): Values that will return None. Defaults to [""].
|
|
664
|
+
normalise_headers (bool): Convert newlines in headers to spaces and strip them. Ignored if dialect supplied. Defaults to True.
|
|
658
665
|
dialect (Dialect): This can be set to override the above. See Frictionless docs.
|
|
659
666
|
detector (Detector): This can be set to override the above. See Frictionless docs.
|
|
660
667
|
layout (Layout): This can be set to override the above. See Frictionless docs.
|
|
@@ -766,6 +773,7 @@ class Download(BaseDownload):
|
|
|
766
773
|
default_type (str | None): Default field type if infer_types False. Defaults to string.
|
|
767
774
|
float_numbers (bool): Use float not Decimal if infer_types True. Defaults to True.
|
|
768
775
|
null_values (list[Any]): Values that will return None. Defaults to [""].
|
|
776
|
+
normalise_headers (bool): Convert newlines in headers to spaces and strip them. Ignored if dialect supplied. Defaults to True.
|
|
769
777
|
dialect (Dialect): This can be set to override the above. See Frictionless docs.
|
|
770
778
|
detector (Detector): This can be set to override the above. See Frictionless docs.
|
|
771
779
|
layout (Layout): This can be set to override the above. See Frictionless docs.
|
|
@@ -863,6 +871,7 @@ class Download(BaseDownload):
|
|
|
863
871
|
default_type (str | None): Default field type if infer_types False. Defaults to string.
|
|
864
872
|
float_numbers (bool): Use float not Decimal if infer_types True. Defaults to True.
|
|
865
873
|
null_values (list[Any]): Values that will return None. Defaults to [""].
|
|
874
|
+
normalise_headers (bool): Convert newlines in headers to spaces and strip them. Ignored if dialect supplied. Defaults to True.
|
|
866
875
|
dialect (Dialect): This can be set to override the above. See Frictionless docs.
|
|
867
876
|
detector (Detector): This can be set to override the above. See Frictionless docs.
|
|
868
877
|
layout (Layout): This can be set to override the above. See Frictionless docs.
|
|
@@ -932,6 +941,7 @@ class Download(BaseDownload):
|
|
|
932
941
|
default_type (str | None): Default field type if infer_types False. Defaults to string.
|
|
933
942
|
float_numbers (bool): Use float not Decimal if infer_types True. Defaults to True.
|
|
934
943
|
null_values (list[Any]): Values that will return None. Defaults to [""].
|
|
944
|
+
normalise_headers (bool): Convert newlines in headers to spaces and strip them. Ignored if dialect supplied. Defaults to True.
|
|
935
945
|
dialect (Dialect): This can be set to override the above. See Frictionless docs.
|
|
936
946
|
detector (Detector): This can be set to override the above. See Frictionless docs.
|
|
937
947
|
layout (Layout): This can be set to override the above. See Frictionless docs.
|
|
@@ -1003,6 +1013,7 @@ class Download(BaseDownload):
|
|
|
1003
1013
|
default_type (str | None): Default field type if infer_types False. Defaults to string.
|
|
1004
1014
|
float_numbers (bool): Use float not Decimal if infer_types True. Defaults to True.
|
|
1005
1015
|
null_values (list[Any]): Values that will return None. Defaults to [""].
|
|
1016
|
+
normalise_headers (bool): Convert newlines in headers to spaces and strip them. Ignored if dialect supplied. Defaults to True.
|
|
1006
1017
|
dialect (Dialect): This can be set to override the above. See Frictionless docs.
|
|
1007
1018
|
detector (Detector): This can be set to override the above. See Frictionless docs.
|
|
1008
1019
|
layout (Layout): This can be set to override the above. See Frictionless docs.
|
|
@@ -1078,6 +1089,7 @@ class Download(BaseDownload):
|
|
|
1078
1089
|
default_type (str | None): Default field type if infer_types False. Defaults to string.
|
|
1079
1090
|
float_numbers (bool): Use float not Decimal if infer_types True. Defaults to True.
|
|
1080
1091
|
null_values (list[Any]): Values that will return None. Defaults to [""].
|
|
1092
|
+
normalise_headers (bool): Convert newlines in headers to spaces and strip them. Ignored if dialect supplied. Defaults to True.
|
|
1081
1093
|
dialect (Dialect): This can be set to override the above. See Frictionless docs.
|
|
1082
1094
|
detector (Detector): This can be set to override the above. See Frictionless docs.
|
|
1083
1095
|
layout (Layout): This can be set to override the above. See Frictionless docs.
|
|
@@ -1157,6 +1169,7 @@ class Download(BaseDownload):
|
|
|
1157
1169
|
default_type (str | None): Default field type if infer_types False. Defaults to string.
|
|
1158
1170
|
float_numbers (bool): Use float not Decimal if infer_types True. Defaults to True.
|
|
1159
1171
|
null_values (list[Any]): Values that will return None. Defaults to [""].
|
|
1172
|
+
normalise_headers (bool): Convert newlines in headers to spaces and strip them. Ignored if dialect supplied. Defaults to True.
|
|
1160
1173
|
dialect (Dialect): This can be set to override the above. See Frictionless docs.
|
|
1161
1174
|
detector (Detector): This can be set to override the above. See Frictionless docs.
|
|
1162
1175
|
layout (Layout): This can be set to override the above. See Frictionless docs.
|
|
@@ -1257,9 +1270,9 @@ class Download(BaseDownload):
|
|
|
1257
1270
|
kwargs["rate_limit"] = rate_limit
|
|
1258
1271
|
|
|
1259
1272
|
cls.downloaders = {"default": cls(**kwargs)}
|
|
1260
|
-
for name in custom_configs:
|
|
1273
|
+
for name, custom_config in custom_configs.items():
|
|
1261
1274
|
args_copy = deepcopy(kwargs)
|
|
1262
|
-
args_copy.update(
|
|
1275
|
+
args_copy.update(custom_config)
|
|
1263
1276
|
cls.downloaders[name] = cls(**args_copy)
|
|
1264
1277
|
|
|
1265
1278
|
@classmethod
|
hdx/utilities/easy_logging.py
CHANGED
|
File without changes
|
hdx/utilities/email.py
CHANGED
|
@@ -7,7 +7,7 @@ from email.mime.multipart import MIMEMultipart
|
|
|
7
7
|
from email.mime.text import MIMEText
|
|
8
8
|
from os.path import expanduser
|
|
9
9
|
from pathlib import Path
|
|
10
|
-
from typing import Any
|
|
10
|
+
from typing import Any, Self
|
|
11
11
|
|
|
12
12
|
from hdx.utilities.loader import load_json, load_yaml
|
|
13
13
|
|
|
@@ -91,7 +91,7 @@ class Email:
|
|
|
91
91
|
self.sender = email_config_dict.get("sender", self.username)
|
|
92
92
|
self.server = None
|
|
93
93
|
|
|
94
|
-
def __enter__(self) ->
|
|
94
|
+
def __enter__(self) -> Self:
|
|
95
95
|
"""Return Email object for with statement.
|
|
96
96
|
|
|
97
97
|
Returns:
|
|
@@ -99,7 +99,7 @@ class Email:
|
|
|
99
99
|
"""
|
|
100
100
|
return self
|
|
101
101
|
|
|
102
|
-
def __exit__(self, *args:
|
|
102
|
+
def __exit__(self, *args: object) -> None:
|
|
103
103
|
"""Close Email object for end of with statement.
|
|
104
104
|
|
|
105
105
|
Args:
|
hdx/utilities/encoding.py
CHANGED
|
File without changes
|
hdx/utilities/error_handler.py
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
import logging
|
|
4
4
|
import sys
|
|
5
5
|
from collections.abc import Sequence
|
|
6
|
-
from
|
|
6
|
+
from types import TracebackType
|
|
7
|
+
from typing import Any, Self
|
|
7
8
|
|
|
8
9
|
from hdx.utilities.dictandlist import dict_of_sets_add
|
|
9
10
|
|
|
@@ -67,7 +68,7 @@ class ErrorHandler:
|
|
|
67
68
|
Returns:
|
|
68
69
|
A formatted message stating the missing value and its type
|
|
69
70
|
"""
|
|
70
|
-
return f"{value_type} {
|
|
71
|
+
return f"{value_type} {value!s} not found"
|
|
71
72
|
|
|
72
73
|
def add_missing_value(
|
|
73
74
|
self,
|
|
@@ -155,11 +156,11 @@ class ErrorHandler:
|
|
|
155
156
|
None
|
|
156
157
|
"""
|
|
157
158
|
|
|
158
|
-
for
|
|
159
|
+
for warnings in self.shared_errors["warning"].values():
|
|
159
160
|
warnings = sorted(warnings)
|
|
160
161
|
for warning in warnings:
|
|
161
162
|
logger.warning(warning)
|
|
162
|
-
for
|
|
163
|
+
for errors in self.shared_errors["error"].values():
|
|
163
164
|
errors = sorted(errors)
|
|
164
165
|
for error in errors:
|
|
165
166
|
logger.error(error)
|
|
@@ -174,10 +175,15 @@ class ErrorHandler:
|
|
|
174
175
|
if self.should_exit_on_error and self.shared_errors["error"]:
|
|
175
176
|
sys.exit(1)
|
|
176
177
|
|
|
177
|
-
def __enter__(self) ->
|
|
178
|
+
def __enter__(self) -> Self:
|
|
178
179
|
return self
|
|
179
180
|
|
|
180
|
-
def __exit__(
|
|
181
|
+
def __exit__(
|
|
182
|
+
self,
|
|
183
|
+
exc_type: type[BaseException] | None,
|
|
184
|
+
exc_value: BaseException | None,
|
|
185
|
+
traceback: TracebackType | None,
|
|
186
|
+
) -> None:
|
|
181
187
|
self.log()
|
|
182
188
|
if exc_type is None:
|
|
183
189
|
self.exit_on_error()
|
hdx/utilities/file_hashing.py
CHANGED
|
@@ -43,7 +43,7 @@ def hash_excel_buffer(buffer: bytes) -> str:
|
|
|
43
43
|
f"Error hashing xlsx: The Excel file is corrupted or unreadable: {e}"
|
|
44
44
|
)
|
|
45
45
|
return ""
|
|
46
|
-
except Exception as e:
|
|
46
|
+
except Exception as e: # noqa: BLE001
|
|
47
47
|
logger.error(f"Unexpected error hashing xlsx: {e}")
|
|
48
48
|
return ""
|
|
49
49
|
finally:
|
|
@@ -14,6 +14,17 @@ from frictionless import (
|
|
|
14
14
|
from frictionless.errors import ResourceError
|
|
15
15
|
from frictionless.formats import CsvControl, ExcelControl, JsonControl
|
|
16
16
|
from frictionless.resources import TableResource
|
|
17
|
+
from frictionless.types import ISample
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class NormalisedHeaderDialect(Dialect):
|
|
21
|
+
"""Dialect that converts newlines in headers to spaces and strips them, as
|
|
22
|
+
frictionless did before 5.20."""
|
|
23
|
+
|
|
24
|
+
def read_labels(self, sample: ISample) -> list[str]:
|
|
25
|
+
return [
|
|
26
|
+
label.replace("\n", " ").strip() for label in super().read_labels(sample)
|
|
27
|
+
]
|
|
17
28
|
|
|
18
29
|
|
|
19
30
|
def get_frictionless_control(**kwargs: Any) -> tuple[Control, Any]:
|
|
@@ -106,12 +117,18 @@ def get_frictionless_dialect(
|
|
|
106
117
|
ignore_blank_rows: Whether to ignore blank rows. Defaults to True.
|
|
107
118
|
**kwargs: See below
|
|
108
119
|
columns (Sequence[int] | Sequence[str] | None): Columns to pick. Defaults to all.
|
|
120
|
+
normalise_headers (bool): Convert newlines in headers to spaces and strip them. Ignored if dialect supplied. Defaults to True.
|
|
109
121
|
dialect (Dialect): This can be set to override the above. See Frictionless docs.
|
|
110
122
|
|
|
111
123
|
Returns:
|
|
112
124
|
(frictionless Dialect object, Any)
|
|
113
125
|
"""
|
|
114
|
-
|
|
126
|
+
normalise_headers = kwargs.pop("normalise_headers", True)
|
|
127
|
+
if normalise_headers:
|
|
128
|
+
default_dialect = NormalisedHeaderDialect()
|
|
129
|
+
else:
|
|
130
|
+
default_dialect = Dialect()
|
|
131
|
+
dialect = kwargs.get("dialect", default_dialect)
|
|
115
132
|
columns = kwargs.pop("columns", None)
|
|
116
133
|
if columns:
|
|
117
134
|
dialect.pick_fields = columns
|
|
@@ -156,6 +173,7 @@ def get_frictionless_tableresource(
|
|
|
156
173
|
null_values (list[Any]): Values that will return None. Defaults to [""].
|
|
157
174
|
control (Control): This can be set to override the above. See Frictionless docs.
|
|
158
175
|
detector (Detector): This can be set to override the above. See Frictionless docs.
|
|
176
|
+
normalise_headers (bool): Convert newlines in headers to spaces and strip them. Ignored if dialect supplied. Defaults to True.
|
|
159
177
|
dialect (Dialect): This can be set to override the above. See Frictionless docs.
|
|
160
178
|
schema (Schema): This can be set to override the above. See Frictionless docs.
|
|
161
179
|
|
hdx/utilities/html.py
CHANGED
|
File without changes
|
hdx/utilities/loader.py
CHANGED
|
File without changes
|
hdx/utilities/matching.py
CHANGED
|
@@ -301,7 +301,7 @@ def get_code_from_name(
|
|
|
301
301
|
if not fuzzy_match or is_list:
|
|
302
302
|
unmatched.append(name)
|
|
303
303
|
return None
|
|
304
|
-
names = [x for x in code_lookup
|
|
304
|
+
names = [x for x in code_lookup if len(x) > match_threshold]
|
|
305
305
|
name_index = RapidFuzzMatcher().match(
|
|
306
306
|
possible_names=names,
|
|
307
307
|
name=name,
|
|
@@ -373,7 +373,7 @@ def earliest_index(string_to_search: str, strings_to_try: Sequence[str]) -> int
|
|
|
373
373
|
indices.append(index)
|
|
374
374
|
except ValueError:
|
|
375
375
|
indices.append(after_string)
|
|
376
|
-
earliest_index =
|
|
376
|
+
earliest_index = min(indices)
|
|
377
377
|
if earliest_index == after_string:
|
|
378
378
|
return None
|
|
379
379
|
else:
|
hdx/utilities/path.py
CHANGED
|
@@ -184,10 +184,10 @@ def temp_dir_batch(
|
|
|
184
184
|
delete_on_success,
|
|
185
185
|
delete_on_failure,
|
|
186
186
|
tempdir=tempdir,
|
|
187
|
-
) as
|
|
187
|
+
) as folder_path:
|
|
188
188
|
yield {
|
|
189
|
-
"folder":
|
|
190
|
-
"batch": read_or_create_batch(
|
|
189
|
+
"folder": folder_path,
|
|
190
|
+
"batch": read_or_create_batch(folder_path, batch),
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
|
|
@@ -294,10 +294,9 @@ def wheretostart_tempdir_batch(
|
|
|
294
294
|
"""
|
|
295
295
|
delete_if_exists = False
|
|
296
296
|
wheretostart = getenv("WHERETOSTART")
|
|
297
|
-
if wheretostart:
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
logger.info("Removing progress file and will start from beginning!")
|
|
297
|
+
if wheretostart and wheretostart.upper() == "RESET":
|
|
298
|
+
delete_if_exists = True
|
|
299
|
+
logger.info("Removing progress file and will start from beginning!")
|
|
301
300
|
with temp_dir_batch(
|
|
302
301
|
folder,
|
|
303
302
|
delete_if_exists,
|
|
@@ -372,10 +371,9 @@ def multiple_progress_storing_tempdir(
|
|
|
372
371
|
"""
|
|
373
372
|
delete_if_exists = False
|
|
374
373
|
wheretostartenv = getenv("WHERETOSTART")
|
|
375
|
-
if wheretostartenv:
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
logger.info("Removing progress file and will start from beginning!")
|
|
374
|
+
if wheretostartenv and wheretostartenv.upper() == "RESET":
|
|
375
|
+
delete_if_exists = True
|
|
376
|
+
logger.info("Removing progress file and will start from beginning!")
|
|
379
377
|
with temp_dir_batch(
|
|
380
378
|
folder,
|
|
381
379
|
delete_if_exists,
|
|
@@ -404,9 +402,9 @@ def multiple_progress_storing_tempdir(
|
|
|
404
402
|
delete_on_failure=False,
|
|
405
403
|
batch=batch,
|
|
406
404
|
tempdir=tempdir,
|
|
407
|
-
) as
|
|
405
|
+
) as batch_info:
|
|
408
406
|
for info, nextdict in progress_storing_folder(
|
|
409
|
-
|
|
407
|
+
batch_info, iterators[i], key, wheretostart
|
|
410
408
|
):
|
|
411
409
|
save_text(info["progress"], progress_file)
|
|
412
410
|
yield i, info, nextdict
|
hdx/utilities/retriever.py
CHANGED
|
@@ -4,7 +4,7 @@ from copy import deepcopy
|
|
|
4
4
|
from os import mkdir
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
from shutil import rmtree
|
|
7
|
-
from typing import Any
|
|
7
|
+
from typing import Any, ClassVar
|
|
8
8
|
|
|
9
9
|
from slugify import slugify
|
|
10
10
|
|
|
@@ -34,7 +34,7 @@ class Retrieve(BaseDownload):
|
|
|
34
34
|
log_level: Level at which to log messages. Defaults to logging.INFO.
|
|
35
35
|
"""
|
|
36
36
|
|
|
37
|
-
retrievers = {}
|
|
37
|
+
retrievers: ClassVar[dict[str, "Retrieve"]] = {}
|
|
38
38
|
|
|
39
39
|
def __init__(
|
|
40
40
|
self,
|
|
@@ -122,7 +122,7 @@ class Retrieve(BaseDownload):
|
|
|
122
122
|
self,
|
|
123
123
|
url: Path | str,
|
|
124
124
|
filename: str | None = None,
|
|
125
|
-
possible_extensions: tuple[str, ...] =
|
|
125
|
+
possible_extensions: tuple[str, ...] = (),
|
|
126
126
|
**kwargs: Any,
|
|
127
127
|
) -> tuple[str, Any]:
|
|
128
128
|
"""Get filename from url and given parameters.
|
|
@@ -186,7 +186,7 @@ class Retrieve(BaseDownload):
|
|
|
186
186
|
fallback: bool = False,
|
|
187
187
|
resume: bool = False,
|
|
188
188
|
retries: int = 0,
|
|
189
|
-
log_level: int = None,
|
|
189
|
+
log_level: int | None = None,
|
|
190
190
|
**kwargs: Any,
|
|
191
191
|
) -> Path:
|
|
192
192
|
"""Retrieve file.
|
|
@@ -241,7 +241,7 @@ class Retrieve(BaseDownload):
|
|
|
241
241
|
filename: str | None = None,
|
|
242
242
|
logstr: str | None = None,
|
|
243
243
|
fallback: bool = False,
|
|
244
|
-
log_level: int = None,
|
|
244
|
+
log_level: int | None = None,
|
|
245
245
|
**kwargs: Any,
|
|
246
246
|
) -> str:
|
|
247
247
|
"""Download text.
|
|
@@ -292,7 +292,7 @@ class Retrieve(BaseDownload):
|
|
|
292
292
|
filename: str | None = None,
|
|
293
293
|
logstr: str | None = None,
|
|
294
294
|
fallback: bool = False,
|
|
295
|
-
log_level: int = None,
|
|
295
|
+
log_level: int | None = None,
|
|
296
296
|
**kwargs: Any,
|
|
297
297
|
) -> Any:
|
|
298
298
|
"""Retrieve YAML.
|
|
@@ -343,7 +343,7 @@ class Retrieve(BaseDownload):
|
|
|
343
343
|
filename: str | None = None,
|
|
344
344
|
logstr: str | None = None,
|
|
345
345
|
fallback: bool = False,
|
|
346
|
-
log_level: int = None,
|
|
346
|
+
log_level: int | None = None,
|
|
347
347
|
**kwargs: Any,
|
|
348
348
|
) -> Any:
|
|
349
349
|
"""Retrieve JSON.
|
|
@@ -446,7 +446,7 @@ class Retrieve(BaseDownload):
|
|
|
446
446
|
temp_dir: Path | str,
|
|
447
447
|
save: bool = False,
|
|
448
448
|
use_saved: bool = False,
|
|
449
|
-
ignore: Sequence[str] =
|
|
449
|
+
ignore: Sequence[str] = (),
|
|
450
450
|
delete: bool = True,
|
|
451
451
|
**kwargs: Any,
|
|
452
452
|
) -> None:
|
hdx/utilities/session.py
CHANGED
|
File without changes
|
hdx/utilities/state.py
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
import logging
|
|
4
4
|
from collections.abc import Callable
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from
|
|
6
|
+
from types import TracebackType
|
|
7
|
+
from typing import Any, Self
|
|
7
8
|
|
|
8
9
|
from hdx.utilities.dateparse import iso_string_from_datetime, parse_date
|
|
9
10
|
from hdx.utilities.loader import load_text
|
|
@@ -37,7 +38,7 @@ class State:
|
|
|
37
38
|
self.write_fn = write_fn
|
|
38
39
|
self.state = self.read()
|
|
39
40
|
|
|
40
|
-
def __enter__(self) ->
|
|
41
|
+
def __enter__(self) -> Self:
|
|
41
42
|
"""Allow usage of with.
|
|
42
43
|
|
|
43
44
|
Returns:
|
|
@@ -45,7 +46,12 @@ class State:
|
|
|
45
46
|
"""
|
|
46
47
|
return self
|
|
47
48
|
|
|
48
|
-
def __exit__(
|
|
49
|
+
def __exit__(
|
|
50
|
+
self,
|
|
51
|
+
exc_type: type[BaseException] | None,
|
|
52
|
+
exc_value: BaseException | None,
|
|
53
|
+
traceback: TracebackType | None,
|
|
54
|
+
) -> None:
|
|
49
55
|
"""Allow usage of with.
|
|
50
56
|
|
|
51
57
|
Args:
|
hdx/utilities/text.py
CHANGED
|
@@ -60,7 +60,7 @@ def remove_end_characters(string: str, characters_to_remove: str = punctuation)
|
|
|
60
60
|
Returns:
|
|
61
61
|
String with any characters at end of string that are in characters_to_remove removed
|
|
62
62
|
"""
|
|
63
|
-
while string[-1] in characters_to_remove:
|
|
63
|
+
while string and string[-1] in characters_to_remove:
|
|
64
64
|
string = string[:-1]
|
|
65
65
|
return string
|
|
66
66
|
|
hdx/utilities/useragent.py
CHANGED
|
File without changes
|
hdx/utilities/uuid.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: hdx-python-utilities
|
|
3
|
-
Version: 4.2.
|
|
3
|
+
Version: 4.2.7
|
|
4
4
|
Summary: HDX Python Utilities for streaming tabular data, date and time handling and other helpful functions
|
|
5
5
|
Project-URL: Homepage, https://github.com/OCHA-DAP/hdx-python-utilities
|
|
6
6
|
Author-email: Michael Rans <rans@email.com>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
hdx/utilities/__init__.py,sha256=DQztoBWScN4UoX3pTjA6JN_CHX-Lls3duu41YLJtdcM,72
|
|
2
|
+
hdx/utilities/_version.py,sha256=h4Ocm059KhrmW9LjVPUzFYdcMdF2OXrkmAKxCgyYAy4,520
|
|
3
|
+
hdx/utilities/base_downloader.py,sha256=FuE3CyGVOaKJaJm4bRDMstwiR65HB5JNiceDYUQBrk0,3599
|
|
4
|
+
hdx/utilities/compare.py,sha256=WOFH4Ic2ljMb2BF-UseGZAogeSC8pitRbyfo6HRt56s,1151
|
|
5
|
+
hdx/utilities/dateparse.py,sha256=RGFBuOHE2pflqAY824XLfrBUt1tyY_ieG5yJtlqZOEY,42006
|
|
6
|
+
hdx/utilities/dictandlist.py,sha256=GCpws3WzVtJg8zxQJxlZXqOeOxNMk3Dn74oq-jxDQ-g,15590
|
|
7
|
+
hdx/utilities/downloader.py,sha256=q3-ZLciQ-_L-k58GnFJm4UHQovTn2kTdAJ0N4SyWVh0,61280
|
|
8
|
+
hdx/utilities/easy_logging.py,sha256=UizwMsYpFcKmY3x7qVPxi4cIpEyqpKQaKhby_kuFH4A,2129
|
|
9
|
+
hdx/utilities/email.py,sha256=T-56gxAxrL_HQEjVtgjgC0bSRRAQSNn9qQgaUYGzp3c,8226
|
|
10
|
+
hdx/utilities/encoding.py,sha256=_y7kdLG-AFkwIrbG-pNmsWQNbIv8GGNK8nFEpbnWSzI,2102
|
|
11
|
+
hdx/utilities/error_handler.py,sha256=1c82AJu-mnjuNaGfn9MpmU6xqaHgc-GNyIBiYOiZIpw,5938
|
|
12
|
+
hdx/utilities/errors_onexit.py,sha256=mnllrcWJt3zbfzAact-UWU-ZhymhWCZpPmMfpZCfVEU,383
|
|
13
|
+
hdx/utilities/file_hashing.py,sha256=5LMBbeJXQQMsZZGE8hdVg5n9DCi0G1PkMRqz8OBO8qw,3634
|
|
14
|
+
hdx/utilities/frictionless_wrapper.py,sha256=o28-F-0uc5D5ym6kgZZpfzhsXEEITIk6NMBfsuNfFPA,9353
|
|
15
|
+
hdx/utilities/html.py,sha256=KX5m9mXbSsruzqIVg60REJMvvtd0R_pahrKUb4bGPYQ,2880
|
|
16
|
+
hdx/utilities/loader.py,sha256=_0cbraMPneahCiQCetUovwMMaHCBmPhirys9QPMiD7c,6097
|
|
17
|
+
hdx/utilities/matching.py,sha256=nlGoYHUnKulekkqtY1tVfn8mWuGdw4oWCmM2p668rpo,18249
|
|
18
|
+
hdx/utilities/path.py,sha256=C_4UNqufrfWHZd-l1t1dUo9codhjNcpvknz2viYacIA,15415
|
|
19
|
+
hdx/utilities/retriever.py,sha256=8nrNwGO2zJImbdlMtfbFAUrEb0OQKnw2wUXPYvmBQWk,18447
|
|
20
|
+
hdx/utilities/saver.py,sha256=O9QHGjqH9E4UMnDzmDPmvINCq8qGbljq4U_l9VnLfdM,8038
|
|
21
|
+
hdx/utilities/session.py,sha256=RuxZqr2jX7xZ3qUlGSH5ZInCFsSl6THOXk0bUPgFtzw,9866
|
|
22
|
+
hdx/utilities/state.py,sha256=TSZXwiZSgGCiedXsy_CCDREK-oYZ6S28vKHqzpcq61w,4057
|
|
23
|
+
hdx/utilities/text.py,sha256=Z2eJWO_-dDA7WthkovthM0dgXmN0NYwU7mbn-WoUhGI,9747
|
|
24
|
+
hdx/utilities/url.py,sha256=iN4tqU7sbpXc3EXMNaQfoot8Wm98AvDKN_oKS2heuAE,4312
|
|
25
|
+
hdx/utilities/useragent.py,sha256=u1nwquIei93lLMAGqHrLs0w99qIIM1A2yUY7AOMSFy4,6862
|
|
26
|
+
hdx/utilities/uuid.py,sha256=ysPLCRnwkDYA-ifL-pYJzBigh-jm8_zjqVjcwYSZzno,573
|
|
27
|
+
hdx/utilities/zip_crc.py,sha256=qs-81dd1oX6uIfwH7DUoZaS7OngHwOb7lnogBVmtBl8,4275
|
|
28
|
+
hdx_python_utilities-4.2.7.dist-info/METADATA,sha256=FGk-B4TJ74RvmvZKtF3ILnrfas2-K5FAUvrrwxEfImI,5409
|
|
29
|
+
hdx_python_utilities-4.2.7.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
30
|
+
hdx_python_utilities-4.2.7.dist-info/licenses/LICENSE,sha256=wc-4GpMn-ODs-U_bTe1YCiPVgvcjzrpYOx2wPuyAeII,1079
|
|
31
|
+
hdx_python_utilities-4.2.7.dist-info/RECORD,,
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
hdx/utilities/__init__.py,sha256=DQztoBWScN4UoX3pTjA6JN_CHX-Lls3duu41YLJtdcM,72
|
|
2
|
-
hdx/utilities/_version.py,sha256=7bhmAD-On_XHKZRDnLBnKaG2dkNHvJ2D5XVBOhtc5UA,520
|
|
3
|
-
hdx/utilities/base_downloader.py,sha256=jFQ0zf9FdAjNBKBieZj47Aejl0cn92jVvajuYASH394,3471
|
|
4
|
-
hdx/utilities/compare.py,sha256=3w12iMELCBsR9gKXM7zyRZAf8YSeRylJwmGuLlEkAVQ,1145
|
|
5
|
-
hdx/utilities/dateparse.py,sha256=rs8uUSy_YnGxCqMNv8LWbaZHYmmtdAbJnzwsOenq0FE,41971
|
|
6
|
-
hdx/utilities/dictandlist.py,sha256=ho760YhYUGrd4GpkDekgFJiOg2bpqOHwvjTQmQx82h0,15590
|
|
7
|
-
hdx/utilities/downloader.py,sha256=nyjuzrEHELdU81gAdUQsFkujM42fHOXh4DO1UcPRBpg,59973
|
|
8
|
-
hdx/utilities/easy_logging.py,sha256=UizwMsYpFcKmY3x7qVPxi4cIpEyqpKQaKhby_kuFH4A,2129
|
|
9
|
-
hdx/utilities/email.py,sha256=BMNqtKq0R20qnopd6tZkzrk8l3-2CeIcsRNcoQ4DEp0,8220
|
|
10
|
-
hdx/utilities/encoding.py,sha256=_y7kdLG-AFkwIrbG-pNmsWQNbIv8GGNK8nFEpbnWSzI,2102
|
|
11
|
-
hdx/utilities/error_handler.py,sha256=bzT08uMzefn4XetUmONPSMV2zKjRDBGQ6adWdSMOc2U,5821
|
|
12
|
-
hdx/utilities/errors_onexit.py,sha256=mnllrcWJt3zbfzAact-UWU-ZhymhWCZpPmMfpZCfVEU,383
|
|
13
|
-
hdx/utilities/file_hashing.py,sha256=p9AN7m4OUFXbzgdtBUFw_npmD_T0l7oFmErjclZSX8k,3618
|
|
14
|
-
hdx/utilities/frictionless_wrapper.py,sha256=ZSv42AC07EN-RQ8jvo6lppLTQiF8H1354F5Ji0pJSVc,8523
|
|
15
|
-
hdx/utilities/html.py,sha256=KX5m9mXbSsruzqIVg60REJMvvtd0R_pahrKUb4bGPYQ,2880
|
|
16
|
-
hdx/utilities/loader.py,sha256=_0cbraMPneahCiQCetUovwMMaHCBmPhirys9QPMiD7c,6097
|
|
17
|
-
hdx/utilities/matching.py,sha256=iBpPVhObqemqRsHOpNOImAKrVQvsd9aGarCvyasVXwk,18262
|
|
18
|
-
hdx/utilities/path.py,sha256=CKyWY-iazfOKL2Nrwi9t8EvN5xMQKLd-yXxyE5wKLv8,15423
|
|
19
|
-
hdx/utilities/retriever.py,sha256=kTrl_LneksM6C7FyWVfwd1-W7qUHnHrqr64lO8MLHuw,18386
|
|
20
|
-
hdx/utilities/saver.py,sha256=O9QHGjqH9E4UMnDzmDPmvINCq8qGbljq4U_l9VnLfdM,8038
|
|
21
|
-
hdx/utilities/session.py,sha256=RuxZqr2jX7xZ3qUlGSH5ZInCFsSl6THOXk0bUPgFtzw,9866
|
|
22
|
-
hdx/utilities/state.py,sha256=2luYzeELMlSh1pwcKRuH1r6dLkCKwuGAF2CVC1oZcNo,3926
|
|
23
|
-
hdx/utilities/text.py,sha256=hx9_sxWpIXfzH1gN5I7o597SUhA9uUBXMrPLdrKvkjo,9736
|
|
24
|
-
hdx/utilities/url.py,sha256=iN4tqU7sbpXc3EXMNaQfoot8Wm98AvDKN_oKS2heuAE,4312
|
|
25
|
-
hdx/utilities/useragent.py,sha256=u1nwquIei93lLMAGqHrLs0w99qIIM1A2yUY7AOMSFy4,6862
|
|
26
|
-
hdx/utilities/uuid.py,sha256=KUpQoo0P3RFO_n6-qdxTDxdaJMUpkTosdI0ulyk-RYA,557
|
|
27
|
-
hdx/utilities/zip_crc.py,sha256=qs-81dd1oX6uIfwH7DUoZaS7OngHwOb7lnogBVmtBl8,4275
|
|
28
|
-
hdx_python_utilities-4.2.5.dist-info/METADATA,sha256=s9GWRw2vU2DH53tDT8swq5Koo0jPEfmyssb_geF6aYc,5409
|
|
29
|
-
hdx_python_utilities-4.2.5.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
30
|
-
hdx_python_utilities-4.2.5.dist-info/licenses/LICENSE,sha256=wc-4GpMn-ODs-U_bTe1YCiPVgvcjzrpYOx2wPuyAeII,1079
|
|
31
|
-
hdx_python_utilities-4.2.5.dist-info/RECORD,,
|
{hdx_python_utilities-4.2.5.dist-info → hdx_python_utilities-4.2.7.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|