File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,11 +66,12 @@ def _get_cc_module(cc):
6666 # Greece uses a "wrong" country code, special case for Northern Ireland
6767 cc = cc .lower ().replace ('el' , 'gr' ).replace ('xi' , 'gb' )
6868 if not _country_code_re .match (cc ):
69- raise InvalidFormat ( )
69+ raise ImportError ( 'Wrong "{}" country code.' . format ( cc ) )
7070 if cc not in _country_modules :
7171 _country_modules [cc ] = get_cc_module (cc , 'vat' )
7272 if not _country_modules [cc ]:
73- raise InvalidComponent () # unknown/unsupported country code
73+ raise ImportError ('Missing validation for "{}" country code.'
74+ '' .format (cc ))
7475 return _country_modules [cc ]
7576
7677
@@ -98,5 +99,7 @@ def is_valid(number):
9899 """Check if the number is a valid VAT number."""
99100 try :
100101 return bool (validate (number ))
102+ except ImportError :
103+ return False
101104 except ValidationError :
102105 return False
Original file line number Diff line number Diff line change @@ -61,20 +61,20 @@ Try validating not specifying a country:
6161>>> vatin.validate('')
6262Traceback (most recent call last):
6363 ...
64- InvalidFormat : ...
64+ ImportError : ...
6565>>> vatin.validate('00')
6666Traceback (most recent call last):
6767 ...
68- InvalidFormat : ...
68+ ImportError : ...
6969
7070
7171Try to validate for countries with no VAT validation:
7272
7373>>> vatin.validate('XX')
7474Traceback (most recent call last):
7575 ...
76- InvalidComponent : ...
76+ ImportError : ...
7777>>> vatin.validate('US')
7878Traceback (most recent call last):
7979 ...
80- InvalidComponent : ...
80+ ImportError : ...
You can’t perform that action at this time.
0 commit comments