teritorio 2021.10.22__py3-none-any.whl → 2024.7.17__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.
teritorio/main.py CHANGED
@@ -1,58 +1,53 @@
1
+ from __future__ import annotations
2
+
1
3
  import json
2
4
  from dataclasses import dataclass
3
5
  from pathlib import Path
4
- from typing import Any, Optional
5
-
6
+ from typing import Any, Generic, TypeVar
6
7
 
7
- class Singleton(type):
8
- def __init__(cls, name, bases, dict_):
9
- super().__init__(name, bases, dict_)
10
- cls.instance = None
8
+ from pyutilkit.classes import Singleton
11
9
 
12
- def __call__(cls, *args, **kwargs):
13
- if cls.instance is None:
14
- cls.instance = super().__call__(*args, **kwargs)
15
- return cls.instance
10
+ T = TypeVar("T")
16
11
 
17
12
 
18
- class DataListIterator:
19
- def __init__(self, data):
13
+ class DataListIterator(Generic[T]):
14
+ def __init__(self, data: dict[str, T]) -> None:
20
15
  self.values = (data[key] for key in sorted(data))
21
16
 
22
- def __iter__(self):
17
+ def __iter__(self) -> DataListIterator[T]:
23
18
  return self
24
19
 
25
- def __next__(self):
20
+ def __next__(self) -> T:
26
21
  return next(self.values)
27
22
 
28
23
 
29
- class DataList:
24
+ class DataList(Generic[T]):
30
25
  _data_path: Path
31
- _object_class: Any
26
+ _object_class: type[T]
32
27
 
33
- def __init__(self):
34
- with open(self._data_path) as file:
35
- data = json.load(file)
28
+ def __init__(self) -> None:
29
+ with self._data_path.open() as file:
30
+ data = json.load(file, object_hook=_list_to_tuple)
36
31
 
37
- self._data = {}
38
- for key, value in data.items():
39
- obj = self._object_class(**value)
32
+ self._data: dict[str, T] = {}
33
+ for key, raw_obj in data.items():
34
+ obj = self._object_class(**raw_obj)
40
35
  self._data[key] = obj
41
36
  setattr(self, key, obj)
42
37
 
43
- def __str__(self):
38
+ def __str__(self) -> str:
44
39
  return f"{self.__class__.__name__}()"
45
40
 
46
- def __repr__(self):
41
+ def __repr__(self) -> str:
47
42
  return f"{self.__class__.__name__}()"
48
43
 
49
- def __len__(self):
44
+ def __len__(self) -> int:
50
45
  return len(self._data)
51
46
 
52
- def __getitem__(self, key):
47
+ def __getitem__(self, key: str) -> T:
53
48
  return self._data[key]
54
49
 
55
- def __iter__(self):
50
+ def __iter__(self) -> DataListIterator[T]:
56
51
  return DataListIterator(self._data)
57
52
 
58
53
 
@@ -65,7 +60,7 @@ class Country:
65
60
  numeric_code: int
66
61
 
67
62
 
68
- class Countries(DataList, metaclass=Singleton):
63
+ class Countries(DataList[Country], metaclass=Singleton):
69
64
  _data_path = Path(__file__).parent.joinpath("_data/country.json")
70
65
  _object_class = Country
71
66
 
@@ -74,11 +69,19 @@ class Countries(DataList, metaclass=Singleton):
74
69
  class Currency:
75
70
  code: str
76
71
  name: str
77
- entities: list
72
+ entities: tuple[str, ...]
78
73
  numeric_code: int
79
- minor_units: Optional[int]
74
+ minor_units: int | None
80
75
 
81
76
 
82
- class Currencies(DataList, metaclass=Singleton):
77
+ class Currencies(DataList[Currency], metaclass=Singleton):
83
78
  _data_path = Path(__file__).parent.joinpath("_data/currency.json")
84
79
  _object_class = Currency
