summaryrefslogtreecommitdiff
path: root/venv/lib/python3.11/site-packages/faker/providers/ssn/uk_UA
diff options
context:
space:
mode:
authorcyfraeviolae <cyfraeviolae>2024-04-03 03:10:44 -0400
committercyfraeviolae <cyfraeviolae>2024-04-03 03:10:44 -0400
commit6d7ba58f880be618ade07f8ea080fe8c4bf8a896 (patch)
treeb1c931051ffcebd2bd9d61d98d6233ffa289bbce /venv/lib/python3.11/site-packages/faker/providers/ssn/uk_UA
parent4f884c9abc32990b4061a1bb6997b4b37e58ea0b (diff)
venv
Diffstat (limited to 'venv/lib/python3.11/site-packages/faker/providers/ssn/uk_UA')
-rw-r--r--venv/lib/python3.11/site-packages/faker/providers/ssn/uk_UA/__init__.py59
-rw-r--r--venv/lib/python3.11/site-packages/faker/providers/ssn/uk_UA/__pycache__/__init__.cpython-311.pycbin0 -> 3895 bytes
2 files changed, 59 insertions, 0 deletions
diff --git a/venv/lib/python3.11/site-packages/faker/providers/ssn/uk_UA/__init__.py b/venv/lib/python3.11/site-packages/faker/providers/ssn/uk_UA/__init__.py
new file mode 100644
index 0000000..e647be2
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/faker/providers/ssn/uk_UA/__init__.py
@@ -0,0 +1,59 @@
+import random
+
+from datetime import date, datetime
+from typing import Optional
+
+from ....typing import SexLiteral
+from .. import Provider as SsnProvider
+
+
+def select_gender(gender: SexLiteral) -> int:
+ """Choose an even number for Female and odd number for Male."""
+ gender = 0 if gender.lower() == "f" else 1
+ return random.choice(range(gender, 10, 2))
+
+
+def calculate_day_count(birthday: date) -> int:
+ """Calculate the day count from reference date '31 December 1899'."""
+ ref_date = date(1899, 12, 31)
+ return (birthday - ref_date).days
+
+
+def calculate_check_sum(val: str) -> int:
+ """Calculate checksum using INN calculation method."""
+ weights = [-1, 5, 7, 9, 4, 6, 10, 5, 7]
+ checksum = sum(int(v) * w for v, w in zip(val, weights))
+
+ return checksum % 11 % 10
+
+
+class Provider(SsnProvider):
+ def ssn(self, birthday: Optional[str] = None, gender: Optional[SexLiteral] = None) -> str:
+ """
+ Ukrainian "Реєстраційний номер облікової картки платника податків"
+ also known as "Ідентифікаційний номер фізичної особи".
+ @params: birthday: "DD-MM-YYYY" format, default random date
+ @params: gender: "M" or "F" default: random gender
+
+ :sample:
+ :sample: birthday='22-06-1990', gender='F'
+ """
+
+ try:
+ # generate day of birthday date object
+ if birthday:
+ dob = datetime.strptime(birthday, "%d-%m-%Y").date()
+ else:
+ dob = self.generator.date_object()
+ except Exception:
+ raise ValueError("Birthday format must be DD-MM-YYYY")
+
+ if gender and gender not in ("M", "F"):
+ raise ValueError('Gender must be "m" or "f" or None')
+
+ day_count = calculate_day_count(dob)
+ people_num = self.random_number(3, fix_len=True)
+ gender_ = select_gender(gender) if gender else random.randint(0, 1)
+ ssn_without_checksum = f"{day_count}{people_num}{gender_}"
+ checksum = calculate_check_sum(ssn_without_checksum)
+ return f"{ssn_without_checksum}{checksum}"
diff --git a/venv/lib/python3.11/site-packages/faker/providers/ssn/uk_UA/__pycache__/__init__.cpython-311.pyc b/venv/lib/python3.11/site-packages/faker/providers/ssn/uk_UA/__pycache__/__init__.cpython-311.pyc
new file mode 100644
index 0000000..c31698a
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/faker/providers/ssn/uk_UA/__pycache__/__init__.cpython-311.pyc
Binary files differ