Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions plugins/TagFix_Postcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TagFix_Postcode(Plugin):
not_for = ("EG") # Egypt is transitioning to a new format. At 2024-04-15 there were still 2.4M entries in OSM in the old format

def parse_format(self, reline, format):
format = format.replace('optionally ', '')
format = format.replace('optionally ', '').replace("\n", " ")
if format[-1] == ')':
format = map(lambda x: x.strip(), format[:-1].split('('))
elif ' or ' in format:
Expand All @@ -44,15 +44,15 @@ def parse_format(self, reline, format):
regexs = []
for f in format:
if reline.match(f):
regexs.append(f.replace(" ", "").replace("-", "").replace(".", "").replace("N", "[0-9]").replace("A", "[A-Z]").replace("CC", "(:?"+self.Country+")?"))
regexs.append(f.replace(" ", "").replace("-", "").replace(".", "").replace("N", "[0-9]").replace("A", "[A-Z]").replace("?", "[A-Z0-9]").replace("CC", "(:?"+self.Country+")?"))

if len(regexs) > 1:
return "^(("+(")|(".join(regexs))+"))$"
elif len(regexs) == 1:
return "^"+regexs[0]+"$"

def list_postcode(self):
reline = re.compile("^[-CAN ]+$")
reline = re.compile("^[-CAN ?]+$")
data = urlread(u"https://en.wikipedia.org/wiki/List_of_postal_codes?action=raw", 1)
data = read_wiki_table(data)

Expand Down Expand Up @@ -270,6 +270,8 @@ class father:
config = _config()
a.father = father()
a.init(None)
assert a.node(None, {"addr:postcode":"123"})
assert a.node(None, {"addr:postcode":"A123"})
assert not a.node(None, {"addr:postcode":"AB123"})
assert not a.node(None, {"addr:postcode":"AB1234"})
assert not a.node(None, {"addr:postcode":"AB12345"})
Loading