Download tasks/data/forward/agilegeeks__pyvat.591565e/solution/golden.patch from Lego-X/ProgramGen: direct link, hf CLI and curl.
- Browser
- Download file 94.6 kB
-
https://huggingface.co/datasets/Lego-X/ProgramGen/resolve/main/tasks/data/forward/agilegeeks__pyvat.591565e/solution/golden.patch
- Command line
-
hf download hf://datasets/Lego-X/ProgramGen/tasks/data/forward/agilegeeks__pyvat.591565e/solution/golden.patch
-
curl -L -o golden.patch https://huggingface.co/datasets/Lego-X/ProgramGen/resolve/main/tasks/data/forward/agilegeeks__pyvat.591565e/solution/golden.patch
94.6 kB
diff --git a/pyVat/__init__.py b/pyVat/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/pyVat/api.py b/pyVat/api.py
new file mode 100644
index 0000000000000000000000000000000000000000..622908d11ef2b42c26047f3d2e49542b282917a0
--- /dev/null
+++ b/pyVat/api.py
@@ -0,0 +1,133 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+import sys
+
+
+EU_COUNTRIES = [
+ 'AT',
+ 'BE',
+ 'BG',
+ 'CY',
+ 'CZ',
+ 'DK',
+ 'EE',
+ 'FI',
+ 'FR',
+ 'DE',
+ 'GR',
+ 'HR',
+ 'HU',
+ 'IE',
+ 'IT',
+ 'LV',
+ 'LT',
+ 'LU',
+ 'MT',
+ 'NL',
+ 'PL',
+ 'PT',
+ 'RO',
+ 'SK',
+ 'SI',
+ 'ES',
+ 'SE',
+ 'GB'
+]
+def load_class(module_name, class_name):
+ mod = __import__(module_name, fromlist=[class_name])
+ klass = getattr(mod, class_name)
+ return klass
+
+def load_cc_validator(cc):
+ module_name = 'pyVat.validators.%s' % cc
+ klass_name = 'Validator'
+ klass = load_class(module_name, klass_name)
+ return klass
+
+class VatValidationError(Exception):
+ """
+ Exception thrown by the Validator object when the VAT number is not valid
+ """
+ pass
+
+class Validator(object):
+
+ def __init__(self, vat_number, vat_country_code=None):
+
+ self.error_message = None
+ self.vat_number = vat_number
+ self.vat_country_code = vat_country_code
+
+
+ def clean(self):
+ vat_number = self.vat_number
+ vat_country_code = self.vat_country_code
+
+ try:
+ vat_number = str(vat_number)
+ except:
+ VatValidationError('Invalid VAT number provided')
+ vat_number = vat_number.replace(' ', '')
+
+ if vat_country_code is not None:
+ try:
+ vat_country_code = str(vat_country_code)
+ except:
+ VatValidationError('Invalid VAT country provided')
+ vat_country_code = vat_country_code.replace(' ', '')
+ vat_country_code = vat_country_code.upper()
+ # if no vat_country_code provided we try to extract it from vat_number
+ else:
+ try:
+ vat_country_code = vat_number[:2]
+ except:
+ raise VatValidationError('Invalid VAT number provided')
+
+ vat_country_code = vat_country_code.upper()
+
+
+ vat_number = vat_number[2:]
+
+ if vat_country_code == 'EL':
+ vat_country_code = 'GR'
+
+ if vat_country_code not in EU_COUNTRIES:
+ raise VatValidationError('Invalid VAT country')
+
+ if len(vat_number)>2:
+ if vat_number[:2].upper() == vat_country_code:
+ vat_number = vat_number[2:]
+
+ return vat_number.upper(),vat_country_code.upper()
+
+ def validate(self):
+ try:
+ self.vat_number, self.country_code = self.clean()
+ except VatValidationError as e:
+ self.error_message = str(e)
+ return False
+
+ validator_klass = load_cc_validator(self.country_code.lower())
+ validator = validator_klass()
+ return validator.validate(str(self.vat_number))
diff --git a/pyVat/validators/__init__.py b/pyVat/validators/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/pyVat/validators/at.py b/pyVat/validators/at.py
new file mode 100644
index 0000000000000000000000000000000000000000..2594bf77d846e39042ff6c450b854bcac87902dd
--- /dev/null
+++ b/pyVat/validators/at.py
@@ -0,0 +1,53 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+ def __init__(self):
+ self.regexp = re.compile(r'^U\d{8}$', re.IGNORECASE)
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ checksum = int (vat_number[8])
+
+ r = 0
+ for i in range(3,8,2):
+ digit = int (vat_number[i-1])
+ r = r + ( int( digit/5 ) + (digit*2)%10 )
+
+ c = 4
+ for i in range(2,9,2):
+ c = c + int (vat_number[i-1])
+
+ c9 = (10 - (r+c)%10) % 10
+
+ return checksum == c9
diff --git a/pyVat/validators/be.py b/pyVat/validators/be.py
new file mode 100644
index 0000000000000000000000000000000000000000..bba21e52de2d149ebb13ba3dcc4ad11164af7ec5
--- /dev/null
+++ b/pyVat/validators/be.py
@@ -0,0 +1,43 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+ def __init__(self):
+ self.regexp = re.compile(r'^0[1-9]{1}\d{8}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ checksum = int(vat_number[8:10])
+ checkval = 97 - ( int(vat_number[:8]) % 97 )
+
+ return checkval == checksum
diff --git a/pyVat/validators/bg.py b/pyVat/validators/bg.py
new file mode 100644
index 0000000000000000000000000000000000000000..a427522d7ba1390be3e1e032a61a8cede58797b8
--- /dev/null
+++ b/pyVat/validators/bg.py
@@ -0,0 +1,93 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{9,10}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ # if is legal entity
+ if (len(vat_number)==9):
+ checksum = int(vat_number[8])
+ a1 = self.sum_weights(list(range(1,9)), vat_number[:8])
+ r1 = a1 % 11
+
+ if r1 == 10:
+ a2 = self.sum_weights(list(range(3,11)), vat_number[:8])
+ r2 = a2 % 11
+ if r2 == 10:
+ r = 0
+ else:
+ r = r2
+ else:
+ r = r1
+
+ return checksum == r
+
+ # physical person
+ checksum = int(vat_number[9])
+ weights = [2, 4, 8, 5, 10, 9, 7, 3, 6]
+ a1 = self.sum_weights(weights, vat_number[:9])
+ r1 = a1 % 11
+ if r1 == 10:
+ r = 0
+ else:
+ r = r1
+ if checksum == r:
+ return True
+
+ # foreigners
+ checksum = int(vat_number[9])
+ weights = [21, 19, 17, 13, 11, 9, 7, 3, 1]
+ a1 = self.sum_weights(weights, vat_number[:9])
+ r = a1 % 10
+ if checksum == r:
+ return True
+
+ # others
+ checksum = int(vat_number[9])
+ weights = [4, 3, 2, 7, 6, 5, 4, 3, 2]
+ a1 = self.sum_weights(weights, vat_number[:9])
+ r1 = 11 - a1 % 11
+ if r1 == 11:
+ r = 0
+ elif r1 == 10:
+ return False
+ else:
+ r = r1
+ if checksum == r:
+ return True
+
+ return False
diff --git a/pyVat/validators/cy.py b/pyVat/validators/cy.py
new file mode 100644
index 0000000000000000000000000000000000000000..5f26b59ecf0e687e906c683a2cb5b91014a8c1df
--- /dev/null
+++ b/pyVat/validators/cy.py
@@ -0,0 +1,98 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{8}[a-z]$', re.IGNORECASE)
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+ if int(vat_number[0]) not in [0, 1, 3, 4, 5, 9]:
+ return False
+ if vat_number[:2] == str('12'):
+ return False
+
+ odd_digit_mapping = {
+ 0: 1,
+ 1: 0,
+ 2: 5,
+ 3: 7,
+ 4: 9,
+ 5: 13,
+ 6: 15,
+ 7: 17,
+ 8: 19,
+ 9: 21
+ }
+ a1 = 0
+ for i in range(8):
+ if i % 2 == 0:
+ a1 = a1 + odd_digit_mapping [ int(vat_number[i]) ]
+ else:
+ a1 = a1 + + int(vat_number[i])
+
+ r = a1 % 26
+
+ last_char_mapping = {
+ 0: 'A',
+ 1: 'B',
+ 2: 'C',
+ 3: 'D',
+ 4: 'E',
+ 5: 'F',
+ 6: 'G',
+ 7: 'H',
+ 8: 'I',
+ 9: 'J',
+ 10: 'K',
+ 11: 'L',
+ 12: 'M',
+ 13: 'N',
+ 14: 'O',
+ 15: 'P',
+ 16: 'Q',
+ 17: 'R',
+ 18: 'S',
+ 19: 'T',
+ 20: 'U',
+ 21: 'V',
+ 22: 'W',
+ 23: 'X',
+ 24: 'Y',
+ 25: 'Z'
+ }
+
+ last_char = vat_number[8]
+ last_char = last_char.upper()
+
+ return last_char_mapping[r] == last_char
diff --git a/pyVat/validators/cz.py b/pyVat/validators/cz.py
new file mode 100644
index 0000000000000000000000000000000000000000..6099d5a13887cee558ca6a59d68c7c3de22e0e24
--- /dev/null
+++ b/pyVat/validators/cz.py
@@ -0,0 +1,144 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+import math
+import calendar
+import datetime
+from .generic import GenericValidator
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{8,10}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ # legal entities
+ if len(vat_number) == 8:
+ if vat_number[0] == str('9'):
+ return False
+ checksum = int (vat_number[7])
+ a1 = self.sum_weights(list(range(8,1,-1)), vat_number[:8])
+ if a1 % 11 == 0:
+ a2 = a1 + 11
+ else:
+ a2 = math.ceil(a1/11) * 11
+ c8 = (a2 - a1) % 10
+
+ return checksum == c8
+
+ # individuals
+ if len(vat_number) == 9:
+
+ # special cases
+ if vat_number[0] == str('6'):
+ checksum = int(vat_number[8])
+ a1 = self.sum_weights(list(range(8, 1, -1)), vat_number[1:8])
+ if a1 % 11 == 0:
+ a2 = a1 + 11
+ else:
+ a2 = math.ceil(a1/11) * 11
+ d = a2 - a1
+ last_digit_mapping = {
+ 1: 8,
+ 2: 7,
+ 3: 6,
+ 4: 5,
+ 5: 4,
+ 6: 3,
+ 7: 2,
+ 8: 1,
+ 9: 0,
+ 10: 9,
+ 11: 8
+ }
+ return checksum == last_digit_mapping[d]
+ else:
+ # common individuals
+ if int(vat_number[:2])>53:
+ return False
+
+ monthval = int(vat_number[2:4])
+ if monthval not in range (1,13) and monthval not in range(51,63):
+ return False
+
+ if monthval>12:
+ monthval = monthval - 50
+ num_days_month = calendar.monthrange( int(str('19').join(vat_number[:2])), monthval)[1]
+
+ daysval = int(vat_number[4:6])
+ if daysval<1 or daysval>num_days_month:
+ return False
+
+ return True
+
+ # individuals - born between 1954 and 1999
+ if len(vat_number) == 10:
+ if int(vat_number) % 11 != 0:
+ return False
+
+ current_year = str(datetime.date.today().year)
+ current_year = int(current_year[2:])
+ yearval = int(vat_number[:2])
+ if yearval not in range (current_year+1) and yearval not in range(54,100):
+ return False
+
+ monthval = int(vat_number[2:4])
+ if monthval not in range(1, 13) and monthval not in range(21, 33)\
+ and monthval not in range(51, 63) and monthval not in range(71, 83):
+ return False
+
+ if monthval in range(21,33):
+ monthval = monthval - 20
+ elif monthval in range(51,63):
+ monthval = monthval - 50
+ elif monthval in range(71,83):
+ monthval = monthval - 70
+ else:
+ monthval
+
+
+ year_prefix = str('19')
+ if yearval<13:
+ year_prefix = str('20')
+ num_days_month = calendar.monthrange(int(year_prefix.join(vat_number[:2])), monthval)[1]
+ daysval = int(vat_number[4:6])
+ if daysval < 1 or daysval > num_days_month:
+ return False
+
+ a1 = 0
+ for i in range(0,9,2):
+ a1 = a1 + int(vat_number[i] + vat_number[i+1])
+
+ if a1 % 11 != 0:
+ return False
+
+ return True
+
+ return False
diff --git a/pyVat/validators/de.py b/pyVat/validators/de.py
new file mode 100644
index 0000000000000000000000000000000000000000..53092fe90f7c0f87add3d3ea261dcba717b542df
--- /dev/null
+++ b/pyVat/validators/de.py
@@ -0,0 +1,58 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{9}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ checksum = int (vat_number[8])
+
+ if vat_number[0] == str('0'):
+ return False
+
+ p = 10
+ for i in range(8):
+ s = int(vat_number[i]) + p
+ m = s % 10
+ if m == 0:
+ m = 10
+ p = (2 * m) % 11
+ r = 11 - p
+ if r == 10:
+ c9 = 0
+ else:
+ c9 = r
+
+ return checksum == c9
diff --git a/pyVat/validators/dk.py b/pyVat/validators/dk.py
new file mode 100644
index 0000000000000000000000000000000000000000..d3dea9c431934bc2c6fb0ba5b0a093334bf13560
--- /dev/null
+++ b/pyVat/validators/dk.py
@@ -0,0 +1,48 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{8}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ if vat_number[0] == str('0'):
+ return False
+
+ r = self.sum_weights([2, 7, 6, 5, 4, 3, 2, 1], vat_number)
+ if r % 11 == 0:
+ return True
+
+ return False
diff --git a/pyVat/validators/ee.py b/pyVat/validators/ee.py
new file mode 100644
index 0000000000000000000000000000000000000000..8236020bb45c807a90e9df5c7026a6db6de0ab7f
--- /dev/null
+++ b/pyVat/validators/ee.py
@@ -0,0 +1,50 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+import math
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{9}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ if vat_number[:2] != str('10'):
+ return False
+
+ checksum = int(vat_number[8])
+
+ a1 = self.sum_weights([3, 7, 1, 3, 7, 1, 3, 7], vat_number)
+ a2 = math.ceil(a1 / 10) * 10
+ c9 = a2 - a1
+
+ return checksum == c9
diff --git a/pyVat/validators/es.py b/pyVat/validators/es.py
new file mode 100644
index 0000000000000000000000000000000000000000..59d8411c90ae0d41211aad08d4d587d6f65042f4
--- /dev/null
+++ b/pyVat/validators/es.py
@@ -0,0 +1,152 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+import math
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+ def __init__(self):
+ self.regexp = re.compile(r'^[\da-z]\d{7}[\da-z]$', re.IGNORECASE)
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+ checksum = vat_number[8].upper()
+
+ try:
+ int( vat_number[8] )
+ except:
+ c9_is_number = False
+ else:
+ c9_is_number = True
+
+ try:
+ int( vat_number[0] )
+ except:
+ c1_is_number = False
+ else:
+ c1_is_number = True
+
+ c1 = vat_number[0].upper()
+ if c9_is_number:
+ if c1 not in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'U', 'V']:
+ return False
+ else:
+ if c1 not in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'K',
+ 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'W', 'X', 'Y', 'Z' ]:
+ return False
+
+ # Juridical entities other than national ones
+ if c9_is_number is False and c1 in ['A', 'B', 'C', 'D', 'E', 'F', 'G',
+ 'H', 'N', 'P', 'Q', 'R', 'S', 'W']:
+ s1 = int(vat_number[2]) + int(vat_number[4]) + int(vat_number[6])
+ s2 = 0
+ for i in range(1,8,2):
+ digit = int(vat_number[i])
+ s2 = s2 + int(digit/5) + (2 * digit) % 10
+ r = 10 - (s1 + s2) % 10
+ last_digit_mapping = {
+ 1: 'A',
+ 2: 'B',
+ 3: 'C',
+ 4: 'D',
+ 5: 'E',
+ 6: 'F',
+ 7: 'G',
+ 8: 'H',
+ 9: 'I',
+ 10: 'J'
+ }
+ if checksum == last_digit_mapping[r]:
+ return True
+
+ # # Physical persons
+ if c9_is_number is False:
+ if c1 in ['K', 'L', 'M', 'X', 'Y', 'Z'] or c1_is_number:
+ new_c1 = c1
+ if new_c1 == 'Y':
+ new_c1 = 1
+ if new_c1 == 'Z':
+ new_c1 = 2
+ new_vat_number = str(new_c1) + vat_number[1:]
+
+ try:
+ int(new_c1)
+ except:
+ new_c1_is_number = False
+ else:
+ new_c1_is_number = True
+
+ if new_c1_is_number:
+ r = sum(int(i) for i in new_vat_number[:8]) %23 + 1
+ else:
+ r = sum(int(i) for i in new_vat_number[1:8]) % 23 + 1
+ last_digit_mapping = {
+ 1: 'T',
+ 2: 'R',
+ 3: 'W',
+ 4: 'A',
+ 5: 'G',
+ 6: 'M',
+ 7: 'Y',
+ 8: 'F',
+ 9: 'P',
+ 10: 'D',
+ 11: 'X',
+ 12: 'B',
+ 13: 'N',
+ 14: 'J',
+ 15: 'Z',
+ 16: 'S',
+ 17: 'Q',
+ 18: 'V',
+ 19: 'H',
+ 20: 'L',
+ 21: 'C',
+ 22: 'K',
+ 23: 'E'
+ }
+ if checksum == last_digit_mapping[r]:
+ return True
+
+ if c9_is_number:
+ checksum = int(vat_number[8])
+ s1 = int(vat_number[2]) + int(vat_number[4]) + int(vat_number[6])
+ s2 = 0
+ for i in range(1, 8, 2):
+ digit = int(vat_number[i])
+ s2 = s2 + int(digit / 5) + (2 * digit) % 10
+ r = 10 - (s1 + s2) % 10
+
+ return checksum == (r % 10)
+
+ return False
+
+
+
diff --git a/pyVat/validators/fi.py b/pyVat/validators/fi.py
new file mode 100644
index 0000000000000000000000000000000000000000..edc5b4e6b5363061dfc5975d556a5c38bfb0ab42
--- /dev/null
+++ b/pyVat/validators/fi.py
@@ -0,0 +1,48 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{8}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ checksum = int(vat_number[7])
+
+ r = 11 - self.sum_weights([7,9,10,5,8,4,2], vat_number) % 11
+ if r == 10:
+ return False
+ elif (r == 11 and checksum == 0) or checksum == r:
+ return True
+ else:
+ return False
diff --git a/pyVat/validators/fr.py b/pyVat/validators/fr.py
new file mode 100644
index 0000000000000000000000000000000000000000..31fb8693b24f6619afe1b051c77d3fd66444126e
--- /dev/null
+++ b/pyVat/validators/fr.py
@@ -0,0 +1,112 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+import sys
+from .generic import GenericValidator
+
+PY_3_OR_HIGHER = sys.version_info >= (3, 0)
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+ ccm = {
+ 0: '0',
+ 1: '1',
+ 2: '2',
+ 3: '3',
+ 4: '4',
+ 5: '5',
+ 6: '6',
+ 7: '7',
+ 8: '8',
+ 9: '9',
+ 10: 'A',
+ 11: 'B',
+ 12: 'C',
+ 13: 'D',
+ 14: 'E',
+ 15: 'F',
+ 16: 'G',
+ 17: 'H',
+ 18: 'J',
+ 19: 'K',
+ 20: 'L',
+ 21: 'M',
+ 22: 'N',
+ 23: 'P',
+ 24: 'Q',
+ 25: 'R',
+ 26: 'S',
+ 27: 'T',
+ 28: 'U',
+ 29: 'V',
+ 30: 'W',
+ 31: 'X',
+ 32: 'Y',
+ 33: 'Z'
+
+ }
+
+ def __init__(self):
+ self.regexp = re.compile(r'^[\da-z]{2}\d{9}$', re.IGNORECASE)
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ try:
+ int(vat_number)
+ except:
+ new_style = True
+ else:
+ new_style = False
+
+ if new_style is False:
+ checkval = int(vat_number[2:] + '12') % 97
+ return int(vat_number[:2]) == checkval
+ else:
+ if PY_3_OR_HIGHER:
+ inv_ccm = {v: k for k, v in Validator.ccm.items()}
+ else:
+ inv_ccm = {v: k for k, v in Validator.ccm.iteritems()}
+
+ s1 = inv_ccm[vat_number[0]]
+ s2 = inv_ccm[vat_number[1]]
+
+ try:
+ c1 = int(vat_number[0])
+ except:
+ s = s1 * 34 + s2 - 100
+ else:
+ s = s1 * 24 + s2 - 10
+
+ p = s / 11 + 1
+ r1 = s % 11
+ r2 = int(vat_number[2:]) % 11
+
+ return r1 == r2
+
+
diff --git a/pyVat/validators/gb.py b/pyVat/validators/gb.py
new file mode 100644
index 0000000000000000000000000000000000000000..3fc3b413308b4cb51645c04c0d7604e16b3d851c
--- /dev/null
+++ b/pyVat/validators/gb.py
@@ -0,0 +1,74 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+import math
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+ def __init__(self):
+ self.regexp = re.compile(r'^((\d{9})|(\d{12})|(GD\d{3})|(HA\d{3}))$', re.IGNORECASE)
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ # Format 1
+ if len(vat_number) == 5:
+ ranges = {
+ 'GD': range(500),
+ 'HA': range(500,1000),
+ }
+ if int(vat_number[2:]) not in ranges[ vat_number[:2] ]:
+ return False
+ return True
+
+ # Format 2
+ c89 = int(vat_number[7:9])
+ c17 = int(vat_number[:7])
+ r = self.sum_weights(list(range(8, 1, -1)), vat_number[:7]) + c89
+ r1 = r % 97
+ r2 = (r + 55) % 97
+ if (r1 * r2) != 0 or (r1 + r2) == 0:
+ return False
+ if r1 == 0:
+ for rng in [range(100000, 1000000),
+ range(9490001, 9700001),
+ range(9990001, 10000000)]:
+ if c17 in rng:
+ return False
+
+ if r2 == 0:
+ if c17 in range(1, 1000001):
+ return False
+
+ if len(vat_number) == 12:
+ if int(vat_number[9:]) == 0:
+ return False
+
+ return True
diff --git a/pyVat/validators/generic.py b/pyVat/validators/generic.py
new file mode 100644
index 0000000000000000000000000000000000000000..2b91dff95de2392b53defb92a9e3fbe611288580
--- /dev/null
+++ b/pyVat/validators/generic.py
@@ -0,0 +1,43 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+
+class GenericValidator(object):
+ """
+ Generic validator
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^.{1,}$')
+
+ def validate(self, vat_number):
+ vat_number = str(vat_number)
+ if not self.regexp.match(vat_number):
+ return False
+
+
+ def sum_weights(self, weights, number, start_pos=0):
+ checkval = 0;
+ for i in range(start_pos, len(weights)):
+ checkval = checkval + int(number[i]) * weights[i]
+ return checkval
\ No newline at end of file
diff --git a/pyVat/validators/gr.py b/pyVat/validators/gr.py
new file mode 100644
index 0000000000000000000000000000000000000000..9f83afc9fa3719fb43130d2ff6ad894915c22fb0
--- /dev/null
+++ b/pyVat/validators/gr.py
@@ -0,0 +1,47 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+import math
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{9}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ checksum = int(vat_number[8])
+
+ a1 = self.sum_weights([256, 128, 64, 32, 16, 8, 4, 2], vat_number)
+ a2 = a1 % 11
+ c9 = a2 % 10
+
+ return checksum == c9
diff --git a/pyVat/validators/hr.py b/pyVat/validators/hr.py
new file mode 100644
index 0000000000000000000000000000000000000000..51104e53082c07d1e2c6e9149393cd0deec96f31
--- /dev/null
+++ b/pyVat/validators/hr.py
@@ -0,0 +1,39 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{11}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ return True
diff --git a/pyVat/validators/hu.py b/pyVat/validators/hu.py
new file mode 100644
index 0000000000000000000000000000000000000000..4418392863ebda6dd29aad138754906ec322495e
--- /dev/null
+++ b/pyVat/validators/hu.py
@@ -0,0 +1,49 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{8}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ checksum = vat_number[7]
+ a1 = str(self.sum_weights([9,7,3,1,9,7,3],vat_number))
+ if a1[-1] == '0':
+ checkval = '0'
+ else:
+ checkval = str(10 - int(a1[-1]))
+ return checkval == checksum
+
+
+
diff --git a/pyVat/validators/ie.py b/pyVat/validators/ie.py
new file mode 100644
index 0000000000000000000000000000000000000000..09ef11acfc23675fa8db9b0955714bd628857dbd
--- /dev/null
+++ b/pyVat/validators/ie.py
@@ -0,0 +1,82 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ check_char_mapping = {
+ 0: 'W',
+ 1: 'A',
+ 2: 'B',
+ 3: 'C',
+ 4: 'D',
+ 5: 'E',
+ 6: 'F',
+ 7: 'G',
+ 8: 'H',
+ 9: 'I',
+ 10: 'J',
+ 11: 'K',
+ 12: 'L',
+ 13: 'M',
+ 14: 'N',
+ 15: 'O',
+ 16: 'P',
+ 17: 'Q',
+ 18: 'R',
+ 19: 'S',
+ 20: 'T',
+ 21: 'U',
+ 22: 'V'
+ }
+
+ def __init__(self):
+ self.regexp = re.compile(r'^((\d{7}[a-z])|(\d[a-z\+\*]\d{5}[a-z]))$', re.IGNORECASE)
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+ checksum = vat_number[7]
+
+ #check for old style - second char sould be a letter
+ try:
+ int(vat_number[1])
+ except:
+ old_style = True
+ else:
+ old_style = False
+
+ if old_style:
+ n = '0' + vat_number[2:7] + vat_number[0]
+ r = self.sum_weights(list(range(8,1,-1)), n) % 23
+ else:
+ r = r = self.sum_weights(list(range(8,1,-1)), vat_number) % 23
+
+ return checksum == Validator.check_char_mapping[r]
diff --git a/pyVat/validators/it.py b/pyVat/validators/it.py
new file mode 100644
index 0000000000000000000000000000000000000000..ebc82aab950936499fb5efe9668b11e52d95ffed
--- /dev/null
+++ b/pyVat/validators/it.py
@@ -0,0 +1,57 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{11}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+ checksum = int(vat_number[10])
+
+ c8910 = int(vat_number[7:10])
+ if c8910 not in range(1, 102) and c8910 not in [120, 121, 999, 888]:
+ return False
+
+ s1 = 0
+ for i in range(0,9,2):
+ s1 = s1 + int(vat_number[i])
+
+ s2 = 0
+ for i in range(1,10,2):
+ n = int(vat_number[i])
+ s2 = s2 + int(n/5) + (2 * n) % 10
+
+ checkval = (10 - (s1 + s2) % 10) % 10
+
+ return checksum == checkval
\ No newline at end of file
diff --git a/pyVat/validators/lt.py b/pyVat/validators/lt.py
new file mode 100644
index 0000000000000000000000000000000000000000..6f34cffdf995529ccc823e5cffe98f8500efca2a
--- /dev/null
+++ b/pyVat/validators/lt.py
@@ -0,0 +1,73 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^((\d{9})|(\d{12}))$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ # Legal entities
+ if len(vat_number) == 9:
+ checksum = int(vat_number[8])
+ if int(vat_number[7]) != 1:
+ return False
+ r1 = self.sum_weights(list(range(1,9)), vat_number) % 11
+ if r1 != 10:
+ checkval = r1
+ else:
+ rng = list(range(3,10)) + [1]
+ r2 = self.sum_weights(rng, vat_number) % 11
+ if r2 == 10:
+ checkval = 0
+ else:
+ checkval = r2
+ else:
+ # Temporarily registered taxpayers
+ checksum = int(vat_number[11])
+ if int(vat_number[10]) != 1:
+ return False
+
+ rng = list(range(1,10)) + list(range(1,3))
+ r1 = self.sum_weights(rng, vat_number) % 11
+ if r1 != 10:
+ checkval = r1
+ else:
+ rng = list(range(3, 10)) + list(range(1,5))
+ r2 = self.sum_weights(rng, vat_number) % 11
+ if r2 == 10:
+ checkval = 0
+ else:
+ checkval = r2
+ return checksum == checkval
diff --git a/pyVat/validators/lu.py b/pyVat/validators/lu.py
new file mode 100644
index 0000000000000000000000000000000000000000..2ee8867b5e1fd835c333d3d46af3ed9a8c157a18
--- /dev/null
+++ b/pyVat/validators/lu.py
@@ -0,0 +1,43 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{8}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+ checksum = int(vat_number[6:])
+ checkval = int(vat_number[:6]) % 89
+ return checksum == checkval
+
diff --git a/pyVat/validators/lv.py b/pyVat/validators/lv.py
new file mode 100644
index 0000000000000000000000000000000000000000..fdc81993515b02d624e7ce2231f73351e9380468
--- /dev/null
+++ b/pyVat/validators/lv.py
@@ -0,0 +1,65 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+import datetime
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{11}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ # Legal entities
+ if int(vat_number[0]) > 3:
+ checksum = int(vat_number[10])
+ a1 = self.sum_weights([9,1,4,8,3,10,2,5,7,6], vat_number)
+ r = 3 - a1 % 11
+ if r < -1:
+ checkval = r + 11
+ elif r > 1:
+ checkval = r
+ else:
+ return False
+
+ return checkval == checksum
+ # Natural persons
+ else:
+ try:
+ datetime.datetime.strptime(vat_number[:6], '%d%m%y')
+ except:
+ return False
+ else:
+ return True
+
+
+
diff --git a/pyVat/validators/mt.py b/pyVat/validators/mt.py
new file mode 100644
index 0000000000000000000000000000000000000000..ff6fdbb751643e78f550862452bf0986629883a5
--- /dev/null
+++ b/pyVat/validators/mt.py
@@ -0,0 +1,52 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{8}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+ checksum = int(vat_number[6:])
+
+ if int(vat_number[:6])<= 100000:
+ return False
+
+ a1 = self.sum_weights([3,4,6,7,8,9], vat_number)
+ r = 37 - a1 % 37
+ if r == 0:
+ checkval = 37
+ else:
+ checkval = r
+ return checksum == checkval
+
diff --git a/pyVat/validators/nl.py b/pyVat/validators/nl.py
new file mode 100644
index 0000000000000000000000000000000000000000..976c8f79653ea0b4f43552fd50524bef3685342b
--- /dev/null
+++ b/pyVat/validators/nl.py
@@ -0,0 +1,52 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{9}B\d{2}$', re.IGNORECASE)
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ if vat_number[10:] == '00':
+ return False
+
+ checksum = int(vat_number[8])
+
+ a1 = self.sum_weights(list(range(9,1,-1)), vat_number)
+ a2 = a1 % 11
+ if a2 == 10:
+ return False
+
+ return checksum == a2
+
diff --git a/pyVat/validators/pl.py b/pyVat/validators/pl.py
new file mode 100644
index 0000000000000000000000000000000000000000..6df00557edcb0ec6da881ba95a2be2cdbc77850c
--- /dev/null
+++ b/pyVat/validators/pl.py
@@ -0,0 +1,48 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{10}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ checksum = int(vat_number[9])
+
+ a1 = self.sum_weights([6,5,7,2,3,4,5,6,7], vat_number)
+ r = a1 % 11
+ if r == 10:
+ return False
+
+ return checksum == r
diff --git a/pyVat/validators/pt.py b/pyVat/validators/pt.py
new file mode 100644
index 0000000000000000000000000000000000000000..faf7d9472f55ef2cb4367cccfea0cb950ca5400b
--- /dev/null
+++ b/pyVat/validators/pt.py
@@ -0,0 +1,50 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{9}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ if vat_number[0] == '0':
+ return False
+
+ checksum = int(vat_number[8])
+ a1 = self.sum_weights(list(range(9,1,-1)), vat_number)
+ r = 11 - a1 % 11
+ if r in [10,11]:
+ r = 0
+ return checksum == r
+
diff --git a/pyVat/validators/ro.py b/pyVat/validators/ro.py
new file mode 100644
index 0000000000000000000000000000000000000000..6fab5068219547f3e2712dcdd68cc2878d7190fb
--- /dev/null
+++ b/pyVat/validators/ro.py
@@ -0,0 +1,56 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{2,10}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ if vat_number[0] == '0':
+ return False
+
+ vat_number = vat_number.rjust(10,str('0'))
+ checksum = int (vat_number[9])
+ weights = [7, 5, 3, 2, 1, 7, 5, 3, 2]
+ checkval = self.sum_weights(weights, vat_number)
+ checkval = (checkval * 10) % 11
+ if checkval==10:
+ checkval=0
+ return checkval == checksum
\ No newline at end of file
diff --git a/pyVat/validators/se.py b/pyVat/validators/se.py
new file mode 100644
index 0000000000000000000000000000000000000000..2cd73fdb81f6d0ed8eace3100134e36c789f1c35
--- /dev/null
+++ b/pyVat/validators/se.py
@@ -0,0 +1,53 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{12}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ if int(vat_number[10:]) not in range(1,95):
+ return False
+
+ checksum = int(vat_number[9])
+ r = 0
+ for i in range(0,9,2):
+ n = int(vat_number[i])
+ r = r + int(n / 5) + (2 * n) % 10
+ c = 0
+ for i in (range(1,8,2)):
+ c = c + int(vat_number[i])
+ checkval = (10 - (r + c) % 10) % 10
+ return checksum == checkval
diff --git a/pyVat/validators/si.py b/pyVat/validators/si.py
new file mode 100644
index 0000000000000000000000000000000000000000..95f944f1b4587e2cbf37fb885bb8122ded7902ed
--- /dev/null
+++ b/pyVat/validators/si.py
@@ -0,0 +1,54 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{8}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ if int(vat_number[:7])<1000000:
+ return False
+
+ checksum = int(vat_number[7])
+ a1 = self.sum_weights(list(range(8,1,-1)), vat_number)
+ r = 11 - a1 % 11
+ if r == 10:
+ checkval = 0
+ elif r == 11:
+ return False
+ else:
+ checkval = r
+
+ return checksum == checkval
diff --git a/pyVat/validators/sk.py b/pyVat/validators/sk.py
new file mode 100644
index 0000000000000000000000000000000000000000..bb4a96aed6c51b7cc5559ddbaa12ec57a832abfb
--- /dev/null
+++ b/pyVat/validators/sk.py
@@ -0,0 +1,48 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+from .generic import GenericValidator
+
+
+class Validator(GenericValidator):
+ """
+ For rules see /docs/VIES-VAT Validation Routines-v15.0.doc
+ """
+
+ def __init__(self):
+ self.regexp = re.compile(r'^\d{10}$')
+
+ def validate(self, vat_number):
+ if super(Validator, self).validate(vat_number) is False:
+ return False
+
+ vat_number = str(vat_number)
+
+ if int(vat_number[0]) == 0:
+ return False
+
+ if int(vat_number[2]) not in [2,3,4,7,8,9]:
+ return False
+
+ r = int(vat_number) % 11
+ return r == 0
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/tests/test_validator.py b/tests/test_validator.py
new file mode 100644
index 0000000000000000000000000000000000000000..07f1dd856a58448600fd79fd13461d88e3ffa424
--- /dev/null
+++ b/tests/test_validator.py
@@ -0,0 +1,399 @@
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+import unittest
+
+from pyVat.api import Validator
+
+class TestValidator(unittest.TestCase):
+
+ def test_at(self):
+ validator = Validator('ATU10223006')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'AT')
+
+ validator = Validator('ATU10223005')
+ self.assertFalse(validator.validate())
+
+ def test_be(self):
+ validator = Validator('BE0776091951')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'BE')
+ self.assertEqual(validator.vat_number, '0776091951')
+
+ validator = Validator('BE0776091950')
+ self.assertFalse(validator.validate())
+
+ validator = Validator('BE0842411247')
+ self.assertTrue(validator.validate())
+
+ def test_bg(self):
+
+ # test legal entity
+ validator = Validator('BG101004508')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'BG')
+ self.assertEqual(validator.vat_number, '101004508')
+
+ validator = Validator('BG101004502')
+ self.assertFalse(validator.validate())
+
+ # test physical person
+ validator = Validator('BG0041010002')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'BG')
+ self.assertEqual(validator.vat_number, '0041010002')
+
+ # foreigners
+ validator = Validator('BG0000100159')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'BG')
+ self.assertEqual(validator.vat_number, '0000100159')
+
+ # others
+ validator = Validator('BG0000100153')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'BG')
+ self.assertEqual(validator.vat_number, '0000100153')
+
+ validator = Validator('BG202618588')
+ self.assertTrue(validator.validate())
+
+ def test_cy(self):
+ validator = Validator('CY00532445O') # the last char is O from oranges
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'CY')
+ self.assertEqual(validator.vat_number, '00532445O')
+
+ validator = Validator('CY12000139V')
+ self.assertFalse(validator.validate())
+
+
+ def test_cz(self):
+
+ # test legal entity
+ validator = Validator('CZ46505334')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'CZ')
+ self.assertEqual(validator.vat_number, '46505334')
+
+ validator = Validator('CZ46505332')
+ self.assertFalse(validator.validate())
+
+ # test individuals - special cases
+ validator = Validator('CZ640903926')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'CZ')
+ self.assertEqual(validator.vat_number, '640903926')
+
+ validator = Validator('CZ46505331')
+ self.assertFalse(validator.validate())
+
+ # test common individuals
+ validator = Validator('CZ395601439')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'CZ')
+ self.assertEqual(validator.vat_number, '395601439')
+ validator = Validator('CZ520229439')
+ self.assertTrue(validator.validate())
+
+ validator = Validator('CZ705601439')
+ self.assertFalse(validator.validate())
+
+ # test common individuals born after 1953
+ validator = Validator('CZ7103192745')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'CZ')
+ self.assertEqual(validator.vat_number, '7103192745')
+
+ validator = Validator('CZ7103192744')
+ self.assertFalse(validator.validate())
+
+ validator = Validator('CZ26159708')
+ self.assertTrue(validator.validate())
+
+ def test_de(self):
+ validator = Validator('DE111111125')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'DE')
+ self.assertEqual(validator.vat_number, '111111125')
+ validator = Validator('DE124718735')
+ self.assertTrue(validator.validate())
+ validator = Validator('DE180295363')
+ self.assertTrue(validator.validate())
+ validator = Validator('DE123475223')
+ self.assertTrue(validator.validate())
+
+ validator = Validator('DE111111122')
+ self.assertFalse(validator.validate())
+
+ def test_dk(self):
+ validator = Validator('DK88146328')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'DK')
+ self.assertEqual(validator.vat_number, '88146328')
+
+ validator = Validator('DK88146327')
+ self.assertFalse(validator.validate())
+
+ def test_ee(self):
+ validator = Validator('EE100207415')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'EE')
+ self.assertEqual(validator.vat_number, '100207415')
+
+ validator = Validator('EE100207417')
+ self.assertFalse(validator.validate())
+
+ def test_gr(self):
+ validator = Validator('EL040127797')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'GR')
+ self.assertEqual(validator.vat_number, '040127797')
+ validator = Validator('040127797', 'EL')
+ self.assertTrue(validator.validate())
+
+ validator = Validator('EL040127798')
+ self.assertFalse(validator.validate())
+
+ validator = Validator('EL999863881')
+ self.assertTrue(validator.validate())
+
+ def test_es(self):
+ # Juridical entities other than national ones
+ validator = Validator('esa0011012B')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'ES')
+ self.assertEqual(validator.vat_number, 'A0011012B')
+ validator = Validator('ESA0011012B')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'ES')
+ self.assertEqual(validator.vat_number, 'A0011012B')
+ validator = Validator('ESA0011012B', 'ES')
+ self.assertTrue(validator.validate())
+
+ validator = Validator('ESA0011011B')
+ self.assertFalse(validator.validate())
+
+ # Physical persons
+ validator = Validator('ESZ3964521D')
+ self.assertTrue(validator.validate())
+ validator = Validator('ESM3964521F')
+ self.assertTrue(validator.validate())
+
+ # National juridical entities
+ validator = Validator('ESB84968312')
+ self.assertTrue(validator.validate())
+ validator = Validator('ESB50860162')
+ self.assertTrue(validator.validate())
+ validator = Validator('ESB30034573')
+ self.assertTrue(validator.validate())
+
+ def test_fi(self):
+ validator = Validator('fi09853608')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'FI')
+
+ validator = Validator('FI09853607')
+ self.assertFalse(validator.validate())
+
+ def test_fr(self):
+ # old style
+ validator = Validator('FR00300076965')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'FR')
+ validator = Validator('FR06300076967')
+ self.assertTrue(validator.validate())
+ validator = Validator('FR46441049376')
+ self.assertTrue(validator.validate())
+ validator = Validator('Fr28316607779')
+ self.assertTrue(validator.validate())
+
+ validator = Validator('FR00300076964')
+ self.assertFalse(validator.validate())
+
+ validator = Validator('FR2A316607779')
+ self.assertTrue(validator.validate())
+
+ # new style
+ validator = Validator('FR0K300076962')
+ self.assertTrue(validator.validate())
+
+ def test_gb(self):
+ # format 1 - 5 chars
+ validator = Validator('GbGD232')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'GB')
+ validator = Validator('GBHA232')
+ self.assertFalse(validator.validate())
+ validator = Validator('GBGD755')
+ self.assertFalse(validator.validate())
+ self.assertEqual(validator.country_code, 'GB')
+ validator = Validator('GBHA957')
+ self.assertTrue(validator.validate())
+
+ #format 2
+ validator = Validator('GB434031494')
+ self.assertTrue(validator.validate())
+ validator = Validator('GB263321723')
+ self.assertTrue(validator.validate())
+ validator = Validator('GB151699094')
+ self.assertTrue(validator.validate())
+
+
+ def test_hr(self):
+ validator = Validator('HR99999999999')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'HR')
+ validator = Validator('HR9999999999')
+ self.assertFalse(validator.validate())
+
+ def test_hu(self):
+ # format 1 - 5 chars
+ validator = Validator('HU21376414')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'HU')
+ validator = Validator('hu 10597190')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'HU')
+
+
+ def test_ie(self):
+ # old style format
+ validator = Validator('IE8Z49289F')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'IE')
+ validator = Validator('IE26287395')
+ self.assertFalse(validator.validate())
+
+ # new style
+ validator = Validator('IE3628739L')
+ self.assertTrue(validator.validate())
+
+ def test_it(self):
+ validator = Validator('IT00000010215')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'IT')
+ validator = Validator('IT00000017775')
+ self.assertFalse(validator.validate())
+
+ def test_lt(self):
+ # juridical entities
+ validator = Validator('LT213179412')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'LT')
+ validator = Validator('LT213179422')
+ self.assertFalse(validator.validate())
+
+ # Temporarily registered taxpayers
+ validator = Validator('LT290061371314')
+ self.assertTrue(validator.validate())
+ validator = Validator('LT290061371324')
+ self.assertFalse(validator.validate())
+
+ def test_lu(self):
+ validator = Validator('LU10000356')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'LU')
+ validator = Validator('LU14516304')
+ self.assertTrue(validator.validate())
+ validator = Validator('LU10000355')
+ self.assertFalse(validator.validate())
+
+ def test_lv(self):
+ # juridical entities
+ validator = Validator('LV40003009497')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'LV')
+ validator = Validator('LV40003009498')
+ self.assertFalse(validator.validate())
+
+ # natural persons
+ validator = Validator('LV07091910933')
+ self.assertTrue(validator.validate())
+ validator = Validator('LV32091910933')
+ self.assertFalse(validator.validate())
+
+ def test_mt(self):
+ validator = Validator('MT15121333')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'MT')
+ validator = Validator('MT15121332')
+ self.assertFalse(validator.validate())
+
+ def test_nl(self):
+ validator = Validator('NL010000446B01')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'NL')
+ validator = Validator('NL000000446B01')
+ self.assertFalse(validator.validate())
+
+ def test_pl(self):
+ validator = Validator('PL5260001246')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'PL')
+ validator = Validator('PL5260001244')
+ self.assertFalse(validator.validate())
+
+ def test_pt(self):
+ validator = Validator('PT502757191')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'PT')
+ validator = Validator('PT502757190')
+ self.assertFalse(validator.validate())
+
+ def test_ro(self):
+ validator = Validator('RO2785503')
+ self.assertTrue( validator.validate() )
+ self.assertEqual( validator.country_code, 'RO' )
+ self.assertEqual( validator.vat_number, '2785503' )
+ validator = Validator('2785503', 'RO')
+ self.assertTrue(validator.validate())
+
+ validator = Validator('ro 99 908')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'RO')
+
+ validator = Validator('RO2785500')
+ self.assertFalse(validator.validate())
+
+ def test_se(self):
+ validator = Validator('SE556188840401')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'SE')
+ validator = Validator('SE556183840407')
+ self.assertFalse(validator.validate())
+
+ def test_si(self):
+ validator = Validator('SI15012557')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'SI')
+ validator = Validator('SI15012556')
+ self.assertFalse(validator.validate())
+
+ def test_sk(self):
+ validator = Validator('SK4030000007')
+ self.assertTrue(validator.validate())
+ self.assertEqual(validator.country_code, 'SK')
+ validator = Validator('SK5407062531')
+ self.assertFalse(validator.validate())
+ validator = Validator('SK0407062531')
+ self.assertFalse(validator.validate())
+
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestValidator)
+unittest.TextTestRunner(verbosity=2).run(suite)
diff --git a/pyVat/__init__.py b/pyVat/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/pyVat/api.py b/pyVat/api.py
new file mode 100644
index 0000000000000000000000000000000000000000..622908d11ef2b42c26047f3d2e49542b282917a0
--- /dev/null
+++ b/pyVat/api.py
+# Copyright 2018 Agile Geeks
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+# and associated documentation files (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge, publish, distribute,
+# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
+# is furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in all copies or substantial
+# portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
+# LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+from __future__ import (
+ unicode_literals,
+ print_function,
+ division
+)
+import re
+import sys
+
+
+EU_COUNTRIES = [
+ 'AT',
+ 'BE',
+ 'BG',
+ 'CY',
+ 'CZ',
+ 'DK',
+ 'EE',
+ 'FI',
+ 'FR',
+ 'DE',
+ 'GR',
+ 'HR',
+ 'HU',
+ 'IE',
+ 'IT',
+ 'LV',
+ 'LT',
+ 'LU',
+ 'MT',
+ 'NL',
+ 'PL',
+ 'PT',
+ 'RO',
+ 'SK',
+ 'SI',
+ 'ES',
+ 'SE',
+ 'GB'
+]
+def load_class(module_name, class_name):
+ mod = __import__(module_name, fromlist=[class_name])
+ klass = getattr(mod, class_name)
+ return klass
+
+def load_cc_validator(cc):
+ module_name = 'pyVat.validators.%s' % cc
+ klass_name = 'Validator'
+ klass = load_class(module_name, klass_name)
+ return klass
+
+class VatValidationError(Exception):
+ """
+ Exception thrown by the Validator object when the VAT number is not valid
+ """
+ pass
+
+class Validator(object):
+
+ def __init__(self, vat_number, vat_country_code=None):
+
+ self.error_message = None
+ self.vat_number = vat_number
+ self.vat_country_code = vat_country_code
+
+
+ def clean(self):
+ vat_number = self.vat_number
+ vat_country_code = self.vat_country_code
+
+ try:
+ vat_number = str(vat_number)
+ except:
+ VatValidationError('Invalid VAT number provided')
+ vat_number = vat_number.replace(' ', '')