def verify_vat(vat_id, default_prefix=u''):
 vat_id = re.sub(u'\\s+', u'', vat_id.upper())
 vat_id = vat_id.replace(u'-', u'')
 prefix = vat_id[:2]
 if (prefix not in PATTERNS):
  prefix = default_prefix
 spec = PATTERNS.get(prefix)
 if ((not spec) or (not prefix)):
  raise VatCannotIdentifyValidationError(u'VAT ID could not be identified')
 if (not vat_id.startswith(prefix)):
  vat_id = (prefix + vat_id)
 patterns = (spec.get(u'pattern') or [])
 if isinstance(patterns, six.string_types):
  patterns = [patterns]
 for pat in patterns:
  regexp = compile_pattern(prefix, pat)
  match = regexp.match(vat_id)
  if match:
   return (prefix, match.groups())
 raise VatInvalidValidationError((u'VAT ID for %(country)s could not be validated' % spec))

def verify_vat ( vat_id , default_prefix = u'' ) : vat_id = re . sub ( u'\\s+' , u'' , vat_id . upper ( ) ) vat_id = vat_id . replace ( u'-' , u'' ) prefix = vat_id [ : 2 ] if ( prefix not in PATTERNS ) : prefix = default_prefix spec = PATTERNS . get ( prefix ) if ( ( not spec ) or ( not prefix ) ) : raise VatCannotIdentifyValidationError ( u'VAT ID could not be identified' ) if ( not vat_id . startswith ( prefix ) ) : vat_id = ( prefix + vat_id ) patterns = ( spec . get ( u'pattern' ) or [ ] ) if isinstance ( patterns , six . string_types ) : patterns = [ patterns ] for pat in patterns : regexp = compile_pattern ( prefix , pat ) match = regexp . match ( vat_id ) if match : return ( prefix , match . groups ( ) ) raise VatInvalidValidationError ( ( u'VAT ID for %(country)s could not be validated' % spec ) )
verify an eu vat id .