Skip to content

Commit

Permalink
Whitelist uppercase PT infrastructure in Greece
Browse files Browse the repository at this point in the history
See #2368
  • Loading branch information
Famlam authored and frodrigo committed Oct 27, 2024
1 parent 3018e04 commit 7ab7d7a
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions plugins/Name_UpperCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,26 @@ def init(self, logger):
)
self.UpperTitleCase = re.compile(r".*[\p{Lu}\p{Lt}]{5,}")
self.RomanNumber = re.compile(r".*[IVXCDLM]{5,}")
self.country = None

if "country" in self.father.config.options:
country = self.father.config.options.get("country")[:2]
self.whitelist = set(UpperCase_WhiteList.get(country, []))
self.country = self.father.config.options.get("country")[:2]
self.whitelist = set(UpperCase_WhiteList.get(self.country, []))
nsi_whitelist = set(filter(lambda name: self.UpperTitleCase.match(name) and not self.RomanNumber.match(name),
whitelist_from_nsi(country.lower())))
whitelist_from_nsi(self.country.lower())))
self.whitelist.update(nsi_whitelist)
else:
self.whitelist = set()

def node(self, data, tags):
err = []
if u"name" in tags:
if "name" in tags:
# Whitelist bus stops in Greece, see #2368
if self.country and self.country == "GR" and "public_transport" in tags and tags["public_transport"] in ("stop_position", "platform", "station"):
return err

# first check if the name *might* match
if self.UpperTitleCase.match(tags[u"name"]) and not self.RomanNumber.match(tags[u"name"]):
if self.UpperTitleCase.match(tags["name"]) and not self.RomanNumber.match(tags["name"]):
if not self.whitelist or not any(map(lambda whitelist: whitelist in tags["name"], self.whitelist)):
err.append({"class": 803, "text": T_("Concerns tag: `{0}`", '='.join(['name', tags['name']])) })
else:
Expand Down Expand Up @@ -102,3 +107,21 @@ class father:
{u"name": u"ƻאᎯᚦ京"},
]:
assert not a.node(None, t), t

def test_GR(self):
a = Name_UpperCase(None)
class _config:
options = {"country": "GR", "language": "el"}
class father:
config = _config()
a.father = father()
a.init(None)
for t in [{"name": u"ΠΛΑΤΕΙΑ ΕΛΕΥΘΕΡΙΑΣ"},
{"name": "ABCDEFGHIJKLMNOPQRSTUVWXYZ"},
]:
self.check_err(a.node(None, t), t)
self.check_err(a.way(None, t, None), t)

for t in [{"name": u"ΠΛΑΤΕΙΑ ΕΛΕΥΘΕΡΙΑΣ", "public_transport": "stop_position"},
]:
assert not a.node(None, t), t

0 comments on commit 7ab7d7a

Please sign in to comment.