hdx-python-utilities 4.2.4__py3-none-any.whl → 4.2.6__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 +8 -4
- hdx/utilities/compare.py +2 -2
- hdx/utilities/dateparse.py +25 -23
- hdx/utilities/dictandlist.py +1 -1
- hdx/utilities/downloader.py +16 -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/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 +0 -0
- hdx/utilities/useragent.py +0 -0
- hdx/utilities/uuid.py +1 -1
- {hdx_python_utilities-4.2.4.dist-info → hdx_python_utilities-4.2.6.dist-info}/METADATA +2 -4
- hdx_python_utilities-4.2.6.dist-info/RECORD +31 -0
- {hdx_python_utilities-4.2.4.dist-info → hdx_python_utilities-4.2.6.dist-info}/WHEEL +1 -1
- hdx_python_utilities-4.2.4.dist-info/RECORD +0 -31
- {hdx_python_utilities-4.2.4.dist-info → hdx_python_utilities-4.2.6.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.6'
|
|
22
|
+
__version_tuple__ = version_tuple = (4, 2, 6)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
hdx/utilities/base_downloader.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
2
|
from collections.abc import Iterator, Sequence
|
|
3
3
|
from pathlib import Path
|
|
4
|
-
from
|
|
5
|
-
|
|
6
|
-
from typing_extensions import Self
|
|
4
|
+
from types import TracebackType
|
|
5
|
+
from typing import Any, Self
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
class DownloadError(Exception):
|
|
@@ -22,7 +21,12 @@ class BaseDownload(ABC):
|
|
|
22
21
|
"""
|
|
23
22
|
return self
|
|
24
23
|
|
|
25
|
-
def __exit__(
|
|
24
|
+
def __exit__(
|
|
25
|
+
self,
|
|
26
|
+
exc_type: type[BaseException] | None,
|
|
27
|
+
exc_value: BaseException | None,
|
|
28
|
+
traceback: TracebackType | None,
|
|
29
|
+
) -> None:
|
|
26
30
|
"""Subclasses should define this to allow with usage.
|
|
27
31
|
|
|
28
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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import re
|
|
4
4
|
import time
|
|
5
5
|
from calendar import monthrange
|
|
6
|
-
from datetime import datetime, timedelta
|
|
6
|
+
from datetime import UTC, datetime, timedelta
|
|
7
7
|
from io import StringIO
|
|
8
8
|
|
|
9
9
|
import dateutil
|
|
@@ -27,7 +27,7 @@ default_date = datetime(
|
|
|
27
27
|
minute=0,
|
|
28
28
|
second=0,
|
|
29
29
|
microsecond=0,
|
|
30
|
-
tzinfo=
|
|
30
|
+
tzinfo=UTC,
|
|
31
31
|
)
|
|
32
32
|
default_ed_year = 9990
|
|
33
33
|
default_enddate_notz = datetime(
|
|
@@ -47,7 +47,7 @@ default_enddate = datetime(
|
|
|
47
47
|
minute=0,
|
|
48
48
|
second=0,
|
|
49
49
|
microsecond=0,
|
|
50
|
-
tzinfo=
|
|
50
|
+
tzinfo=UTC,
|
|
51
51
|
)
|
|
52
52
|
|
|
53
53
|
# Used https://stackoverflow.com/questions/1703546/parsing-date-time-string-with-timezone-abbreviated-name-in-python/4766400#4766400
|
|
@@ -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
|
|
|
@@ -805,7 +805,7 @@ def now_utc() -> datetime:
|
|
|
805
805
|
Returns:
|
|
806
806
|
Now with UTC timezone
|
|
807
807
|
"""
|
|
808
|
-
return datetime.now(
|
|
808
|
+
return datetime.now(UTC)
|
|
809
809
|
|
|
810
810
|
|
|
811
811
|
def now_utc_notz() -> datetime:
|
|
@@ -814,7 +814,7 @@ def now_utc_notz() -> datetime:
|
|
|
814
814
|
Returns:
|
|
815
815
|
Now in UTC but with timezone removed
|
|
816
816
|
"""
|
|
817
|
-
return datetime.now(
|
|
817
|
+
return datetime.now(UTC).replace(tzinfo=None)
|
|
818
818
|
|
|
819
819
|
|
|
820
820
|
def parse_date_range(
|
|
@@ -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)
|
|
@@ -959,25 +959,25 @@ def parse_date_range(
|
|
|
959
959
|
if max_endtime:
|
|
960
960
|
enddate = enddate.replace(hour=23, minute=59, second=59, microsecond=999999)
|
|
961
961
|
if timezone_handling == 0:
|
|
962
|
-
startdate = startdate.replace(tzinfo=
|
|
963
|
-
enddate = enddate.replace(tzinfo=
|
|
962
|
+
startdate = startdate.replace(tzinfo=UTC)
|
|
963
|
+
enddate = enddate.replace(tzinfo=UTC)
|
|
964
964
|
elif timezone_handling == 3:
|
|
965
965
|
if startdate.tzinfo is None:
|
|
966
|
-
startdate = startdate.replace(tzinfo=
|
|
966
|
+
startdate = startdate.replace(tzinfo=UTC)
|
|
967
967
|
if enddate.tzinfo is None:
|
|
968
|
-
enddate = enddate.replace(tzinfo=
|
|
968
|
+
enddate = enddate.replace(tzinfo=UTC)
|
|
969
969
|
elif timezone_handling == 4:
|
|
970
|
-
startdate = startdate.astimezone(
|
|
971
|
-
enddate = enddate.astimezone(
|
|
970
|
+
startdate = startdate.astimezone(UTC)
|
|
971
|
+
enddate = enddate.astimezone(UTC)
|
|
972
972
|
elif timezone_handling == 5:
|
|
973
973
|
if startdate.tzinfo is None:
|
|
974
|
-
startdate = startdate.replace(tzinfo=
|
|
974
|
+
startdate = startdate.replace(tzinfo=UTC)
|
|
975
975
|
else:
|
|
976
|
-
startdate = startdate.astimezone(
|
|
976
|
+
startdate = startdate.astimezone(UTC)
|
|
977
977
|
if enddate.tzinfo is None:
|
|
978
|
-
enddate = enddate.replace(tzinfo=
|
|
978
|
+
enddate = enddate.replace(tzinfo=UTC)
|
|
979
979
|
else:
|
|
980
|
-
enddate = enddate.astimezone(
|
|
980
|
+
enddate = enddate.astimezone(UTC)
|
|
981
981
|
if not include_microseconds:
|
|
982
982
|
startdate = startdate.replace(microsecond=0)
|
|
983
983
|
enddate = enddate.replace(microsecond=0)
|
|
@@ -1092,24 +1092,26 @@ def get_timestamp_from_datetime(date: datetime) -> float:
|
|
|
1092
1092
|
+ date.microsecond / 1e6
|
|
1093
1093
|
)
|
|
1094
1094
|
else:
|
|
1095
|
-
return (date - datetime(1970, 1, 1, tzinfo=
|
|
1095
|
+
return (date - datetime(1970, 1, 1, tzinfo=UTC)).total_seconds()
|
|
1096
1096
|
|
|
1097
1097
|
|
|
1098
1098
|
def get_datetime_from_timestamp(
|
|
1099
1099
|
timestamp: float,
|
|
1100
|
-
timezone: datetime.tzinfo =
|
|
1101
|
-
today: datetime =
|
|
1100
|
+
timezone: datetime.tzinfo = UTC,
|
|
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)
|
|
@@ -1150,7 +1152,7 @@ def get_quarter_start(year: int, quarter: int) -> datetime:
|
|
|
1150
1152
|
First day of quarter
|
|
1151
1153
|
"""
|
|
1152
1154
|
month = 3 * (quarter - 1) + 1
|
|
1153
|
-
return datetime(year, month, 1, tzinfo=
|
|
1155
|
+
return datetime(year, month, 1, tzinfo=UTC)
|
|
1154
1156
|
|
|
1155
1157
|
|
|
1156
1158
|
def get_quarter_end(
|
|
@@ -1183,5 +1185,5 @@ def get_quarter_end(
|
|
|
1183
1185
|
seconds = 0
|
|
1184
1186
|
microseconds = 0
|
|
1185
1187
|
return datetime(
|
|
1186
|
-
year, month, 1, hours, minutes, seconds, microseconds, tzinfo=
|
|
1188
|
+
year, month, 1, hours, minutes, seconds, microseconds, tzinfo=UTC
|
|
1187
1189
|
) + timedelta(days=-1)
|
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
|
|
@@ -1257,9 +1262,9 @@ class Download(BaseDownload):
|
|
|
1257
1262
|
kwargs["rate_limit"] = rate_limit
|
|
1258
1263
|
|
|
1259
1264
|
cls.downloaders = {"default": cls(**kwargs)}
|
|
1260
|
-
for name in custom_configs:
|
|
1265
|
+
for name, custom_config in custom_configs.items():
|
|
1261
1266
|
args_copy = deepcopy(kwargs)
|
|
1262
|
-
args_copy.update(
|
|
1267
|
+
args_copy.update(custom_config)
|
|
1263
1268
|
cls.downloaders[name] = cls(**args_copy)
|
|
1264
1269
|
|
|
1265
1270
|
@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:
|
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
|
File without changes
|
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.6
|
|
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>
|
|
@@ -18,13 +18,12 @@ Classifier: Operating System :: Unix
|
|
|
18
18
|
Classifier: Programming Language :: Python
|
|
19
19
|
Classifier: Programming Language :: Python :: 3
|
|
20
20
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
22
21
|
Classifier: Programming Language :: Python :: 3.11
|
|
23
22
|
Classifier: Programming Language :: Python :: 3.12
|
|
24
23
|
Classifier: Programming Language :: Python :: 3.13
|
|
25
24
|
Classifier: Programming Language :: Python :: 3.14
|
|
26
25
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
-
Requires-Python: >=3.
|
|
26
|
+
Requires-Python: >=3.11
|
|
28
27
|
Requires-Dist: frictionless>=5.19.0
|
|
29
28
|
Requires-Dist: ijson>=3.5.0
|
|
30
29
|
Requires-Dist: jsonlines>=4.0.0
|
|
@@ -36,7 +35,6 @@ Requires-Dist: ratelimit
|
|
|
36
35
|
Requires-Dist: requests-file
|
|
37
36
|
Requires-Dist: ruamel-yaml
|
|
38
37
|
Requires-Dist: tableschema-to-template>=0.0.13
|
|
39
|
-
Requires-Dist: typing-extensions
|
|
40
38
|
Requires-Dist: xlrd>=2.0.1
|
|
41
39
|
Requires-Dist: xlsx2csv==0.8.4
|
|
42
40
|
Requires-Dist: xlwt>=1.3.0
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
hdx/utilities/__init__.py,sha256=DQztoBWScN4UoX3pTjA6JN_CHX-Lls3duu41YLJtdcM,72
|
|
2
|
+
hdx/utilities/_version.py,sha256=Y-5NJHzmJl7W6Exx0Ccv80jq3MxoLMAAB5OlzaNziII,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=3iFloCEMzbQyKSxXK7cOfzcfE32XdyPNEoQ0qUV0Bu4,60168
|
|
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=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=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=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=ysPLCRnwkDYA-ifL-pYJzBigh-jm8_zjqVjcwYSZzno,573
|
|
27
|
+
hdx/utilities/zip_crc.py,sha256=qs-81dd1oX6uIfwH7DUoZaS7OngHwOb7lnogBVmtBl8,4275
|
|
28
|
+
hdx_python_utilities-4.2.6.dist-info/METADATA,sha256=7NWBd9dliPftFSJhzSTtIzZfNq5l2yw7vEd1SKKTTAU,5409
|
|
29
|
+
hdx_python_utilities-4.2.6.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
30
|
+
hdx_python_utilities-4.2.6.dist-info/licenses/LICENSE,sha256=wc-4GpMn-ODs-U_bTe1YCiPVgvcjzrpYOx2wPuyAeII,1079
|
|
31
|
+
hdx_python_utilities-4.2.6.dist-info/RECORD,,
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
hdx/utilities/__init__.py,sha256=DQztoBWScN4UoX3pTjA6JN_CHX-Lls3duu41YLJtdcM,72
|
|
2
|
-
hdx/utilities/_version.py,sha256=v35Uwrw-IApU2AA-2B77yCvOvNQ1Vh7gXvxfaJ9Vd14,520
|
|
3
|
-
hdx/utilities/base_downloader.py,sha256=SzGSz57CwdmtvL2gaNAldXtfQ4uN4F5mjYkBAyq3U7M,3501
|
|
4
|
-
hdx/utilities/compare.py,sha256=3w12iMELCBsR9gKXM7zyRZAf8YSeRylJwmGuLlEkAVQ,1145
|
|
5
|
-
hdx/utilities/dateparse.py,sha256=aoDt3m0PadBqYz9F4-3eCRndH071Vwo2JQOqwop_agQ,42138
|
|
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.4.dist-info/METADATA,sha256=oC90FU8ppn928R0rUprL9pH_9MzhSsGXfum9eOUq_VM,5493
|
|
29
|
-
hdx_python_utilities-4.2.4.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
30
|
-
hdx_python_utilities-4.2.4.dist-info/licenses/LICENSE,sha256=wc-4GpMn-ODs-U_bTe1YCiPVgvcjzrpYOx2wPuyAeII,1079
|
|
31
|
-
hdx_python_utilities-4.2.4.dist-info/RECORD,,
|
{hdx_python_utilities-4.2.4.dist-info → hdx_python_utilities-4.2.6.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|