diff options
author | cyfraeviolae <cyfraeviolae> | 2024-04-03 03:10:44 -0400 |
---|---|---|
committer | cyfraeviolae <cyfraeviolae> | 2024-04-03 03:10:44 -0400 |
commit | 6d7ba58f880be618ade07f8ea080fe8c4bf8a896 (patch) | |
tree | b1c931051ffcebd2bd9d61d98d6233ffa289bbce /venv/lib/python3.11/site-packages/faker/providers/ssn/es_CL | |
parent | 4f884c9abc32990b4061a1bb6997b4b37e58ea0b (diff) |
venv
Diffstat (limited to 'venv/lib/python3.11/site-packages/faker/providers/ssn/es_CL')
2 files changed, 67 insertions, 0 deletions
diff --git a/venv/lib/python3.11/site-packages/faker/providers/ssn/es_CL/__init__.py b/venv/lib/python3.11/site-packages/faker/providers/ssn/es_CL/__init__.py new file mode 100644 index 0000000..fcfb772 --- /dev/null +++ b/venv/lib/python3.11/site-packages/faker/providers/ssn/es_CL/__init__.py @@ -0,0 +1,67 @@ +from itertools import cycle + +from .. import Provider as BaseProvider + + +def rut_check_digit(number: int) -> str: + """ + Calculate the last character of a RUT number + :return: RUT check digit + """ + + sum = 0 + for factor in cycle(range(2, 8)): + if number == 0: + break + sum += factor * (number % 10) + number //= 10 + mod = -sum % 11 + if mod == 11: + return "0" + elif mod == 10: + return "K" + else: + return str(mod) + + +class Provider(BaseProvider): + """ + A Faker provider for the Chilean VAT IDs, also known as RUTs. + + Sources: + + - https://es.wikipedia.org/wiki/Rol_%C3%9Anico_Tributario - Definition and check digit calculation + - https://presslatam.cl/2018/04/el-problema-de-la-escasez-y-stock-disponible-de-los-ruts-en-chile/ + paragraph 4, where known ranges are described. + """ + + minimum_rut_person = 10 + maximum_rut_person = 31999999 + minimum_rut_company = 60000000 + maximum_rut_company = 99999999 + rut_format = "{:,d}-{:s}" + + def person_rut(self) -> str: + """ + :return: a random Chilean RUT between a 10 and 31.999.999 range + """ + return self.rut(self.minimum_rut_person, self.maximum_rut_person) + + def company_rut(self) -> str: + """ + :return: a random Chilean RUT between 60.000.000 and 99.999.999 + """ + return self.rut(self.minimum_rut_company, self.maximum_rut_company) + + def rut(self, min: int = minimum_rut_person, max: int = maximum_rut_company) -> str: + """ + Generates a RUT within the specified ranges, inclusive. + + :param min: Minimum RUT to generate. + :param max: Maximum RUT to generate. + :return: a random Chilean RUT between 35.000.000 and 99.999.999 + """ + + digits = self.random_int(min, max) + check = rut_check_digit(digits) + return self.rut_format.format(digits, check).replace(",", ".") diff --git a/venv/lib/python3.11/site-packages/faker/providers/ssn/es_CL/__pycache__/__init__.cpython-311.pyc b/venv/lib/python3.11/site-packages/faker/providers/ssn/es_CL/__pycache__/__init__.cpython-311.pyc Binary files differnew file mode 100644 index 0000000..c89db78 --- /dev/null +++ b/venv/lib/python3.11/site-packages/faker/providers/ssn/es_CL/__pycache__/__init__.cpython-311.pyc |