nepali 0.5.5__py3-none-any.whl → 1.2.0__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.
- nepali/__init__.py +1 -1
- nepali/char.py +102 -81
- nepali/constants.py +66 -0
- nepali/date_converter.py +334 -0
- nepali/datetime/__init__.py +13 -14
- nepali/datetime/_datetime.py +391 -402
- nepali/datetime/_formatter.py +325 -0
- nepali/datetime/_humanize.py +117 -132
- nepali/datetime/_nepalimonth.py +118 -0
- nepali/datetime/_nepaliweek.py +125 -0
- nepali/datetime/parser/__init__.py +4 -4
- nepali/datetime/parser/_parser.py +59 -50
- nepali/datetime/parser/validators.py +249 -159
- nepali/datetime/utils.py +38 -0
- nepali/exceptions.py +8 -3
- nepali/locations/__init__.py +3 -0
- nepali/locations/_data.py +4271 -0
- nepali/locations/_locations.py +38 -0
- nepali/locations/models.py +104 -0
- nepali/locations/utils.py +54 -0
- nepali/number/__init__.py +19 -0
- nepali/number/_nepalinumber.py +563 -0
- nepali/number/_number.py +53 -0
- nepali/number/utils.py +72 -0
- nepali/phone_number.py +183 -0
- nepali/templatetags/__init__.py +0 -0
- nepali/templatetags/nepalidatetime.py +194 -24
- nepali/templatetags/nepalinumber.py +97 -7
- nepali/tests/test_date_converter.py +148 -0
- nepali/tests/test_datetime.py +275 -29
- nepali/tests/test_humanize.py +78 -7
- nepali/tests/test_locations.py +154 -0
- nepali/tests/test_nepalimonth.py +152 -0
- nepali/tests/test_nepaliweek.py +154 -0
- nepali/tests/test_number.py +3152 -0
- nepali/tests/test_parser.py +82 -69
- nepali/tests/test_phone_number.py +254 -0
- nepali/tests/test_timezone.py +192 -0
- nepali/timezone.py +50 -7
- nepali/utils.py +9 -68
- nepali-1.2.0.dist-info/METADATA +476 -0
- nepali-1.2.0.dist-info/RECORD +46 -0
- {nepali-0.5.5.dist-info → nepali-1.2.0.dist-info}/WHEEL +1 -1
- {nepali-0.5.5.dist-info → nepali-1.2.0.dist-info/licenses}/LICENSE +1 -1
- {nepali-0.5.5.dist-info → nepali-1.2.0.dist-info}/top_level.txt +0 -0
- nepali/datetime/_converter.py +0 -394
- nepali/datetime/_formarter.py +0 -314
- nepali/datetime.py +0 -1169
- nepali/number.py +0 -51
- nepali-0.5.5.dist-info/METADATA +0 -220
- nepali-0.5.5.dist-info/RECORD +0 -27
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from .models import District, Municipality, MunicipalityType, Province
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def _loadData() -> tuple[list[Province], list[District], list[Municipality]]:
|
|
5
|
+
from ._data import _location_data
|
|
6
|
+
|
|
7
|
+
provinces = []
|
|
8
|
+
districts = []
|
|
9
|
+
municipalities = []
|
|
10
|
+
for province_data in _location_data:
|
|
11
|
+
province = Province(
|
|
12
|
+
name=province_data["name"], name_nepali=province_data["name_nepali"]
|
|
13
|
+
)
|
|
14
|
+
provinces.append(province)
|
|
15
|
+
|
|
16
|
+
for district_data in province_data["districts"]:
|
|
17
|
+
district = District(
|
|
18
|
+
province=province,
|
|
19
|
+
name=district_data["name"],
|
|
20
|
+
name_nepali=district_data["name_nepali"],
|
|
21
|
+
)
|
|
22
|
+
districts.append(district)
|
|
23
|
+
|
|
24
|
+
for municipality_data in district_data["municipalities"]:
|
|
25
|
+
municipality = Municipality(
|
|
26
|
+
district=district,
|
|
27
|
+
name=municipality_data["name"],
|
|
28
|
+
name_nepali=municipality_data["name_nepali"],
|
|
29
|
+
municipality_type=MunicipalityType(
|
|
30
|
+
municipality_data["municipality_type"]
|
|
31
|
+
),
|
|
32
|
+
)
|
|
33
|
+
municipalities.append(municipality)
|
|
34
|
+
|
|
35
|
+
return provinces, districts, municipalities
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
provinces, districts, municipalities = _loadData()
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Location:
|
|
5
|
+
def __init__(self, name: str, name_nepali: str):
|
|
6
|
+
self.__name = name
|
|
7
|
+
self.__name_nepali = name_nepali
|
|
8
|
+
|
|
9
|
+
def __str__(self):
|
|
10
|
+
return self.name
|
|
11
|
+
|
|
12
|
+
def __repr__(self):
|
|
13
|
+
return self.name
|
|
14
|
+
|
|
15
|
+
@property
|
|
16
|
+
def name(self):
|
|
17
|
+
return self.__name
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def name_nepali(self):
|
|
21
|
+
return self.__name_nepali
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Province(Location):
|
|
25
|
+
def __init__(self, name: str, name_nepali: str):
|
|
26
|
+
super().__init__(name, name_nepali)
|
|
27
|
+
self.__districts = []
|
|
28
|
+
self.__municipalities = []
|
|
29
|
+
|
|
30
|
+
def _add_district(self, district: "District") -> None:
|
|
31
|
+
"""Do not use outside of the model, automatically called from the models."""
|
|
32
|
+
self.__districts.append(district)
|
|
33
|
+
|
|
34
|
+
def _add_municipality(self, municipality: "Municipality") -> None:
|
|
35
|
+
"""Do not use outside of the model, automatically called from the models."""
|
|
36
|
+
self.__municipalities.append(municipality)
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def districts(self) -> list["District"]:
|
|
40
|
+
return self.__districts
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def municipalities(self) -> list["Municipality"]:
|
|
44
|
+
return self.__municipalities
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class District(Location):
|
|
48
|
+
def __init__(self, province: Province, name: str, name_nepali: str):
|
|
49
|
+
super().__init__(name, name_nepali)
|
|
50
|
+
self.__province = province
|
|
51
|
+
self.__municipalities = []
|
|
52
|
+
self.__province._add_district(self)
|
|
53
|
+
|
|
54
|
+
def _add_municipality(self, district: "Municipality") -> None:
|
|
55
|
+
"""Do not use outside of the model, automatically called from the models."""
|
|
56
|
+
self.__municipalities.append(district)
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
def province(self) -> Province:
|
|
60
|
+
return self.__province
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def municipalities(self) -> list["Municipality"]:
|
|
64
|
+
return self.__municipalities
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class MunicipalityType(Enum):
|
|
68
|
+
METROPOLITAN = "Metropolitan City"
|
|
69
|
+
SUB_METROPOLITAN = "Sub-Metropolitan City"
|
|
70
|
+
MUNICIPALITY = "Municipality"
|
|
71
|
+
RURAL_MUNICIPALITY = "Rural Municipality"
|
|
72
|
+
|
|
73
|
+
def __str__(self) -> str:
|
|
74
|
+
return self.value
|
|
75
|
+
|
|
76
|
+
def __repr__(self) -> str:
|
|
77
|
+
return self.value
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class Municipality(Location):
|
|
81
|
+
def __init__(
|
|
82
|
+
self,
|
|
83
|
+
district: District,
|
|
84
|
+
name: str,
|
|
85
|
+
name_nepali: str,
|
|
86
|
+
municipality_type: MunicipalityType,
|
|
87
|
+
):
|
|
88
|
+
super().__init__(name, name_nepali)
|
|
89
|
+
self.__district = district
|
|
90
|
+
self.__municipality_type = municipality_type
|
|
91
|
+
self.__district._add_municipality(self)
|
|
92
|
+
self.__district.province._add_municipality(self)
|
|
93
|
+
|
|
94
|
+
@property
|
|
95
|
+
def province(self) -> Province:
|
|
96
|
+
return self.district.province
|
|
97
|
+
|
|
98
|
+
@property
|
|
99
|
+
def district(self) -> District:
|
|
100
|
+
return self.__district
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def municipality_type(self) -> MunicipalityType:
|
|
104
|
+
return self.__municipality_type
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from functools import partial
|
|
3
|
+
|
|
4
|
+
from ._locations import districts, municipalities, provinces
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"get_province",
|
|
8
|
+
"get_district",
|
|
9
|
+
"get_municipality",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _filter_location(
|
|
14
|
+
*, locations, name=None, name_nepali=None, exact=False, multiple=False
|
|
15
|
+
):
|
|
16
|
+
if not name and not name_nepali:
|
|
17
|
+
raise ValueError("name or name_nepali must be passed")
|
|
18
|
+
|
|
19
|
+
if exact and multiple:
|
|
20
|
+
raise ValueError("Both the exact and multiple cannot be true")
|
|
21
|
+
|
|
22
|
+
# making name as lower case
|
|
23
|
+
if name:
|
|
24
|
+
name = name.lower()
|
|
25
|
+
|
|
26
|
+
# taking field and value for filtering
|
|
27
|
+
# eg. field = name and value ="Bagmati Province"
|
|
28
|
+
field, value = ("name", name) if name else ("name_nepali", name_nepali)
|
|
29
|
+
|
|
30
|
+
# filtering data
|
|
31
|
+
if exact:
|
|
32
|
+
filtered_locations = [
|
|
33
|
+
location
|
|
34
|
+
for location in locations
|
|
35
|
+
if getattr(location, field).lower() == value
|
|
36
|
+
]
|
|
37
|
+
else:
|
|
38
|
+
pattern = re.compile(rf".*{value}.*")
|
|
39
|
+
filtered_locations = [
|
|
40
|
+
location
|
|
41
|
+
for location in locations
|
|
42
|
+
if re.match(pattern, getattr(location, field).lower())
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
# returning data if not filtered location is available
|
|
46
|
+
if len(filtered_locations) == 0 and not multiple:
|
|
47
|
+
return None
|
|
48
|
+
|
|
49
|
+
return filtered_locations if multiple else filtered_locations[0]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
get_province = partial(_filter_location, locations=provinces)
|
|
53
|
+
get_district = partial(_filter_location, locations=districts)
|
|
54
|
+
get_municipality = partial(_filter_location, locations=municipalities)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from ._nepalinumber import nepalinumber
|
|
2
|
+
from ._number import NepaliNumber
|
|
3
|
+
from .utils import (
|
|
4
|
+
add_comma,
|
|
5
|
+
add_comma_english,
|
|
6
|
+
convert_and_add_comma,
|
|
7
|
+
english_to_nepali,
|
|
8
|
+
nepali_to_english,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"NepaliNumber",
|
|
13
|
+
"add_comma",
|
|
14
|
+
"add_comma_english",
|
|
15
|
+
"convert_and_add_comma",
|
|
16
|
+
"english_to_nepali",
|
|
17
|
+
"nepali_to_english",
|
|
18
|
+
"nepalinumber",
|
|
19
|
+
]
|