[addresses] adding new config for postal codes around the world. Allows appending the ISO alpha-2 country code to the beginning of the postcode as in e.g. SI-1000 (only used if the postcode begins with a digit). This system was used for postal codes in continental Europe as a recommendation from the CEPT. Now 7 member states still use it, so in those countries add the country-code with higher probability. The config also contains the license plate codes for countries where e.g. L-1234 might be used instead of LU-1234. Allows configuring in which countries postcodes should be validated using Google's per-country validation regexes (and the ability to override with a custom regex), and in which countries other admin component names should be stripped.
This commit is contained in:
@@ -35,26 +35,3 @@ class GoogleI18N(object):
|
||||
|
||||
|
||||
google_i18n = GoogleI18N()
|
||||
|
||||
|
||||
class PostcodeRegexes(object):
|
||||
def __init__(self):
|
||||
self.responses = {}
|
||||
self.postcode_regexes = {}
|
||||
|
||||
def get(self, country_code):
|
||||
ret = self.postcode_regexes.get(country_code.lower())
|
||||
if ret is None:
|
||||
response = google_i18n.get(country_code)
|
||||
if response:
|
||||
postcode_expression = response.get('zip')
|
||||
if not postcode_expression:
|
||||
self.postcode_regexes[country_code.lower()] = None
|
||||
return None
|
||||
ret = re.compile(postcode_expression, re.I)
|
||||
self.postcode_regexes[country_code.lower()] = ret
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
postcode_regexes = PostcodeRegexes()
|
||||
|
||||
Reference in New Issue
Block a user