├── tests ├── utils │ └── __init__.py ├── mymodule │ ├── __init__.py │ └── en_US │ │ └── __init__.py ├── __init__.py ├── requirements.txt ├── providers │ ├── test_bank.py │ ├── test_job.py │ ├── test_automotive.py │ ├── test_color.py │ ├── test_currency.py │ ├── test_file.py │ ├── __init__.py │ ├── test_isbn.py │ └── test_phone_number.py └── test_generator.py ├── .coveragerc ├── readthedocs.yml ├── MANIFEST.in ├── docs ├── locales │ └── .happygit ├── providers │ └── .happygit ├── index.rst ├── coding_style.rst └── communityproviders.rst ├── setup.cfg ├── faker ├── providers │ ├── job │ │ ├── en_US │ │ │ └── __init__.py │ │ ├── fa_IR │ │ │ └── __init__.py │ │ └── uk_UA │ │ │ └── __init__.py │ ├── color │ │ ├── en_US │ │ │ └── __init__.py │ │ ├── hu_HU │ │ │ └── __init__.py │ │ └── ru_RU │ │ │ └── __init__.py │ ├── file │ │ └── en_US │ │ │ └── __init__.py │ ├── isbn │ │ ├── en_US │ │ │ └── __init__.py │ │ ├── rules.py │ │ ├── isbn.py │ │ └── __init__.py │ ├── misc │ │ └── en_US │ │ │ └── __init__.py │ ├── barcode │ │ ├── en_US │ │ │ └── __init__.py │ │ └── __init__.py │ ├── profile │ │ ├── en_US │ │ │ └── __init__.py │ │ └── __init__.py │ ├── python │ │ └── en_US │ │ │ └── __init__.py │ ├── currency │ │ └── en_US │ │ │ └── __init__.py │ ├── date_time │ │ ├── en_US │ │ │ └── __init__.py │ │ ├── ar_EG │ │ │ └── __init__.py │ │ ├── ko_KR │ │ │ └── __init__.py │ │ ├── pl_PL │ │ │ └── __init__.py │ │ ├── fr_FR │ │ │ └── __init__.py │ │ ├── sl_SI │ │ │ └── __init__.py │ │ ├── id_ID │ │ │ └── __init__.py │ │ ├── ru_RU │ │ │ └── __init__.py │ │ ├── hr_HR │ │ │ └── __init__.py │ │ └── hu_HU │ │ │ └── __init__.py │ ├── credit_card │ │ └── en_US │ │ │ └── __init__.py │ ├── user_agent │ │ └── en_US │ │ │ └── __init__.py │ ├── bank │ │ ├── nl_NL │ │ │ └── __init__.py │ │ ├── no_NO │ │ │ └── __init__.py │ │ ├── de_AT │ │ │ └── __init__.py │ │ ├── de_DE │ │ │ └── __init__.py │ │ ├── en_GB │ │ │ └── __init__.py │ │ ├── fr_FR │ │ │ └── __init__.py │ │ ├── it_IT │ │ │ └── __init__.py │ │ └── __init__.py │ ├── company │ │ ├── en_US │ │ │ └── __init__.py │ │ ├── sl_SI │ │ │ └── __init__.py │ │ ├── cs_CZ │ │ │ └── __init__.py │ │ ├── hr_HR │ │ │ └── __init__.py │ │ ├── ja_JP │ │ │ └── __init__.py │ │ ├── sk_SK │ │ │ └── __init__.py │ │ ├── sv_SE │ │ │ └── __init__.py │ │ ├── bg_BG │ │ │ └── __init__.py │ │ ├── hu_HU │ │ │ └── __init__.py │ │ ├── no_NO │ │ │ └── __init__.py │ │ ├── ru_RU │ │ │ └── __init__.py │ │ ├── de_DE │ │ │ └── __init__.py │ │ ├── id_ID │ │ │ └── __init__.py │ │ ├── pt_PT │ │ │ └── __init__.py │ │ ├── zh_CN │ │ │ └── __init__.py │ │ ├── fr_CH │ │ │ └── __init__.py │ │ ├── zh_TW │ │ │ └── __init__.py │ │ └── fi_FI │ │ │ └── __init__.py │ ├── internet │ │ ├── en_US │ │ │ └── __init__.py │ │ ├── pt_PT │ │ │ └── __init__.py │ │ ├── fi_FI │ │ │ └── __init__.py │ │ ├── ko_KR │ │ │ └── __init__.py │ │ ├── fa_IR │ │ │ └── __init__.py │ │ ├── en_AU │ │ │ └── __init__.py │ │ ├── pt_BR │ │ │ └── __init__.py │ │ ├── de_AT │ │ │ └── __init__.py │ │ ├── id_ID │ │ │ └── __init__.py │ │ ├── no_NO │ │ │ └── __init__.py │ │ ├── sv_SE │ │ │ └── __init__.py │ │ ├── bs_BA │ │ │ └── __init__.py │ │ ├── ja_JP │ │ │ └── __init__.py │ │ ├── zh_CN │ │ │ └── __init__.py │ │ ├── zh_TW │ │ │ └── __init__.py │ │ ├── de_DE │ │ │ └── __init__.py │ │ ├── hr_HR │ │ │ └── __init__.py │ │ ├── pl_PL │ │ │ └── __init__.py │ │ ├── hu_HU │ │ │ └── __init__.py │ │ ├── fr_CH │ │ │ └── __init__.py │ │ ├── it_IT │ │ │ └── __init__.py │ │ ├── cs_CZ │ │ │ └── __init__.py │ │ ├── fr_FR │ │ │ └── __init__.py │ │ ├── sk_SK │ │ │ └── __init__.py │ │ ├── sl_SI │ │ │ └── __init__.py │ │ ├── uk_UA │ │ │ └── __init__.py │ │ ├── ar_AA │ │ │ └── __init__.py │ │ ├── ru_RU │ │ │ └── __init__.py │ │ ├── bg_BG │ │ │ └── __init__.py │ │ └── el_GR │ │ │ └── __init__.py │ ├── ssn │ │ ├── ru_RU │ │ │ └── __init__.py │ │ ├── ko_KR │ │ │ └── __init__.py │ │ ├── zh_TW │ │ │ └── __init__.py │ │ ├── __init__.py │ │ ├── en_GB │ │ │ └── __init__.py │ │ ├── he_IL │ │ │ └── __init__.py │ │ ├── uk_UA │ │ │ └── __init__.py │ │ ├── fr_CH │ │ │ └── __init__.py │ │ ├── it_IT │ │ │ └── __init__.py │ │ ├── hr_HR │ │ │ └── __init__.py │ │ ├── pt_BR │ │ │ └── __init__.py │ │ ├── nl_NL │ │ │ └── __init__.py │ │ ├── sv_SE │ │ │ └── __init__.py │ │ ├── pl_PL │ │ │ └── __init__.py │ │ ├── nl_BE │ │ │ └── __init__.py │ │ ├── fi_FI │ │ │ └── __init__.py │ │ ├── et_EE │ │ │ └── __init__.py │ │ └── en_CA │ │ │ └── __init__.py │ ├── automotive │ │ ├── pt_BR │ │ │ └── __init__.py │ │ ├── hu_HU │ │ │ └── __init__.py │ │ ├── en_GB │ │ │ └── __init__.py │ │ ├── id_ID │ │ │ └── __init__.py │ │ ├── __init__.py │ │ ├── en_CA │ │ │ └── __init__.py │ │ ├── ar_JO │ │ │ └── __init__.py │ │ ├── ar_PS │ │ │ └── __init__.py │ │ ├── ar_SA │ │ │ └── __init__.py │ │ └── de_DE │ │ │ └── __init__.py │ ├── phone_number │ │ ├── lt_LT │ │ │ └── __init__.py │ │ ├── lv_LV │ │ │ └── __init__.py │ │ ├── ru_RU │ │ │ └── __init__.py │ │ ├── ja_JP │ │ │ └── __init__.py │ │ ├── ne_NP │ │ │ └── __init__.py │ │ ├── hi_IN │ │ │ └── __init__.py │ │ ├── fi_FI │ │ │ └── __init__.py │ │ ├── es_ES │ │ │ └── __init__.py │ │ ├── hu_HU │ │ │ └── __init__.py │ │ ├── it_IT │ │ │ └── __init__.py │ │ ├── no_NO │ │ │ └── __init__.py │ │ ├── uk_UA │ │ │ └── __init__.py │ │ ├── en_CA │ │ │ └── __init__.py │ │ ├── tr_TR │ │ │ └── __init__.py │ │ ├── __init__.py │ │ ├── sl_SI │ │ │ └── __init__.py │ │ ├── sk_SK │ │ │ └── __init__.py │ │ ├── zh_TW │ │ │ └── __init__.py │ │ ├── sv_SE │ │ │ └── __init__.py │ │ ├── bg_BG │ │ │ └── __init__.py │ │ ├── de_DE │ │ │ └── __init__.py │ │ ├── dk_DK │ │ │ └── __init__.py │ │ ├── he_IL │ │ │ └── __init__.py │ │ ├── zh_CN │ │ │ └── __init__.py │ │ ├── nl_BE │ │ │ └── __init__.py │ │ ├── nl_NL │ │ │ └── __init__.py │ │ ├── el_GR │ │ │ └── __init__.py │ │ ├── tw_GH │ │ │ └── __init__.py │ │ ├── id_ID │ │ │ └── __init__.py │ │ ├── ko_KR │ │ │ └── __init__.py │ │ ├── en_US │ │ │ └── __init__.py │ │ ├── es_MX │ │ │ └── __init__.py │ │ ├── hr_HR │ │ │ └── __init__.py │ │ ├── bs_BA │ │ │ └── __init__.py │ │ ├── pl_PL │ │ │ └── __init__.py │ │ ├── cs_CZ │ │ │ └── __init__.py │ │ ├── fr_CH │ │ │ └── __init__.py │ │ ├── fr_FR │ │ │ └── __init__.py │ │ ├── pt_PT │ │ │ └── __init__.py │ │ ├── en_AU │ │ │ └── __init__.py │ │ ├── ar_JO │ │ │ └── __init__.py │ │ ├── fa_IR │ │ │ └── __init__.py │ │ └── pt_BR │ │ │ └── __init__.py │ ├── person │ │ ├── ar_PS │ │ │ └── __init__.py │ │ ├── ar_SA │ │ │ └── __init__.py │ │ └── lt_LT │ │ │ └── __init__.py │ ├── lorem │ │ ├── he_IL │ │ │ └── __init__.py │ │ └── la │ │ │ └── __init__.py │ └── address │ │ ├── no_NO │ │ └── __init__.py │ │ ├── es_ES │ │ └── __init__.py │ │ └── es │ │ └── __init__.py ├── __init__.py ├── __main__.py ├── utils │ ├── __init__.py │ ├── datasets.py │ ├── decorators.py │ ├── loading.py │ ├── distribution.py │ └── datetime_safe.py ├── config.py └── compat.py ├── .bumpversion.cfg ├── tox.ini ├── Makefile ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md ├── .circleci └── config.yml ├── .travis.yml ├── .gitignore ├── LICENSE.txt ├── appveyor.yml ├── CONTRIBUTING.rst └── setup.py /tests/utils/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/mymodule/__init__.py: -------------------------------------------------------------------------------- 1 | localized = True 2 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | [paths] 2 | source = faker/ 3 | omit = faker/build_docs.py 4 | -------------------------------------------------------------------------------- /readthedocs.yml: -------------------------------------------------------------------------------- 1 | formats: 2 | - none 3 | python: 4 | pip_install: true 5 | version: 3 6 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include *.rst 2 | include *.md 3 | include *.txt 4 | include *.json 5 | graft tests 6 | -------------------------------------------------------------------------------- /docs/locales/.happygit: -------------------------------------------------------------------------------- 1 | # this file is intentionally empty so that git can keep track of this directory -------------------------------------------------------------------------------- /docs/providers/.happygit: -------------------------------------------------------------------------------- 1 | # this file is intentionally empty so that git can keep track of this directory -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal = 1 3 | 4 | [metadata] 5 | license_file = LICENSE.txt 6 | 7 | [pep8] 8 | max-line-length = 80 -------------------------------------------------------------------------------- /faker/providers/job/en_US/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as BaseProvider 2 | 3 | 4 | class Provider(BaseProvider): 5 | pass 6 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | try: 2 | string_types = (basestring,) 3 | except NameError: # pragma: no cover 4 | string_types = (str,) 5 | -------------------------------------------------------------------------------- /faker/providers/color/en_US/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as ColorProvider 2 | 3 | 4 | class Provider(ColorProvider): 5 | pass 6 | -------------------------------------------------------------------------------- /faker/providers/file/en_US/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as FileProvider 2 | 3 | 4 | class Provider(FileProvider): 5 | pass 6 | -------------------------------------------------------------------------------- /faker/providers/isbn/en_US/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as ISBNProvider 2 | 3 | 4 | class Provider(ISBNProvider): 5 | pass 6 | -------------------------------------------------------------------------------- /faker/providers/misc/en_US/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as MiscProvider 2 | 3 | 4 | class Provider(MiscProvider): 5 | pass 6 | -------------------------------------------------------------------------------- /faker/providers/barcode/en_US/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as BarCodeProvider 2 | 3 | 4 | class Provider(BarCodeProvider): 5 | pass 6 | -------------------------------------------------------------------------------- /faker/providers/profile/en_US/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as ProfileProvider 2 | 3 | 4 | class Provider(ProfileProvider): 5 | pass 6 | -------------------------------------------------------------------------------- /faker/providers/python/en_US/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as PythonProvider 2 | 3 | 4 | class Provider(PythonProvider): 5 | pass 6 | -------------------------------------------------------------------------------- /.bumpversion.cfg: -------------------------------------------------------------------------------- 1 | [bumpversion] 2 | current_version = 0.9.0 3 | files = setup.py faker/__init__.py docs/conf.py 4 | commit = True 5 | tag = True 6 | 7 | -------------------------------------------------------------------------------- /faker/providers/currency/en_US/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as CurrencyProvider 2 | 3 | 4 | class Provider(CurrencyProvider): 5 | pass 6 | -------------------------------------------------------------------------------- /faker/providers/date_time/en_US/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as DateTimeProvider 2 | 3 | 4 | class Provider(DateTimeProvider): 5 | pass 6 | -------------------------------------------------------------------------------- /faker/__init__.py: -------------------------------------------------------------------------------- 1 | VERSION = '0.9.0' 2 | 3 | from faker.generator import Generator 4 | from faker.factory import Factory 5 | 6 | Faker = Factory.create 7 | -------------------------------------------------------------------------------- /faker/providers/credit_card/en_US/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as CreditCardProvider 2 | 3 | 4 | class Provider(CreditCardProvider): 5 | pass 6 | -------------------------------------------------------------------------------- /faker/providers/user_agent/en_US/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as UserAgentProvider 2 | 3 | 4 | class Provider(UserAgentProvider): 5 | pass 6 | -------------------------------------------------------------------------------- /tests/requirements.txt: -------------------------------------------------------------------------------- 1 | mock==2.0.0 2 | UkPostcodeParser==1.1.2 3 | email_validator==1.0.3 4 | python-dateutil>=2.4 5 | six>=1.10 6 | text-unidecode==1.2 7 | -------------------------------------------------------------------------------- /faker/__main__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | if __name__ == "__main__": 4 | from faker.cli import execute_from_command_line 5 | execute_from_command_line() 6 | -------------------------------------------------------------------------------- /faker/providers/bank/nl_NL/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as BankProvider 2 | 3 | class Provider(BankProvider): 4 | bban_format = '????##########' 5 | country_code = 'NL' 6 | -------------------------------------------------------------------------------- /faker/providers/bank/no_NO/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as BankProvider 2 | 3 | class Provider(BankProvider): 4 | bban_format = '###########' 5 | country_code = 'NO' 6 | -------------------------------------------------------------------------------- /faker/providers/bank/de_AT/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as BankProvider 2 | 3 | class Provider(BankProvider): 4 | bban_format = '################' 5 | country_code = 'AT' 6 | -------------------------------------------------------------------------------- /faker/providers/bank/de_DE/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as BankProvider 2 | 3 | class Provider(BankProvider): 4 | bban_format = '##################' 5 | country_code = 'DE' 6 | -------------------------------------------------------------------------------- /faker/providers/bank/en_GB/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as BankProvider 2 | 3 | class Provider(BankProvider): 4 | bban_format = '????#############' 5 | country_code = 'GB' 6 | -------------------------------------------------------------------------------- /faker/providers/company/en_US/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as CompanyProvider 3 | 4 | 5 | class Provider(CompanyProvider): 6 | pass 7 | -------------------------------------------------------------------------------- /faker/providers/bank/fr_FR/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as BankProvider 2 | 3 | class Provider(BankProvider): 4 | bban_format = '########################' 5 | country_code = 'FR' 6 | -------------------------------------------------------------------------------- /faker/providers/bank/it_IT/__init__.py: -------------------------------------------------------------------------------- 1 | from .. import Provider as BankProvider 2 | 3 | class Provider(BankProvider): 4 | bban_format = '?######################' 5 | country_code = 'IT' 6 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist=py{27,35,36,37,py250,py3240} 3 | skip_missing_interpreters = true 4 | 5 | [testenv] 6 | commands = python setup.py test 7 | deps = -r{toxinidir}/tests/requirements.txt 8 | -------------------------------------------------------------------------------- /tests/mymodule/en_US/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from faker.providers import BaseProvider 3 | 4 | 5 | class Provider(BaseProvider): 6 | def foo(self): 7 | return 'bar' 8 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | test: 2 | coverage run --source=faker --omit=faker/build_docs.py setup.py test 3 | 4 | release: 5 | rm -rf build dist 6 | python setup.py sdist bdist_wheel 7 | git push --tags 8 | twine upload dist/* 9 | -------------------------------------------------------------------------------- /faker/providers/internet/en_US/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | pass 8 | -------------------------------------------------------------------------------- /faker/providers/ssn/ru_RU/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as SsnProvider 4 | 5 | 6 | class Provider(SsnProvider): 7 | ssn_formats = ("############",) 8 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Brief summary of the issue goes here. 2 | 3 | ### Steps to reproduce 4 | 5 | 1. step 1 6 | 1. step 2 7 | 1. step 3 8 | 9 | ### Expected behavior 10 | 11 | X should be ... 12 | 13 | ### Actual behavior 14 | 15 | X is ... 16 | -------------------------------------------------------------------------------- /faker/providers/automotive/pt_BR/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | 4 | from .. import Provider as AutomotiveProvider 5 | 6 | 7 | class Provider(AutomotiveProvider): 8 | 9 | license_formats = ( 10 | '???-####', 11 | ) 12 | -------------------------------------------------------------------------------- /PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### What does this changes 2 | 3 | Brief summary of the changes 4 | 5 | ### What was wrong 6 | 7 | Description of what was the root cause of the issue. 8 | 9 | ### How this fixes it 10 | 11 | Description of how the changes fix the issue. 12 | 13 | Fixes #... 14 | -------------------------------------------------------------------------------- /faker/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | 4 | def is_string(var): 5 | try: 6 | return isinstance(var, basestring) 7 | except NameError: 8 | return isinstance(var, str) 9 | 10 | 11 | def quote(var): 12 | return ('"{0}"' if '"' not in var else "'{0}'").format(var) 13 | -------------------------------------------------------------------------------- /faker/providers/phone_number/lt_LT/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+370 ########', 8 | '+(370) ########', 9 | '+370########' 10 | ) 11 | -------------------------------------------------------------------------------- /faker/providers/phone_number/lv_LV/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+371 ########', 8 | '+(371) ########', 9 | '+371########' 10 | ) 11 | -------------------------------------------------------------------------------- /faker/providers/ssn/ko_KR/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as SsnProvider 4 | 5 | 6 | class Provider(SsnProvider): 7 | ssn_formats = ("##0#0#-1######", "##0#1#-1######", "##0#2#-1######", 8 | "##0#0#-2######", "##0#1#-2######", "##0#2#-2######",) 9 | -------------------------------------------------------------------------------- /faker/providers/ssn/zh_TW/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as SsnProvider 4 | 5 | 6 | class Provider(SsnProvider): 7 | ssn_formats = ("?#########",) 8 | 9 | def ssn(self): 10 | return self.bothify(self.random_element(self.ssn_formats)).upper() 11 | -------------------------------------------------------------------------------- /faker/providers/ssn/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | localized = True 4 | 5 | from .. import BaseProvider 6 | 7 | 8 | class Provider(BaseProvider): 9 | ssn_formats = ("###-##-####",) 10 | 11 | def ssn(self): 12 | return self.bothify(self.random_element(self.ssn_formats)) 13 | -------------------------------------------------------------------------------- /faker/providers/phone_number/ru_RU/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+7 ### ### ####', 8 | '+7 ### ### ## ##', 9 | '+7 (###) ###-##-##', 10 | '+7 (###) ###-####' 11 | ) 12 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | jobs: 4 | build: 5 | docker: 6 | - image: circleci/python:latest-node-browsers 7 | steps: 8 | - checkout 9 | - run: pip install --user virtualenv 10 | - run: virtualenv faker 11 | - run: source faker/bin/activate && pip install tox 12 | - run: source faker/bin/activate && tox 13 | -------------------------------------------------------------------------------- /faker/providers/automotive/hu_HU/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | 4 | from __future__ import unicode_literals 5 | from .. import Provider as AutomotiveProvider 6 | 7 | 8 | class Provider(AutomotiveProvider): 9 | # from https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_Hungary 10 | license_formats = ( 11 | '???-###', 12 | ) 13 | -------------------------------------------------------------------------------- /faker/providers/phone_number/ja_JP/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | from .. import Provider as PhoneNumberProvider 4 | 5 | 6 | class Provider(PhoneNumberProvider): 7 | formats = ( 8 | '070-####-####', 9 | '080-####-####', 10 | '090-####-####', 11 | '##-####-####', 12 | ) 13 | -------------------------------------------------------------------------------- /faker/providers/phone_number/ne_NP/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+977 ##########', 8 | '+977 ### #######', 9 | '984#######', 10 | '985#######', 11 | '980#######', 12 | ) 13 | -------------------------------------------------------------------------------- /faker/providers/phone_number/hi_IN/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+91 ##########', 8 | '+91 ### #######', 9 | '0##-########', 10 | '0##########', 11 | '0#### ######', 12 | ) 13 | -------------------------------------------------------------------------------- /faker/providers/company/sl_SI/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as CompanyProvider 3 | 4 | 5 | class Provider(CompanyProvider): 6 | formats = ( 7 | '{{last_name}} {{company_suffix}}', 8 | '{{first_name}} {{last_name}} s.p.', 9 | ) 10 | 11 | company_suffixes = ( 12 | 'd.o.o.', 'd.d.', 13 | ) 14 | -------------------------------------------------------------------------------- /faker/providers/internet/pt_PT/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | safe_email_tlds = ('com', 'net', 'pt', 'pt') 8 | free_email_domains = ('gmail.com', 'hotmail.com', 'clix.pt', 'sapo.pt') 9 | tlds = ('com', 'com', 'com', 'net', 'org', 'pt', 'pt', 'pt') 10 | -------------------------------------------------------------------------------- /faker/providers/phone_number/fi_FI/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+358 ## #######', 8 | '+358 #########', 9 | '+358#########', 10 | '(+358) #########', 11 | '0#########', 12 | '0## ### ####' 13 | ) 14 | -------------------------------------------------------------------------------- /faker/providers/automotive/en_GB/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as AutomotiveProvider 5 | 6 | 7 | class Provider(AutomotiveProvider): 8 | # from 9 | # https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_the_United_Kingdom 10 | license_formats = ( 11 | '??## ???', 12 | '??##???' 13 | ) 14 | -------------------------------------------------------------------------------- /faker/providers/phone_number/es_ES/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+34 ### ### ###', 8 | '+34 #########', 9 | '+34 ### ## ## ##', 10 | '+34### ### ###', 11 | '+34#########', 12 | '+34### ## ## ##', 13 | ) 14 | -------------------------------------------------------------------------------- /tests/providers/test_bank.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | import re 4 | import unittest 5 | 6 | from faker import Faker 7 | 8 | class TestNoNO(unittest.TestCase): 9 | """ Tests the bban in no_NO locale """ 10 | 11 | def setUp(self): 12 | self.factory = Faker('no_NO') 13 | 14 | def test_bban(self): 15 | bban = self.factory.bban() 16 | assert re.match("\d{11}", bban) 17 | -------------------------------------------------------------------------------- /faker/providers/color/hu_HU/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from collections import OrderedDict 3 | 4 | from faker.providers import BaseProvider 5 | 6 | 7 | class Provider(BaseProvider): 8 | 9 | safe_colors = ( 10 | 'fekete', 'bordó', 'zöld', 'királykék', 'oliva', 11 | 'bíbor', 'kékeszöld', 'citromzöld', 'kék', 'ezüst', 12 | 'szürke', 'sárga', 'mályva', 'akvamarin', 'fehér', 13 | ) 14 | -------------------------------------------------------------------------------- /faker/providers/phone_number/hu_HU/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+36 ## ###-####', 8 | '(06)##/###-####', 9 | '(##)/###-####', 10 | '##/###-####', 11 | '##/### ####', 12 | '06-#/### ####', 13 | '06-##/### ####' 14 | ) 15 | -------------------------------------------------------------------------------- /faker/providers/company/cs_CZ/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as CompanyProvider 3 | 4 | 5 | class Provider(CompanyProvider): 6 | formats = ( 7 | '{{last_name}} {{company_suffix}}', 8 | '{{last_name}} {{last_name}} {{company_suffix}}', 9 | '{{last_name}}', 10 | ) 11 | 12 | company_suffixes = ( 13 | 's.r.o.', 'o.s.', 'a.s.', 14 | ) 15 | -------------------------------------------------------------------------------- /faker/providers/company/hr_HR/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as CompanyProvider 3 | 4 | 5 | class Provider(CompanyProvider): 6 | formats = ( 7 | '{{last_name}} {{company_suffix}}', 8 | '{{last_name}} {{last_name}} {{company_suffix}}', 9 | '{{last_name}}', 10 | ) 11 | 12 | company_suffixes = ( 13 | 'd.o.o.', 'd.d.', 'j.d.o.o.' 14 | ) 15 | -------------------------------------------------------------------------------- /faker/config.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from importlib import import_module 3 | from faker.utils.loading import find_available_locales, find_available_providers 4 | 5 | DEFAULT_LOCALE = 'en_US' 6 | 7 | META_PROVIDERS_MODULES = [ 8 | 'faker.providers', 9 | ] 10 | 11 | PROVIDERS = find_available_providers( 12 | [import_module(path) for path in META_PROVIDERS_MODULES]) 13 | 14 | AVAILABLE_LOCALES = find_available_locales(PROVIDERS) 15 | -------------------------------------------------------------------------------- /faker/providers/company/ja_JP/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | from .. import Provider as CompanyProvider 4 | 5 | 6 | class Provider(CompanyProvider): 7 | formats = ( 8 | '{{company_prefix}} {{last_name}}', 9 | ) 10 | 11 | company_prefixes = ('株式会社', '有限会社', '合同会社') 12 | 13 | def company_prefix(self): 14 | return self.random_element(self.company_prefixes) 15 | -------------------------------------------------------------------------------- /faker/providers/company/sk_SK/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as CompanyProvider 3 | 4 | 5 | class Provider(CompanyProvider): 6 | formats = ( 7 | '{{last_name}} {{company_suffix}}', 8 | '{{last_name}} {{last_name}} {{company_suffix}}', 9 | '{{last_name}}', 10 | ) 11 | 12 | company_suffixes = ( 13 | 's.r.o.', 'v.o.s.', 'a.s.', 'k.s.', 14 | ) 15 | -------------------------------------------------------------------------------- /faker/providers/internet/fi_FI/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | 8 | free_email_domains = ( 9 | 'gmail.com', 'googlemail.com', 'hotmail.com', 'suomi24.fi', 10 | 'kolumbus.fi', 'luukku.com', 'surffi.net' 11 | ) 12 | 13 | tlds = ('com', 'com', 'com', 'fi', 'fi', 'net', 'org') 14 | -------------------------------------------------------------------------------- /faker/providers/internet/ko_KR/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | 8 | free_email_domains = ( 9 | 'gmail.com', 'daum.net', 'hotmail.com', 'hanmail.net', 10 | 'naver.com', 'nate.com', 'live.com', 'dreamwiz.com', 11 | ) 12 | tlds = ('com', 'com', 'com', 'kr', 'kr', 'net', 'org',) 13 | -------------------------------------------------------------------------------- /faker/providers/phone_number/it_IT/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+39 ### ## ## ####', 8 | '+39 ## #######', 9 | '+39 ## ########', 10 | '+39 ### #######', 11 | '+39 ### ########', 12 | '+39 #### #######', 13 | '+39 #### ########' 14 | ) 15 | -------------------------------------------------------------------------------- /faker/providers/internet/fa_IR/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | from .. import Provider as BaseProvider 4 | 5 | 6 | class Provider(BaseProvider): 7 | safe_email_tlds = ('com', 'net', 'ir', 'org') 8 | free_email_domains = ('chmail.ir', 'mailfa.com', 9 | 'gmail.com', 'hotmail.com', 'yahoo.com') 10 | tlds = ('com', 'com', 'com', 'net', 'org', 'ir', 'ir', 'ir') 11 | -------------------------------------------------------------------------------- /faker/providers/company/sv_SE/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as CompanyProvider 5 | 6 | 7 | class Provider(CompanyProvider): 8 | formats = ( 9 | '{{last_name}} {{company_suffix}}', 10 | '{{last_name}} {{last_name}} {{company_suffix}}', 11 | '{{last_name}} & {{last_name}} {{company_suffix}}', 12 | ) 13 | 14 | company_suffixes = ( 15 | 'AB', 'HB' 16 | ) 17 | -------------------------------------------------------------------------------- /faker/providers/phone_number/no_NO/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+47#########', 8 | '+47 ## ## ## ##', 9 | '## ## ## ##', 10 | '## ## ## ##', 11 | '########', 12 | '########', 13 | '9## ## ###', 14 | '4## ## ###', 15 | '9#######', 16 | '4#######', 17 | ) 18 | -------------------------------------------------------------------------------- /faker/providers/phone_number/uk_UA/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as PhoneNumberProvider 4 | 5 | 6 | class Provider(PhoneNumberProvider): 7 | formats = ( 8 | '###-##-##', 9 | '### ## ##', 10 | '0## ### ## ##', 11 | '0## ###-##-##', 12 | '+38 0## ###-##-##', 13 | '+38 0## ###-##-##', 14 | '+38 (0##) ###-##-##', 15 | '+38 0## ### ## ##', 16 | ) 17 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | sudo: false 3 | branches: 4 | only: 5 | - master 6 | python: 7 | - 2.7 8 | - 3.4 9 | - 3.5 10 | - 3.6 11 | - "pypy-5.3.1" 12 | - "pypy3" 13 | before_install: 14 | - pip install pep8 15 | install: 16 | - pip install -U setuptools 17 | - pip install -e . 18 | - pip install -r tests/requirements.txt 19 | - pip install coveralls 20 | script: 21 | - coverage run --source=faker setup.py test 22 | after_success: 23 | - coveralls 24 | -------------------------------------------------------------------------------- /faker/providers/automotive/id_ID/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as AutomotiveProvider 5 | 6 | 7 | class Provider(AutomotiveProvider): 8 | # Currently this is my own work 9 | license_formats = ( 10 | '? ### ??', 11 | '? ### ???', 12 | '?? ### ??', 13 | '?? ### ???', 14 | '? #### ??', 15 | '? #### ???', 16 | '?? #### ??', 17 | '?? #### ???', 18 | ) 19 | -------------------------------------------------------------------------------- /faker/providers/automotive/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | localized = True 4 | 5 | from .. import BaseProvider 6 | from string import ascii_uppercase 7 | import re 8 | 9 | 10 | class Provider(BaseProvider): 11 | license_formats = () 12 | 13 | def license_plate(self): 14 | temp = re.sub(r'\?', 15 | lambda x: self.random_element(ascii_uppercase), 16 | self.random_element(self.license_formats)) 17 | return self.numerify(temp) 18 | -------------------------------------------------------------------------------- /faker/providers/phone_number/en_CA/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '%##-###-####', 8 | '%##.###.####', 9 | '%## ### ####', 10 | '(%##) ###-####', 11 | '1-%##-###-####', 12 | '1 (%##) ###-####', 13 | '+1 (%##) ###-####', 14 | '%##-###-#### x###', 15 | '(%##) ###-#### x###', 16 | ) 17 | -------------------------------------------------------------------------------- /faker/providers/phone_number/tr_TR/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+90(###)#######', 8 | '+90 (###) #######', 9 | '0### ### ## ##', 10 | '0##########', 11 | '0###-### ####', 12 | '(###)### ####', 13 | '### # ###', 14 | '+90(###)###-####x###', 15 | '+90(###)###-####x####' 16 | ) 17 | -------------------------------------------------------------------------------- /faker/providers/internet/en_AU/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | 8 | free_email_domains = ( 9 | 'gmail.com', 10 | 'yahoo.com', 11 | 'hotmail.com', 12 | 'yahoo.com.au', 13 | 'hotmail.com.au', 14 | ) 15 | 16 | tlds = ('com', 'com.au', 'org', 'org.au', 'net', 17 | 'net.au', 'biz', 'info', 'edu', 'edu.au') 18 | -------------------------------------------------------------------------------- /faker/providers/internet/pt_BR/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | safe_email_tlds = ('com', 'net', 'br', 'br') 8 | free_email_domains = ( 9 | 'gmail.com', 10 | 'hotmail.com', 11 | 'yahoo.com.br', 12 | 'uol.com.br', 13 | 'bol.com.br', 14 | 'ig.com.br') 15 | tlds = ('com', 'com', 'com', 'net', 'org', 'br', 'br', 'br') 16 | -------------------------------------------------------------------------------- /faker/providers/phone_number/__init__.py: -------------------------------------------------------------------------------- 1 | localized = True 2 | 3 | from .. import BaseProvider 4 | 5 | 6 | class Provider(BaseProvider): 7 | formats = ('###-###-###',) 8 | 9 | msisdn_formats = ( 10 | '#############', 11 | ) 12 | 13 | def phone_number(self): 14 | return self.numerify(self.random_element(self.formats)) 15 | 16 | def msisdn(self): 17 | """ https://en.wikipedia.org/wiki/MSISDN """ 18 | return self.numerify(self.random_element(self.msisdn_formats)) 19 | -------------------------------------------------------------------------------- /faker/providers/phone_number/sl_SI/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '040 ### ###', 8 | '041 ### ###', 9 | '031 ### ###', 10 | '030 ### ###', 11 | '070 ### ###', 12 | '01 #### ###', 13 | '02 #### ###', 14 | '04 #### ###', 15 | '05 #### ###', 16 | '06 #### ###', 17 | '08 #### ###', 18 | ) 19 | -------------------------------------------------------------------------------- /faker/providers/phone_number/sk_SK/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+421 2 ########', 8 | '+421 3# ### ####', 9 | '+421 4# ### ####', 10 | '+421 5# ### ####', 11 | '+421 90# ### ###', 12 | '+421 91# ### ###', 13 | '+421 940 ### ###', 14 | '+421 944 ### ###', 15 | '+421 948 ### ###', 16 | '+421 949 ### ###', 17 | ) 18 | -------------------------------------------------------------------------------- /faker/providers/phone_number/zh_TW/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | from .. import Provider as PhoneNumberProvider 4 | 5 | # phone number from https://en.wikipedia.org/wiki/Telephone_numbers_in_Taiwan 6 | 7 | 8 | class Provider(PhoneNumberProvider): 9 | formats = ("(0#) %#######", 10 | "0#-%#######", 11 | "0## %#######", 12 | "09########", 13 | "09##-######", 14 | "0#-%######", 15 | "0# %######") 16 | -------------------------------------------------------------------------------- /faker/providers/internet/de_AT/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as InternetProvider 5 | 6 | 7 | class Provider(InternetProvider): 8 | 9 | free_email_domains = ( 10 | 'chello.at', 'gmail.com', 'gmx.at', 'kabsi.at', 11 | ) 12 | tlds = ('at', 'co.at', 'com', 'net', 'org', ) 13 | 14 | replacements = ( 15 | ('ä', 'ae'), ('Ä', 'Ae'), 16 | ('ö', 'oe'), ('Ö', 'Oe'), 17 | ('ü', 'ue'), ('Ü', 'Ue'), 18 | ('ß', 'ss'), 19 | ) 20 | -------------------------------------------------------------------------------- /faker/providers/phone_number/sv_SE/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as PhoneNumberProvider 5 | 6 | 7 | class Provider(PhoneNumberProvider): 8 | formats = ( 9 | '+46 (0)8 ### ### ##', 10 | '+46 (0)## ## ## ##', 11 | '+46 (0)### ### ##', 12 | '08-### ### ##', 13 | '08-### ## ##', 14 | '08-## ## ##', 15 | '0##-### ## ##', 16 | '0##-## ## ##', 17 | '0###-## ## ##', 18 | '0###-### ##', 19 | ) 20 | -------------------------------------------------------------------------------- /faker/providers/phone_number/bg_BG/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as PhoneNumberProvider 4 | 5 | 6 | class Provider(PhoneNumberProvider): 7 | formats = ( 8 | '+359(0)#########', 9 | '+359(0)### ######', 10 | '+359(0)### ### ###', 11 | '+359#########', 12 | '0#########', 13 | '0### ######', 14 | '0### ### ###', 15 | '0### ###-###', 16 | '(0###) ######', 17 | '(0###) ### ###', 18 | '(0###) ###-###' 19 | ) 20 | -------------------------------------------------------------------------------- /faker/providers/internet/id_ID/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | tlds = ( 8 | # From https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains 9 | 'com', 'org', 'net', 'int', 'edu', 'gov', 'mil', 10 | 11 | # From https://id.wikipedia.org/wiki/.id 12 | 'id', 'ac.id', 'biz.id', 'co.id', 'desa.id', 'go.id', 'mil.id', 13 | 'my.id', 'net.id', 'or.id', 'ponpes.id', 'sch.id', 'web.id', 14 | ) 15 | -------------------------------------------------------------------------------- /faker/providers/internet/no_NO/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | import re 6 | 7 | 8 | class Provider(InternetProvider): 9 | 10 | tlds = ('com', 'com', 'com', 'net', 'org', 'no', 'no', 'no', 'no', 'no') 11 | 12 | replacements = ( 13 | ('æ', 'ae'), ('Æ', 'Ae'), 14 | ('ø', 'oe'), ('Ø', 'Oe'), 15 | ('å', 'aa'), ('Å', 'Aa'), 16 | ('ä', 'ae'), ('Ä', 'Ae'), 17 | ('ö', 'oe'), ('Ö', 'Oe'), 18 | ('ü', 'ue'), ('Ü', 'Ue'), 19 | ) 20 | -------------------------------------------------------------------------------- /faker/providers/phone_number/de_DE/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as PhoneNumberProvider 5 | 6 | 7 | class Provider(PhoneNumberProvider): 8 | formats = ( 9 | '+49(0)##########', 10 | '+49(0)#### ######', 11 | '+49 (0) #### ######', 12 | '+49(0) #########', 13 | '+49(0)#### #####', 14 | '0##########', 15 | '0#########', 16 | '0#### ######', 17 | '0#### #####', 18 | '(0####) ######', 19 | '(0####) #####', 20 | ) 21 | -------------------------------------------------------------------------------- /faker/providers/phone_number/dk_DK/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as PhoneNumberProvider 5 | 6 | 7 | class Provider(PhoneNumberProvider): 8 | formats = ( 9 | '+45(0)##########', 10 | '+45(0)#### ######', 11 | '+45 (0) #### ######', 12 | '+45(0) #########', 13 | '+45(0)#### #####', 14 | '0##########', 15 | '0#########', 16 | '0#### ######', 17 | '0#### #####', 18 | '(0####) ######', 19 | '(0####) #####', 20 | ) 21 | -------------------------------------------------------------------------------- /faker/providers/internet/sv_SE/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as InternetProvider 5 | 6 | 7 | class Provider(InternetProvider): 8 | 9 | free_email_domains = ( 10 | 'telia.com', 'gmail.com', 'swipnet.se', 'googlemail.com', 'live.se', 11 | 'spray.se', 'yahoo.de', 12 | ) 13 | tlds = ('com', 'com', 'com', 'se', 'se', 'se', 'net', 'org') 14 | 15 | replacements = ( 16 | ('å', 'a'), ('Å', 'A'), 17 | ('ä', 'a'), ('Ä', 'A'), 18 | ('ö', 'o'), ('Ö', 'O'), 19 | ) 20 | -------------------------------------------------------------------------------- /faker/providers/date_time/ar_EG/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | 4 | 5 | from ..ar_AA import Provider as ArabicDateTimeProvider 6 | 7 | 8 | class Provider(ArabicDateTimeProvider): 9 | MONTH_NAMES = { 10 | '01': 'يناير', 11 | '02': 'فبراير', 12 | '03': 'مارس', 13 | '04': 'أبريل', 14 | '05': 'مايو', 15 | '06': 'يونيو', 16 | '07': 'يوليو', 17 | '08': 'أغسطس', 18 | '09': 'سبتمبر', 19 | '10': 'أكتوبر', 20 | '11': 'نوفمبر', 21 | '12': 'ديسمبر' 22 | } 23 | -------------------------------------------------------------------------------- /faker/utils/datasets.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from collections import Counter 4 | from functools import reduce 5 | import operator 6 | 7 | 8 | def add_dicts(*args): 9 | """ 10 | Adds two or more dicts together. Common keys will have their values added. 11 | 12 | For example:: 13 | 14 | >>> t1 = {'a':1, 'b':2} 15 | >>> t2 = {'b':1, 'c':3} 16 | >>> t3 = {'d':4} 17 | 18 | >>> add_dicts(t1, t2, t3) 19 | {'a': 1, 'c': 3, 'b': 3, 'd': 4} 20 | 21 | """ 22 | 23 | counters = [Counter(arg) for arg in args] 24 | return dict(reduce(operator.add, counters)) 25 | -------------------------------------------------------------------------------- /faker/providers/company/bg_BG/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as CompanyProvider 4 | 5 | 6 | class Provider(CompanyProvider): 7 | formats = ( 8 | '{{last_name}} {{company_suffix}}', 9 | '{{last_name}} {{last_name}} {{company_suffix}}', 10 | '{{last_name}}', 11 | ) 12 | 13 | company_suffixes = ( 14 | 'АД', 'AD', 15 | 'ADSITz', 'АДСИЦ', 16 | 'EAD', 'ЕАД', 17 | 'EOOD', 'ЕООД', 18 | 'ET', 'ET', 19 | 'OOD', 'ООД', 20 | 'KD', 'КД', 21 | 'KDA', 'КДА', 22 | 'SD', 'СД' 23 | ) 24 | -------------------------------------------------------------------------------- /faker/providers/company/hu_HU/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as CompanyProvider 5 | 6 | 7 | class Provider(CompanyProvider): 8 | formats = ( 9 | '{{last_name}} {{company_suffix}}', 10 | '{{last_name}} {{last_name}} {{company_suffix}}', 11 | '{{last_name}} és {{last_name}} {{company_suffix}}', 12 | '{{last_name}} és társa {{company_suffix}}' 13 | ) 14 | 15 | company_suffixes = ('Kft.', 'Kht.', 'Zrt.', 'Bt.', 'Nyrt.', 'Kkt.') 16 | 17 | def company_suffix(self): 18 | return self.random_element(self.company_suffixes) 19 | -------------------------------------------------------------------------------- /faker/providers/company/no_NO/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as CompanyProvider 4 | 5 | 6 | class Provider(CompanyProvider): 7 | formats = [ 8 | '{{last_name}} {{company_suffix}}', 9 | '{{last_name}} {{company_suffix}}', 10 | '{{last_name}} {{company_suffix}}', 11 | '{{last_name}}-{{last_name}} {{company_suffix}}', 12 | '{{last_name}}, {{last_name}} og {{last_name}}', 13 | '{{last_name}}-{{last_name}}' 14 | ] 15 | 16 | company_suffixes = [ 17 | 'Gruppen', 'AS', 'ASA', 'BA', 'RFH', 'og Sønner', '& co.' 18 | ] 19 | -------------------------------------------------------------------------------- /faker/providers/phone_number/he_IL/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '02#######', 8 | '02-####-###', 9 | '03#######', 10 | '03-####-###', 11 | '04#######', 12 | '04-####-###', 13 | '08#######', 14 | '08-####-###', 15 | '09#######', 16 | '09-####-###', 17 | '05#-###-####', 18 | '05# ###-####', 19 | '05# ### ####', 20 | '05#-#######', 21 | '05# #######', 22 | '05########', 23 | ) 24 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. Faker documentation master file, created by 2 | sphinx-quickstart on Tue Mar 11 11:25:48 2014. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to Faker's documentation! 7 | ================================= 8 | 9 | .. include:: ../README.rst 10 | 11 | 12 | Contents 13 | -------- 14 | 15 | .. toctree:: 16 | :maxdepth: 2 17 | 18 | providers 19 | communityproviders 20 | locales 21 | coding_style 22 | 23 | 24 | 25 | Indices and tables 26 | ================== 27 | 28 | * :ref:`genindex` 29 | * :ref:`modindex` 30 | * :ref:`search` 31 | -------------------------------------------------------------------------------- /faker/providers/internet/bs_BA/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | 8 | free_email_domains = ( 9 | 'gmail.com', 'hotmail.com', 'yahoo.com', 'outlook.com', 10 | 'bih.net.ba', 'tel.net.ba', 11 | ) 12 | 13 | tlds = ('ba', 'com.ba', 'org.ba', 'net.ba', 'gov.ba', 'edu.ba', 'unsa.ba') 14 | 15 | replacements = ( 16 | ('č', 'c'), ('Č', 'C'), 17 | ('ć', 'c'), ('Ć', 'C'), 18 | ('đ', 'dj'), ('Đ', 'Dj'), 19 | ('š', 's'), ('Š', 'S'), 20 | ('ž', 'z'), ('Ž', 'Z') 21 | ) 22 | -------------------------------------------------------------------------------- /faker/providers/phone_number/zh_CN/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | from .. import Provider as PhoneNumberProvider 4 | 5 | 6 | class Provider(PhoneNumberProvider): 7 | phonenumber_prefixes = [134, 135, 136, 137, 138, 139, 147, 150, 8 | 151, 152, 157, 158, 159, 182, 187, 188, 9 | 130, 131, 132, 145, 155, 156, 185, 186, 10 | 145, 133, 153, 180, 181, 189] 11 | formats = [str(i) + "########" for i in phonenumber_prefixes] 12 | 13 | def phonenumber_prefix(self): 14 | return self.random_element(self.phonenumber_prefixes) 15 | -------------------------------------------------------------------------------- /faker/providers/internet/ja_JP/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | from faker.utils.decorators import slugify 5 | 6 | 7 | class Provider(InternetProvider): 8 | user_name_formats = ( 9 | '{{last_romanized_name}}.{{first_romanized_name}}', 10 | '{{first_romanized_name}}.{{last_romanized_name}}', 11 | '{{first_romanized_name}}##', 12 | '?{{last_romanized_name}}', 13 | ) 14 | tlds = ('com', 'com', 'com', 'net', 'org', 'jp', 'jp', 'jp') 15 | 16 | @slugify 17 | def domain_word(self): 18 | return self.generator.format('last_romanized_name') 19 | -------------------------------------------------------------------------------- /faker/providers/internet/zh_CN/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | from faker.utils.decorators import slugify 5 | 6 | 7 | class Provider(InternetProvider): 8 | user_name_formats = ( 9 | '{{last_romanized_name}}.{{first_romanized_name}}', 10 | '{{first_romanized_name}}.{{last_romanized_name}}', 11 | '{{first_romanized_name}}##', 12 | '?{{last_romanized_name}}', 13 | ) 14 | tlds = ('com', 'com', 'com', 'net', 'org', 'cn', 'cn', 'cn') 15 | 16 | @slugify 17 | def domain_word(self): 18 | return self.generator.format('last_romanized_name') 19 | -------------------------------------------------------------------------------- /faker/providers/internet/zh_TW/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | from faker.utils.decorators import slugify 5 | 6 | 7 | class Provider(InternetProvider): 8 | user_name_formats = ( 9 | '{{last_romanized_name}}.{{first_romanized_name}}', 10 | '{{first_romanized_name}}.{{last_romanized_name}}', 11 | '{{first_romanized_name}}##', 12 | '?{{last_romanized_name}}', 13 | ) 14 | tlds = ('com', 'com', 'com', 'net', 'org', 'tw', 'tw', 'tw') 15 | 16 | @slugify 17 | def domain_word(self): 18 | return self.generator.format('last_romanized_name') 19 | -------------------------------------------------------------------------------- /faker/providers/internet/de_DE/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as InternetProvider 5 | 6 | 7 | class Provider(InternetProvider): 8 | 9 | free_email_domains = ( 10 | 'aol.de', 'gmail.com', 'gmx.de', 'googlemail.com', 'hotmail.de', 11 | 'web.de', 'yahoo.de', 12 | ) 13 | tlds = ('com', 'com', 'com', 'net', 'org', 'de', 'de', 'de', ) 14 | 15 | replacements = ( 16 | ('ä', 'ae'), ('Ä', 'Ae'), 17 | ('ö', 'oe'), ('Ö', 'Oe'), 18 | ('ü', 'ue'), ('Ü', 'Ue'), 19 | ('é', 'e'), ('É', 'E'), 20 | ('à', 'a'), ('À', 'A'), 21 | ('ß', 'ss'), 22 | ) 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | *.py[cod] 3 | 4 | # C extensions 5 | *.so 6 | 7 | # Packages 8 | *.egg 9 | *.egg-info 10 | dist 11 | build 12 | docs/_build 13 | docs/locales.rst 14 | docs/locales/*.rst 15 | docs/providers.rst 16 | docs/providers/*.rst 17 | eggs 18 | .eggs 19 | parts 20 | var 21 | sdist 22 | develop-eggs 23 | .installed.cfg 24 | lib 25 | lib64 26 | 27 | # Installer logs 28 | pip-log.txt 29 | 30 | # Unit test / coverage reports 31 | .coverage 32 | .tox 33 | nosetests.xml 34 | 35 | # Translations 36 | *.mo 37 | 38 | # Mr Developer 39 | .mr.developer.cfg 40 | .project 41 | .pydevproject 42 | .idea 43 | .projectile 44 | .ropeproject 45 | .DS_Store 46 | .venv 47 | 48 | # IDE 49 | *.sw[po] 50 | -------------------------------------------------------------------------------- /faker/providers/company/ru_RU/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as CompanyProvider 5 | 6 | 7 | class Provider(CompanyProvider): 8 | formats = ( 9 | '{{company_prefix}} «{{last_name}}»', 10 | '{{company_prefix}} «{{last_name}} {{last_name}}»', 11 | '{{company_prefix}} «{{last_name}}-{{last_name}}»', 12 | '{{company_prefix}} «{{last_name}}, {{last_name}} и {{last_name}}»', 13 | '{{last_name}}', 14 | ) 15 | 16 | company_prefixes = ( 17 | 'РАО', 'АО', 'ИП', 'НПО', 18 | ) 19 | 20 | def company_prefix(self): 21 | return self.random_element(self.company_prefixes) 22 | -------------------------------------------------------------------------------- /faker/providers/phone_number/nl_BE/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as PhoneNumberProvider 5 | 6 | 7 | class Provider(PhoneNumberProvider): 8 | formats = ( 9 | '0### ######', 10 | '0## #######', 11 | '+32### ######', 12 | '+32## #######', 13 | '+32(0)### ######', 14 | '+32(0)## #######', 15 | '(0###) ######', 16 | '(0##) #######', 17 | '0###-######', 18 | '0##-#######', 19 | '+32###-######', 20 | '+32##-#######', 21 | '+32(0)###-######', 22 | '+32(0)##-#######', 23 | '(0###)-######', 24 | '(0##)-#######', 25 | ) 26 | -------------------------------------------------------------------------------- /faker/providers/phone_number/nl_NL/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as PhoneNumberProvider 5 | 6 | 7 | class Provider(PhoneNumberProvider): 8 | formats = ( 9 | '0### ######', 10 | '0## #######', 11 | '+31### ######', 12 | '+31## #######', 13 | '+31(0)### ######', 14 | '+31(0)## #######', 15 | '(0###) ######', 16 | '(0##) #######', 17 | '0###-######', 18 | '0##-#######', 19 | '+31###-######', 20 | '+31##-#######', 21 | '+31(0)###-######', 22 | '+31(0)##-#######', 23 | '(0###)-######', 24 | '(0##)-#######', 25 | ) 26 | -------------------------------------------------------------------------------- /faker/providers/internet/hr_HR/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | 8 | free_email_domains = ( 9 | 'gmail.com', 'hotmail.com', 'yahoo.com', 10 | 'net.hr', 'zg.t-com.hr', 'inet.hr', 't.ht.hr', 'vip.hr', 11 | 'globalnet.hr', 'xnet.hr', 'yahoo.hr', 'zagreb.hr', 12 | ) 13 | 14 | tlds = ('hr', 'com', 'com.hr', 'info', 'org', 'net', 'biz') 15 | 16 | replacements = ( 17 | ('č', 'c'), ('Č', 'C'), 18 | ('ć', 'c'), ('Ć', 'C'), 19 | ('đ', 'dj'), ('Đ', 'Dj'), 20 | ('š', 's'), ('Š', 'S'), 21 | ('ž', 'z'), ('Ž', 'Z'), 22 | ) 23 | -------------------------------------------------------------------------------- /faker/compat.py: -------------------------------------------------------------------------------- 1 | try: 2 | from inspect import getfullargspec as _getargspec 3 | except ImportError: 4 | from inspect import getargspec as _getargspec 5 | 6 | 7 | class getargspec(object): 8 | def __init__(self, method): 9 | self.argspec = _getargspec(method) 10 | 11 | @property 12 | def args(self): 13 | return self.argspec.args 14 | 15 | @property 16 | def varargs(self): 17 | return self.argspec.varargs 18 | 19 | @property 20 | def varkw(self): 21 | if hasattr(self.argspec, 'keywords'): 22 | return self.argspec.keywords 23 | return self.argspec.varkw 24 | 25 | @property 26 | def defaults(self): 27 | return self.argspec.defaults 28 | -------------------------------------------------------------------------------- /faker/providers/phone_number/el_GR/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '69########', 8 | '69## ######', 9 | '69## ### ###', 10 | 11 | '210#######', 12 | '210 #######', 13 | '210 ### ####', 14 | 15 | '2##0######', 16 | '2##0 ######', 17 | '2##0 ### ###', 18 | 19 | '2###0#####', 20 | '2###0 ## ###', 21 | 22 | '(+30) 69## ######', 23 | '+30 69## ######', 24 | '+3069########', 25 | '(+30) 2### ######', 26 | '+30 2### ######', 27 | '+302#########', 28 | ) 29 | -------------------------------------------------------------------------------- /faker/providers/internet/pl_PL/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | 4 | from .. import Provider as InternetProvider 5 | 6 | 7 | class Provider(InternetProvider): 8 | 9 | free_email_domains = ( 10 | 'onet.pl', 11 | 'interia.pl', 12 | 'gmail.com', 13 | 'o2.pl', 14 | 'yahoo.com', 15 | 'hotmail.com', 16 | ) 17 | 18 | tlds = ('com', 'com', 'com', 'net', 'org', 'pl', 'pl', 'pl') 19 | 20 | replacements = ( 21 | ('ą', 'a'), 22 | ('ć', 'c'), 23 | ('ę', 'e'), 24 | ('ł', 'l'), 25 | ('ń', 'n'), 26 | ('ó', 'o'), 27 | ('ś', 's'), 28 | ('ź', 'z'), 29 | ('ż', 'z'), 30 | ) 31 | -------------------------------------------------------------------------------- /faker/providers/person/ar_PS/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from ..ar_AA import Provider as ArabicPersonProvider 4 | 5 | 6 | class Provider(ArabicPersonProvider): 7 | last_names = ( 8 | 'خوري', 'شاهين', 'البرغوثي', 'الحسيني', 'الزيدانية', 'جرار', 9 | 'السكاكيني', 'طوقان', 'نسيبة', 'النشاشيبي', 'الخازن', 'ترابين', 10 | 'دغمش', 'دلاشة', 'الزيتاوي', 'صليبا', 'التركمان', 'الإغباري', 11 | 'كسواني', 'جزار', 'أبو اسنينة', 'التميمي', 'الجنيدي', 'بدر', 12 | 'أبو شقدم', 'أبو غليون', 'أبو قمر', 'الأدغم', 'حوسة', 'الصالحي', 13 | 'حمامي', 'هاشم', 'الحنبلي', 'أستيتية', 'مرمش', 'قرادة', 14 | 'فطاير', 'الخماش', 'الخياط', 'النعنيش', 'مهيار', 'أبو شلبك', 15 | ) 16 | -------------------------------------------------------------------------------- /faker/providers/company/de_DE/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as CompanyProvider 5 | 6 | 7 | class Provider(CompanyProvider): 8 | formats = ( 9 | '{{last_name}} {{company_suffix}}', 10 | '{{last_name}} {{last_name}} {{company_suffix}}', 11 | '{{last_name}}', 12 | ) 13 | 14 | company_suffixes = ( 15 | 'AG', 'AG', 'AG', 'AG', 'AG & Co. KG', 'AG & Co. KGaA', 'AG & Co. OHG', 16 | 'GbR', 'GbR', 'GmbH', 'GmbH', 'GmbH', 'GmbH', 'GmbH & Co. KG', 17 | 'GmbH & Co. KG', 'GmbH & Co. KGaA', 'GmbH & Co. OHG', 'KG', 'KG', 'KG', 18 | 'KGaA', 'OHG mbH', 'Stiftung & Co. KG', 'Stiftung & Co. KGaA', 'e.G.', 19 | 'e.V.', 20 | ) 21 | -------------------------------------------------------------------------------- /faker/providers/internet/hu_HU/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | 8 | free_email_domains = ( 9 | 'gmail.com', 10 | 'hotmail.com', 11 | 'yahoo.com' 12 | ) 13 | 14 | tlds = ( 15 | 'hu', 16 | 'com', 17 | 'com.hu', 18 | 'info', 19 | 'org', 20 | 'net', 21 | 'biz' 22 | ) 23 | 24 | replacements = ( 25 | ('ö', 'o'), 26 | ('ü', 'u'), 27 | ('á', 'a'), 28 | ('é', 'e'), 29 | ('í', 'i'), 30 | ('ó', 'i'), 31 | ('ő', 'o'), 32 | ('ú', 'u'), 33 | ('ű', 'u') 34 | ) 35 | -------------------------------------------------------------------------------- /faker/providers/phone_number/tw_GH/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+23327#######', 8 | '+23357#######', 9 | '+23355#######', 10 | '+23324#######', 11 | '+23354#######', 12 | '+23320#######', 13 | '+23350#######', 14 | '+23326#######', 15 | '+23356#######', 16 | '+23328#######', 17 | '024#######', 18 | '054#######', 19 | '055#######', 20 | '027#######', 21 | '057#######', 22 | '020#######', 23 | '050#######', 24 | '026#######', 25 | '056#######', 26 | '028#######', 27 | ) 28 | -------------------------------------------------------------------------------- /tests/test_generator.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from faker import Generator 3 | 4 | try: 5 | from mock import patch 6 | except ImportError: # pragma: no cover 7 | from unittest.mock import patch 8 | 9 | 10 | class GeneratorTestCase(unittest.TestCase): 11 | 12 | def setUp(self): 13 | self.generator = Generator() 14 | 15 | @patch('random.getstate') 16 | def test_get_random(self, mock_system_random): 17 | random_instance = self.generator.random 18 | random_instance.getstate() 19 | self.assertFalse(mock_system_random.called) 20 | 21 | @patch('random.seed') 22 | def test_random_seed_doesnt_seed_system_random(self, mock_system_random): 23 | self.generator.seed(0) 24 | self.assertFalse(mock_system_random.called) 25 | -------------------------------------------------------------------------------- /docs/coding_style.rst: -------------------------------------------------------------------------------- 1 | Coding Style 2 | ============ 3 | 4 | Lines length should not exceed 80 characters, as per `PEP 8`_. 5 | 6 | 7 | Encoding 8 | -------- 9 | 10 | Every Python source file should be encoded as UTF-8. 11 | As per `PEP 263`_, the first or the second line must be:: 12 | 13 | # coding=utf-8 14 | 15 | 16 | Data Sets 17 | --------- 18 | 19 | For each data set, please provide a comment with reference to the source 20 | and/or origin of the data. 21 | 22 | 23 | Name Lists 24 | ---------- 25 | 26 | When you have long lists of names, please order them alphabetically. Keep the lines length as close as possible to 80 characters, without exceeding the limit. 27 | 28 | 29 | .. _`pep 8`: https://python.org/dev/peps/pep-0008 30 | .. _`pep 263`: https://python.org/dev/peps/pep-0263 31 | -------------------------------------------------------------------------------- /faker/utils/decorators.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from functools import wraps 4 | 5 | from faker.utils import text 6 | 7 | 8 | def slugify(fn): 9 | @wraps(fn) 10 | def wrapper(*args, **kwargs): 11 | return text.slugify(fn(*args, **kwargs)) 12 | return wrapper 13 | 14 | 15 | def slugify_domain(fn): 16 | @wraps(fn) 17 | def wrapper(*args, **kwargs): 18 | return text.slugify(fn(*args, **kwargs), allow_dots=True) 19 | return wrapper 20 | 21 | 22 | def slugify_unicode(fn): 23 | @wraps(fn) 24 | def wrapper(*args, **kwargs): 25 | return text.slugify(fn(*args, **kwargs), allow_unicode=True) 26 | return wrapper 27 | 28 | 29 | def lowercase(fn): 30 | @wraps(fn) 31 | def wrapper(*args, **kwargs): 32 | return fn(*args, **kwargs).lower() 33 | return wrapper 34 | -------------------------------------------------------------------------------- /faker/providers/person/ar_SA/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from ..ar_AA import Provider as ArabicPersonProvider 4 | 5 | 6 | class Provider(ArabicPersonProvider): 7 | last_names = ( 8 | 'حجار', 'آل الشيخ', 'الحجار', 'حنبولي', 'آل سعود', 'آل علي', 9 | 'آل جعفر', 'أبا الخيل', 'المهنا', 'مهنا', 'بن لادن', 'كانو', 10 | 'الجفالي', 'فصيل', 'آل رفيع', 'آل بن لافي', 'آل العسكري', 11 | 'آل بن ظافر', 'آل عواض', 'المشاولة', 'آل مقطة', 'آل عايض', 12 | 'آل معيض', 'آل حسين', 'المغاولة', 'آل خضير', 'آل صفوان', 13 | 'آل محمد بن علي بن جماز', 'آل عطفة', 'آل قصير', 'آل سلطان', 14 | 'العليان', 'الشايع', 'أبو داوود', 'الدباغ', 'العجلان', 'الراشد', 15 | 'المهيدب', 'العقيل', 'شربتلي', 'الخرافي', 'أبو داوود', 'الجابر', 16 | 'بقشان', 'الحكير', 17 | ) 18 | -------------------------------------------------------------------------------- /faker/providers/internet/fr_CH/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | safe_email_tlds = ('org', 'com', 'net', 'ch',) 8 | free_email_domains = ( 9 | 'gmail.com', 10 | 'hotmail.fr', 11 | 'yahoo.fr', 12 | 'bluewin.ch', 13 | 'romandie.com', 14 | 'hispeed.ch', 15 | 'sunrise.ch', 16 | 'vtxnet.ch') 17 | tlds = ('com', 'com', 'com', 'net', 'org', 'ch', 'ch', 'ch') 18 | 19 | replacements = ( 20 | ('ä', 'ae'), ('à', 'a'), ('â', 'a'), 21 | ('ç', 'c'), 22 | ('é', 'e'), ('è', 'e'), ('ê', 'e'), ('ë', 'e'), 23 | ('ï', 'i'), ('î', 'i'), 24 | ('ö', 'oe'), ('ô', 'o'), 25 | ('ü', 'ue'), ('ù', 'u'), ('ü', 'u'), 26 | ('ß', 'ss'), 27 | ) 28 | -------------------------------------------------------------------------------- /faker/providers/phone_number/id_ID/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | # Currently this is my own work 7 | formats = ( 8 | '+62-##-###-####', 9 | '+62-0##-###-####', 10 | 11 | '+62 (0##) ### ####', 12 | '+62 (0##) ###-####', 13 | 14 | '+62 (##) ### ####', 15 | '+62 (##) ###-####', 16 | 17 | '+62-###-###-####', 18 | '+62-0###-###-####', 19 | 20 | '+62 (0###) ### ####', 21 | '+62 (0###) ###-####', 22 | 23 | '+62 (###) ### ####', 24 | '+62 (###) ###-####', 25 | 26 | '(0##) ### ####', 27 | '(0##) ###-####', 28 | 29 | '(0###) ### ####', 30 | '(0###) ###-####', 31 | 32 | '08# ### ####', 33 | '08########', 34 | ) 35 | -------------------------------------------------------------------------------- /faker/providers/barcode/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import BaseProvider 5 | 6 | 7 | class Provider(BaseProvider): 8 | 9 | def ean(self, length=13): 10 | code = [self.random_digit() for _ in range(length - 1)] 11 | 12 | if length not in (8, 13): 13 | raise AssertionError("length can only be 8 or 13") 14 | 15 | if length == 8: 16 | weights = [3, 1, 3, 1, 3, 1, 3] 17 | elif length == 13: 18 | weights = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3] 19 | 20 | weighted_sum = sum([x * y for x, y in zip(code, weights)]) 21 | check_digit = (10 - weighted_sum % 10) % 10 22 | code.append(check_digit) 23 | 24 | return ''.join(str(x) for x in code) 25 | 26 | def ean8(self): 27 | return self.ean(8) 28 | 29 | def ean13(self): 30 | return self.ean(13) 31 | -------------------------------------------------------------------------------- /faker/providers/phone_number/ko_KR/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as PhoneNumberProvider 5 | 6 | 7 | class Provider(PhoneNumberProvider): 8 | formats = ( 9 | '02-####-####', 10 | '031-###-####', 11 | '032-###-####', 12 | '033-###-####', 13 | '041-###-####', 14 | '042-###-####', 15 | '043-###-####', 16 | '044-###-####', 17 | '051-###-####', 18 | '052-###-####', 19 | '053-###-####', 20 | '054-###-####', 21 | '055-###-####', 22 | '061-###-####', 23 | '062-###-####', 24 | '063-###-####', 25 | '064-7##-####', 26 | '010-####-####', 27 | '011-###-####', 28 | '016-###-####', 29 | '017-###-####', 30 | '018-###-####', 31 | '019-###-####', 32 | '070-####-####' 33 | ) 34 | -------------------------------------------------------------------------------- /faker/providers/internet/it_IT/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | safe_email_tlds = ('com', 'net', 'eu', 'it', 'it', 'it') 8 | free_email_domains = ( 9 | 'libero.it', 'libero.it', 'libero.it', 10 | 'tim.it', 11 | 'tin.it', 12 | 'alice.it', 13 | 'virgilio.it', 14 | 'tiscali.it', 15 | 'fastwebnet.it', 16 | 'vodafone.it', 17 | 'poste.it', 18 | 'gmail.com', 'gmail.com', 'gmail.com', 19 | 'outlook.com', 20 | 'live.com', 21 | 'hotmail.com', 22 | 'hotmail.it', 23 | 'yahoo.com', 24 | 'tele2.it', 25 | ) 26 | tlds = ('com', 'com', 'com', 'net', 'org', 'eu', 'it', 'it', 'it', 'it') 27 | replacements = ( 28 | ('à', 'a'), ('é', 'e'), ('è', 'e'), 29 | ('ì', 'i'), ('ò', 'o'), ('ù', 'u') 30 | ) 31 | -------------------------------------------------------------------------------- /faker/providers/phone_number/en_US/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+##(#)##########', 8 | '+##(#)##########', 9 | '0##########', 10 | '0##########', 11 | '###-###-####', 12 | '(###)###-####', 13 | '1-###-###-####', 14 | '###.###.####', 15 | '###-###-####', 16 | '(###)###-####', 17 | '1-###-###-####', 18 | '###.###.####', 19 | '###-###-####x###', 20 | '(###)###-####x###', 21 | '1-###-###-####x###', 22 | '###.###.####x###', 23 | '###-###-####x####', 24 | '(###)###-####x####', 25 | '1-###-###-####x####', 26 | '###.###.####x####', 27 | '###-###-####x#####', 28 | '(###)###-####x#####', 29 | '1-###-###-####x#####', 30 | '###.###.####x#####' 31 | ) 32 | -------------------------------------------------------------------------------- /faker/providers/phone_number/es_MX/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+##(#)##########', 8 | '+##(#)##########', 9 | '0##########', 10 | '0##########', 11 | '###-###-####', 12 | '(###)###-####', 13 | '1-###-###-####', 14 | '###.###.####', 15 | '###-###-####', 16 | '(###)###-####', 17 | '1-###-###-####', 18 | '###.###.####', 19 | '###-###-####x###', 20 | '(###)###-####x###', 21 | '1-###-###-####x###', 22 | '###.###.####x###', 23 | '###-###-####x####', 24 | '(###)###-####x####', 25 | '1-###-###-####x####', 26 | '###.###.####x####', 27 | '###-###-####x#####', 28 | '(###)###-####x#####', 29 | '1-###-###-####x#####', 30 | '###.###.####x#####' 31 | ) 32 | -------------------------------------------------------------------------------- /faker/providers/internet/cs_CZ/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | 8 | user_name_formats = ( 9 | '{{last_name_female}}.{{first_name_female}}', 10 | '{{last_name_female}}.{{first_name_female}}', 11 | '{{last_name_male}}.{{first_name_male}}', 12 | '{{last_name_male}}.{{first_name_male}}', 13 | '{{first_name_female}}.{{last_name_female}}', 14 | '{{first_name_male}}.{{last_name_male}}', 15 | '{{first_name}}##', 16 | '?{{last_name}}', 17 | '?{{last_name}}', 18 | '?{{last_name}}', 19 | ) 20 | 21 | email_formats = ('{{user_name}}@{{free_email_domain}}', ) 22 | 23 | free_email_domains = ( 24 | 'seznam.cz', 25 | 'gmail.com', 26 | 'email.cz', 27 | 'post.cz', 28 | 'chello.cz', 29 | 'centrum.cz', 30 | 'volny.cz', 31 | ) 32 | 33 | tlds = ('cz', 'com', 'cz') 34 | -------------------------------------------------------------------------------- /faker/providers/date_time/ko_KR/__init__.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | from __future__ import unicode_literals 3 | 4 | from .. import Provider as DateTimeProvider 5 | 6 | 7 | class Provider(DateTimeProvider): 8 | 9 | def day_of_week(self): 10 | day = self.date('%w') 11 | DAY_NAMES = { 12 | "0": "일요일", 13 | "1": "월요일", 14 | "2": "화요일", 15 | "3": "수요일", 16 | "4": "목요일", 17 | "5": "금요일", 18 | "6": "토요일", 19 | } 20 | return DAY_NAMES[day] 21 | 22 | def month_name(self): 23 | month = self.month() 24 | MONTH_NAMES = { 25 | "01": "1월", 26 | "02": "2월", 27 | "03": "3월", 28 | "04": "4월", 29 | "05": "5월", 30 | "06": "6월", 31 | "07": "7월", 32 | "08": "8월", 33 | "09": "9월", 34 | "10": "10월", 35 | "11": "11월", 36 | "12": "12월", 37 | } 38 | return MONTH_NAMES[month] 39 | -------------------------------------------------------------------------------- /faker/providers/phone_number/hr_HR/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '01 #### ###', 8 | '020 ### ###', 9 | '021 ### ###', 10 | '022 ### ###', 11 | '023 ### ###', 12 | '031 ### ###', 13 | '032 ### ###', 14 | '033 ### ###', 15 | '034 ### ###', 16 | '035 ### ###', 17 | '040 ### ###', 18 | '042 ### ###', 19 | '043 ### ###', 20 | '044 ### ###', 21 | '047 ### ###', 22 | '048 ### ###', 23 | '049 ### ###', 24 | '051 ### ###', 25 | '052 ### ###', 26 | '053 ### ###', 27 | '060 ### ###', 28 | '072 ### ###', 29 | '074 ### ###', 30 | '091 #### ###', 31 | '092 #### ###', 32 | '095 #### ###', 33 | '097 #### ###', 34 | '098 #### ###', 35 | '099 #### ###', 36 | '0800 ## ##', 37 | ) 38 | -------------------------------------------------------------------------------- /faker/providers/date_time/pl_PL/__init__.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | from __future__ import unicode_literals 4 | 5 | from .. import Provider as DateTimeProvider 6 | 7 | 8 | class Provider(DateTimeProvider): 9 | 10 | DAY_NAMES = { 11 | '0': 'poniedziałek', 12 | '1': 'wtorek', 13 | '2': 'środa', 14 | '3': 'czwartek', 15 | '4': 'piątek', 16 | '5': 'sobota', 17 | '6': 'niedziela', 18 | } 19 | 20 | MONTH_NAMES = { 21 | '01': 'styczeń', 22 | '02': 'luty', 23 | '03': 'marzec', 24 | '04': 'kwiecień', 25 | '05': 'maj', 26 | '06': 'czerwiec', 27 | '07': 'lipiec', 28 | '08': 'sierpień', 29 | '09': 'wrzesień', 30 | '10': 'październik', 31 | '11': 'listopad', 32 | '12': 'grudzień' 33 | } 34 | 35 | def day_of_week(self): 36 | day = self.date('%w') 37 | return self.DAY_NAMES[day] 38 | 39 | def month_name(self): 40 | month = self.month() 41 | return self.MONTH_NAMES[month] 42 | -------------------------------------------------------------------------------- /faker/providers/ssn/en_GB/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as BaseProvider 4 | 5 | 6 | class Provider(BaseProvider): 7 | # Source: 8 | # https://en.wikipedia.org/wiki/National_Insurance_number 9 | # UK National Insurance numbers (NINO) follow a specific format 10 | # To avoid generating real NINOs, the prefix and suffix letters 11 | # remain static using values reserved by HMRC (never to be used). 12 | # Example format: "QR 12 34 56 C" or "QR123456C" - only alphanumeric 13 | # and whitespace characters are permitted. Whitespace is for readability 14 | # only and is generally included as per the above examples, but a 15 | # few 'styles' have been included below for the sake of realism. 16 | 17 | nino_formats = ( 18 | 'ZZ ## ## ## T', 19 | 'ZZ######T', 20 | 'ZZ ###### T', 21 | ) 22 | 23 | def ssn(self): 24 | pattern = self.random_element(self.nino_formats) 25 | return self.numerify(self.generator.parse(pattern)) 26 | -------------------------------------------------------------------------------- /tests/providers/test_job.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | 5 | import unittest 6 | 7 | from faker import Faker 8 | 9 | from tests import string_types 10 | 11 | 12 | class TestJob(unittest.TestCase): 13 | """ 14 | Test Job 15 | """ 16 | 17 | def setUp(self): 18 | self.factory = Faker() 19 | 20 | def test_job(self): 21 | job = self.factory.job() 22 | assert isinstance(job, string_types) 23 | 24 | 25 | class TestKoKR(unittest.TestCase): 26 | """ 27 | Test Job ko_KR 28 | """ 29 | 30 | def setUp(self): 31 | self.factory = Faker('ko_KR') 32 | 33 | def test_job(self): 34 | job = self.factory.job() 35 | assert isinstance(job, string_types) 36 | 37 | 38 | class TestHuHU(unittest.TestCase): 39 | "Tests the job module in the Hungarian locale." 40 | 41 | def setUp(self): 42 | self.factory = Faker('hu_HU') 43 | 44 | def test_job(self): 45 | job = self.factory.job() 46 | assert isinstance(job, string_types) 47 | -------------------------------------------------------------------------------- /faker/providers/company/id_ID/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as CompanyProvider 3 | 4 | 5 | class Provider(CompanyProvider): 6 | formats = ( 7 | '{{company_prefix}} {{last_name}}', 8 | '{{company_prefix}} {{last_name}} {{last_name}}', 9 | '{{company_prefix}} {{last_name}} {{company_suffix}}', 10 | '{{company_prefix}} {{last_name}} {{last_name}} {{company_suffix}}', 11 | ) 12 | 13 | # From http://id.wikipedia.org/wiki/Jenis_badan_usaha 14 | # via 15 | # https://github.com/fzaninotto/faker/blob/master/src/Faker/Provider/id_ID/Company.php 16 | company_prefixes = ( 17 | 'PT', 'CV', 'UD', 'PD', 'Perum', 18 | ) 19 | 20 | # From http://id.wikipedia.org/wiki/Jenis_badan_usaha 21 | # via 22 | # https://github.com/fzaninotto/faker/blob/master/src/Faker/Provider/id_ID/Company.php 23 | company_suffixes = ( 24 | '(Persero) Tbk', 'Tbk', 25 | ) 26 | 27 | def company_prefix(self): 28 | return self.random_element(self.company_prefixes) 29 | -------------------------------------------------------------------------------- /faker/providers/internet/fr_FR/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | safe_email_tlds = ('com', 'net', 'fr', 'fr') 8 | free_email_domains = ( 9 | 'voila.fr', 10 | 'gmail.com', 11 | 'hotmail.fr', 12 | 'yahoo.fr', 13 | 'laposte.net', 14 | 'free.fr', 15 | 'sfr.fr', 16 | 'orange.fr', 17 | 'bouygtel.fr', 18 | 'club-internet.fr', 19 | 'dbmail.com', 20 | 'live.com', 21 | 'ifrance.com', 22 | 'noos.fr', 23 | 'tele2.fr', 24 | 'tiscali.fr', 25 | 'wanadoo.fr') 26 | tlds = ('com', 'com', 'com', 'net', 'org', 'fr', 'fr', 'fr') 27 | replacements = ( 28 | ('à', 'a'), ('â', 'a'), ('ä', 'a'), 29 | ('ç', 'c'), 30 | ('é', 'e'), ('è', 'e'), ('ê', 'e'), ('ë', 'e'), ('É', 'e'), 31 | ('ï', 'i'), ('î', 'i'), 32 | ('ô', 'o'), ('ö', 'o'), 33 | ('ù', 'u'), ('ü', 'u'), 34 | ) 35 | -------------------------------------------------------------------------------- /faker/providers/ssn/he_IL/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as SsnProvider 5 | from math import ceil 6 | 7 | 8 | class Provider(SsnProvider): 9 | 10 | def ssn(self): 11 | """ 12 | Returns an Israeli identity number, known as Teudat Zehut ("tz"). 13 | 14 | https://en.wikipedia.org/wiki/Israeli_identity_card 15 | """ 16 | 17 | newID = str(self.generator.random.randrange(111111, 99999999)) 18 | newID = newID.zfill(8) 19 | theSum = 0 20 | indexRange = [0, 2, 4, 6] 21 | for i in indexRange: 22 | digit = newID[i] 23 | num = int(digit) 24 | theSum = theSum + num 25 | num = int(newID[i + 1]) * 2 26 | if num > 9: 27 | num = int(str(num)[0]) + int(str(num)[1]) 28 | theSum = theSum + num 29 | lastDigit = theSum % 10 30 | if lastDigit != 0: 31 | lastDigit = 10 - lastDigit 32 | 33 | return str(newID) + str(lastDigit) 34 | -------------------------------------------------------------------------------- /faker/providers/internet/sk_SK/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | user_name_formats = ( 8 | '{{last_name_female}}.{{first_name_female}}', 9 | '{{last_name_female}}.{{first_name_female}}', 10 | '{{last_name_male}}.{{first_name_male}}', 11 | '{{last_name_male}}.{{first_name_male}}', 12 | '{{first_name_female}}.{{last_name_female}}', 13 | '{{first_name_male}}.{{last_name_male}}', 14 | '{{first_name}}##', 15 | '?{{last_name}}', 16 | '?{{last_name}}', 17 | '?{{last_name}}', 18 | ) 19 | 20 | email_formats = ('{{user_name}}@{{free_email_domain}}', ) 21 | 22 | free_email_domains = ( 23 | 'zoznam.sk', 24 | 'gmail.com', 25 | 'centrum.sk', 26 | 'post.sk', 27 | 'chello.sk', 28 | 'pobox.sk', 29 | 'szm.sk', 30 | 'atlas.sk', 31 | 'azet.sk', 32 | 'inmail.sk', 33 | ) 34 | 35 | tlds = ('sk', 'com',) 36 | -------------------------------------------------------------------------------- /faker/providers/date_time/fr_FR/__init__.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | from __future__ import unicode_literals 3 | 4 | from .. import Provider as DateTimeProvider 5 | 6 | 7 | class Provider(DateTimeProvider): 8 | 9 | def day_of_week(self): 10 | day = self.date('%w') 11 | DAY_NAMES = { 12 | "0": "Dimanche", 13 | "1": "Lundi", 14 | "2": "Mardi", 15 | "3": "Mercredi", 16 | "4": "Jeudi", 17 | "5": "Vendredi", 18 | "6": "Samedi", 19 | } 20 | return DAY_NAMES[day] 21 | 22 | def month_name(self): 23 | month = self.month() 24 | MONTH_NAMES = { 25 | "01": "Janvier", 26 | "02": "Février", 27 | "03": "Mars", 28 | "04": "Avril", 29 | "05": "Mai", 30 | "06": "Juin", 31 | "07": "Juillet", 32 | "08": "Août", 33 | "09": "Septembre", 34 | "10": "Octobre", 35 | "11": "Novembre", 36 | "12": "Décembre", 37 | } 38 | return MONTH_NAMES[month] 39 | -------------------------------------------------------------------------------- /faker/providers/date_time/sl_SI/__init__.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | from __future__ import unicode_literals 3 | 4 | from .. import Provider as DateTimeProvider 5 | 6 | 7 | class Provider(DateTimeProvider): 8 | 9 | def day_of_week(self): 10 | day = self.date('%w') 11 | DAY_NAMES = { 12 | "0": "Nedelja", 13 | "1": "Ponedeljek", 14 | "2": "Torek", 15 | "3": "Sreda", 16 | "4": "Četrtek", 17 | "5": "Petek", 18 | "6": "Sobota", 19 | } 20 | return DAY_NAMES[day] 21 | 22 | def month_name(self): 23 | month = self.month() 24 | MONTH_NAMES = { 25 | "01": "Januar", 26 | "02": "Februar", 27 | "03": "Marec", 28 | "04": "April", 29 | "05": "Maj", 30 | "06": "Junij", 31 | "07": "Julij", 32 | "08": "Avgust", 33 | "09": "September", 34 | "10": "Oktober", 35 | "11": "November", 36 | "12": "December", 37 | } 38 | return MONTH_NAMES[month] 39 | -------------------------------------------------------------------------------- /faker/providers/date_time/id_ID/__init__.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as DateTimeProvider 5 | 6 | 7 | class Provider(DateTimeProvider): 8 | 9 | def day_of_week(self): 10 | day = self.date('%w') 11 | DAY_NAMES = { 12 | "0": "Senin", 13 | "1": "Selasa", 14 | "2": "Rabu", 15 | "3": "Kamis", 16 | "4": "Jumat", 17 | "5": "Sabtu", 18 | "6": "Minggu", 19 | } 20 | 21 | return DAY_NAMES[day] 22 | 23 | def month_name(self): 24 | month = self.month() 25 | MONTH_NAMES = { 26 | "01": "Januari", 27 | "02": "Februari", 28 | "03": "Maret", 29 | "04": "April", 30 | "05": "Mei", 31 | "06": "Juni", 32 | "07": "Juli", 33 | "08": "Agustus", 34 | "09": "September", 35 | "10": "Oktober", 36 | "11": "November", 37 | "12": "Desember", 38 | } 39 | 40 | return MONTH_NAMES[month] 41 | -------------------------------------------------------------------------------- /faker/providers/date_time/ru_RU/__init__.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | from __future__ import unicode_literals 3 | 4 | from .. import Provider as DateTimeProvider 5 | 6 | 7 | class Provider(DateTimeProvider): 8 | 9 | def day_of_week(self): 10 | day = self.date('%w') 11 | DAY_NAMES = { 12 | "0": "Воскресенье", 13 | "1": "Понедельник", 14 | "2": "Вторник", 15 | "3": "Среда", 16 | "4": "Четверг", 17 | "5": "Пятница", 18 | "6": "Суббота", 19 | } 20 | return DAY_NAMES[day] 21 | 22 | def month_name(self): 23 | month = self.month() 24 | MONTH_NAMES = { 25 | "01": "Январь", 26 | "02": "Февраль", 27 | "03": "Март", 28 | "04": "Апрель", 29 | "05": "Май", 30 | "06": "Июнь", 31 | "07": "Июль", 32 | "08": "Август", 33 | "09": "Сентябрь", 34 | "10": "Октябрь", 35 | "11": "Ноябрь", 36 | "12": "Декабрь", 37 | } 38 | return MONTH_NAMES[month] 39 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Daniele Faraglia 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /faker/providers/automotive/en_CA/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as AutomotiveProvider 5 | 6 | 7 | class Provider(AutomotiveProvider): 8 | # from 9 | # https://www.revolvy.com/main/index.php?s=Canadian%20licence%20plate%20designs%20and%20serial%20formats 10 | license_formats = ( 11 | # Alberta 12 | '???-####', 13 | # BC 14 | '??# ##?', 15 | '?? ####', 16 | # Manitoba 17 | '??? ###', 18 | # New Brunswick 19 | '??? ###', 20 | # Newfoundland and Labrador 21 | '??? ###', 22 | # NWT 23 | '######', 24 | # Nova Scotia 25 | '??? ###', 26 | # Nunavut 27 | '### ###', 28 | # Ontario 29 | '### ???', 30 | '???? ###', 31 | '??# ###', 32 | '### #??', 33 | '?? ####', 34 | 'GV??-###', 35 | # PEI 36 | '## ##??', 37 | # Quebec 38 | '?## ???', 39 | # Saskatchewan 40 | '### ???', 41 | # Yukon 42 | '???##' 43 | ) 44 | -------------------------------------------------------------------------------- /faker/providers/date_time/hr_HR/__init__.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | from __future__ import unicode_literals 3 | 4 | from .. import Provider as DateTimeProvider 5 | 6 | 7 | class Provider(DateTimeProvider): 8 | 9 | def day_of_week(self): 10 | day = self.date('%w') 11 | DAY_NAMES = { 12 | "0": "Nedjelja", 13 | "1": "Ponedjeljak", 14 | "2": "Utorak", 15 | "3": "Srijeda", 16 | "4": "Četvrtak", 17 | "5": "Petak", 18 | "6": "Subota", 19 | } 20 | return DAY_NAMES[day] 21 | 22 | def month_name(self): 23 | month = self.month() 24 | MONTH_NAMES = { 25 | "01": "Siječanj", 26 | "02": "Veljača", 27 | "03": "Ožujak", 28 | "04": "Travanj", 29 | "05": "Svibanj", 30 | "06": "Lipanj", 31 | "07": "Srpanj", 32 | "08": "Kolovoz", 33 | "09": "Rujan", 34 | "10": "Listopad", 35 | "11": "Studeni", 36 | "12": "Prosinac", 37 | } 38 | return MONTH_NAMES[month] 39 | -------------------------------------------------------------------------------- /faker/providers/phone_number/bs_BA/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '030 ### ###', 8 | '031 ### ###', 9 | '032 ### ###', 10 | '033 ### ###', 11 | '034 ### ###', 12 | '035 ### ###', 13 | '036 ### ###', 14 | '037 ### ###', 15 | '038 ### ###', 16 | '039 ### ###', 17 | '049 ### ###', 18 | '050 ### ###', 19 | '051 ### ###', 20 | '052 ### ###', 21 | '053 ### ###', 22 | '054 ### ###', 23 | '055 ### ###', 24 | '056 ### ###', 25 | '057 ### ###', 26 | '058 ### ###', 27 | '059 ### ###', 28 | '060 ### ###', 29 | '060 #### ###', 30 | '061 ### ###', 31 | '062 ### ###', 32 | '063 ### ###', 33 | '064 ### ###', 34 | '065 ### ###', 35 | '066 ### ###', 36 | '067 ### ###', 37 | '070 20# ###', 38 | '+387 61 ### ###', 39 | '+387 (0)61 ### ###' 40 | ) 41 | -------------------------------------------------------------------------------- /faker/providers/date_time/hu_HU/__init__.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as DateTimeProvider 5 | 6 | 7 | class Provider(DateTimeProvider): 8 | 9 | def day_of_week(self): 10 | day = self.date('%w') 11 | DAY_NAMES = { 12 | "0": "hétfő", 13 | "1": "kedd", 14 | "2": "szerda", 15 | "3": "csütörtök", 16 | "4": "péntek", 17 | "5": "szombat", 18 | "6": "vasárnap", 19 | } 20 | 21 | return DAY_NAMES[day] 22 | 23 | def month_name(self): 24 | month = self.month() 25 | MONTH_NAMES = { 26 | "01": "január", 27 | "02": "február", 28 | "03": "március", 29 | "04": "április", 30 | "05": "május", 31 | "06": "junius", 32 | "07": "julius", 33 | "08": "augusztus", 34 | "09": "szeptember", 35 | "10": "október", 36 | "11": "november", 37 | "12": "december", 38 | } 39 | 40 | return MONTH_NAMES[month] 41 | -------------------------------------------------------------------------------- /faker/providers/phone_number/pl_PL/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | # Mobile 8 | # Government website: http://www.uke.gov.pl/numeracja-843 9 | '50# ### ###', 10 | '51# ### ###', 11 | '53# ### ###', 12 | '57# ### ###', 13 | '60# ### ###', 14 | '66# ### ###', 15 | '69# ### ###', 16 | '72# ### ###', 17 | '73# ### ###', 18 | '78# ### ###', 19 | '79# ### ###', 20 | '88# ### ###', 21 | 22 | '+48 50# ### ###', 23 | '+48 51# ### ###', 24 | '+48 53# ### ###', 25 | '+48 57# ### ###', 26 | '+48 60# ### ###', 27 | '+48 66# ### ###', 28 | '+48 69# ### ###', 29 | '+48 72# ### ###', 30 | '+48 73# ### ###', 31 | '+48 78# ### ###', 32 | '+48 79# ### ###', 33 | '+48 88# ### ###', 34 | 35 | '32 ### ## ##', 36 | '+48 32 ### ## ##', 37 | '22 ### ## ##', 38 | '+48 22 ### ## ##', 39 | ) 40 | -------------------------------------------------------------------------------- /faker/providers/phone_number/cs_CZ/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '601 ### ###', 8 | '603 ### ###', 9 | '608 ### ###', 10 | '790 ### ###', 11 | '602 ### ###', 12 | '604 ### ###', 13 | '770 ### ###', 14 | '606 ### ###', 15 | '605 ### ###', 16 | '773 ### ###', 17 | '607 ### ###', 18 | '730 ### ###', 19 | '774 ### ###', 20 | '702 ### ###', 21 | '731 ### ###', 22 | '775 ### ###', 23 | '720 ### ###', 24 | '732 ### ###', 25 | '776 ### ###', 26 | '721 ### ###', 27 | '733 ### ###', 28 | '777 ### ###', 29 | '722 ### ###', 30 | '734 ### ###', 31 | '723 ### ###', 32 | '736 ### ###', 33 | '724 ### ###', 34 | '737 ### ###', 35 | '725 ### ###', 36 | '738 ### ###', 37 | '726 ### ###', 38 | '739 ### ###', 39 | '727 ### ###', 40 | '728 ### ###', 41 | '729 ### ###', 42 | ) 43 | -------------------------------------------------------------------------------- /faker/providers/phone_number/fr_CH/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+41 2# ### ## ##', 8 | '+41 3# ### ## ##', 9 | '+41 4# ### ## ##', 10 | '+41 5# ### ## ##', 11 | '+41 6# ### ## ##', 12 | '+41 7# ### ## ##', 13 | '+41 8# ### ## ##', 14 | '+41 9# ### ## ##', 15 | '+41 (0)2# ### ## ##', 16 | '+41 (0)3# ### ## ##', 17 | '+41 (0)4# ### ## ##', 18 | '+41 (0)5# ### ## ##', 19 | '+41 (0)6# ### ## ##', 20 | '+41 (0)7# ### ## ##', 21 | '+41 (0)8# ### ## ##', 22 | '+41 (0)9# ### ## ##', 23 | '02# ### ## ##', 24 | '03# ### ## ##', 25 | '04# ### ## ##', 26 | '05# ### ## ##', 27 | '06# ### ## ##', 28 | '07# ### ## ##', 29 | '08# ### ## ##', 30 | '09# ### ## ##', 31 | # see: http://www.bakom.admin.ch/themen/telekom/00479/00607/index.html 32 | '084# ### ###', 33 | '0878 ### ###', 34 | '0900 ### ###', 35 | '0901 ### ###', 36 | '0906 ### ###', 37 | ) 38 | -------------------------------------------------------------------------------- /faker/providers/ssn/uk_UA/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | 4 | from datetime import date 5 | 6 | from .. import Provider as SsnProvider 7 | 8 | 9 | class Provider(SsnProvider): 10 | def ssn(self): 11 | """ 12 | Ukrainian "Реєстраційний номер облікової картки платника податків" 13 | also known as "Ідентифікаційний номер фізичної особи". 14 | """ 15 | digits = [] 16 | 17 | # Number of days between 1899-12-31 and a birth date 18 | for digit in str((self.generator.date_object() - 19 | date(1899, 12, 31)).days): 20 | digits.append(int(digit)) 21 | 22 | # Person's sequence number 23 | for _ in range(4): 24 | digits.append(self.random_int(0, 9)) 25 | 26 | checksum = (digits[0] * -1 + digits[1] * 5 + digits[2] * 7 + digits[3] * 9 + 27 | digits[4] * 4 + digits[5] * 6 + digits[6] * 10 + digits[7] * 5 + 28 | digits[8] * 7) 29 | # Remainder of a checksum divided by 11 or 1 if it equals to 10 30 | digits.append(checksum % 11 % 10) 31 | 32 | return ''.join(str(digit) for digit in digits) 33 | -------------------------------------------------------------------------------- /faker/providers/internet/sl_SI/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | 8 | user_name_formats = ( 9 | '{{last_name}}.{{first_name_female}}', 10 | '{{last_name}}.{{first_name_male}}', 11 | '{{first_name_female}}.{{last_name}}', 12 | '{{first_name_male}}.{{last_name}}', 13 | '{{first_name}}##', 14 | ) 15 | 16 | email_formats = ('{{user_name}}@{{free_email_domain}}', ) 17 | 18 | free_email_domains = ( 19 | 'gmail.com', 'siol.net', 'email.si', 'volja.net', 20 | ) 21 | 22 | uri_pages = ( 23 | 'index', 'domov', 'iskanje', 'main', 'novica', 24 | 'homepage', 'kategorija', 'registracija', 'login', 25 | 'faq', 'o-nas', 'pogoji', 26 | 'zasebnost', 'avtor' 27 | ) 28 | uri_paths = ( 29 | 'app', 'main', 'wp-content', 'iskanje', 'kategorija', 'novica', 30 | 'kategorije', 'novice', 'blog', 'komentarji', 'seznam') 31 | uri_extensions = ( 32 | '.html', '.html', '.html', '.htm', '.htm', '.php', 33 | '.php', '.jsp', '.asp' 34 | ) 35 | 36 | tlds = ('si', 'com',) 37 | -------------------------------------------------------------------------------- /faker/providers/phone_number/fr_FR/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+33 (0)1 ## ## ## ##', 8 | '+33 (0)1 ## ## ## ##', 9 | '+33 (0)2 ## ## ## ##', 10 | '+33 (0)3 ## ## ## ##', 11 | '+33 (0)4 ## ## ## ##', 12 | '+33 (0)5 ## ## ## ##', 13 | '+33 (0)6 ## ## ## ##', 14 | '+33 (0)8 ## ## ## ##', 15 | '+33 1 ## ## ## ##', 16 | '+33 1 ## ## ## ##', 17 | '+33 2 ## ## ## ##', 18 | '+33 3 ## ## ## ##', 19 | '+33 4 ## ## ## ##', 20 | '+33 5 ## ## ## ##', 21 | '+33 6 ## ## ## ##', 22 | '+33 8 ## ## ## ##', 23 | '01########', 24 | '01########', 25 | '02########', 26 | '03########', 27 | '04########', 28 | '05########', 29 | '06########', 30 | '08########', 31 | '01 ## ## ## ##', 32 | '01 ## ## ## ##', 33 | '02 ## ## ## ##', 34 | '03 ## ## ## ##', 35 | '04 ## ## ## ##', 36 | '05 ## ## ## ##', 37 | '06 ## ## ## ##', 38 | '08 ## ## ## ##', 39 | ) 40 | -------------------------------------------------------------------------------- /faker/providers/phone_number/pt_PT/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '(351) 91# ### ###', 8 | '(351) 92# ### ###', 9 | '(351) 93# ### ###', 10 | '(351) 96# ### ###', 11 | '(351) 2## ### ###', 12 | '(351) 91#######', 13 | '(351) 92#######', 14 | '(351) 93#######', 15 | '(351) 96#######', 16 | '(351) 2########', 17 | '(351) 91# ### ###', 18 | '(351) 92# ### ###', 19 | '(351) 93# ### ###', 20 | '(351) 96# ### ###', 21 | '(351) 2## ### ###', 22 | '(351) 91#######', 23 | '(351) 92#######', 24 | '(351) 93#######', 25 | '(351) 96#######', 26 | '(351) 2########', 27 | '+35191#######', 28 | '+35192#######', 29 | '+35193#######', 30 | '+35196#######', 31 | '+3512########', 32 | '91# ### ###', 33 | '92# ### ###', 34 | '93# ### ###', 35 | '96# ### ###', 36 | '2## ### ###', 37 | '91#######', 38 | '92#######', 39 | '93#######', 40 | '96#######', 41 | '2########', 42 | ) 43 | -------------------------------------------------------------------------------- /faker/providers/ssn/fr_CH/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as SsnProvider 5 | 6 | 7 | class Provider(SsnProvider): 8 | ssn_formats = ("###.####.####.##",) 9 | 10 | def ssn(self): 11 | """ 12 | Returns a 13 digits Swiss SSN named AHV (German) or 13 | AVS (French and Italian) 14 | See: http://www.bsv.admin.ch/themen/ahv/00011/02185/ 15 | """ 16 | def _checksum(digits): 17 | evensum = sum(digits[:-1:2]) 18 | oddsum = sum(digits[1::2]) 19 | return (10 - ((evensum + oddsum * 3) % 10)) % 10 20 | 21 | digits = [7, 5, 6] 22 | # create an array of first 9 elements initialized randomly 23 | digits += self.generator.random.sample(range(10), 9) 24 | # determine the last digit to make it qualify the test 25 | digits.append(_checksum(digits)) 26 | # repeat steps until it does qualify the test 27 | 28 | digits = ''.join([str(d) for d in digits]) 29 | ssn = digits[:3] + '.' \ 30 | + digits[3:7] + '.' \ 31 | + digits[7:11] + '.' \ 32 | + digits[11:] 33 | return ssn 34 | -------------------------------------------------------------------------------- /tests/providers/test_automotive.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | 4 | import re 5 | import unittest 6 | 7 | from faker import Faker 8 | from six import string_types 9 | 10 | 11 | class TestPtBR(unittest.TestCase): 12 | 13 | def setUp(self): 14 | self.factory = Faker('pt_BR') 15 | self.format = re.compile(r'[\w]{3}-[\d]{4}') 16 | 17 | def test_plate_has_been_generated(self): 18 | plate = self.factory.license_plate() 19 | assert isinstance(plate, string_types) 20 | assert self.format.match(plate), "%s is not in the correct format." % plate 21 | 22 | 23 | class TestHuHU(unittest.TestCase): 24 | 25 | def setUp(self): 26 | self.factory = Faker('hu_HU') 27 | 28 | def test_hu_HU_plate_format(self): 29 | plate = self.factory.license_plate() 30 | assert re.match("[A-Z]{3}-\d{3}", plate), "%s is not in the correct format." % plate 31 | 32 | 33 | class TestDeDe(unittest.TestCase): 34 | 35 | def setUp(self): 36 | self.factory = Faker('de_DE') 37 | 38 | def test_de_DE_plate_format(self): 39 | plate = self.factory.license_plate() 40 | assert re.match(r"[A-Z\u00D6\u00DC]{1,3}-[A-Z]{1,2}-\d{1,4}", plate, flags=re.UNICODE), "%s is not in the correct format." % plate 41 | -------------------------------------------------------------------------------- /faker/providers/bank/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | localized = True 4 | default_locale = 'en_GB' 5 | 6 | from .. import BaseProvider 7 | import string 8 | from string import ascii_uppercase 9 | import re 10 | 11 | class Provider(BaseProvider): 12 | """ 13 | Provider for IBAN/BBAN: it generates valid (valid length, valid checksum) 14 | IBAN/BBANs for the given country. But the ids of the banks are random and 15 | not valid banks! Same for account numbers. 16 | """ 17 | 18 | ALPHA = {c: str(ord(c) % 55) for c in string.ascii_uppercase} 19 | 20 | # see https://en.wikipedia.org/wiki/International_Bank_Account_Number 21 | bban_format = '????#############' 22 | country_code = 'GB' 23 | 24 | def bank_country(self): 25 | return self.country_code 26 | 27 | def bban(self): 28 | temp = re.sub(r'\?', 29 | lambda x: self.random_element(ascii_uppercase), 30 | self.bban_format) 31 | return self.numerify(temp) 32 | 33 | def iban(self): 34 | bban = self.bban() 35 | 36 | check = bban + self.country_code + '00' 37 | check = int(''.join(self.ALPHA.get(c, c) for c in check)) 38 | check = 98 - (check % 97) 39 | check = str(check).zfill(2) 40 | 41 | return self.country_code + check + bban 42 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # https://ci.appveyor.com/project/joke2k/faker 2 | build: false 3 | 4 | environment: 5 | PYTHONIOENCODING: "utf-8" 6 | matrix: 7 | - PYTHON: "C:\\Python27" 8 | PYTHON_VERSION: "2.7.x" 9 | PYTHON_ARCH: "32" 10 | 11 | - PYTHON: "C:\\Python35" 12 | PYTHON_VERSION: "3.5.x" 13 | PYTHON_ARCH: "32" 14 | 15 | - PYTHON: "C:\\Python36" 16 | PYTHON_VERSION: "3.6.x" 17 | PYTHON_ARCH: "32" 18 | 19 | - PYTHON: "C:\\Python37" 20 | PYTHON_VERSION: "3.7.x" 21 | PYTHON_ARCH: "32" 22 | 23 | - PYTHON: "C:\\Python27-x64" 24 | PYTHON_VERSION: "2.7.x" 25 | PYTHON_ARCH: "64" 26 | 27 | - PYTHON: "C:\\Python35-x64" 28 | PYTHON_VERSION: "3.5.x" 29 | PYTHON_ARCH: "64" 30 | 31 | - PYTHON: "C:\\Python36-x64" 32 | PYTHON_VERSION: "3.6.x" 33 | PYTHON_ARCH: "64" 34 | 35 | - PYTHON: "C:\\Python37-x64" 36 | PYTHON_VERSION: "3.7.x" 37 | PYTHON_ARCH: "64" 38 | 39 | init: 40 | - "ECHO %PYTHON%" 41 | - ps: "ls C:/Python*" 42 | 43 | install: 44 | - "%PYTHON%/python.exe -m pip install -U pip" 45 | - "%PYTHON%/Scripts/pip.exe install -e ." 46 | - "%PYTHON%/Scripts/pip.exe install -r tests/requirements.txt" 47 | 48 | test_script: 49 | - "%PYTHON%/Scripts/pip.exe --version" 50 | - "%PYTHON%/python.exe setup.py test" 51 | -------------------------------------------------------------------------------- /faker/providers/ssn/it_IT/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 'it_IT ssn provider (yields italian fiscal codes)' 3 | 4 | from __future__ import unicode_literals 5 | from string import ascii_uppercase, digits 6 | from .. import Provider as SsnProvider 7 | 8 | 9 | ALPHANUMERICS = sorted(digits + ascii_uppercase) 10 | ALPHANUMERICS_DICT = dict((char, index) 11 | for index, char in enumerate(ALPHANUMERICS)) 12 | CHECKSUM_TABLE = ( 13 | (1, 0, 5, 7, 9, 13, 15, 17, 19, 21, 1, 0, 5, 7, 9, 13, 15, 17, 19, 14 | 21, 2, 4, 18, 20, 11, 3, 6, 8, 12, 14, 16, 10, 22, 25, 24, 23), 15 | (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 16 | 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25)) 17 | 18 | 19 | def checksum(value): 20 | ''' 21 | Calculates the checksum char used for the 16th char. 22 | Author: Vincenzo Palazzo 23 | ''' 24 | return chr(65 + sum(CHECKSUM_TABLE[index % 2][ALPHANUMERICS_DICT[char]] 25 | for index, char in enumerate(value)) % 26) 26 | 27 | 28 | class Provider(SsnProvider): 29 | ''' 30 | Generates italian fiscal codes. 31 | ''' 32 | fiscal_code_format = '??????##?##?###' 33 | 34 | def ssn(self): 35 | code = self.bothify(self.fiscal_code_format).upper() 36 | return code + checksum(code) 37 | -------------------------------------------------------------------------------- /faker/providers/company/pt_PT/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as CompanyProvider 4 | 5 | 6 | class Provider(CompanyProvider): 7 | formats = ( 8 | '{{last_name}} {{company_suffix}}', 9 | '{{last_name}} {{last_name}} {{company_suffix}}', 10 | '{{last_name}}', 11 | '{{last_name}}', 12 | ) 13 | 14 | catch_phrase_formats = ( 15 | '{{catch_phrase_noun}} {{catch_phrase_verb}} {{catch_phrase_attribute}}', ) 16 | 17 | nouns = ( 18 | 'a segurança', 'o prazer', 'o conforto', 'a simplicidade', 'a certeza', 19 | 'a arte', 'o poder', 'o direito', 'a possibilidade', 'a vantagem', 20 | 'a liberdade' 21 | ) 22 | 23 | verbs = ( 24 | 'de conseguir', 'de avançar', 'de evoluir', 'de mudar', 'de inovar', 25 | 'de ganhar', 'de atingir os seus objetivos', 26 | 'de concretizar seus projetos', 'de realizar seus sonhos' 27 | ) 28 | 29 | attributes = ( 30 | 'de maneira eficaz', 'mais rapidamente', 'mais facilmente', 31 | 'simplesmente', 'com toda a tranquilidade', 'antes de tudo', 32 | 'naturalmente', 'sem preocupação', 'em estado puro', 'com força total', 33 | 'direto da fonte', 'com confiança' 34 | ) 35 | 36 | company_suffixes = ('S/A', 'S.A.', 'Lda.', 'e Filhos') 37 | -------------------------------------------------------------------------------- /faker/providers/internet/uk_UA/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | 4 | from .. import Provider as InternetProvider 5 | 6 | 7 | class Provider(InternetProvider): 8 | free_email_domains = ( 9 | 'email.ua', 'gmail.com', 'gov.ua', 'i.ua', 'meta.ua', 'ukr.net' 10 | ) 11 | tlds = ('com', 'info', 'net', 'org', 'ua', 'укр') 12 | 13 | replacements = ( 14 | ('А', 'a'), ('Б', 'b'), ('В', 'v'), ('Г', 'h'), ('Ґ', 'g'), ('Д', 'd'), 15 | ('Е', 'e'), ('Є', 'ye'), ('Ж', 'zh'), ('З', 'z'), ('И', 'y'), 16 | ('І', 'i'), ('Ї', 'yi'), ('Й', 'y'), ('К', 'k'), ('Л', 'l'), 17 | ('М', 'm'), ('Н', 'n'), ('О', 'o'), ('П', 'p'), ('Р', 'r'), ('С', 's'), 18 | ('Т', 't'), ('У', 'u'), ('Ф', 'f'), ('Х', 'kh'), ('Ц', 'ts'), 19 | ('Ч', 'ch'), ('Ш', 'sh'), ('Щ', 'shch'), ('Ь', 'ʹ'), ('Ю', 'yu'), 20 | ('Я', 'ya'), ('а', 'a'), ('б', 'b'), ('в', 'v'), ('г', 'h'), 21 | ('ґ', 'g'), ('д', 'd'), ('е', 'e'), ('є', 'ie'), ('ж', 'zh'), 22 | ('з', 'z'), ('и', 'y'), ('і', 'i'), ('ї', 'i'), ('й', 'i'), 23 | ('к', 'k'), ('л', 'l'), ('м', 'm'), ('н', 'n'), ('о', 'o'), ('п', 'p'), 24 | ('р', 'r'), ('с', 's'), ('т', 't'), ('у', 'u'), ('ф', 'f'), 25 | ('х', 'kh'), ('ц', 'ts'), ('ч', 'ch'), ('ш', 'sh'), ('щ', 'shch'), 26 | ('ь', 'ʹ'), ('ю', 'iu'), ('я', 'ia') 27 | ) 28 | -------------------------------------------------------------------------------- /faker/providers/internet/ar_AA/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as InternetProvider 5 | 6 | 7 | class Provider(InternetProvider): 8 | 9 | replacements = ( 10 | ('س', 's'), 11 | ('ق', 'q'), 12 | ('ب', 'b'), 13 | ('خ', 'x'), 14 | ('ش', '$'), 15 | ('َ', 'a'), 16 | ('ئ', '}'), 17 | ('إ', '<'), 18 | ('ل', 'l'), 19 | ('ٰ', '`'), 20 | ('ف', 'f'), 21 | ('و', 'w'), 22 | ('ض', 'D'), 23 | ('ي', 'y'), 24 | ('ُ', 'u'), 25 | ('ة', 'p'), 26 | ('ظ', 'Z'), 27 | ('ث', 'v'), 28 | ('ـ', '_'), 29 | ('ج', 'j'), 30 | ('د', 'd'), 31 | ('ح', 'H'), 32 | ('ا', 'A'), 33 | ('أ', '>'), 34 | ('ر', 'r'), 35 | ('ى', 'Y'), 36 | ('ذ', '*'), 37 | ('ْ', 'o'), 38 | ('ن', 'n'), 39 | ('ّ', '~'), 40 | ('ك', 'k'), 41 | ('ء', "'"), 42 | ('ط', 'T'), 43 | ('ت', 't'), 44 | ('ه', 'h'), 45 | ('ً', 'F'), 46 | ('ؤ', '&'), 47 | ('ٍ', 'K'), 48 | ('ِ', 'i'), 49 | ('ص', 'S'), 50 | ('ٱ', '{'), 51 | ('ٌ', 'N'), 52 | ('م', 'm'), 53 | ('ز', 'z'), 54 | ('ع', 'E'), 55 | ('آ', '|'), 56 | ('غ', 'g') 57 | ) 58 | -------------------------------------------------------------------------------- /faker/providers/ssn/hr_HR/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as SsnProvider 5 | 6 | 7 | def checksum(digits): 8 | """ 9 | Calculate and return control digit for given list of digits based on 10 | ISO7064, MOD 11,10 standard. 11 | """ 12 | remainder = 10 13 | for digit in digits: 14 | remainder = (remainder + digit) % 10 15 | if remainder == 0: 16 | remainder = 10 17 | remainder = (remainder * 2) % 11 18 | 19 | control_digit = 11 - remainder 20 | if control_digit == 10: 21 | control_digit = 0 22 | return control_digit 23 | 24 | 25 | class Provider(SsnProvider): 26 | """ 27 | The Personal identification number (Croatian: Osobni identifikacijski 28 | broj or OIB) is a permanent national identification number of every 29 | Croatian citizen and legal persons domiciled in the Republic of Croatia. 30 | 31 | OIB consists of 11 digits which contain no personal information. The OIB 32 | is constructed from ten randomly chosen digits and one digit control number 33 | (international standard ISO 7064, module 11.10). 34 | """ 35 | 36 | def ssn(self): 37 | digits = self.generator.random.sample(range(10), 10) 38 | 39 | digits.append(checksum(digits)) 40 | 41 | return ''.join(map(str, digits)) 42 | -------------------------------------------------------------------------------- /faker/providers/company/zh_CN/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | from .. import Provider as CompanyProvider 4 | 5 | 6 | class Provider(CompanyProvider): 7 | formats = ["{{company_prefix}}{{company_suffix}}", ] 8 | 9 | company_prefixes = ["超艺", "和泰", "九方", "鑫博腾飞", "戴硕电子", "济南亿次元", 10 | "海创", "创联世纪", "凌云", "泰麒麟", "彩虹", "兰金电子", 11 | "晖来计算机", "天益", "恒聪百汇", "菊风公司", "惠派国际公司", 12 | "创汇", "思优", "时空盒数字", "易动力", "飞海科技", "华泰通安", 13 | "盟新", "商软冠联", "图龙信息", "易动力", "华远软件", "创亿", 14 | "时刻", "开发区世创", "明腾", "良诺", "天开", "毕博诚", "快讯", 15 | "凌颖信息", "黄石金承", "恩悌", "雨林木风计算机", "双敏电子", 16 | "维旺明", "网新恒天", "数字100", "飞利信", "立信电子", "联通时科", 17 | "中建创业", "新格林耐特", "新宇龙信息", "浙大万朋", "MBP软件", 18 | "昂歌信息", "万迅电脑", "方正科技", "联软", "七喜", "南康", "银嘉", 19 | "巨奥", "佳禾", "国讯", "信诚致远", "浦华众城", "迪摩", "太极", 20 | "群英", "合联电子", "同兴万点", "襄樊地球村", "精芯", "艾提科信", 21 | "昊嘉", "鸿睿思博", "四通", "富罳", "商软冠联", "诺依曼软件", 22 | "东方峻景", "华成育卓", "趋势", "维涛", "通际名联"] 23 | company_suffixes = [n + "有限公司" for n in ["科技", "网络", "信息", "传媒"]] 24 | 25 | def company_prefix(self): 26 | return self.random_element(self.company_prefixes) 27 | -------------------------------------------------------------------------------- /faker/providers/automotive/ar_JO/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as AutomotiveProvider 5 | 6 | 7 | class Provider(AutomotiveProvider): 8 | # Source: 9 | # https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_Jordan 10 | license_formats = ( 11 | '{{initials}}-####', 12 | '{{initials}}-#####', 13 | ) 14 | 15 | def initials(self): 16 | return self.random_element([ 17 | '1', # Ministers 18 | '2', '3', # Parliament 19 | '5', # General Government 20 | 21 | '6', # Aqaba free zone 22 | '7', '8', # Diplomatic 23 | '9', # Temporary 24 | '10', '23', # Passenger cars 25 | '38', '39', # Crew cabs 26 | '41', '42', # Light goods vehicles 27 | '44', # Tractors 28 | '46', # Motorcycles and scooters 29 | '50', # Taxi 30 | '56', # Small buses 31 | '58', # Coaches 32 | '60', # HGVs 33 | '70', # Rental Cars 34 | '71', # Trailer 35 | '90', # Army 36 | '95', # Ambulance 37 | '96', # Gendarmerie 38 | '99', # Police 39 | ]) 40 | 41 | def license_plate(self): 42 | pattern = self.random_element(self.license_formats) 43 | return self.numerify(self.generator.parse(pattern)) 44 | -------------------------------------------------------------------------------- /tests/providers/test_color.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from re import search 3 | from faker import Faker 4 | 5 | 6 | class TestColor(unittest.TestCase): 7 | 8 | def setUp(self): 9 | self.factory = Faker('en_US') 10 | 11 | def test_safe_hex_color(self): 12 | assert all((search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', self.factory.safe_hex_color()) 13 | for _ in range(1000))) 14 | 15 | def test_hex_color(self): 16 | assert all((search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', self.factory.hex_color()) 17 | for _ in range(1000))) 18 | 19 | def test_rgb_color(self): 20 | maxval = 0 21 | minval = 0 22 | 23 | for _ in range(1000): 24 | current = list(map(int, self.factory.rgb_color().split(','))) 25 | if max(current) > maxval: 26 | maxval = max(current) 27 | if min(current) > minval: 28 | minval = min(current) 29 | 30 | assert maxval <= 255 31 | assert minval >= 0 32 | 33 | def test_rgb_css_color(self): 34 | maxval = 0 35 | minval = 0 36 | 37 | for _ in range(1000): 38 | current = list(map(int, self.factory.rgb_css_color()[4:-1].split(','))) 39 | if max(current) > maxval: 40 | maxval = max(current) 41 | if min(current) > minval: 42 | minval = min(current) 43 | 44 | assert maxval <= 255 45 | assert minval >= 0 46 | -------------------------------------------------------------------------------- /faker/providers/ssn/pt_BR/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as SsnProvider 5 | 6 | 7 | def checksum(digits): 8 | """ 9 | Returns the checksum of CPF digits. 10 | References to the algorithm: 11 | https://pt.wikipedia.org/wiki/Cadastro_de_pessoas_f%C3%ADsicas#Algoritmo 12 | https://metacpan.org/source/MAMAWE/Algorithm-CheckDigits-v1.3.0/lib/Algorithm/CheckDigits/M11_004.pm 13 | """ 14 | s = 0 15 | p = len(digits) + 1 16 | for i in range(0, len(digits)): 17 | s += digits[i] * p 18 | p -= 1 19 | 20 | reminder = s % 11 21 | if reminder == 0 or reminder == 1: 22 | return 0 23 | else: 24 | return 11 - reminder 25 | 26 | 27 | class Provider(SsnProvider): 28 | """ 29 | Provider for Brazilian SSN also known in Brazil as CPF. 30 | There are two methods Provider.ssn and Provider.cpf 31 | The snn returns a valid number with numbers only 32 | The cpf return a valid number formatted with brazilian mask. eg nnn.nnn.nnn-nn 33 | """ 34 | 35 | def ssn(self): 36 | digits = self.generator.random.sample(range(10), 9) 37 | 38 | dv = checksum(digits) 39 | digits.append(dv) 40 | digits.append(checksum(digits)) 41 | 42 | return ''.join(map(str, digits)) 43 | 44 | def cpf(self): 45 | c = self.ssn() 46 | return c[:3] + '.' + c[3:6] + '.' + c[6:9] + '-' + c[9:] 47 | -------------------------------------------------------------------------------- /tests/providers/test_currency.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from faker import Faker 4 | from faker.providers.currency import Provider as CurrencyProvider 5 | 6 | 7 | class TestCurrencyProvider(unittest.TestCase): 8 | def setUp(self): 9 | self.factory = Faker() 10 | 11 | def test_currency(self): 12 | for _ in range(99): 13 | cur = self.factory.currency() 14 | self.assertIsInstance(cur, tuple) 15 | self.assertIn(cur, CurrencyProvider.currencies) 16 | 17 | def test_currency_code(self): 18 | for _ in range(99): 19 | code = self.factory.currency_code() 20 | self.assertIsInstance(code, str) 21 | 22 | def test_currency_name(self): 23 | for _ in range(99): 24 | name = self.factory.currency_name() 25 | self.assertIsInstance(name, str) 26 | 27 | def test_cryptocurrency(self): 28 | for _ in range(99): 29 | cur = self.factory.cryptocurrency() 30 | self.assertIsInstance(cur, tuple) 31 | self.assertIn(cur, CurrencyProvider.cryptocurrencies) 32 | 33 | def test_cryptocurrency_code(self): 34 | for _ in range(99): 35 | code = self.factory.cryptocurrency_code() 36 | self.assertIsInstance(code, str) 37 | 38 | def test_cryptocurrency_name(self): 39 | for _ in range(99): 40 | name = self.factory.cryptocurrency_name() 41 | self.assertIsInstance(name, str) 42 | -------------------------------------------------------------------------------- /faker/providers/company/fr_CH/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from ..fr_FR import Provider as CompanyProvider 4 | 5 | 6 | class Provider(CompanyProvider): 7 | company_suffixes = ('SA', 'Sàrl.') 8 | 9 | def ide(self): 10 | """ 11 | Generates a IDE number (9 digits). 12 | http://www.bfs.admin.ch/bfs/portal/fr/index/themen/00/05/blank/03/02.html 13 | """ 14 | def _checksum(digits): 15 | factors = (5, 4, 3, 2, 7, 6, 5, 4) 16 | sum_ = 0 17 | for i in range(len(digits)): 18 | sum_ += digits[i] * factors[i] 19 | return sum_ % 11 20 | 21 | while True: 22 | # create an array of first 8 elements initialized randomly 23 | digits = self.generator.random.sample(range(10), 8) 24 | # sum those 8 digits according to (part of) the "modulo 11" 25 | sum_ = _checksum(digits) 26 | # determine the last digit to make it qualify the test 27 | control_number = 11 - sum_ 28 | if control_number != 10: 29 | digits.append(control_number) 30 | break 31 | 32 | digits = ''.join([str(digit) for digit in digits]) 33 | # finally return our random but valid BSN 34 | return 'CHE-' + digits[0:3] + '.'\ 35 | + digits[3:6] + '.'\ 36 | + digits[6:9] 37 | uid = ide 38 | # uid: german name for ide 39 | idi = ide 40 | # idi: italian name for ide 41 | -------------------------------------------------------------------------------- /faker/utils/loading.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | from importlib import import_module 4 | import pkgutil 5 | 6 | 7 | def get_path(module): 8 | if getattr(sys, 'frozen', False): 9 | # frozen 10 | base_dir = os.path.dirname(sys.executable) 11 | lib_dir = os.path.join(base_dir, "lib") 12 | module_to_rel_path = os.path.join(*module.__package__.split(".")) 13 | path = os.path.join(lib_dir, module_to_rel_path) 14 | else: 15 | # unfrozen 16 | path = os.path.dirname(os.path.realpath(module.__file__)) 17 | return path 18 | 19 | 20 | def list_module(module): 21 | path = get_path(module) 22 | modules = [name for _, name, 23 | is_pkg in pkgutil.iter_modules([path]) if is_pkg] 24 | return modules 25 | 26 | 27 | def find_available_locales(providers): 28 | available_locales = set() 29 | 30 | for provider_path in providers: 31 | 32 | provider_module = import_module(provider_path) 33 | if getattr(provider_module, 'localized', False): 34 | langs = list_module(provider_module) 35 | available_locales.update(langs) 36 | return available_locales 37 | 38 | 39 | def find_available_providers(modules): 40 | available_providers = set() 41 | for providers_mod in modules: 42 | providers = [ 43 | '.'.join([providers_mod.__package__, mod]) 44 | for mod in list_module(providers_mod) if mod != '__pycache__' 45 | ] 46 | available_providers.update(providers) 47 | return sorted(available_providers) 48 | -------------------------------------------------------------------------------- /faker/providers/ssn/nl_NL/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as SsnProvider 5 | 6 | 7 | class Provider(SsnProvider): 8 | 9 | def ssn(self): 10 | """ 11 | Returns a 9 digits Dutch SSN called "burgerservicenummer (BSN)". 12 | 13 | the Dutch "burgerservicenummer (BSN)" needs to pass the "11-proef", 14 | which is a check digit approach; this function essentially reverses 15 | the checksum steps to create a random valid BSN (which is 9 digits). 16 | """ 17 | # see http://nl.wikipedia.org/wiki/Burgerservicenummer (in Dutch) 18 | def _checksum(digits): 19 | factors = (9, 8, 7, 6, 5, 4, 3, 2, -1) 20 | s = 0 21 | for i in range(len(digits)): 22 | s += digits[i] * factors[i] 23 | return s 24 | 25 | while True: 26 | # create an array of first 8 elements initialized randomly 27 | digits = self.generator.random.sample(range(10), 8) 28 | # sum those 8 digits according to (part of) the "11-proef" 29 | s = _checksum(digits) 30 | # determine the last digit to make it qualify the test 31 | digits.append((s % 11) % 10) 32 | # repeat steps until it does qualify the test 33 | if 0 == (_checksum(digits) % 11): 34 | break 35 | 36 | # build the resulting BSN 37 | bsn = "".join([str(e) for e in digits]) 38 | # finally return our random but valid BSN 39 | return bsn 40 | -------------------------------------------------------------------------------- /faker/providers/phone_number/en_AU/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | # Local calls 8 | '#### ####', 9 | '####-####', 10 | '####.####', # domain registrars apparently use this 11 | '########', 12 | # National dialing 13 | '0{{area_code}} #### ####', 14 | '0{{area_code}}-####-####', 15 | '0{{area_code}}.####.####', 16 | '0{{area_code}}########', 17 | # Optional parenthesis 18 | '(0{{area_code}}) #### ####', 19 | '(0{{area_code}})-####-####', 20 | '(0{{area_code}}).####.####', 21 | '(0{{area_code}})########', 22 | # International drops the 0 23 | '+61 {{area_code}} #### ####', 24 | '+61-{{area_code}}-####-####', 25 | '+61.{{area_code}}.####.####', 26 | '+61{{area_code}}########', 27 | # 04 Mobile telephones (Australia-wide) mostly commonly written 4 - 3 - 28 | # 3 instead of 2 - 4 - 4 29 | '04## ### ###', 30 | '04##-###-###', 31 | '04##.###.###', 32 | '+61 4## ### ###', 33 | '+61-4##-###-###', 34 | '+61.4##.###.###', 35 | ) 36 | 37 | def area_code(self): 38 | return self.numerify(self.random_element( 39 | ['2', 40 | '3', 41 | '7', 42 | '8'])) 43 | 44 | def phone_number(self): 45 | pattern = self.random_element(self.formats) 46 | return self.numerify(self.generator.parse(pattern)) 47 | -------------------------------------------------------------------------------- /faker/providers/company/zh_TW/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | from .. import Provider as CompanyProvider 4 | 5 | 6 | class Provider(CompanyProvider): 7 | formats = ("{{company_prefix}}{{company_suffix}}", ) 8 | 9 | company_prefixes = ( 10 | "品王餐飲", "一統企業", "品誠", "台灣電信", 11 | "Goagle", "一統星巴克", "台日積體電路", "榮長航空", 12 | "台灣印無品良", "華中航空", "台灣人銀行", "國中鋼鐵", 13 | "海鴻精密", "台灣鐵高", "家宜家居(KIEA)", "天上雜誌", 14 | "台灣力電", "碩華電腦", "雄豹旅遊", "光新三越百貨", 15 | "台灣軟微", "鐵台", "一統超商", "碁宏", 16 | "創群光電(奇原美電子)", "台灣酒菸", "美奧廣告", "AYHOO!摩奇", 17 | "台灣台油", "達宏國際電子", "華晶國際酒店", "秀威影城", 18 | "王鼎餐飲集團", "台灣五星電子", "遊戲葡萄數位科技", "橋子王生技", 19 | "大八電視", "台灣業糖", "都亞緻麗", "台灣來自水", 20 | "麥當當", "風微廣場", "見遠雜誌", "石金堂", 21 | "邦城文化事業", "華中郵政", "達友光電", "中台信託商業銀行", 22 | "台北登來喜大飯店", "全味食品工業", "遠西百貨", "旗花(台灣銀)行", 23 | "冠智科技", "丹味企業", "發聯科技", "台灣雅萊(Y'ORÉAL)", 24 | "古太可口可樂", "榮長海運", "達廣電腦", "華福大飯店", 25 | "立三電視", "星燦國際旅行社", "衣優庫(Nuiqlo)", "德汎", 26 | "台北眾大捷運", "共公電視", "明陽海運", "雄遠建設事業", 27 | "台灣迪奧汽車", "台灣地土銀行", "天中電視", "月日光半導體", 28 | "塑台石化", "樂可旅遊集團", "信永藥品", "輝燁企業", 29 | "興復航空運輸", "豐兆國際商業銀行", "平太洋崇光百貨", "神漢名店百貨", 30 | "台灣士賓", "賓國大飯店", "業商週刊", "台灣BIM", 31 | "湖劍山世界", "合作庫金商業銀行", "台北邦富商業銀行", "愛味之", 32 | "邦富人壽保險", "律理法律", "心安食品服務(斯摩漢堡)", "松黑", 33 | "台灣生資堂", "鮮爭", "達台電子", "聯燁鋼鐵", "華聯電子", 34 | "瑞輝大藥廠", "隆豐大飯店(北台君悅)", "資華粧業(生資堂)") 35 | 36 | company_suffixes = ("", "有限公司", "股份有限公司", "資訊有限公司") 37 | 38 | def company_prefix(self): 39 | return self.random_element(self.company_prefixes) 40 | -------------------------------------------------------------------------------- /faker/providers/lorem/he_IL/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | from .. import Provider as LoremProvider 4 | 5 | 6 | class Provider(LoremProvider): 7 | word_list = ( 8 | "אאוגו", "אגת", "אדיפיסינג", "אדנדום", "אט", "איאקוליס", "איבן", "איף", 9 | "איפסום", "אלית", "אלמנקום", "אמט", "אס", "אפאח", "אקווזמן", "ארווס", 10 | "בגורמי", "בורק?", "בלובק", "בלינדו", "בלינך", "בליקרה", "בעליק", 11 | "בעריר", "בראיט", "ברומץ", "בריקנה", "ברשג", "גדדיש", "גולר", "גק", 12 | "דול", "דולור", "דומור", "דז", "דיאם", "דלאמת", "דס", "הבקיץ", "הדש", 13 | "הועניב", "היושבב", "הכייר", "השמה", "התידם", "וואל", "וולופטה", 14 | "וחאית", "ולחת", "ולתיעם", "ומעיוט", "ומרגשח", "וסטיבולום", "וסתעד", 15 | "וק", "ותלברו", "זותה", "חשלו", "טידום", "יבש", "יהול", "ישבעס", "כאנה", 16 | "כלרשט", "להאמית", "לורם", "ליאמום", "ליבם", "ליץ", "לכימפו", "לכנו", 17 | "לכנוץ", "למטכין", "למרקוח", "למרקל", "לפמעט", "לפריקך", "לפתיעם", 18 | "לקטוס", "לרטי", "לתיג", "לתכי", "מא", "מגמש", "מונחף", "מונפרד", 19 | "מונפרר", "מוסן", "מורגם", "מיחוצים", "מנורך", "מנכם", "מנק", "מנת", 20 | "מרגשי", "נובש", "נולום", "נון", "נונסטי", "ניבאה", "ניסי", "ניצאחו", 21 | "נמרגי", "נשואי", "סאפיאן", "סוברט", "סולגק", "סוליסי", "סחטיר", 22 | "סטום", "סיט", "סילקוף", "סכעיט", "סת", "סתשם", "עמחליף", "ערששף", 23 | "פוסיליס", "צוט", "צופעט", "צורק", "קוויז", "קוויס", "קולהע", "קולורס", 24 | "קונדימנטום", "קונסקטורר", "קורוס", "קלאצי", "קלובר", "קראס", "קרהשק", 25 | "רוגצה", "שבצק", "שהכים", "שלושע", "שמחויט", "שנרא", "שעותלשך", "שערש", 26 | "תוק", "תצטנפל", "תצטריק", "תרבנך" 27 | ) 28 | -------------------------------------------------------------------------------- /docs/communityproviders.rst: -------------------------------------------------------------------------------- 1 | .. ref-communityproviders: 2 | 3 | Community Providers 4 | =================== 5 | 6 | Here's a list of Providers written by the community: 7 | 8 | +---------------+--------------------------+----------------------------------+ 9 | | Provider name | Description | URL | 10 | +===============+==========================+==================================+ 11 | | WebProvider | Web-related data such as | `faker_web`_ + 12 | | | mime-type and web server | + 13 | | | versions. | + 14 | +---------------+--------------------------+----------------------------------+ 15 | | CloudProvider | Cloud-related data | `faker_cloud`_ + 16 | | | generic or specialized | + 17 | | | by cloud. | + 18 | +---------------+--------------------------+----------------------------------+ 19 | | Wi-Fi ESSID | Fake Wi-Fi ESSIDs. | `faker_wifi_essid`_ + 20 | +---------------+--------------------------+----------------------------------+ 21 | | Credit Score | Fake credit score data | `faker_credit_score`_ | 22 | | | for testing purposes | | 23 | +---------------+--------------------------+----------------------------------+ 24 | 25 | .. _faker_web: https://pypi.org/project/faker_web/ 26 | .. _faker_cloud: https://pypi.org/project/faker-cloud/ 27 | .. _faker_wifi_essid: https://pypi.org/project/faker-wifi-essid/ 28 | .. _faker_credit_score: https://pypi.org/project/faker-credit-score/ 29 | -------------------------------------------------------------------------------- /faker/providers/ssn/sv_SE/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as SsnProvider 5 | import datetime 6 | 7 | 8 | class Provider(SsnProvider): 9 | 10 | def ssn(self, min_age=18, max_age=90): 11 | """ 12 | Returns a 10 digit Swedish SSN, "Personnummer". 13 | 14 | It consists of 10 digits in the form YYMMDD-SSGQ, where 15 | YYMMDD is the date of birth, SSS is a serial number 16 | and Q is a control character (Luhn checksum). 17 | 18 | http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden) 19 | """ 20 | def _luhn_checksum(number): 21 | def digits_of(n): 22 | return [int(d) for d in str(n)] 23 | digits = digits_of(number) 24 | odd_digits = digits[-1::-2] 25 | even_digits = digits[-2::-2] 26 | checksum = 0 27 | checksum += sum(odd_digits) 28 | for d in even_digits: 29 | checksum += sum(digits_of(d * 2)) 30 | return checksum % 10 31 | 32 | def _calculate_luhn(partial_number): 33 | check_digit = _luhn_checksum(int(partial_number) * 10) 34 | return check_digit if check_digit == 0 else 10 - check_digit 35 | 36 | age = datetime.timedelta( 37 | days=self.generator.random.randrange(min_age * 365, max_age * 365)) 38 | birthday = datetime.datetime.now() - age 39 | pnr_date = birthday.strftime('%y%m%d') 40 | suffix = str(self.generator.random.randrange(0, 999)).zfill(3) 41 | luhn_checksum = str(_calculate_luhn(pnr_date + suffix)) 42 | pnr = '{0}-{1}{2}'.format(pnr_date, suffix, luhn_checksum) 43 | 44 | return pnr 45 | -------------------------------------------------------------------------------- /faker/providers/automotive/ar_PS/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as AutomotiveProvider 5 | 6 | 7 | class Provider(AutomotiveProvider): 8 | # Source: 9 | # https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_the_Palestinian_National_Authority 10 | license_formats = ( 11 | # Private vehicles 12 | '{{district}}-####-3#', 13 | '{{district}}-####-4#', 14 | '{{district}}-####-7#', 15 | '{{district}}-####-9#', 16 | # Public transport 17 | '{{district}}-####-30', 18 | # Authority vehicles 19 | '####', 20 | # New police vehicles 21 | '####-99', 22 | 23 | # Gaza strip after 2012 24 | 25 | # Private 26 | '1-####-0#', 27 | '3-####-0#', 28 | # Commercial 29 | '1-####-1#', 30 | '3-####-1#', 31 | # Public 32 | '1-####-2#', 33 | '3-####-2#', 34 | # Municipal 35 | '1-####-4#', 36 | '3-####-4#', 37 | # Governmental, and Governmental personal vehicles 38 | '1-####-5#', 39 | '3-####-5#', 40 | ) 41 | 42 | def district(self): 43 | return self.random_element([ 44 | # Gaza Strip 45 | '1', 46 | '3', 47 | 48 | # Northern West Bank (Nablus, Tulkarm, Qalqilya, Jenin) 49 | '4', 50 | '7', 51 | 52 | # Central West Bank (Ramallah, Jerusalem, Jericho) 53 | '5', 54 | '6', 55 | 56 | # Southern West Bank (Bethlehem, Hebron) 57 | '8', 58 | '9', 59 | ]) 60 | 61 | def license_plate(self): 62 | pattern = self.random_element(self.license_formats) 63 | return self.numerify(self.generator.parse(pattern)) 64 | -------------------------------------------------------------------------------- /tests/providers/test_file.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | 3 | import unittest 4 | import re 5 | 6 | from faker import Faker 7 | 8 | 9 | class TestFile(unittest.TestCase): 10 | """ Tests file """ 11 | 12 | def setUp(self): 13 | self.factory = Faker() 14 | 15 | def test_file_path(self): 16 | for _ in range(100): 17 | file_path = self.factory.file_path() 18 | self.assertTrue(re.search(r'\/\w+\/\w+\.\w+', file_path)) 19 | file_path = self.factory.file_path(depth=3) 20 | self.assertTrue(re.search(r'\/\w+\/\w+\/\w+\.\w+', file_path)) 21 | file_path = self.factory.file_path(extension='pdf') 22 | self.assertTrue(re.search(r'\/\w+\/\w+\.pdf', file_path)) 23 | file_path = self.factory.file_path(category='image') 24 | self.assertTrue(re.search(r'\/\w+\/\w+\.(bmp|gif|jpeg|jpg|png|tiff)', file_path)) 25 | 26 | def test_unix_device(self): 27 | reg_device = re.compile('^/dev/(vd|sd|xvd)[a-z]$') 28 | # Test default 29 | for _ in range(100): 30 | path = self.factory.unix_device() 31 | self.assertTrue(reg_device.match(path)) 32 | # Test with prefix 33 | for _ in range(100): 34 | path = self.factory.unix_device('sd') 35 | self.assertTrue(reg_device.match(path)) 36 | self.assertTrue(path.startswith('/dev/sd')) 37 | 38 | def test_unix_partition(self): 39 | reg_part = re.compile('^/dev/(vd|sd|xvd)[a-z]\d$') 40 | # Test default 41 | for _ in range(100): 42 | path = self.factory.unix_partition() 43 | self.assertTrue(reg_part.match(path)) 44 | # Test with prefix 45 | for _ in range(100): 46 | path = self.factory.unix_partition('sd') 47 | self.assertTrue(reg_part.match(path)) 48 | self.assertTrue(path.startswith('/dev/sd')) 49 | -------------------------------------------------------------------------------- /faker/providers/isbn/rules.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """ 3 | This module exists solely to figure how long a registrant/publication 4 | number may be within an ISBN. The rules change based on the prefix and 5 | language/region. This list of rules only encapsulates the 978 prefix 6 | for English books. 978 is the largest and, until recently, the only 7 | prefix. 8 | 9 | The complete list of prefixes and rules can be found at 10 | https://www.isbn-international.org/range_file_generation 11 | """ 12 | 13 | from collections import namedtuple 14 | 15 | RegistrantRule = namedtuple( 16 | 'RegistrantRule', ['min', 'max', 'registrant_length']) 17 | 18 | # Structure: RULES[`EAN Prefix`][`Registration Group`] = [Rule1, Rule2, ...] 19 | RULES = { 20 | '978': { 21 | '0': [ 22 | RegistrantRule('0000000', '1999999', 2), 23 | RegistrantRule('2000000', '2279999', 3), 24 | RegistrantRule('2280000', '2289999', 4), 25 | RegistrantRule('2290000', '6479999', 3), 26 | RegistrantRule('6480000', '6489999', 7), 27 | RegistrantRule('6490000', '6999999', 3), 28 | RegistrantRule('7000000', '8499999', 4), 29 | RegistrantRule('8500000', '8999999', 5), 30 | RegistrantRule('9000000', '9499999', 6), 31 | RegistrantRule('9500000', '9999999', 7) 32 | ], 33 | '1': [ 34 | RegistrantRule('0000000', '0999999', 2), 35 | RegistrantRule('1000000', '3999999', 3), 36 | RegistrantRule('4000000', '5499999', 4), 37 | RegistrantRule('5500000', '7319999', 5), 38 | RegistrantRule('7320000', '7399999', 7), 39 | RegistrantRule('7400000', '8697999', 5), 40 | RegistrantRule('8698000', '9729999', 6), 41 | RegistrantRule('9730000', '9877999', 4), 42 | RegistrantRule('9878000', '9989999', 6), 43 | RegistrantRule('9990000', '9999999', 7) 44 | ] 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/providers/__init__.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from faker import Faker 3 | from faker.providers import BaseProvider 4 | 5 | 6 | class BaseProviderTestCase(unittest.TestCase): 7 | def setUp(self): 8 | self.factory = Faker('en_US') 9 | self.factory.seed(0) 10 | self.provider = BaseProvider(generator=self.factory) 11 | 12 | def test_random_digit_or_empty(self): 13 | ret = self.provider.random_digit_or_empty() 14 | assert isinstance(ret, int) 15 | assert ret >= 0 and ret <= 9 16 | 17 | self.factory.seed(1) 18 | assert self.provider.random_digit_or_empty() == '' 19 | 20 | def test_random_digit_not_null_or_empty(self): 21 | ret = self.provider.random_digit_not_null_or_empty() 22 | assert isinstance(ret, int) 23 | assert ret >= 0 and ret <= 9 24 | 25 | self.factory.seed(1) 26 | assert self.provider.random_digit_not_null_or_empty() == '' 27 | 28 | def test_randomize_nb_elements(self): 29 | assert self.provider.randomize_nb_elements(number=1, le=True, ge=True) == 1 30 | 31 | assert self.provider.randomize_nb_elements(le=True, ge=True) == 10 32 | 33 | number = 9999 34 | random_times = 100 35 | lower_bound = int(number * 0.6) 36 | upper_bound = int(number * 1.4) 37 | 38 | for _ in range(random_times): 39 | res = self.provider.randomize_nb_elements(number=number, le=True) 40 | assert res >= lower_bound 41 | assert res <= number, "'{}' is not <= than '{}'".format(res, number) 42 | 43 | for _ in range(random_times): 44 | res = self.provider.randomize_nb_elements(number=number, ge=True) 45 | assert res >= number 46 | assert res <= upper_bound 47 | 48 | for _ in range(random_times): 49 | res = self.provider.randomize_nb_elements(number=number) 50 | assert res >= lower_bound 51 | assert res <= upper_bound 52 | -------------------------------------------------------------------------------- /faker/providers/internet/ru_RU/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | user_name_formats = ( 8 | '{{last_name_female}}.{{first_name_female}}', 9 | '{{last_name_male}}.{{first_name_male}}', 10 | '{{last_name_male}}.{{first_name_male}}', 11 | '{{first_name_male}}.{{last_name_male}}', 12 | '{{first_name}}##', 13 | '{{first_name}}_##', 14 | '?{{last_name}}', 15 | '{{first_name}}{{year}}', 16 | '{{first_name}}_{{year}}' 17 | ) 18 | 19 | email_formats = ( 20 | '{{user_name}}@{{free_email_domain}}', 21 | '{{user_name}}@{{domain_name}}') 22 | 23 | free_email_domains = ( 24 | 'gmail.com', 25 | 'yahoo.com', 26 | 'hotmail.com', 27 | 'mail.ru', 28 | 'yandex.ru', 29 | 'rambler.ru') 30 | 31 | tlds = ('ru', 'com', 'biz', 'info', 'net', 'org', 'edu') 32 | 33 | replacements = ( 34 | ('А', 'a'), ('Б', 'b'), ('В', 'v'), ('Г', 'g'), ('Д', 'd'), ('Е', 'e'), 35 | ('Ё', 'e'), ('Ж', 'zh'), ('З', 'z'), ('И', 'i'), ('Й', ''), ('К', 'k'), 36 | ('Л', 'l'), ('М', 'm'), ('Н', 'n'), ('О', 'o'), ('П', 'p'), ('Р', 'r'), 37 | ('С', 's'), ('Т', 't'), ('У', 'u'), ('Ф', 'f'), ('Х', 'h'), ('Ц', 'ts'), 38 | ('Ч', 'ch'), ('Ш', 'sh'), ('Щ', 'shch'), ('Ъ', ''), ('Ы', 'i'), 39 | ('Ь', ''), ('Э', 'e'), ('Ю', 'yu'), ('Я', 'ya'), ('а', 'a'), ('б', 'b'), 40 | ('в', 'v'), ('г', 'g'), ('д', 'd'), ('е', 'e'), ('ё', 'e'), ('ж', 'zh'), 41 | ('з', 'z'), ('и', 'i'), ('й', ''), ('к', 'k'), ('л', 'l'), ('м', 'm'), 42 | ('н', 'n'), ('о', 'o'), ('п', 'p'), ('р', 'r'), ('с', 's'), ('т', 't'), 43 | ('у', 'u'), ('ф', 'f'), ('х', 'h'), ('ц', 'ts'), ('ч', 'ch'), 44 | ('ш', 'sh'), ('щ', 'shch'), ('ъ', ''), ('ы', 'i'), ('ь', ''), 45 | ('э', 'e'), ('ю', 'ju'), ('я', 'ja') 46 | ) 47 | -------------------------------------------------------------------------------- /faker/providers/phone_number/ar_JO/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | # Source: https://en.wikipedia.org/wiki/Telephone_numbers_in_Jordan 7 | 8 | cellphone_formats = ( 9 | '+9627{{operator_id}}#######', 10 | '+962 7 {{operator_id}}### ####', 11 | '07{{operator_id}}#######', 12 | '07{{operator_id}} ### ####', 13 | ) 14 | 15 | telephone_formats = ( 16 | '+962{{area_code}}#######', 17 | '+962 {{area_code}} ### ####', 18 | '0{{area_code}}#######', 19 | '0{{area_code}} ### ####', 20 | ) 21 | 22 | services_phones_formats = ( 23 | '9##', 24 | '12##', 25 | '13##', 26 | '14##', 27 | ) 28 | 29 | formats = cellphone_formats + \ 30 | telephone_formats + \ 31 | services_phones_formats 32 | 33 | def operator_id(self): 34 | return self.random_element([ 35 | '4', 36 | '7', 37 | '8', 38 | '9', 39 | ]) 40 | 41 | def area_code(self): 42 | return self.random_element([ 43 | '2', 44 | '3', 45 | '5', 46 | '6', 47 | '7', 48 | ]) 49 | 50 | def cellphone_number(self): 51 | pattern = self.random_element(self.cellphone_formats) 52 | return self.numerify(self.generator.parse(pattern)) 53 | 54 | def telephone_number(self): 55 | pattern = self.random_element(self.telephone_formats) 56 | return self.numerify(self.generator.parse(pattern)) 57 | 58 | def service_phone_number(self): 59 | pattern = self.random_element(self.services_phones_formats) 60 | return self.numerify(self.generator.parse(pattern)) 61 | 62 | def phone_number(self): 63 | pattern = self.random_element(self.formats) 64 | return self.numerify(self.generator.parse(pattern)) 65 | -------------------------------------------------------------------------------- /faker/utils/distribution.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | import bisect 4 | from faker.generator import random as mod_random 5 | 6 | 7 | def random_sample(random=None): 8 | if random is None: 9 | random = mod_random 10 | return random.uniform(0.0, 1.0) 11 | 12 | 13 | def cumsum(it): 14 | total = 0 15 | for x in it: 16 | total += x 17 | yield total 18 | 19 | 20 | def choices_distribution_unique(a, p, random=None, length=1): 21 | # As of Python 3.7, there isn't a way to sample unique elements that takes 22 | # weight into account. 23 | if random is None: 24 | random = mod_random 25 | 26 | assert len(a) == len(p) 27 | assert len(a) >= length, "You can't request more unique samples than elements in the dataset." 28 | 29 | choices = [] 30 | items = list(a) 31 | probabilities = list(p) 32 | for i in range(length): 33 | cdf = list(cumsum(probabilities)) 34 | normal = cdf[-1] 35 | cdf2 = [float(i) / float(normal) for i in cdf] 36 | uniform_sample = random_sample(random=random) 37 | idx = bisect.bisect_right(cdf2, uniform_sample) 38 | item = items[idx] 39 | choices.append(item) 40 | probabilities.pop(idx) 41 | items.pop(idx) 42 | return choices 43 | 44 | 45 | def choices_distribution(a, p, random=None, length=1): 46 | if random is None: 47 | random = mod_random 48 | 49 | assert len(a) == len(p) 50 | 51 | if hasattr(random, 'choices'): 52 | choices = random.choices(a, weights=p, k=length) 53 | return choices 54 | else: 55 | choices = [] 56 | 57 | cdf = list(cumsum(p)) 58 | normal = cdf[-1] 59 | cdf2 = [float(i) / float(normal) for i in cdf] 60 | for i in range(length): 61 | uniform_sample = random_sample(random=random) 62 | idx = bisect.bisect_right(cdf2, uniform_sample) 63 | item = a[idx] 64 | choices.append(item) 65 | return choices 66 | -------------------------------------------------------------------------------- /faker/providers/company/fi_FI/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as CompanyProvider 3 | 4 | 5 | class Provider(CompanyProvider): 6 | formats = ( 7 | '{{last_name}} {{company_suffix}}', 8 | '{{last_name}} {{last_name}} {{company_suffix}}', 9 | '{{last_name}} {{last_name}} {{company_suffix}}', 10 | '{{last_name}}' 11 | ) 12 | 13 | company_suffixes = ( 14 | 'As Oy', 'Tmi', 'Oy', 'Oyj', 'Ky', 'Osk', 'ry' 15 | ) 16 | 17 | def company_business_id(self): 18 | """ 19 | Returns Finnish company Business Identity Code (y-tunnus). 20 | Format is 8 digits - e.g. FI99999999,[8] last digit is a check 21 | digit utilizing MOD 11-2. The first digit is zero for some old 22 | organizations. This function provides current codes starting with 23 | non-zero. 24 | """ 25 | def calculate_checksum(number): 26 | """Calculate the checksum using mod 11,2 method""" 27 | factors = [7, 9, 10, 5, 8, 4, 2] 28 | sum_ = 0 29 | for x, y in zip(number, factors): 30 | sum_ = sum_ + int(x) * y 31 | if sum_ % 11 == 0: 32 | return '0' 33 | else: 34 | return str(11 - sum_ % 11) 35 | 36 | first_digit = str(self.random_digit_not_null()) 37 | body = first_digit + self.bothify('######') 38 | cs = calculate_checksum(body) 39 | return body + '-' + str(cs) 40 | 41 | def company_vat(self): 42 | """ 43 | Returns Finnish VAT identification number (Arvonlisaveronumero). 44 | This can be calculated from company business identity code by 45 | adding prefix "FI" and removing dash before checksum. 46 | """ 47 | def convert_to_vat(business_id): 48 | """ 49 | Convert business id to VATIN 50 | """ 51 | return 'FI' + business_id.replace('-', '') 52 | 53 | return convert_to_vat(self.company_business_id()) 54 | -------------------------------------------------------------------------------- /faker/providers/internet/bg_BG/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | 6 | class Provider(InternetProvider): 7 | 8 | user_name_formats = ( 9 | '{{last_name_female}}.{{first_name_female}}', 10 | '{{last_name_male}}.{{first_name_male}}', 11 | '{{last_name_male}}.{{first_name_male}}', 12 | '{{first_name_male}}.{{last_name_male}}', 13 | '{{first_name}}##', 14 | '?{{last_name}}', 15 | '{{first_name}}{{year}}' 16 | ) 17 | 18 | email_formats = ( 19 | '{{user_name}}@{{free_email_domain}}', 20 | '{{user_name}}@{{domain_name}}') 21 | 22 | free_email_domains = ( 23 | 'gmail.com', 'yahoo.com', 'hotmail.com', 'mail.bg', 'abv.bg', 'dir.bg' 24 | ) 25 | 26 | tlds = ('bg', 'com', 'biz', 'info', 'net', 'org', 'edu') 27 | 28 | replacements = ( 29 | ('Б', 'b'), ('Г', 'r'), ('Д', 'd'), ('Ж', 'zh'), ('З', 'z'), ('И', 'i'), 30 | ('Й', 'i'), ('Л', 'l'), ('П', 'p'), ('Ф', 'f'), ('Ц', 'ts'), ('Ч', 'ch'), 31 | ('Ш', 'sh'), ('Щ', 'sht'), ('Ъ', 'u'), ('Ь', ''), ('Ю', 'yu'), ('Я', 'ya'), 32 | ('б', 'b'), ('в', 'v'), ('д', 'd'), ('ж', 'zh'), ('з', 'z'), ('и', 'i'), 33 | ('й', 'i'), ('к', 'k'), ('л', 'l'), ('м', 'm'), ('н', 'n'), ('п', 'p'), 34 | ('т', 't'), ('ф', 'f'), ('ц', 'ts'), ('ч', 'ch'), ('ш', 'sh'), ('щ', 'sht'), 35 | ('ъ', 'u'), ('ь', ''), ('ю', 'yu'), ('я', 'ya'), ('Б', 'b'), ('Г', 'r'), 36 | ('Д', 'd'), ('Ж', 'zh'), ('З', 'z'), ('И', 'i'), ('Й', 'i'), ('Л', 'l'), 37 | ('П', 'p'), ('Ф', 'f'), ('Ц', 'ts'), ('Ч', 'ch'), ('Ш', 'sh'), ('Щ', 'sht'), 38 | ('Ъ', 'u'), ('Ь', ''), ('Ю', 'yu'), ('Я', 'ya'), ('б', 'b'), ('в', 'v'), 39 | ('д', 'd'), ('ж', 'zh'), ('з', 'z'), ('и', 'i'), ('й', 'i'), ('к', 'k'), 40 | ('л', 'l'), ('м', 'm'), ('н', 'n'), ('п', 'p'), ('т', 't'), ('ф', 'f'), 41 | ('ц', 'ts'), ('ч', 'ch'), ('ш', 'sh'), ('щ', 'sht'), ('ъ', 'u'), ('ь', ''), 42 | ('ю', 'yu'), ('я', 'ya') 43 | ) 44 | -------------------------------------------------------------------------------- /faker/providers/profile/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from .. import BaseProvider 4 | import itertools 5 | 6 | 7 | class Provider(BaseProvider): 8 | """ 9 | This provider is a collection of functions to generate personal profiles and identities. 10 | 11 | """ 12 | 13 | def simple_profile(self, sex=None): 14 | """ 15 | Generates a basic profile with personal informations 16 | """ 17 | SEX = ["F", "M"] 18 | if sex not in SEX: 19 | sex = self.random_element(SEX) 20 | if sex == 'F': 21 | name = self.generator.name_female() 22 | elif sex == 'M': 23 | name = self.generator.name_male() 24 | return { 25 | "username": self.generator.user_name(), 26 | "name": name, 27 | "sex": sex, 28 | "address": self.generator.address(), 29 | "mail": self.generator.free_email(), 30 | 31 | #"password":self.generator.password() 32 | "birthdate": self.generator.date_of_birth(), 33 | 34 | } 35 | 36 | def profile(self, fields=None, sex=None): 37 | """ 38 | Generates a complete profile. 39 | If "fields" is not empty, only the fields in the list will be returned 40 | """ 41 | if fields is None: 42 | fields = [] 43 | 44 | d = { 45 | "job": self.generator.job(), 46 | "company": self.generator.company(), 47 | "ssn": self.generator.ssn(), 48 | "residence": self.generator.address(), 49 | "current_location": (self.generator.latitude(), self.generator.longitude()), 50 | "blood_group": "".join(self.random_element(list(itertools.product(["A", "B", "AB", "O"], ["+", "-"])))), 51 | "website": [self.generator.url() for _ in range(1, self.random_int(2, 5))] 52 | } 53 | 54 | d = dict(d, **self.generator.simple_profile(sex)) 55 | # field selection 56 | if len(fields) > 0: 57 | d = dict((k, v) for (k, v) in d.items() if k in fields) 58 | 59 | return d 60 | -------------------------------------------------------------------------------- /faker/providers/ssn/pl_PL/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as SsnProvider 5 | 6 | 7 | def checksum(digits): 8 | """ 9 | Calculates and returns a control digit for given list of digits basing on PESEL standard. 10 | """ 11 | weights_for_check_digit = [9, 7, 3, 1, 9, 7, 3, 1, 9, 7] 12 | check_digit = 0 13 | 14 | for i in range(0, 10): 15 | check_digit += weights_for_check_digit[i] * digits[i] 16 | 17 | check_digit %= 10 18 | 19 | return check_digit 20 | 21 | 22 | def calculate_month(birth_date): 23 | """ 24 | Calculates and returns a month number basing on PESEL standard. 25 | """ 26 | year = int(birth_date.strftime('%Y')) 27 | month = int(birth_date.strftime('%m')) + ((int(year / 100) - 14) % 5) * 20 28 | 29 | return month 30 | 31 | 32 | class Provider(SsnProvider): 33 | 34 | def ssn(self): 35 | """ 36 | Returns 11 character Polish national identity code (Public Electronic Census System, 37 | Polish: Powszechny Elektroniczny System Ewidencji Ludności - PESEL). 38 | 39 | It has the form YYMMDDZZZXQ, where YYMMDD is the date of birth (with century 40 | encoded in month field), ZZZ is the personal identification number, X denotes sex 41 | (even for females, odd for males) and Q is a parity number. 42 | 43 | https://en.wikipedia.org/wiki/National_identification_number#Poland 44 | """ 45 | birth_date = self.generator.date_time() 46 | 47 | year_without_century = int(birth_date.strftime('%y')) 48 | month = calculate_month(birth_date) 49 | day = int(birth_date.strftime('%d')) 50 | 51 | pesel_digits = [ 52 | int(year_without_century / 10), 53 | year_without_century % 10, 54 | int(month / 10), 55 | month % 10, 56 | int(day / 10), day % 10 57 | ] 58 | 59 | for _ in range(4): 60 | pesel_digits.append(self.random_digit()) 61 | 62 | pesel_digits.append(checksum(pesel_digits)) 63 | 64 | return ''.join(str(digit) for digit in pesel_digits) 65 | -------------------------------------------------------------------------------- /faker/providers/automotive/ar_SA/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | 5 | import re 6 | 7 | from .. import Provider as AutomotiveProvider 8 | 9 | 10 | class Provider(AutomotiveProvider): 11 | # Source: 12 | # https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_Saudi_Arabia 13 | LICENSE_FORMAT_EN = '#### ???' 14 | LICENSE_FORMAT_AR = '? ? ? ####' 15 | 16 | PLATE_CHARS_EN = 'ABDEGHJKLNRSTUVXZ' 17 | PLATE_CHARS_AR = 'أبدعقهحكلنرسطوىصم' 18 | 19 | PLATE_MAP = { 20 | 'A': 'ا', 21 | 'B': 'ب', 22 | 'D': 'د', 23 | 'E': 'ع', 24 | 'G': 'ق', 25 | 'H': 'ه', 26 | 'J': 'ح', 27 | 'K': 'ك', 28 | 'L': 'ل', 29 | 'N': 'ن', 30 | 'R': 'ر', 31 | 'S': 'س', 32 | 'T': 'ط', 33 | 'U': 'و', 34 | 'V': 'ى', 35 | 'X': 'ص', 36 | 'Z': 'م', 37 | 38 | '0': '٠', 39 | '1': '١', 40 | '2': '٢', 41 | '3': '٣', 42 | '4': '٤', 43 | '5': '٥', 44 | '6': '٦', 45 | '7': '٧', 46 | '8': '٨', 47 | '9': '٩', 48 | } 49 | 50 | def license_plate_en(self): 51 | return self.bothify( 52 | self.LICENSE_FORMAT_EN, letters=self.PLATE_CHARS_EN 53 | ) 54 | 55 | def license_plate_ar(self): 56 | english_plate = self.license_plate_en() 57 | return self._translate_license_plate(english_plate) 58 | 59 | def _translate_license_plate(self, license_plate): 60 | nums = list(reversed(license_plate[0:4])) 61 | chars = list(license_plate[5:8]) 62 | 63 | numerated = re.sub( 64 | r'\#', 65 | lambda x: self.PLATE_MAP[nums.pop()], 66 | self.LICENSE_FORMAT_AR 67 | ) 68 | ar_plate = re.sub( 69 | r'\?', 70 | lambda x: self.PLATE_MAP[chars.pop()], 71 | numerated 72 | ) 73 | 74 | return ar_plate 75 | 76 | def license_plate(self): 77 | en_palate = self.license_plate_en() 78 | ar_palate = self._translate_license_plate(en_palate) 79 | 80 | return en_palate, ar_palate 81 | -------------------------------------------------------------------------------- /tests/providers/test_isbn.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from faker.providers.isbn.en_US import Provider as ISBNProvider 3 | from faker.providers.isbn import ISBN10, ISBN13 4 | from faker.providers.isbn.rules import RegistrantRule 5 | 6 | 7 | class TestISBN10(unittest.TestCase): 8 | 9 | def test_check_digit_is_correct(self): 10 | isbn = ISBN10(group='1', registrant='4516', publication='7331') 11 | assert isbn.check_digit == '0' 12 | isbn = ISBN10(group='0', registrant='06', publication='230125') 13 | assert isbn.check_digit == 'X' 14 | isbn = ISBN10(group='1', registrant='4936', publication='8222') 15 | assert isbn.check_digit == '9' 16 | 17 | def test_format_length(self): 18 | isbn = ISBN10(group='1', registrant='4516', publication='7331') 19 | assert len(isbn.format()) == 10 20 | 21 | 22 | class TestISBN13(unittest.TestCase): 23 | 24 | def test_check_digit_is_correct(self): 25 | isbn = ISBN13(ean='978', group='1', registrant='4516', publication='7331') 26 | assert isbn.check_digit == '9' 27 | isbn = ISBN13(ean='978', group='1', registrant='59327', publication='599') 28 | assert isbn.check_digit == '0' 29 | isbn = ISBN13(ean='978', group='1', registrant='4919', publication='2757') 30 | assert isbn.check_digit == '1' 31 | 32 | def test_format_length(self): 33 | isbn = ISBN13(ean='978', group='1', registrant='4516', publication='7331') 34 | assert len(isbn.format()) == 13 35 | 36 | 37 | class TestProvider(unittest.TestCase): 38 | 39 | def setUp(self): 40 | self.prov = ISBNProvider(None) 41 | 42 | def test_reg_pub_separation(self): 43 | r1 = RegistrantRule('0000000', '0000001', 1) 44 | r2 = RegistrantRule('0000002', '0000003', 2) 45 | assert self.prov._registrant_publication('0000000', [r1, r2]) == ('0', '000000') 46 | assert self.prov._registrant_publication('0000002', [r1, r2]) == ('00', '00002') 47 | 48 | def test_rule_not_found(self): 49 | with self.assertRaises(Exception): 50 | r = RegistrantRule('0000000', '0000001', 1) 51 | self.prov._registrant_publication('0000002', [r]) 52 | 53 | -------------------------------------------------------------------------------- /faker/providers/address/no_NO/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | 4 | from .. import Provider as AddressProvider 5 | 6 | 7 | class Provider(AddressProvider): 8 | city_suffixes = ['berg', 'borg', 'by', 'bø', 'dal', 'eid', 'fjell', 9 | 'fjord', 'foss', 'grunn', 'hamn', 'havn', 'helle', 'mark', 10 | 'nes', 'odden', 'sand', 'sjøen', 'stad', 'strand', 11 | 'strøm', 'sund', 'vik', 'vær', 'våg', 'ø', 'øy', 'ås'] 12 | street_suffixes = ['alléen', 'bakken', 'berget', 'bråten', 'eggen', 13 | 'engen', 'ekra', 'faret', 'flata', 'gata', 'gjerdet', 14 | 'grenda', 'gropa', 'hagen', 'haugen', 'havna', 'holtet', 15 | 'høgda', 'jordet', 'kollen', 'kroken', 'lia', 'lunden', 16 | 'lyngen', 'løkka', 'marka', 'moen', 'myra', 'plassen', 17 | 'ringen', 'roa', 'røa', 'skogen', 'skrenten', 18 | 'spranget', 'stien', 'stranda', 'stubben', 'stykket', 19 | 'svingen', 'tjernet', 'toppen', 'tunet', 'vollen', 20 | 'vika', 'åsen'] 21 | city_formats = [ 22 | '{{first_name}}{{city_suffix}}', '{{last_name}}'] 23 | street_name_formats = [ 24 | '{{last_name}}{{street_suffix}}', 25 | ] 26 | street_address_formats = ('{{street_name}} {{building_number}}',) 27 | address_formats = ('{{street_address}}, {{postcode}} {{city}}',) 28 | building_number_formats = ('%', '%', '%', '%?', '##', '##', '##?', '###',) 29 | building_number_suffixes = { 30 | 'A': 0.2, 'B': 0.2, 'C': 0.2, 'D': 0.1, 'E': 0.1, 'F': 0.1, 'G': 0.05, 31 | 'H': 0.05} 32 | postcode_formats = ('####',) 33 | 34 | def building_number(self): 35 | suffix = self.random_element(self.building_number_suffixes) 36 | return self.numerify( 37 | self.random_element( 38 | self.building_number_formats)).replace( 39 | '?', suffix) 40 | 41 | def city_suffix(self): 42 | return self.random_element(self.city_suffixes) 43 | 44 | def street_suffix(self): 45 | return self.random_element(self.street_suffixes) 46 | -------------------------------------------------------------------------------- /tests/providers/test_phone_number.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | 5 | import re 6 | import unittest 7 | 8 | from faker import Faker 9 | from tests import string_types 10 | 11 | 12 | class TestPhoneNumber(unittest.TestCase): 13 | """ Tests phone_number in the ja_JP locale """ 14 | 15 | def setUp(self): 16 | self.factory = Faker() 17 | 18 | def test_phone_number(self): 19 | pn = self.factory.phone_number() 20 | 21 | assert pn 22 | assert isinstance(pn, string_types) 23 | 24 | def test_phone_number_ja(self): 25 | factory = Faker('ja') 26 | pn = factory.phone_number() 27 | formats = ('070', '080', '090') 28 | 29 | assert pn 30 | assert isinstance(pn, string_types) 31 | first, second, third = pn.split('-') 32 | assert first 33 | assert first.isdigit() 34 | assert second 35 | assert second.isdigit() 36 | assert third 37 | assert third.isdigit() 38 | if len(first) == 2: 39 | assert len(second) == 4 40 | assert len(third) == 4 41 | else: 42 | assert len(first) == 3 43 | assert len(second) == 4 44 | assert len(third) == 4 45 | assert first in formats 46 | 47 | def test_msisdn(self): 48 | msisdn = self.factory.msisdn() 49 | 50 | assert msisdn is not None 51 | assert isinstance(msisdn, string_types) 52 | assert len(msisdn) == 13 53 | assert msisdn.isdigit() 54 | 55 | def test_msisdn_pt_br(self): 56 | factory = Faker('pt_br') 57 | msisdn = factory.msisdn() 58 | formats = ('5511', '5521', '5531', '5541', '5551', '5561', '5571', '5581') 59 | 60 | assert msisdn is not None 61 | assert isinstance(msisdn, string_types) 62 | assert len(msisdn) == 13 63 | assert msisdn.isdigit() 64 | assert msisdn[0:4] in formats 65 | 66 | class TestHuHU(unittest.TestCase): 67 | 68 | def setUp(self): 69 | self.factory = Faker('hu_HU') 70 | 71 | def test_phone_number(self): 72 | phone_number = self.factory.phone_number() 73 | re.match(r"[1-9]\d/\d{3} \d{4}", phone_number) 74 | -------------------------------------------------------------------------------- /faker/providers/isbn/isbn.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | """ 3 | This module is responsible for generating the check digit and formatting 4 | ISBN numbers. 5 | """ 6 | 7 | 8 | class ISBN(object): 9 | 10 | MAX_LENGTH = 13 11 | 12 | def __init__(self, ean=None, group=None, registrant=None, publication=None): 13 | self.ean = ean 14 | self.group = group 15 | self.registrant = registrant 16 | self.publication = publication 17 | 18 | 19 | class ISBN13(ISBN): 20 | 21 | def __init__(self, *args, **kwargs): 22 | super(ISBN13, self).__init__(*args, **kwargs) 23 | self.check_digit = self._check_digit() 24 | 25 | def _check_digit(self): 26 | """ Calculate the check digit for ISBN-13. 27 | See https://en.wikipedia.org/wiki/International_Standard_Book_Number 28 | for calculation. 29 | """ 30 | weights = (1 if x % 2 == 0 else 3 for x in range(12)) 31 | body = ''.join([self.ean, self.group, self.registrant, 32 | self.publication]) 33 | remainder = sum(int(b) * w for b, w in zip(body, weights)) % 10 34 | diff = 10 - remainder 35 | check_digit = 0 if diff == 10 else diff 36 | return str(check_digit) 37 | 38 | def format(self, separator=''): 39 | return separator.join([self.ean, self.group, self.registrant, 40 | self.publication, self.check_digit]) 41 | 42 | 43 | class ISBN10(ISBN): 44 | 45 | def __init__(self, *args, **kwargs): 46 | super(ISBN10, self).__init__(*args, **kwargs) 47 | self.check_digit = self._check_digit() 48 | 49 | def _check_digit(self): 50 | """ Calculate the check digit for ISBN-10. 51 | See https://en.wikipedia.org/wiki/International_Standard_Book_Number 52 | for calculation. 53 | """ 54 | weights = range(1, 10) 55 | body = ''.join([self.group, self.registrant, self.publication]) 56 | remainder = sum(int(b) * w for b, w in zip(body, weights)) % 11 57 | check_digit = 'X' if remainder == 10 else str(remainder) 58 | return str(check_digit) 59 | 60 | def format(self, separator=''): 61 | return separator.join([self.group, self.registrant, self.publication, 62 | self.check_digit]) 63 | -------------------------------------------------------------------------------- /faker/providers/ssn/nl_BE/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as SsnProvider 5 | 6 | """ 7 | For more info on rijksregisternummer, see https://nl.wikipedia.org/wiki/Rijksregisternummer 8 | Dutch/French only for now ... 9 | """ 10 | 11 | 12 | class Provider(SsnProvider): 13 | 14 | def ssn(self): 15 | """ 16 | Returns a 11 digits Belgian SSN called "rijksregisternummer" as a string 17 | 18 | The first 6 digits represent the birthdate with (in order) year, month and day. 19 | The second group of 3 digits is represents a sequence number (order of birth). 20 | It is even for women and odd for men. 21 | For men the range starts at 1 and ends 997, for women 2 until 998. 22 | The third group of 2 digits is a checksum based on the previous 9 digits (modulo 97). 23 | Divide those 9 digits by 97, subtract the remainder from 97 and that's the result. 24 | For persons born in or after 2000, the 9 digit number needs to be proceeded by a 2 25 | (add 2000000000) before the division by 97. 26 | 27 | """ 28 | # see http://nl.wikipedia.org/wiki/Burgerservicenummer (in Dutch) 29 | def _checksum(digits): 30 | res = 97 - (digits % 97) 31 | return res 32 | 33 | # Generate a date (random) 34 | mydate = self.generator.date() 35 | # Convert it to an int 36 | elms = mydate.split("-") 37 | # Adjust for year 2000 if necessary 38 | if elms[0][0] == '2': 39 | above = True 40 | else: 41 | above = False 42 | # Only keep the last 2 digits of the year 43 | elms[0] = elms[0][2:4] 44 | # Simulate the gender/sequence - should be 3 digits 45 | seq = self.generator.random_int(1, 998) 46 | # Right justify sequence and append to list 47 | seq_str = "{:0>3}".format(seq) 48 | elms.append(seq_str) 49 | # Now convert list to an integer so the checksum can be calculated 50 | date_as_int = int("".join(elms)) 51 | if above: 52 | date_as_int += 2000000000 53 | # Generate checksum 54 | s = _checksum(date_as_int) 55 | s_rjust = "{:0>2}".format(s) 56 | # return result as a string 57 | elms.append(s_rjust) 58 | return "".join(elms) 59 | -------------------------------------------------------------------------------- /faker/providers/lorem/la/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as LoremProvider 5 | 6 | 7 | class Provider(LoremProvider): 8 | word_list = ( 9 | 'a', 'ab', 'accusamus', 'accusantium', 'ad', 'adipisci', 'alias', 10 | 'aliquam', 'aliquid', 'amet', 'animi', 'aperiam', 'architecto', 11 | 'asperiores', 'aspernatur', 'assumenda', 'at', 'atque', 'aut', 'autem', 12 | 'beatae', 'blanditiis', 'commodi', 'consectetur', 'consequatur', 13 | 'consequuntur', 'corporis', 'corrupti', 'culpa', 'cum', 'cumque', 14 | 'cupiditate', 'debitis', 'delectus', 'deleniti', 'deserunt', 'dicta', 15 | 'dignissimos', 'distinctio', 'dolor', 'dolore', 'dolorem', 'doloremque', 16 | 'dolores', 'doloribus', 'dolorum', 'ducimus', 'ea', 'eaque', 'earum', 17 | 'eius', 'eligendi', 'enim', 'eos', 'error', 'esse', 'est', 'et', 'eum', 18 | 'eveniet', 'ex', 'excepturi', 'exercitationem', 'expedita', 'explicabo', 19 | 'facere', 'facilis', 'fuga', 'fugiat', 'fugit', 'harum', 'hic', 'id', 20 | 'illo', 'illum', 'impedit', 'in', 'incidunt', 'inventore', 'ipsa', 21 | 'ipsam', 'ipsum', 'iste', 'itaque', 'iure', 'iusto', 'labore', 22 | 'laboriosam', 'laborum', 'laudantium', 'libero', 'magnam', 'magni', 23 | 'maiores', 'maxime', 'minima', 'minus', 'modi', 'molestiae', 24 | 'molestias', 'mollitia', 'nam', 'natus', 'necessitatibus', 'nemo', 25 | 'neque', 'nesciunt', 'nihil', 'nisi', 'nobis', 'non', 'nostrum', 26 | 'nulla', 'numquam', 'occaecati', 'odio', 'odit', 'officia', 'officiis', 27 | 'omnis', 'optio', 'pariatur', 'perferendis', 'perspiciatis', 'placeat', 28 | 'porro', 'possimus', 'praesentium', 'provident', 'quae', 'quaerat', 29 | 'quam', 'quas', 'quasi', 'qui', 'quia', 'quibusdam', 'quidem', 'quis', 30 | 'quisquam', 'quo', 'quod', 'quos', 'ratione', 'recusandae', 31 | 'reiciendis', 'rem', 'repellat', 'repellendus', 'reprehenderit', 32 | 'repudiandae', 'rerum', 'saepe', 'sapiente', 'sed', 'sequi', 33 | 'similique', 'sint', 'sit', 'soluta', 'sunt', 'suscipit', 'tempora', 34 | 'tempore', 'temporibus', 'tenetur', 'totam', 'ullam', 'unde', 'ut', 35 | 'vel', 'velit', 'veniam', 'veritatis', 'vero', 'vitae', 'voluptas', 36 | 'voluptate', 'voluptatem', 'voluptates', 'voluptatibus', 'voluptatum' 37 | ) 38 | -------------------------------------------------------------------------------- /faker/providers/job/fa_IR/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | from .. import Provider as BaseProvider 4 | 5 | 6 | class Provider(BaseProvider): 7 | jobs = [ 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 | "سرهنگ", 66 | "غواص", 67 | "پزشک", 68 | "دربان", 69 | "آتش‌نشان", 70 | "ماهی‌گیر", 71 | "میوه‌فروش", 72 | "نگهبان", 73 | "پاسدار", 74 | "قاضی", 75 | "وکیل", 76 | "کارگر", 77 | "شهردار", 78 | "معدن‌چی", 79 | "پرستار", 80 | "افسر", 81 | "عکاس", 82 | "لوله‌کش", 83 | "بازیگر", 84 | "باربر", 85 | "رئیس‌جمهور", 86 | "نخست‌وزیر", 87 | "روانشناس", 88 | "خبر‌نگار", 89 | "بازنشسته", 90 | "مجسمه‌ساز", 91 | "گروهبان", 92 | "مغازه‌دار", 93 | "خواننده", 94 | "سرباز", 95 | "سخن‌ران", 96 | "جراح", 97 | "سفال‌گر", 98 | "جهانگرد", 99 | "جوشکار", 100 | "چشم‌پزشک", 101 | "گزارش‌گر", 102 | "خطاط" 103 | ] 104 | -------------------------------------------------------------------------------- /faker/providers/ssn/fi_FI/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as SsnProvider 5 | import datetime 6 | 7 | 8 | class Provider(SsnProvider): 9 | 10 | def ssn(self, min_age=0, max_age=105, artificial=False): 11 | """ 12 | Returns 11 character Finnish personal identity code (Henkilötunnus, 13 | HETU, Swedish: Personbeteckning). This function assigns random 14 | gender to person. 15 | 16 | HETU consists of eleven characters of the form DDMMYYCZZZQ, where 17 | DDMMYY is the date of birth, C the century sign, ZZZ the individual 18 | number and Q the control character (checksum). The sign for the 19 | century is either + (1800–1899), - (1900–1999), or A (2000–2099). 20 | The individual number ZZZ is odd for males and even for females. 21 | For people born in Finland its range is 002-899 22 | (larger numbers may be used in special cases). 23 | An example of a valid code is 311280-888Y. 24 | 25 | https://en.wikipedia.org/wiki/National_identification_number#Finland 26 | """ 27 | def _checksum(hetu): 28 | checksum_characters = "0123456789ABCDEFHJKLMNPRSTUVWXY" 29 | return checksum_characters[int(hetu) % 31] 30 | 31 | age = datetime.timedelta( 32 | days=self.generator.random.randrange(min_age * 365, max_age * 365)) 33 | birthday = datetime.date.today() - age 34 | hetu_date = "%02d%02d%s" % ( 35 | birthday.day, birthday.month, str(birthday.year)[-2:]) 36 | range = (900, 999) if artificial is True else (2, 899) 37 | suffix = str(self.generator.random.randrange(*range)).zfill(3) 38 | checksum = _checksum(hetu_date + suffix) 39 | separator = self._get_century_code(birthday.year) 40 | hetu = "".join([hetu_date, separator, suffix, checksum]) 41 | return hetu 42 | 43 | @staticmethod 44 | def _get_century_code(year): 45 | """Returns the century code for a given year""" 46 | if 2000 <= year < 3000: 47 | separator = 'A' 48 | elif 1900 <= year < 2000: 49 | separator = '-' 50 | elif 1800 <= year < 1900: 51 | separator = '+' 52 | else: 53 | raise ValueError( 54 | 'Finnish SSN do not support people born ' 55 | 'before the year 1800 or after the year 2999' 56 | ) 57 | return separator 58 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | How to contribute 2 | ================= 3 | 4 | We love pull requests. Here's a quick guide: 5 | 6 | Getting Started 7 | --------------- 8 | 9 | - Make sure you have a `GitHub account `__ 10 | - Submit a ticket for your issue, assuming one does not already exist. 11 | - Clearly describe the issue including steps to reproduce when it is a bug. 12 | - Make sure you fill in the earliest version that you know has the issue. 13 | - Fork the repository on GitHub 14 | 15 | Making Changes 16 | -------------- 17 | 18 | - Create a topic branch from where you want to base your work. 19 | - This is usually the master branch. 20 | - Only target release branches if you are certain your fix must be on 21 | that branch. 22 | - To quickly create a topic branch based on master; 23 | ``git branch fix/master/my_contribution master`` then checkout 24 | the new branch with ``git checkout fix/master/my_contribution``. 25 | Please avoid working directly on the ``master`` branch. 26 | - Make commits of logical units. 27 | - Check for unnecessary whitespace with ``git diff --check`` before 28 | committing. 29 | - Make sure your commit messages are in the proper format. 30 | 31 | :: 32 | 33 | Make the example in CONTRIBUTING imperative and concrete 34 | 35 | Without this patch applied the example commit message in the CONTRIBUTING 36 | document is not a concrete example. This is a problem because the 37 | contributor is left to imagine what the commit message should look like 38 | based on a description rather than an example. This patch fixes the 39 | problem by making the example concrete and imperative. 40 | 41 | The first line is a real life imperative statement with a ticket number 42 | from our issue tracker. The body describes the behavior without the patch, 43 | why this is a problem, and how the patch fixes the problem when applied. 44 | 45 | - Make sure you have added the necessary tests for your changes. 46 | - Run *all* the tests to assure nothing else was accidentally broken. 47 | 48 | Submitting Changes 49 | ------------------ 50 | 51 | - Push your changes to a topic branch in your fork of the repository. 52 | - Submit a pull request to the repository. 53 | 54 | Additional Resources 55 | ==================== 56 | 57 | - `General GitHub documentation `__ 58 | - `GitHub pull request 59 | documentation `__ 60 | -------------------------------------------------------------------------------- /faker/providers/phone_number/fa_IR/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | # Mobile 8 | '+98 91# ### ####', 9 | '091# ### ####', 10 | '+98 920 ### ####', 11 | '0920 ### ####', 12 | '+98 921 ### ####', 13 | '0921 ### ####', 14 | '+98 93# ### ####', 15 | '093# ### ####', 16 | # Land lines, 17 | # https://en.wikipedia.org/wiki/List_of_dialling_codes_in_Iran 18 | '+98 21 #### ####', 19 | '021 #### ####', 20 | '+98 26 #### ####', 21 | '026 #### ####', 22 | '+98 25 #### ####', 23 | '025 #### ####', 24 | '+98 86 #### ####', 25 | '086 #### ####', 26 | '+98 24 #### ####', 27 | '024 #### ####', 28 | '+98 23 #### ####', 29 | '023 #### ####', 30 | '+98 81 #### ####', 31 | '081 #### ####', 32 | '+98 28 #### ####', 33 | '028 #### ####', 34 | '+98 31 #### ####', 35 | '031 #### ####', 36 | '+98 44 #### ####', 37 | '044 #### ####', 38 | '+98 11 #### ####', 39 | '011 #### ####', 40 | '+98 74 #### ####', 41 | '074 #### ####', 42 | '+98 83 #### ####', 43 | '083 #### ####', 44 | '+98 51 #### ####', 45 | '051 #### ####', 46 | '+98 45 #### ####', 47 | '045 #### ####', 48 | '+98 17 #### ####', 49 | '017 #### ####', 50 | '+98 41 #### ####', 51 | '041 #### ####', 52 | '+98 54 #### ####', 53 | '054 #### ####', 54 | '+98 87 #### ####', 55 | '087 #### ####', 56 | '+98 71 #### ####', 57 | '071 #### ####', 58 | '+98 66 #### ####', 59 | '066 #### ####', 60 | '+98 34 #### ####', 61 | '034 #### ####', 62 | '+98 56 #### ####', 63 | '056 #### ####', 64 | '+98 13 #### ####', 65 | '013 #### ####', 66 | '+98 77 #### ####', 67 | '077 #### ####', 68 | '+98 76 #### ####', 69 | '076 #### ####', 70 | '+98 61 #### ####', 71 | '061 #### ####', 72 | '+98 38 #### ####', 73 | '038 #### ####', 74 | '+98 58 #### ####', 75 | '058 #### ####', 76 | '+98 35 #### ####', 77 | '035 #### ####', 78 | '+98 84 #### ####', 79 | '084 #### ####', 80 | '+98 ### #### ####', 81 | '0### #### ####' 82 | ) 83 | -------------------------------------------------------------------------------- /faker/providers/phone_number/pt_BR/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | from .. import Provider as PhoneNumberProvider 3 | 4 | 5 | class Provider(PhoneNumberProvider): 6 | formats = ( 7 | '+55 (011) #### ####', 8 | '+55 (021) #### ####', 9 | '+55 (031) #### ####', 10 | '+55 (041) #### ####', 11 | '+55 (051) #### ####', 12 | '+55 (061) #### ####', 13 | '+55 (071) #### ####', 14 | '+55 (081) #### ####', 15 | '+55 11 #### ####', 16 | '+55 21 #### ####', 17 | '+55 31 #### ####', 18 | '+55 41 #### ####', 19 | '+55 51 ### ####', 20 | '+55 61 #### ####', 21 | '+55 71 #### ####', 22 | '+55 81 #### ####', 23 | '+55 (011) ####-####', 24 | '+55 (021) ####-####', 25 | '+55 (031) ####-####', 26 | '+55 (041) ####-####', 27 | '+55 (051) ####-####', 28 | '+55 (061) ####-####', 29 | '+55 (071) ####-####', 30 | '+55 (081) ####-####', 31 | '+55 11 ####-####', 32 | '+55 21 ####-####', 33 | '+55 31 ####-####', 34 | '+55 41 ####-####', 35 | '+55 51 ### ####', 36 | '+55 61 ####-####', 37 | '+55 71 ####-####', 38 | '+55 81 ####-####', 39 | '(011) #### ####', 40 | '(021) #### ####', 41 | '(031) #### ####', 42 | '(041) #### ####', 43 | '(051) #### ####', 44 | '(061) #### ####', 45 | '(071) #### ####', 46 | '(081) #### ####', 47 | '11 #### ####', 48 | '21 #### ####', 49 | '31 #### ####', 50 | '41 #### ####', 51 | '51 ### ####', 52 | '61 #### ####', 53 | '71 #### ####', 54 | '81 #### ####', 55 | '(011) ####-####', 56 | '(021) ####-####', 57 | '(031) ####-####', 58 | '(041) ####-####', 59 | '(051) ####-####', 60 | '(061) ####-####', 61 | '(071) ####-####', 62 | '(081) ####-####', 63 | '11 ####-####', 64 | '21 ####-####', 65 | '31 ####-####', 66 | '41 ####-####', 67 | '51 ### ####', 68 | '61 ####-####', 69 | '71 ####-####', 70 | '81 ####-####', 71 | '#### ####', 72 | '####-####', 73 | ) 74 | msisdn_formats = ( 75 | '5511#########', 76 | '5521#########', 77 | '5531#########', 78 | '5541#########', 79 | '5551#########', 80 | '5561#########', 81 | '5571#########', 82 | '5581#########', 83 | ) 84 | -------------------------------------------------------------------------------- /faker/providers/color/ru_RU/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from collections import OrderedDict 4 | 5 | from .. import Provider as ColorProvider 6 | 7 | localized = True 8 | 9 | 10 | class Provider(ColorProvider): 11 | all_colors = OrderedDict(( 12 | ("Античный Белый", "#FAEBD7"), 13 | ("Аквамарин", "#7FFFD4"), 14 | ("Лазурный", "#F0FFFF"), 15 | ("Бежевый", "#F5F5DC"), 16 | ("Черный", "#000000"), 17 | ("Синий", "#0000FF"), 18 | ("Сине-фиолетовый", "#8A2BE2"), 19 | ("Коричневый", "#A52A2A"), 20 | ("Шоколадный", "#D2691E"), 21 | ("Коралловый", "#FF7F50"), 22 | ("Васильковый", "#6495ED"), 23 | ("Малиновый", "#DC143C"), 24 | ("Темно-синий", "#00008B"), 25 | ("Темно-голубой", "#008B8B"), 26 | ("Темно-серый", "#A9A9A9"), 27 | ("Темно-зеленый", "#006400"), 28 | ("Темный хаки", "#BDB76B"), 29 | ("Темно-оранжевый", "#FF8C00"), 30 | ("Темно-красный", "#8B0000"), 31 | ("Темно-бирюзовый", "#00CED1"), 32 | ("Темно-фиолетовый", "#9400D3"), 33 | ("Темно-розовый", "#FF1493"), 34 | ("Тусклый серый", "#696969"), 35 | ("Фуксия", "#FF00FF"), 36 | ("Золотой", "#FFD700"), 37 | ("Серый", "#808080"), 38 | ("Зеленый", "#008000"), 39 | ("Желто-зеленый", "#ADFF2F"), 40 | ("Ярко-розовый", "#FF69B4"), 41 | ("Индиго", "#4B0082"), 42 | ("Слоновая кость", "#FFFFF0"), 43 | ("Хаки", "#F0E68C"), 44 | ("Розовато-лавандовый", "#FFF0F5"), 45 | ("Светло-синий", "#ADD8E6"), 46 | ("Светло-голубой", "#E0FFFF"), 47 | ("Светло-серый", "#D3D3D3"), 48 | ("Светло-зеленый", "#90EE90"), 49 | ("Светло-розовый", "#FFB6C1"), 50 | ("Светло-голубой", "#87CEFA"), 51 | ("Светло-желтый", "#FFFFE0"), 52 | ("Каштановый", "#800000"), 53 | ("Оранжевый", "#FFA500"), 54 | ("Оранжево-красный", "#FF4500"), 55 | ("Бледно-зеленый", "#98FB98"), 56 | ("Бледно-Бирюзовый", "#AFEEEE"), 57 | ("Розовый", "#FFC0CB"), 58 | ("Сливовый", "#DDA0DD"), 59 | ("Пурпурный", "#800080"), 60 | ("Красный", "#FF0000"), 61 | ("Цвет морской волны", "#2E8B57"), 62 | ("Серебряный", "#C0C0C0"), 63 | ("Бирюзовый", "#40E0D0"), 64 | ("Фиолетовый", "#EE82EE"), 65 | ("Белый", "#FFFFFF"), 66 | ("Желтый", "#FFFF00"), 67 | ("Желто-зеленый", "#9ACD3"), 68 | )) 69 | 70 | safe_colors = ( 71 | 'черный', 'бордовый', 'зеленый', 'оливковый', 72 | 'пурпурный', 'teal', 'lime', 'синий', 'серебряный', 73 | 'серый', 'желтый', 'фуксия', 'белый' 74 | ) 75 | -------------------------------------------------------------------------------- /faker/providers/internet/el_GR/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as InternetProvider 4 | 5 | import re 6 | from faker.utils.decorators import slugify_domain 7 | 8 | 9 | class Provider(InternetProvider): 10 | 11 | free_email_domains = ( 12 | 'hol.gr', 'gmail.com', 'hotmail.gr', 'yahoo.gr', 'googlemail.gr', 13 | 'otenet.gr', 'forthnet.gr', 14 | ) 15 | tlds = ('com', 'com', 'com', 'net', 'org', 'gr', 'gr', 'gr') 16 | 17 | @slugify_domain 18 | def user_name(self): 19 | pattern = self.random_element(self.user_name_formats) 20 | return latinize(self.bothify(self.generator.parse(pattern))) 21 | 22 | @slugify_domain 23 | def domain_word(self): 24 | company = self.generator.format('company') 25 | company_elements = company.split(' ') 26 | company = latinize(company_elements.pop(0)) 27 | return company 28 | 29 | 30 | # ``slugify`` doesn't replace greek glyphs. 31 | 32 | def remove_accents(value): 33 | """ 34 | Remove accents from characters in the given string. 35 | """ 36 | search = 'ΆΈΉΊΌΎΏάέήίόύώΪϊΐϋΰ' 37 | replace = 'ΑΕΗΙΟΥΩαεηιουωΙιιυυ' 38 | 39 | def replace_accented_character(match): 40 | matched = match.group(0) 41 | if matched in search: 42 | return replace[search.find(matched)] 43 | return matched 44 | 45 | return re.sub(r'[{0}]+'.format(search), replace_accented_character, value) 46 | 47 | 48 | def latinize(value): 49 | """ 50 | Converts (transliterates) greek letters to latin equivalents. 51 | """ 52 | def replace_double_character(match): 53 | search = ('Θ Χ Ψ ' 54 | 'θ χ ψ ' 55 | 'ΟΥ ΑΥ ΕΥ ' 56 | 'Ου Αυ Ευ ' 57 | 'ου αυ ευ').split() 58 | replace = ('TH CH PS ' 59 | 'th ch ps ' 60 | 'OU AU EU ' 61 | 'Ou Au Eu ' 62 | 'ou au eu').split() 63 | matched = match.group(0) 64 | if matched in search: 65 | return replace[search.index(matched)] 66 | return matched 67 | 68 | search = 'ΑΒΓΔΕΖΗΙΚΛΜΝΞΟΠΡΣΣΤΥΦΩαβγδεζηικλμνξοπρσςτυφω' 69 | replace = 'AVGDEZIIKLMNXOPRSSTUFOavgdeziiklmnxoprsstyfo' 70 | 71 | def replace_greek_character(match): 72 | matched = list(match.group(0)) 73 | value = map(lambda l: replace[search.find(l)], matched) 74 | return ''.join(value) 75 | 76 | return re.sub(r'[{0}]+'.format(search), 77 | replace_greek_character, re.sub( 78 | r'([ΘΧΨθχψ]+|ΟΥ|ΑΥ|ΕΥ|Ου|Αυ|Ευ|ου|αυ|ευ)', 79 | replace_double_character, 80 | remove_accents(value))) 81 | -------------------------------------------------------------------------------- /faker/providers/ssn/et_EE/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as SsnProvider 5 | import datetime 6 | import operator 7 | 8 | 9 | def checksum(digits): 10 | """Calculate checksum of Estonian personal identity code. 11 | 12 | Checksum is calculated with "Modulo 11" method using level I or II scale: 13 | Level I scale: 1 2 3 4 5 6 7 8 9 1 14 | Level II scale: 3 4 5 6 7 8 9 1 2 3 15 | 16 | The digits of the personal code are multiplied by level I scale and summed; 17 | if remainder of modulo 11 of the sum is less than 10, checksum is the 18 | remainder. 19 | If remainder is 10, then level II scale is used; checksum is remainder if 20 | remainder < 10 or 0 if remainder is 10. 21 | 22 | See also https://et.wikipedia.org/wiki/Isikukood 23 | """ 24 | sum_mod11 = sum(map(operator.mul, digits, Provider.scale1)) % 11 25 | if sum_mod11 < 10: 26 | return sum_mod11 27 | sum_mod11 = sum(map(operator.mul, digits, Provider.scale2)) % 11 28 | return 0 if sum_mod11 == 10 else sum_mod11 29 | 30 | 31 | class Provider(SsnProvider): 32 | scale1 = (1, 2, 3, 4, 5, 6, 7, 8, 9, 1) 33 | scale2 = (3, 4, 5, 6, 7, 8, 9, 1, 2, 3) 34 | 35 | def ssn(self, min_age=16, max_age=90): 36 | """ 37 | Returns 11 character Estonian personal identity code (isikukood, IK). 38 | 39 | Age of person is between 16 and 90 years, based on local computer date. 40 | This function assigns random sex to person. 41 | An Estonian Personal identification code consists of 11 digits, 42 | generally given without any whitespace or other delimiters. 43 | The form is GYYMMDDSSSC, where G shows sex and century of birth (odd 44 | number male, even number female, 1-2 19th century, 3-4 20th century, 45 | 5-6 21st century), SSS is a serial number separating persons born on 46 | the same date and C a checksum. 47 | 48 | https://en.wikipedia.org/wiki/National_identification_number#Estonia 49 | """ 50 | age = datetime.timedelta( 51 | days=self.generator.random.randrange( 52 | min_age * 365, max_age * 365)) 53 | birthday = datetime.date.today() - age 54 | if birthday.year < 2000: 55 | ik = self.generator.random.choice(('3', '4')) 56 | elif birthday.year < 2100: 57 | ik = self.generator.random.choice(('5', '6')) 58 | else: 59 | ik = self.generator.random.choice(('7', '8')) 60 | 61 | ik += "%02d%02d%02d" % ((birthday.year % 100), birthday.month, 62 | birthday.day) 63 | ik += str(self.generator.random.randrange(0, 999)).zfill(3) 64 | return ik + str(checksum([int(ch) for ch in ik])) 65 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | import os 5 | import io 6 | 7 | from setuptools import setup, find_packages 8 | 9 | here = os.path.abspath(os.path.dirname(__file__)) 10 | with io.open(os.path.join(here, 'README.rst'), encoding='utf-8') as fp: 11 | README = fp.read() 12 | 13 | 14 | version = '0.9.0' 15 | 16 | # this module can be zip-safe if the zipimporter implements iter_modules or if 17 | # pkgutil.iter_importer_modules has registered a dispatch for the zipimporter. 18 | try: 19 | import pkgutil 20 | import zipimport 21 | zip_safe = hasattr(zipimport.zipimporter, "iter_modules") or \ 22 | zipimport.zipimporter in pkgutil.iter_importer_modules.registry.keys() 23 | except (ImportError, AttributeError): 24 | zip_safe = False 25 | 26 | setup( 27 | name='Faker', 28 | version=version, 29 | description="Faker is a Python package that generates fake data for you.", 30 | long_description=README, 31 | entry_points={ 32 | 'console_scripts': ['faker=faker.cli:execute_from_command_line'], 33 | }, 34 | classifiers=[ 35 | # See https://pypi.org/pypi?%3Aaction=list_classifiers 36 | 'Development Status :: 5 - Production/Stable', 37 | 'Environment :: Console', 38 | 'Intended Audience :: Developers', 39 | 'Programming Language :: Python', 40 | 'Programming Language :: Python :: 2', 41 | 'Programming Language :: Python :: 2.7', 42 | 'Programming Language :: Python :: 3', 43 | 'Programming Language :: Python :: 3.4', 44 | 'Programming Language :: Python :: 3.5', 45 | 'Programming Language :: Python :: 3.6', 46 | 'Programming Language :: Python :: Implementation :: CPython', 47 | 'Programming Language :: Python :: Implementation :: PyPy', 48 | 'Topic :: Software Development :: Libraries :: Python Modules', 49 | 'Topic :: Software Development :: Testing', 50 | 'Topic :: Utilities', 51 | 'License :: OSI Approved :: MIT License' 52 | ], 53 | keywords='faker fixtures data test mock generator', 54 | author='joke2k', 55 | author_email='joke2k@gmail.com', 56 | url='https://github.com/joke2k/faker', 57 | license='MIT License', 58 | packages=find_packages(exclude=["docs", "tests", "tests.*"]), 59 | platforms=["any"], 60 | test_suite='tests', 61 | zip_safe=zip_safe, 62 | python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", 63 | install_requires=[ 64 | "python-dateutil>=2.4", 65 | "six>=1.10", 66 | "text-unidecode==1.2", 67 | ], 68 | tests_require=[ 69 | "email_validator>=1.0.0,<1.1.0", 70 | "ukpostcodeparser>=1.1.1", 71 | "mock", 72 | ], 73 | extras_require={ 74 | ':python_version=="2.7"': [ 75 | 'ipaddress', 76 | ], 77 | } 78 | ) 79 | -------------------------------------------------------------------------------- /faker/providers/address/es_ES/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from ..es import Provider as AddressProvider 5 | 6 | 7 | class Provider(AddressProvider): 8 | building_number_formats = ('%', '%#', '%#', '%#', '%##') 9 | street_prefixes = ( 10 | 'Plaza', 'Calle', 'Avenida', 'Via', 'Vial', 'Rambla', 'Glorieta', 11 | 'Urbanización', 'Callejón', 'Cañada', 'Alameda', 'Acceso', 'C.', 12 | 'Ronda', 'Pasaje', 'Cuesta', 'Pasadizo', 'Paseo', 'Camino', 13 | ) 14 | postcode_formats = ('#####', ) 15 | states = ( 16 | 'Álava', 17 | 'Albacete', 18 | 'Alicante', 19 | 'Almería', 20 | 'Asturias', 21 | 'Ávila', 22 | 'Badajoz', 23 | 'Baleares', 24 | 'Barcelona', 25 | 'Burgos', 26 | 'Cáceres', 27 | 'Cádiz', 28 | 'Cantabria', 29 | 'Castellón', 30 | 'Ceuta', 31 | 'Ciudad', 32 | 'Córdoba', 33 | 'Cuenca', 34 | 'Girona', 35 | 'Granada', 36 | 'Guadalajara', 37 | 'Guipúzcoa', 38 | 'Huelva', 39 | 'Huesca', 40 | 'Jaén', 41 | 'La Coruña', 42 | 'La Rioja', 43 | 'Las Palmas', 44 | 'León', 45 | 'Lleida', 46 | 'Lugo', 47 | 'Madrid', 48 | 'Málaga', 49 | 'Melilla', 50 | 'Murcia', 51 | 'Navarra', 52 | 'Ourense', 53 | 'Palencia', 54 | 'Pontevedra', 55 | 'Salamanca', 56 | 'Santa Cruz de Tenerife', 57 | 'Segovia', 58 | 'Sevilla', 59 | 'Soria', 60 | 'Tarragona', 61 | 'Teruel', 62 | 'Toledo', 63 | 'Valencia', 64 | 'Valladolid', 65 | 'Vizcaya', 66 | 'Zamora', 67 | 'Zaragoza') 68 | 69 | city_formats = ( 70 | '{{state_name}}', 71 | ) 72 | 73 | street_name_formats = ( 74 | '{{street_prefix}} {{first_name}} {{last_name}}', 75 | '{{street_prefix}} de {{first_name}} {{last_name}}', 76 | 77 | ) 78 | street_address_formats = ( 79 | '{{street_name}} {{building_number}}', 80 | '{{street_name}} {{building_number}} {{secondary_address}} ', 81 | ) 82 | address_formats = ( 83 | "{{street_address}}\n{{city}}, {{postcode}}", 84 | ) 85 | secondary_address_formats = ('Apt. ##', 'Piso #', 'Puerta #') 86 | 87 | def state_name(self): 88 | return self.random_element(self.states) 89 | 90 | def street_prefix(self): 91 | return self.random_element(self.street_prefixes) 92 | 93 | def secondary_address(self): 94 | return self.numerify( 95 | self.random_element( 96 | self.secondary_address_formats)) 97 | 98 | def state(self): 99 | return self.random_element(self.states) 100 | -------------------------------------------------------------------------------- /faker/providers/job/uk_UA/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as BaseProvider 4 | 5 | 6 | # Ukrainian job names taken from 7 | # https://uk.wikipedia.org/wiki/%D0%A1%D0%BF%D0%B8%D1%81%D0%BE%D0%BA_%D0%BF%D1%80%D0%BE%D1%84%D0%B5%D1%81%D1%96%D0%B9 8 | # on 22th September 2014 9 | class Provider(BaseProvider): 10 | jobs = [ 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 | ] 66 | -------------------------------------------------------------------------------- /faker/providers/isbn/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | from __future__ import unicode_literals 4 | from .. import BaseProvider 5 | from .isbn import ISBN, ISBN10, ISBN13 6 | from .rules import RULES 7 | 8 | 9 | class Provider(BaseProvider): 10 | """ Generates fake ISBNs. ISBN rules vary across languages/regions 11 | so this class makes no attempt at replicating all of the rules. It 12 | only replicates the 978 EAN prefix for the English registration 13 | groups, meaning the first 4 digits of the ISBN-13 will either be 14 | 978-0 or 978-1. Since we are only replicating 978 prefixes, every 15 | ISBN-13 will have a direct mapping to an ISBN-10. 16 | 17 | See https://www.isbn-international.org/content/what-isbn for the 18 | format of ISBNs. 19 | See https://www.isbn-international.org/range_file_generation for the 20 | list of rules pertaining to each prefix/registration group. 21 | """ 22 | 23 | def _body(self): 24 | """ Generate the information required to create an ISBN-10 or 25 | ISBN-13. 26 | """ 27 | ean = self.random_element(RULES.keys()) 28 | reg_group = self.random_element(RULES[ean].keys()) 29 | 30 | # Given the chosen ean/group, decide how long the 31 | # registrant/publication string may be. 32 | # We must allocate for the calculated check digit, so 33 | # subtract 1 34 | reg_pub_len = ISBN.MAX_LENGTH - len(ean) - len(reg_group) - 1 35 | 36 | # Generate a registrant/publication combination 37 | reg_pub = self.numerify('#' * reg_pub_len) 38 | 39 | # Use rules to separate the registrant from the publication 40 | rules = RULES[ean][reg_group] 41 | registrant, publication = self._registrant_publication(reg_pub, rules) 42 | return [ean, reg_group, registrant, publication] 43 | 44 | @staticmethod 45 | def _registrant_publication(reg_pub, rules): 46 | """ Separate the registration from the publication in a given 47 | string. 48 | :param reg_pub: A string of digits representing a registration 49 | and publication. 50 | :param rules: A list of RegistrantRules which designate where 51 | to separate the values in the string. 52 | :returns: A (registrant, publication) tuple of strings. 53 | """ 54 | for rule in rules: 55 | if rule.min <= reg_pub <= rule.max: 56 | reg_len = rule.registrant_length 57 | break 58 | else: 59 | raise Exception('Registrant/Publication not found in registrant ' 60 | 'rule list.') 61 | registrant, publication = reg_pub[:reg_len], reg_pub[reg_len:] 62 | return registrant, publication 63 | 64 | def isbn13(self, separator='-'): 65 | ean, group, registrant, publication = self._body() 66 | isbn = ISBN13(ean, group, registrant, publication) 67 | return isbn.format(separator) 68 | 69 | def isbn10(self, separator='-'): 70 | ean, group, registrant, publication = self._body() 71 | isbn = ISBN10(ean, group, registrant, publication) 72 | return isbn.format(separator) 73 | -------------------------------------------------------------------------------- /faker/providers/person/lt_LT/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import unicode_literals 4 | from .. import Provider as PersonProvider 5 | 6 | 7 | class Provider(PersonProvider): 8 | formats = ( 9 | '{{first_name}} {{last_name}}', 10 | '{{first_name}} {{last_name}}', 11 | '{{last_name}}, {{first_name}}' 12 | ) 13 | 14 | first_names = ( 15 | 'Tomas', 'Lukas', 'Mantas', 'Deividas', 'Arnas', 'Artūras', 16 | 'Karolis', 'Dovydas', 'Dominykas', 'Darius', 'Edvinas', 'Jonas', 17 | 'Martynas', 'Kajus', 'Donatas', 'Andrius', 'Matas', 'Rokas', 18 | 'Augustas', 'Danielius', 'Mindaugas', 'Paulius', 'Marius', 19 | 'Armandas', 'Edgaras', 'Jokūbas', 'Nedas', 'Tadas', 'Nerijus', 20 | 'Simonas', 'Vytautas', 'Artūras', 'Robertas', 'Eimantas', 'Arijus', 21 | 'Nojus', 'Egidijus', 'Aurimas', 'Emilis', 'Laurynas', 'Edvardas', 22 | 'Joris', 'Pijus', 'Erikas', 'Domas', 'Vilius', 'Evaldas', 'Justinas', 23 | 'Aleksandras', 'Kristupas', 'Gabrielius', 'Benas', 'Gytis', 'Arminas', 24 | 'Vakris', 'Tautvydas', 'Domantas', 'Justas', 'Markas', 'Antanas', 25 | 'Arūnas', 'Ernestas', 'Aronas', 'Vaidas', 'Ąžuolas', 'Titas', 'Giedrius', 26 | 'Ignas', 'Povilas', 'Saulius', 'Julius', 'Arvydas', 'Kęstutis', 'Rytis', 27 | 'Aistis', 'Gediminas', 'Algirdas', 'Naglis', 'Irmantas', 'Rolandas', 28 | 'Aivaras', 'Simas', 'Faustas', 'Ramūnas', 'Šarūnas', 'Gustas', 'Tajus', 29 | 'Dainius', 'Arnoldas', 'Linas', 'Rojus', 'Adomas', 'Žygimantas', 30 | 'Ričardas', 'Orestas', 'Kipras', 'Juozas', 'Audrius', 'Romualdas', 31 | 'Petras', 'Eleonora', 'Raminta', 'Dovilė', 'Sandra', 'Dominyka', 'Ana', 32 | 'Erika', 'Kristina', 'Gintarė', 'Rūta', 'Edita', 'Karina', 'Živilė', 33 | 'Jolanta', 'Radvilė', 'Ramunė', 'Svetlana', 'Ugnė', 'Eglė', 'Viktorija', 34 | 'Justina', 'Brigita', 'Rasa', 'Marija', 'Giedrė', 'Iveta', 'Sonata', 35 | 'Vitalija', 'Adrija', 'Goda', 'Paulina', 'Kornelija', 'Liepa', 'Vakarė', 36 | 'Milda', 'Meda', 'Vaida', 'Izabelė', 'Jovita', 'Irma', 'Žemyna', 'Leila', 37 | 'Rimantė', 'Mantė', 'Rytė', 'Perla', 'Greta', 'Monika', 'Ieva', 'Indrė', 38 | 'Ema', 'Aurelija', 'Smiltė', 'Ingrida', 'Simona', 'Amelija', 'Sigita', 39 | 'Olivija', 'Laurita', 'Jorūnė', 'Leticija', 'Vigilija', 'Medėja', 'Laura', 40 | 'Agnė', 'Evelina', 'Kotryna', 'Lėja', 'Aušra', 'Neringa', 'Gerda', 41 | 'Jurgita', 'Rusnė', 'Aušrinė', 'Rita', 'Elena', 'Ineta', 'Ligita', 42 | 'Vasarė', 'Vėjūnė', 'Ignė', 'Gytė', 'Ariana', 'Arielė', 'Vytė', 'Eidvilė', 43 | 'Karolina', 'Miglė', 'Viltė', 'Jolanta', 'Enrika', 'Aurėja', 'Vanesa', 44 | 'Darija', 'Reda', 'Milana', 'Rugilė', 'Diana' 45 | ) 46 | 47 | last_names = ( 48 | 'Kazlauskas', 'Jankauskas', 'Petrauskas', 'Pocius', 'Stankevičius', 49 | 'Vsiliauskas', 'Žukauskas', 'Butkus', 'Paulauskas', 'Urbonas', 50 | 'Kavaliauskas', 'Sakalauskas', 'Žukauskas', 'Akelis', 'Ambrasas', 51 | 'Kairys', 'Kalvaitis', 'Kalvelis', 'Kalvėnas', 'Kaupas', 'Kiška', 52 | 'Gagys', 'Gailius', 'Gailys', 'Gaižauskas', 'Gaičiūnas', 'Galdikas', 53 | 'Gintalas', 'Ginzburgas', 'Grinius', 'Gronskis', 'Nagys', 'Naujokas', 54 | 'Narušis', 'Nausėda', 'Poška', 'Povilonis' 55 | ) 56 | -------------------------------------------------------------------------------- /faker/providers/ssn/en_CA/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | from __future__ import unicode_literals 3 | from .. import Provider as SsnProvider 4 | 5 | def checksum(sin): 6 | """ 7 | Determine validity of a Canadian Social Insurance Number. 8 | Validation is performed using a modified Luhn Algorithm. To check 9 | the Every second digit of the SIN is doubled and the result is 10 | summed. If the result is a multiple of ten, the Social Insurance 11 | Number is considered valid. 12 | 13 | https://en.wikipedia.org/wiki/Social_Insurance_Number 14 | """ 15 | 16 | # Remove spaces and create a list of digits. 17 | checksumCollection = list(sin.replace(' ', '')) 18 | checksumCollection = [int(i) for i in checksumCollection] 19 | 20 | # Discard the last digit, we will be calculating it later. 21 | checksumCollection[-1] = 0 22 | 23 | # Iterate over the provided SIN and double every second digit. 24 | # In the case that doubling that digit results in a two-digit 25 | # number, then add the two digits together and keep that sum. 26 | 27 | for i in range(1, len(checksumCollection), 2): 28 | result = checksumCollection[i] * 2 29 | if result < 10: 30 | checksumCollection[i] = result 31 | else: 32 | checksumCollection[i] = result - 10 + 1 33 | 34 | # The appropriate checksum digit is the value that, when summed 35 | # with the first eight values, results in a value divisible by 10 36 | 37 | check_digit = 10 - (sum(checksumCollection) % 10) 38 | check_digit = (0 if check_digit == 10 else check_digit) 39 | 40 | return check_digit 41 | 42 | class Provider(SsnProvider): 43 | 44 | # In order to create a valid SIN we need to provide a number that 45 | # passes a simple modified Luhn Algorithm checksum. 46 | # 47 | # This function reverses the checksum steps to create a random 48 | # valid nine-digit Canadian SIN (Social Insurance Number) in the 49 | # format '### ### ###'. 50 | def ssn(self): 51 | 52 | # Create an array of 8 elements initialized randomly. 53 | digits = self.generator.random.sample(range(9), 8) 54 | 55 | # The final step of the validation requires that all of the 56 | # digits sum to a multiple of 10. First, sum the first 8 and 57 | # set the 9th to the value that results in a multiple of 10. 58 | check_digit = 10 - (sum(digits) % 10) 59 | check_digit = (0 if check_digit == 10 else check_digit) 60 | 61 | digits.append(check_digit) 62 | 63 | # digits is now the digital root of the number we want 64 | # multiplied by the magic number 121 212 121. The next step is 65 | # to reverse the multiplication which occurred on every other 66 | # element. 67 | for i in range(1, len(digits), 2): 68 | if digits[i] % 2 == 0: 69 | digits[i] = (digits[i] // 2) 70 | else: 71 | digits[i] = (digits[i] + 9) // 2 72 | 73 | # Build the resulting SIN string. 74 | sin = "" 75 | for i in range(0, len(digits)): 76 | sin += str(digits[i]) 77 | # Add a space to make it conform to Canadian formatting. 78 | if i in (2,5): 79 | sin += " " 80 | 81 | # Finally return our random but valid SIN. 82 | return sin 83 | -------------------------------------------------------------------------------- /faker/providers/address/es/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | from .. import Provider as AddressProvider 4 | 5 | 6 | class Provider(AddressProvider): 7 | 8 | # List of Countries https://www.un.org/es/members/ 9 | countries = ( 10 | 'Afganistán', 'Albania', 'Alemania', 'Andorra', 'Angola', 11 | 'Antigua y Barbuda', 'Arabia Saudita', 'Argelia', 'Argentina', 12 | 'Armenia', 'Australia', 'Austria', 'Azerbaiyán', 'Bahamas', 'Bahrein', 13 | 'Bangladesh', 'Barbados', 'Belarús', 'Bélgica', 'Belice', 'Benin', 14 | 'Bhután', 'Bolivia', 'Bosnia y Herzegovina', 'Botswana', 'Brasil', 15 | 'Brunei Darussalam', 'Bulgaria', 'Burkina Faso', 'Burundi', 16 | 'Cabo Verde', 'Camboya', 'Camerún', 'Canadá', 'Chad', 'Chile', 'China', 17 | 'Chipre', 'Colombia', 'Comoras', 'Congo', 'Costa Rica', 18 | 'Côte d\'Ivoire', 'Croacia', 'Cuba', 'Dinamarca', 'Djibouti', 19 | 'Dominicana', 'Ecuador', 'Egipto', 'El Salvador', 20 | 'Emiratos Árabes Unidos', 'Eritrea', 'Eslovaquia', 'Eslovenia', 21 | 'España', 'Estados Unidos de América', 'Estonia', 'Etiopía', 22 | 'ex República Yugoslava de Macedonia', 'Federación de Rusia', 'Fiji', 23 | 'Filipinas', 'Finlandia', 'Francia', 'Gabón', 'Gambia', 'Georgia', 24 | 'Ghana', 'Granada', 'Grecia', 'Guatemala', 'Guinea', 'Guinea Bissau', 25 | 'Guinea Ecuatorial', 'Guyana', 'Haití', 'Honduras', 'Hungría', 'India', 26 | 'Indonesia', 'Irán', 'Iraq', 'Irlanda', 'Islandia', 'Islas Marshall', 27 | 'Islas Salomón', 'Israel', 'Italia', 'Jamaica', 'Japón', 'Jordania', 28 | 'Kazajstán', 'Kenya', 'Kirguistán', 'Kiribati', 'Kuwait', 'Lesotho', 29 | 'Letonia', 'Líbano', 'Liberia', 'Libia', 'Liechtenstein', 'Lituania', 30 | 'Luxemburgo', 'Madagascar', 'Malasia', 'Malawi', 'Maldivas', 'Mali', 31 | 'Malta', 'Marruecos', 'Mauricio', 'Mauritania', 'México', 'Micronesia', 32 | 'Mónaco', 'Mongolia', 'Montenegro', 'Mozambique', 'Myanmar', 'Namibia', 33 | 'Nauru', 'Nicaragua', 'Niger', 'Nigeria', 'Noruega', 'Nueva Zelandia', 34 | 'Omán', 'Países Bajos', 'Pakistán', 'Palau', 'Panamá', 35 | 'Papua Nueva Guinea', 'Paraguay', 'Perú', 'Polonia', 'Portugal', 36 | 'Qatar', 'Reino Unido de Gran Bretaña e Irlanda del Norte', 37 | 'República Árabe Siria', 'República Centroafricana', 'República Checa', 38 | 'República de Corea', 'República de Moldova', 39 | 'República Democrática del Congo', 'República Democrática Popular Lao', 40 | 'República Dominicana', 'República Federal Democrática de Nepal', 41 | 'República Popular Democrática de Corea', 'República Unida de Tanzanía', 42 | 'Rumania', 'Rwanda', 'Saint Kitts y Nevis', 'Samoa', 'San Marino', 43 | 'Santa Lucía', 'Santo Tomé y Príncipe', 'San Vicente y las Granadinas', 44 | 'Senegal', 'Serbia', 'Seychelles', 'Sierra Leona', 'Singapur', 45 | 'Somalia', 'Sri Lanka', 'Sudáfrica', 'Sudán', 'Sudán del Sur', 'Suecia', 46 | 'Suiza', 'Suriname', 'Swazilandia', 'Tailandia', 'Tayikistán', 47 | 'Timor-Leste', 'Togo', 'Tonga', 'Trinidad y Tabago', 'Túnez', 48 | 'Turkmenistán', 'Turquía', 'Tuvalu', 'Ucrania', 'Uganda', 'Uruguay', 49 | 'Uzbekistán', 'Vanuatu', 'Venezuela', 'Vietman', 'Yemen', 'Zambia', 50 | 'Zimbabwe', 51 | ) 52 | -------------------------------------------------------------------------------- /faker/utils/datetime_safe.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | # From django.utils.datetime_safe 4 | 5 | # Python's datetime strftime doesn't handle dates before 1900. 6 | # These classes override date and datetime to support the formatting of a date 7 | # through its full "proleptic Gregorian" date range. 8 | # 9 | # Based on code submitted to comp.lang.python by Andrew Dalke 10 | # 11 | # >>> datetime_safe.date(1850, 8, 2).strftime("%Y/%m/%d was a %A") 12 | # '1850/08/02 was a Friday' 13 | 14 | from __future__ import unicode_literals 15 | from datetime import date as real_date 16 | from datetime import datetime as real_datetime 17 | import re 18 | import time 19 | 20 | 21 | class date(real_date): 22 | def strftime(self, fmt): 23 | return strftime(self, fmt) 24 | 25 | 26 | class datetime(real_datetime): 27 | def strftime(self, fmt): 28 | return strftime(self, fmt) 29 | 30 | def combine(self, date, time): 31 | return datetime(date.year, date.month, date.day, 32 | time.hour, time.minute, time.microsecond, 33 | time.tzinfo) 34 | 35 | def date(self): 36 | return date(self.year, self.month, self.day) 37 | 38 | 39 | def new_date(d): 40 | """Generate a safe date from a datetime.date object.""" 41 | return date(d.year, d.month, d.day) 42 | 43 | 44 | def new_datetime(d): 45 | """ 46 | Generate a safe datetime from a datetime.date or datetime.datetime object. 47 | """ 48 | kw = [d.year, d.month, d.day] 49 | if isinstance(d, real_datetime): 50 | kw.extend([d.hour, d.minute, d.second, d.microsecond, d.tzinfo]) 51 | return datetime(*kw) 52 | 53 | 54 | # This library does not support strftime's "%s" or "%y" format strings. 55 | # Allowed if there's an even number of "%"s because they are escaped. 56 | _illegal_formatting = re.compile(r"((^|[^%])(%%)*%[sy])") 57 | 58 | 59 | def _findall(text, substr): 60 | # Also finds overlaps 61 | sites = [] 62 | i = 0 63 | while True: 64 | j = text.find(substr, i) 65 | if j == -1: 66 | break 67 | sites.append(j) 68 | i = j + 1 69 | return sites 70 | 71 | 72 | def strftime(dt, fmt): 73 | if dt.year >= 1900: 74 | return super(type(dt), dt).strftime(fmt) 75 | illegal_formatting = _illegal_formatting.search(fmt) 76 | if illegal_formatting: 77 | msg = 'strftime of dates before 1900 does not handle {0}' 78 | raise TypeError(msg.format(illegal_formatting.group(0))) 79 | 80 | year = dt.year 81 | # for every non-leap year century, advance by 82 | # 6 years to get into the 28-year repeat cycle 83 | delta = 2000 - year 84 | off = 6 * (delta // 100 + delta // 400) 85 | year += off 86 | 87 | # move to around the year 2000 88 | year += ((2000 - year) // 28) * 28 89 | timetuple = dt.timetuple() 90 | s1 = time.strftime(fmt, (year,) + timetuple[1:]) 91 | sites1 = _findall(s1, str(year)) 92 | 93 | s2 = time.strftime(fmt, (year + 28,) + timetuple[1:]) 94 | sites2 = _findall(s2, str(year + 28)) 95 | 96 | sites = [] 97 | for site in sites1: 98 | if site in sites2: 99 | sites.append(site) 100 | 101 | s = s1 102 | syear = "%04d" % (dt.year,) 103 | for site in sites: 104 | s = s[:site] + syear + s[site + 4:] 105 | return s 106 | -------------------------------------------------------------------------------- /faker/providers/automotive/de_DE/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | 3 | 4 | from __future__ import unicode_literals 5 | from .. import Provider as AutomotiveProvider 6 | import string 7 | 8 | 9 | class Provider(AutomotiveProvider): 10 | 11 | # http://berlin.de/daten/liste-der-kfz-kennzeichen/kfz-kennz-d.csv 12 | license_plate_prefix = ( 13 | 'A', 'AA', 'AB', 'ABI', 'ABG', 'AC', 'AE', 'AIC', 'AK', 'AM', 'AN', 'AÖ', 'AP', 'AS', 'AUR', 'AW', 'AZ', 'B', 14 | 'BA', 'BAD', 'BAR', 'BB', 'BC', 'BD', 'BGL', 'BI', 'BIR', 'BIT', 'BK', 'BL', 'BLK', 'BM', 'BN', 'BO', 'BOR', 15 | 'BOT', 'BP', 'BRA', 'BRB', 'BS', 'BT', 'BTF', 'BÜS', 'BW', 'BWL', 'BYL', 'BZ', 'C', 'CB', 'CE', 'CHA', 'CO', 16 | 'COC', 'COE', 'CUX', 'CW', 'D', 'DA', 'DAH', 'DAN', 'DAU', 'DBR', 'DD', 'DE', 'DEG', 'DEL', 'DGF', 'DH', 'DL', 17 | 'DLG', 'DN', 'Do', 'DON', 'DU', 'DÜW', 'E', 'EA', 'EB', 'EBE', 'ED', 'EE', 'EF', 'EI', 'EIC', 'EL', 'EM', 'EMD', 18 | 'EMS', 'EN', 'ER', 'ERB', 'ERH', 'ERZ', 'ES', 'ESW', 'EU', 'F', 'FB', 'FD', 'FDS', 'FF', 'FFB', 'FG', 'FL', 19 | 'FN', 'FO', 'FR', 'FRG', 'FRI', 'FS', 'FT', 'FÜ', 'G', 'GAP', 'GE', 'GER', 'GF', 'GG', 'GI', 'GL', 'GM', 'GÖ', 20 | 'GP', 'GR', 'GRZ', 'GS', 'GT', 'GTH', 'GÜ', 'GZ', 'H', 'HA', 'HAL', 'HAM', 'HAS', 'HB', 'HBN', 'HD', 'HDH', 21 | 'HE', 'HEF', 'HEI', 'HEL', 'HER', 'HF', 'HG', 'HGW', 'HH', 'HI', 'HL', 'HM', 'HN', 'HO', 'HOL', 'HOM', 'HP', 22 | 'HR', 'HRO', 'HS', 'HSK', 'HST', 'HU', 'HVL', 'HWI', 'HX', 'HZ', 'IGB', 'IK', 'IN', 'IZ', 'J', 'JL', 'K', 'KA', 23 | 'KB', 'KC', 'KE', 'KEH', 'KF', 'KG', 'KH', 'KI', 'KIB', 'KL', 'KLE', 'KN', 'KO', 'KR', 'KS', 'KT', 'KU', 'KÜN', 24 | 'KUS', 'KYF', 'L', 'LA', 'LAU', 'LB', 'LD', 'LDK', 'LDS', 'LER', 'LEV', 'LG', 'LI', 'LIF', 'LIP', 'LL', 'LM', 25 | 'LÖ', 'LOS', 'LRO', 'LSA', 'LSN', 'LU', 'LWL', 'M', 'MA', 'MB', 'MD', 'ME', 'MEI', 'MG', 'MI', 'MIL', 'MK', 26 | 'MKK', 'MM', 'MN', 'MOL', 'MOS', 'MR', 'MS', 'MSH', 'MSP', 'MST', 'MTK', 'MÜ', 'MÜR', 'MVL', 'MYK', 'MZ', 'MZG', 27 | 'N', 'NB', 'ND', 'NDH', 'NE', 'NEA', 'NES', 'NEW', 'NF', 'NI', 'NK', 'NL', 'NM', 'NMS', 'NOH', 'NOM', 'NR', 28 | 'NU', 'NVP', 'NW', 'NWM', 'OA', 'OAL', 'OB', 'OD', 'OE', 'OF', 'OG', 'OH', 'OHA', 'OHV', 'OHZ', 'OL', 'OPR', 29 | 'OS', 'OSL', 'OVP', 'P', 'PA', 'PAF', 'PAN', 'PB', 'PCH', 'PE', 'PF', 'PI', 'PIR', 'PLÖ', 'PM', 'PR', 'PS', 'R', 30 | 'RA', 'RD', 'RE', 'REG', 'RO', 'ROS', 'ROW', 'RP', 'RPL', 'RS', 'RT', 'RÜD', 'RÜG', 'RV', 'RW', 'RZ', 'S', 31 | 'SAD', 'SAL', 'SAW', 'SB', 'SC', 'SDL', 'SE', 'SG', 'SH', 'SHA', 'SHG', 'SHK', 'SHL', 'SI', 'SIG', 'SIM', 'SK', 32 | 'SL', 'SLF', 'SLK', 'SLS', 'SM', 'SN', 'SO', 'SOK', 'SÖM', 'SON', 'SP', 'SPN', 'SR', 'ST', 'STA', 'STD', 'SU', 33 | 'SÜW', 'SW', 'SZ', 'TDO', 'TBB', 'TF', 'TG', 'THL', 'THW', 'TIR', 'TÖL', 'TR', 'TS', 'TÜ', 'TUT', 'UE', 'UL', 34 | 'UM', 'UN', 'V', 'VB', 'VEC', 'VER', 'VIE', 'VK', 'VR', 'VS', 'W', 'WAF', 'WAK', 'WB', 'WE', 'WEN', 'WES', 'WF', 35 | 'WHV', 'WI', 'WIL', 'WL', 'WM', 'WN', 'WND', 'WO', 'WOB', 'WST', 'WT', 'WTM', 'WÜ', 'WUG', 'WUN', 'WW', 'WZ', 36 | 'Y', 'Z', 'ZW', 37 | ) 38 | 39 | license_plate_suffix = ( 40 | '-??-%@@@', 41 | '-?-%@@@', 42 | ) 43 | 44 | def license_plate(self): 45 | return self.random_element(self.license_plate_prefix) + \ 46 | self.lexify(self.numerify(self.random_element(self.license_plate_suffix)), string.ascii_uppercase) 47 | --------------------------------------------------------------------------------