-
Notifications
You must be signed in to change notification settings - Fork 114
/
TagFix_BadKey.py
122 lines (109 loc) · 5.45 KB
/
TagFix_BadKey.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#-*- coding: utf-8 -*-
###########################################################################
## ##
## Copyrights Etienne Chové <[email protected]> 2009 ##
## Copyrights Frédéric Rodrigo 2011-2015 ##
## ##
## This program is free software: you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation, either version 3 of the License, or ##
## (at your option) any later version. ##
## ##
## This program is distributed in the hope that it will be useful, ##
## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
## GNU General Public License for more details. ##
## ##
## You should have received a copy of the GNU General Public License ##
## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
## ##
###########################################################################
from modules.Stablehash import stablehash64
from modules.OsmoseTranslation import T_
from plugins.Plugin import Plugin
class TagFix_BadKey(Plugin):
def init(self, logger):
Plugin.init(self, logger)
doc = dict(
detail = T_(
'''The key of tag contains characters not recommended. The key is
composed of alphanumeric characters: 0-9, a-z (preferably lower case),
separator '_' or ':'. See
[Any_tags_you_like#Syntactic_conventions_for_new_tags](https://wiki.openstreetmap.org/wiki/Any_tags_you_like#Syntactic_conventions_for_new_tags).'''),
fix = T_(
'''Check the key tag, and correct.'''),
trap = T_(
'''There certainly false positives.'''))
self.errors[3050] = self.def_class(item = 3050, level = 1, tags = ['tag', 'fix:chair'],
title = T_('Bad key'),
**doc)
self.errors[30502] = self.def_class(item = 3050, level = 3, tags = ['tag', 'fix:chair'],
title = T_('Bad key'),
**doc)
self.errors[30501] = self.def_class(item = 3050, level = 1, tags = ['tag', 'fix:chair'],
title = T_('Bad key suffix'),
**doc)
import re
self.KeyPart1 = re.compile("^[a-zA-Z_0-9]+$")
self.KeyPart1Less = re.compile("^[-.a-zA-Z_0-9]+$")
self.KeyPart2 = re.compile("^[-_:a-zA-Z_0-9<>°]+$")
self.exceptions = set((
"ISO3166-1", "iso3166-1", "ISO3166-2", "iso3166-2",
"USGS-LULC",
"aims-id",
"au.gov.abs",
"catmp-RoadID",
"dc-gis",
"drive-through",
"e-road",
"nhd-shp",
"voltage-high", "voltage-low",
"cityracks.housenum", "cityracks.installed", "cityracks.large", "cityracks.rackid", "cityracks.small", "cityracks.street", # NYC amenity=bicycle_parking
"strassen-nrw", # DE import
"hazmat",
))
self.exceptions_whole = set((
"railway:memor2+", "railway:tbl1+",
"ref:refuges.info", "ref:clochers.org",
"ref:temples.ru", "ref:sobory.ru",
))
def node(self, data, tags):
err = []
keys = tags.keys()
for k in keys:
part = k.split(':', 1)
if ":(" in k or k.startswith("def:") or part[0] in self.exceptions:
# acess:([date])
# key def: can contains sign =
continue
if k in self.exceptions_whole:
continue
if not self.KeyPart1.match(part[0]):
if self.KeyPart1Less.match(part[0]):
err.append({"class": 30502, "subclass": stablehash64(k), "text": T_("Concerns tag: `{0}`", '='.join([k, tags[k]])) })
else:
err.append({"class": 3050, "subclass": stablehash64(k), "text": T_("Concerns tag: `{0}`", '='.join([k, tags[k]])) })
elif len(part) == 2 and not self.KeyPart2.match(part[1]):
err.append({"class": 30501, "subclass": stablehash64(k), "text": T_("Concerns tag: `{0}`", '='.join([k, tags[k]])) })
return err
def way(self, data, tags, nds):
return self.node(data, tags)
def relation(self, data, tags, members):
return self.node(data, tags)
###########################################################################
from plugins.Plugin import TestPluginCommon
class Test(TestPluginCommon):
def test(self):
a = TagFix_BadKey(None)
a.init(None)
for k in ["toto", "def9", "disused:amenity", "access:([date])", "def:a=b",
"ISO3166-1", "ISO3166-1:alpha2", "nhd-shp:fdate",
"railway:memor2+", "railway:tbl1+",
"strassen-nrw:abs",
"hazmat:4.3",
]:
assert not a.node(None, {k: '1'}), ("key='{0}'".format(k))
for k in ["a-b", "a''b", u"é", u"û", "a=b", u"a:é", "a:a:'",
"railway:memor2++", "railway:memor2+87",
]:
self.check_err(a.node(None, {k: '1'}), ("key='{0}'".format(k)))