80
+
81
+
82
+ def _list_to_tuple(obj: Any) -> Any:
83
+ if isinstance(obj, list):
84
+ return tuple(obj)
85
+ if isinstance(obj, dict):
86
+ return {key: _list_to_tuple(value) for key, value in obj.items()}
87
+ return obj
teritorio/main.pyi ADDED
@@ -0,0 +1,476 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Iterator
4
+ from dataclasses import dataclass
5
+ from pathlib import Path
6
+ from typing import Generic, TypeVar
7
+
8
+ from pyutilkit.classes import Singleton
9
+
10
+ T = TypeVar("T")
11
+
12
+ class DataListIterator(Generic[T]):
13
+ values: Iterator[T]
14
+ def __init__(self, data: dict[str, T]) -> None: ...
15
+ def __iter__(self) -> DataListIterator[T]: ...
16
+ def __next__(self) -> T: ...
17
+
18
+ class DataList(Generic[T]):
19
+ _data_path: Path
20
+ _object_class: type[T]
21
+ _data: dict[str, T]
22
+
23
+ def __init__(self) -> None: ...
24
+ def __str__(self) -> str: ...
25
+ def __repr__(self) -> str: ...
26
+ def __len__(self) -> int: ...
27
+ def __getitem__(self, key: str) -> T: ...
28
+ def __iter__(self) -> DataListIterator[T]: ...
29
+
30
+ @dataclass(frozen=True, order=True)
31
+ class Country:
32
+ english_name: str
33
+ french_name: str
34
+ alpha_2_code: str
35
+ alpha_3_code: str
36
+ numeric_code: int
37
+
38
+ class Countries(DataList[Country], metaclass=Singleton):
39
+ ABW: Country
40
+ AFG: Country
41
+ AGO: Country
42
+ AIA: Country
43
+ ALA: Country
44
+ ALB: Country
45
+ AND: Country
46
+ ARE: Country
47
+ ARG: Country
48
+ ARM: Country
49
+ ASM: Country
50
+ ATA: Country
51
+ ATF: Country
52
+ ATG: Country
53
+ AUS: Country
54
+ AUT: Country
55
+ AZE: Country
56
+ BDI: Country
57
+ BEL: Country
58
+ BEN: Country
59
+ BES: Country
60
+ BFA: Country
61
+ BGD: Country
62
+ BGR: Country
63
+ BHR: Country
64
+ BHS: Country
65
+ BIH: Country
66
+ BLM: Country
67
+ BLR: Country
68
+ BLZ: Country
69
+ BMU: Country
70
+ BOL: Country
71
+ BRA: Country
72
+ BRB: Country
73
+ BRN: Country
74
+ BTN: Country
75
+ BVT: Country
76
+ BWA: Country
77
+ CAF: Country
78
+ CAN: Country
79
+ CCK: Country
80
+ CHE: Country
81
+ CHL: Country
82
+ CHN: Country
83
+ CIV: Country
84
+ CMR: Country
85
+ COD: Country
86
+ COG: Country
87
+ COK: Country
88
+ COL: Country
89
+ COM: Country
90
+ CPV: Country
91
+ CRI: Country
92
+ CUB: Country
93
+ CUW: Country
94
+ CXR: Country
95
+ CYM: Country
96
+ CYP: Country
97
+ CZE: Country
98
+ DEU: Country
99
+ DJI: Country
100
+ DMA: Country
101
+ DNK: Country
102
+ DOM: Country
103
+ DZA: Country
104
+ ECU: Country
105
+ EGY: Country
106
+ ERI: Country
107
+ ESH: Country
108
+ ESP: Country
109
+ EST: Country
110
+ ETH: Country
111
+ FIN: Country
112
+ FJI: Country
113
+ FLK: Country
114
+ FRA: Country
115
+ FRO: Country
116
+ FSM: Country
117
+ GAB: Country
118
+ GBR: Country
119
+ GEO: Country
120
+ GGY: Country
121
+ GHA: Country
122
+ GIB: Country
123
+ GIN: Country
124
+ GLP: Country
125
+ GMB: Country
126
+ GNB: Country
127
+ GNQ: Country
128
+ GRC: Country
129
+ GRD: Country
130
+ GRL: Country
131
+ GTM: Country
132
+ GUF: Country
133
+ GUM: Country
134
+ GUY: Country
135
+ HKG: Country
136
+ HMD: Country
137
+ HND: Country
138
+ HRV: Country
139
+ HTI: Country
140
+ HUN: Country
141
+ IDN: Country
142
+ IMN: Country
143
+ IND: Country
144
+ IOT: Country
145
+ IRL: Country
146
+ IRN: Country
147
+ IRQ: Country
148
+ ISL: Country
149
+ ISR: Country
150
+ ITA: Country
151
+ JAM: Country
152
+ JEY: Country
153
+ JOR: Country
154
+ JPN: Country
155
+ KAZ: Country
156
+ KEN: Country
157
+ KGZ: Country
158
+ KHM: Country
159
+ KIR: Country
160
+ KNA: Country
161
+ KOR: Country
162
+ KWT: Country
163
+ LAO: Country
164
+ LBN: Country
165
+ LBR: Country
166
+ LBY: Country
167
+ LCA: Country
168
+ LIE: Country
169
+ LKA: Country
170
+ LSO: Country
171
+ LTU: Country
172
+ LUX: Country
173
+ LVA: Country
174
+ MAC: Country
175
+ MAF: Country
176
+ MAR: Country
177
+ MCO: Country
178
+ MDA: Country
179
+ MDG: Country
180
+ MDV: Country
181
+ MEX: Country
182
+ MHL: Country
183
+ MKD: Country
184
+ MLI: Country
185
+ MLT: Country
186
+ MMR: Country
187
+ MNE: Country
188
+ MNG: Country
189
+ MNP: Country
190
+ MOZ: Country
191
+ MRT: Country
192
+ MSR: Country
193
+ MTQ: Country
194
+ MUS: Country
195
+ MWI: Country
196
+ MYS: Country
197
+ MYT: Country
198
+ NAM: Country
199
+ NCL: Country
200
+ NER: Country
201
+ NFK: Country
202
+ NGA: Country
203
+ NIC: Country
204
+ NIU: Country
205
+ NLD: Country
206
+ NOR: Country
207
+ NPL: Country
208
+ NRU: Country
209
+ NZL: Country
210
+ OMN: Country
211
+ PAK: Country
212
+ PAN: Country
213
+ PCN: Country
214
+ PER: Country
215
+ PHL: Country
216
+ PLW: Country
217
+ PNG: Country
218
+ POL: Country
219
+ PRI: Country
220
+ PRK: Country
221
+ PRT: Country
222
+ PRY: Country
223
+ PSE: Country
224
+ PYF: Country
225
+ QAT: Country
226
+ REU: Country
227
+ ROU: Country
228
+ RUS: Country
229
+ RWA: Country
230
+ SAU: Country
231
+ SDN: Country
232
+ SEN: Country
233
+ SGP: Country
234
+ SGS: Country
235
+ SHN: Country
236
+ SJM: Country
237
+ SLB: Country
238
+ SLE: Country
239
+ SLV: Country
240
+ SMR: Country
241
+ SOM: Country
242
+ SPM: Country
243
+ SRB: Country
244
+ SSD: Country
245
+ STP: Country
246
+ SUR: Country
247
+ SVK: Country
248
+ SVN: Country
249
+ SWE: Country
250
+ SWZ: Country
251
+ SXM: Country
252
+ SYC: Country
253
+ SYR: Country
254
+ TCA: Country
255
+ TCD: Country
256
+ TGO: Country
257
+ THA: Country
258
+ TJK: Country
259
+ TKL: Country
260
+ TKM: Country
261
+ TLS: Country
262
+ TON: Country
263
+ TTO: Country
264
+ TUN: Country
265
+ TUR: Country
266
+ TUV: Country
267
+ TWN: Country
268
+ TZA: Country
269
+ UGA: Country
270
+ UKR: Country
271
+ UMI: Country
272
+ URY: Country
273
+ USA: Country
274
+ UZB: Country
275
+ VAT: Country
276
+ VCT: Country
277
+ VEN: Country
278
+ VGB: Country
279
+ VIR: Country
280
+ VNM: Country
281
+ VUT: Country
282
+ WLF: Country
283
+ WSM: Country
284
+ YEM: Country
285
+ ZAF: Country
286
+ ZMB: Country
287
+ ZWE: Country
288
+
289
+ @dataclass(frozen=True, order=True)
290
+ class Currency:
291
+ code: str
292
+ name: str
293
+ entities: tuple[str, ...]
294
+ numeric_code: int
295
+ minor_units: int | None
296
+
297
+ class Currencies(DataList[Currency], metaclass=Singleton):
298
+ AED: Currency
299
+ AFN: Currency
300
+ ALL: Currency
301
+ AMD: Currency
302
+ ANG: Currency
303
+ AOA: Currency
304
+ ARS: Currency
305
+ AUD: Currency
306
+ AWG: Currency
307
+ AZN: Currency
308
+ BAM: Currency
309
+ BBD: Currency
310
+ BDT: Currency
311
+ BGN: Currency
312
+ BHD: Currency
313
+ BIF: Currency
314
+ BMD: Currency
315
+ BND: Currency
316
+ BOB: Currency
317
+ BOV: Currency
318
+ BRL: Currency
319
+ BSD: Currency
320
+ BTN: Currency
321
+ BWP: Currency
322
+ BYN: Currency
323
+ BZD: Currency
324
+ CAD: Currency
325
+ CDF: Currency
326
+ CHE: Currency
327
+ CHF: Currency
328
+ CHW: Currency
329
+ CLF: Currency
330
+ CLP: Currency
331
+ CNY: Currency
332
+ COP: Currency
333
+ COU: Currency
334
+ CRC: Currency
335
+ CUC: Currency
336
+ CUP: Currency
337
+ CVE: Currency
338
+ CZK: Currency
339
+ DJF: Currency
340
+ DKK: Currency
341
+ DOP: Currency
342
+ DZD: Currency
343
+ EGP: Currency
344
+ ERN: Currency
345
+ ETB: Currency
346
+ EUR: Currency
347
+ FJD: Currency
348
+ FKP: Currency
349
+ GBP: Currency
350
+ GEL: Currency
351
+ GHS: Currency
352
+ GIP: Currency
353
+ GMD: Currency
354
+ GNF: Currency
355
+ GTQ: Currency
356
+ GYD: Currency
357
+ HKD: Currency
358
+ HNL: Currency
359
+ HTG: Currency
360
+ HUF: Currency
361
+ IDR: Currency
362
+ ILS: Currency
363
+ INR: Currency
364
+ IQD: Currency
365
+ IRR: Currency
366
+ ISK: Currency
367
+ JMD: Currency
368
+ JOD: Currency
369
+ JPY: Currency
370
+ KES: Currency
371
+ KGS: Currency
372
+ KHR: Currency
373
+ KMF: Currency
374
+ KPW: Currency
375
+ KRW: Currency
376
+ KWD: Currency
377
+ KYD: Currency
378
+ KZT: Currency
379
+ LAK: Currency
380
+ LBP: Currency
381
+ LKR: Currency
382
+ LRD: Currency
383
+ LSL: Currency
384
+ LYD: Currency
385
+ MAD: Currency
386
+ MDL: Currency
387
+ MGA: Currency
388
+ MKD: Currency
389
+ MMK: Currency
390
+ MNT: Currency
391
+ MOP: Currency
392
+ MRU: Currency
393
+ MUR: Currency
394
+ MVR: Currency
395
+ MWK: Currency
396
+ MXN: Currency
397
+ MXV: Currency
398
+ MYR: Currency
399
+ MZN: Currency
400
+ NAD: Currency
401
+ NGN: Currency
402
+ NIO: Currency
403
+ NOK: Currency
404
+ NPR: Currency
405
+ NZD: Currency
406
+ OMR: Currency
407
+ PAB: Currency
408
+ PEN: Currency
409
+ PGK: Currency
410
+ PHP: Currency
411
+ PKR: Currency
412
+ PLN: Currency
413
+ PYG: Currency
414
+ QAR: Currency
415
+ RON: Currency
416
+ RSD: Currency
417
+ RUB: Currency
418
+ RWF: Currency
419
+ SAR: Currency
420
+ SBD: Currency
421
+ SCR: Currency
422
+ SDG: Currency
423
+ SEK: Currency
424
+ SGD: Currency
425
+ SHP: Currency
426
+ SLE: Currency
427
+ SOS: Currency
428
+ SRD: Currency
429
+ SSP: Currency
430
+ STN: Currency
431
+ SVC: Currency
432
+ SYP: Currency
433
+ SZL: Currency
434
+ THB: Currency
435
+ TJS: Currency
436
+ TMT: Currency
437
+ TND: Currency
438
+ TOP: Currency
439
+ TRY: Currency
440
+ TTD: Currency
441
+ TWD: Currency
442
+ TZS: Currency
443
+ UAH: Currency
444
+ UGX: Currency
445
+ USD: Currency
446
+ USN: Currency
447
+ UYI: Currency
448
+ UYU: Currency
449
+ UYW: Currency
450
+ UZS: Currency
451
+ VED: Currency
452
+ VES: Currency
453
+ VND: Currency
454
+ VUV: Currency
455
+ WST: Currency
456
+ XAF: Currency
457
+ XAG: Currency
458
+ XAU: Currency
459
+ XBA: Currency
460
+ XBB: Currency
461
+ XBC: Currency
462
+ XBD: Currency
463
+ XCD: Currency
464
+ XDR: Currency
465
+ XOF: Currency
466
+ XPD: Currency
467
+ XPF: Currency
468
+ XPT: Currency
469
+ XSU: Currency
470
+ XTS: Currency
471
+ XUA: Currency
472
+ XXX: Currency
473
+ YER: Currency
474
+ ZAR: Currency
475
+ ZMW: Currency
476
+ ZWL: Currency
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.3
2
+ Name: teritorio
3
+ Version: 2024.7.17
4
+ Summary: A library for country and currency ISO codes
5
+ Home-page: https://teritorio.readthedocs.io/en/stable/
6
+ License: BSD-3-Clause
7
+ Keywords: country,currency,iso
8
+ Author: Stephanos Kuma
9
+ Author-email: "Stephanos Kuma" <stephanos@kuma.ai>
10
+ Requires-Python: >=3.9
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Financial and Insurance Industry
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Dist: pyutilkit (~=0.4)
15
+ Project-URL: Documentation, https://teritorio.readthedocs.io/en/stable/
16
+ Project-URL: Repository, https://github.com/spapanik/teritorio
17
+ Description-Content-Type: text/markdown
18
+
19
+ # teritorio: ISO codes for countries and currencies
20
+
21
+ [![tests][test_badge]][test_url]
22
+ [![license][licence_badge]][licence_url]
23
+ [![pypi][pypi_badge]][pypi_url]
24
+ [![downloads][pepy_badge]][pepy_url]
25
+ [![code style: black][black_badge]][black_url]
26
+ [![build automation: yam][yam_badge]][yam_url]
27
+ [![Lint: ruff][ruff_badge]][ruff_url]
28
+
29
+ `teritorio` two iterable singletons that `Countries` and `Currencies`,
30
+ that contain all the relevant ISO information about countries and
31
+ currencies, respectively.
32
+
33
+ ## Versioning
34
+
35
+ The project project adheres to [Calendar Versioning](https://calver.org). The reason is that the data are
36
+ dominated by political decisions, making semantic versioning largely irrelevant.
37
+
38
+ ## Links
39
+
40
+ - [Documentation]
41
+ - [Changelog]
42
+
43
+ [test_badge]: https://github.com/spapanik/teritorio/actions/workflows/tests.yml/badge.svg
44
+ [test_url]: https://github.com/spapanik/teritorio/actions/workflows/tests.yml
45
+ [licence_badge]: https://img.shields.io/pypi/l/teritorio
46
+ [licence_url]: https://github.com/spapanik/teritorio/blob/main/docs/LICENSE.md
47
+ [pypi_badge]: https://img.shields.io/pypi/v/teritorio
48
+ [pypi_url]: https://pypi.org/project/teritorio
49
+ [pepy_badge]: https://pepy.tech/badge/teritorio
50
+ [pepy_url]: https://pepy.tech/project/teritorio
51
+ [black_badge]: https://img.shields.io/badge/code%20style-black-000000.svg
52
+ [black_url]: https://github.com/psf/black
53
+ [yam_badge]: https://img.shields.io/badge/build%20automation-yamk-success
54
+ [yam_url]: https://github.com/spapanik/yamk
55
+ [ruff_badge]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v1.json
56
+ [ruff_url]: https://github.com/charliermarsh/ruff
57
+ [Documentation]: https://teritorio.readthedocs.io/en/stable/
58
+ [Changelog]: https://github.com/spapanik/teritorio/blob/main/docs/CHANGELOG.md
59
+ [Calendar Versioning]: https://calver.org
@@ -0,0 +1,9 @@
1
+ teritorio/__init__.py,sha256=sP9e4uVdaAe2-FYeoO_Yv1Sx_-08G68lK695bO4kapE,115
2
+ teritorio/_data/country.json,sha256=X9zFAvkKdcU0rvncwVwdQdAAMAfpt663AXp05Hcjaks,48421
3
+ teritorio/_data/currency.json,sha256=PKnc-qpKj9wKnWXmS7OXS5WiHoUdwNp3-guDbtpGTCc,33422
4
+ teritorio/main.py,sha256=U342OeuNMRXg8sUKpD3DFa6g9PVtj-OB48OSx-alE70,2143
5
+ teritorio/main.pyi,sha256=Nc2lLWDas9TCm7iXjVTgAa_fsYbtCMucrrbHfnfnL5g,8661
6
+ teritorio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ teritorio-2024.7.17.dist-info/METADATA,sha256=8AnuqqGTLHTA-aQzhxqbo-CNENTM8aeI3GKzWNzvm3o,2533
8
+ teritorio-2024.7.17.dist-info/WHEEL,sha256=k5X_cv0nlsobEJ2RWm08o6BGpyHHSLnOdq47ItFx1Pg,87
9
+ teritorio-2024.7.17.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry 1.0.3
2
+ Generator: phosphorus 0.4.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
CHANGELOG.md DELETED
@@ -1,37 +0,0 @@
1
- # Changelog
2
- All notable changes to this project will be documented in this file.
3
-
4
- The format is based on [Keep a Changelog][clog], and this project adheres to [Calendar Versioning][calver].
5
-
6
- ## [Unreleased]
7
-
8
- ## [2021.10.22]
9
- ### Added
10
- - Added python310 support
11
- - Added VED
12
-
13
- ### Changed
14
- - Changed versioning scheme to calendar versioning
15
-
16
- ## [1.1.0] - 2020-08-31
17
- ### Added
18
- - Add support for python 3.6
19
-
20
- ## [1.0.1] - 2019-11-21
21
- ### Fixed
22
- - Fixed some typos
23
-
24
- ## [1.0.0] - 2019-11-14
25
- ### Added
26
- - Added currency ISO codes (ISO-4217)
27
- - Added country ISO codes (ISO-3166)
28
-
29
-
30
- [unreleased]: https://github.com/spapanik/teritorio/compare/v2021.10.22...master
31
- [2021.10.22]: https://github.com/spapanik/teritorio/compare/v1.1.0...v2021.10.22
32
- [1.0.1]: https://github.com/spapanik/teritorio/compare/v1.0.1...v1.1.0
33
- [1.0.1]: https://github.com/spapanik/teritorio/compare/v1.0.0...v1.0.1
34
- [1.0.0]: https://github.com/spapanik/teritorio/releases/tag/v1.0.0
35
-
36
- [clog]: https://keepachangelog.com/en/1.0.0/
37
- [calver]: https://calver.org