__init__.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # coding=utf-8
  2. localized = True
  3. default_locale = 'en_GB'
  4. from .. import BaseProvider
  5. import string
  6. from string import ascii_uppercase
  7. import re
  8. class Provider(BaseProvider):
  9. """
  10. Provider for IBAN/BBAN: it generates valid (valid length, valid checksum)
  11. IBAN/BBANs for the given country. But the ids of the banks are random and
  12. not valid banks! Same for account numbers.
  13. """
  14. ALPHA = {c: str(ord(c) % 55) for c in string.ascii_uppercase}
  15. # see https://en.wikipedia.org/wiki/International_Bank_Account_Number
  16. bban_format = '????#############'
  17. country_code = 'GB'
  18. def bank_country(self):
  19. return self.country_code
  20. def bban(self):
  21. temp = re.sub(r'\?',
  22. lambda x: self.random_element(ascii_uppercase),
  23. self.bban_format)
  24. return self.numerify(temp)
  25. def iban(self):
  26. bban = self.bban()
  27. check = bban + self.country_code + '00'
  28. check = int(''.join(self.ALPHA.get(c, c) for c in check))
  29. check = 98 - (check % 97)
  30. check = str(check).zfill(2)
  31. return self.country_code + check + bban