-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbase.py
65 lines (54 loc) · 1.55 KB
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from enum import Enum
from dataclasses import dataclass
class VietNamDivisionType(str, Enum):
# Level 1
TINH = 'tỉnh'
THANH_PHO_TRUNG_UONG = 'thành phố trung ương'
# Level 2
HUYEN = 'huyện'
QUAN = 'quận'
THANH_PHO = 'thành phố'
THI_XA = 'thị xã'
# Level 3
XA = 'xã'
THI_TRAN = 'thị trấn'
PHUONG = 'phường'
# I make Ward as a type from dataclass, to:
# - Work-around problem with fast-enum
# - Using fast-enum to work-around problem of slow loading standard Enum type in Python.
# In the future, when Python fix the issue with slow Enum, I will base Ward on NamedTuple,
# as other types in this module.
# This dataclass needs to be frozen, because of fastenum
@dataclass(frozen=True)
class Ward:
name: str
code: int
division_type: VietNamDivisionType
codename: str
district_code: int
def __eq__(self, other: object):
if not isinstance(other, Ward):
return False
return other.code == self.code
@dataclass
class District:
name: str
code: int
division_type: VietNamDivisionType
codename: str
province_code: int
def __eq__(self, other: object):
if not isinstance(other, District):
return False
return other.code == self.code
@dataclass
class Province:
name: str
code: int
division_type: VietNamDivisionType
codename: str
phone_code: int
def __eq__(self, other: object):
if not isinstance(other, Province):
return False
return other.code == self.code