forked from osm-fr/osmose-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTagFix_BadValue.py
154 lines (137 loc) · 7.12 KB
/
TagFix_BadValue.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#-*- coding: utf-8 -*-
###########################################################################
## ##
## Copyrights Etienne Chové <[email protected]> 2009 ##
## Copyrights Frédéric Rodrigo 2011 ##
## ##
## 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 plugins.Plugin import Plugin
from modules.Stablehash import stablehash64
class TagFix_BadValue(Plugin):
def init(self, logger):
Plugin.init(self, logger)
self.errors[3040] = self.def_class(item = 3040, level = 1, tags = ['value', 'fix:chair'],
title = T_('Bad value in a tag'))
import re
self.Values_open = re.compile("^[a-z0-9_]+( *; *[a-z0-9_]+)*$")
self.check_list_open = set( (
'abutters', 'access', 'admin_level', 'aerialway', 'aeroway', 'amenity',
'barrier', 'bicycle', 'boat', 'border_type', 'boundary', 'bridge', 'building', 'construction',
'covered', 'craft', 'crossing', 'cutting',
'disused', 'drive_in', 'drive_through',
'electrified', 'embankment', 'emergency',
'fenced', 'foot', 'ford',
'geological', 'goods',
'hgv', 'highway', 'historic',
'internet_access',
'landuse', 'lanes', 'leisure',
'man_made', 'military', 'mooring', 'motorboat', 'mountain_pass', 'natural', 'noexit',
'office',
'power', 'public_transport',
'railway', 'route',
'sac_scale', 'service', 'shop', 'smoothness', 'sport', 'surface',
'tactile_paving', 'toll', 'tourism', 'tracktype', 'traffic_calming', 'trail_visibility',
'tunnel',
'usage',
'vehicle',
'wall', 'waterway', 'wheelchair', 'wood'
) )
self.check_list_open_node = self.check_list_open
self.check_list_open_way = self.check_list_open
self.check_list_open_relation = self.check_list_open.copy()
self.check_list_open_relation.add('type')
self.exceptions_open = { "type": ( "associatedStreet",
"turnlanes:lengths",
"turnlanes:turns",
"restriction:hgv", "restriction:caravan", "restriction:motorcar", "restriction:bus", "restriction:agricultural", "restriction:bicycle", "restriction:hazmat",
"TMC" ),
"service": ( "drive-through", ),
"aerialway": ( "j-bar", "t-bar", ),
"surface": ( "concrete:plates", "concrete:lanes",
"paving_stones:20", "paving_stones:30", "paving_stones:50",
"cobblestone:10", "cobblestone:20", "cobblestone:flattened"),
"shop": ( "e-cigarette" ),
"barrier": ( "full-height_turnstile" ),
"man_made": ( "MDF" ),
}
self.check_list_closed = set( (
'area',
'narrow',
'oneway',
) )
self.allow_closed = { "area": ( "yes", "no", ),
"narrow": ( "yes", "no", ),
"oneway": ( "yes", "no", "1", "-1", "reversible", "alternating"),
}
def check(self, data, tags, check_list_open):
err = []
keyss = tags.keys()
keys = set(keyss) & check_list_open
for k in keys:
if not self.Values_open.match(tags[k]):
if k in self.exceptions_open:
if tags[k] in self.exceptions_open[k]:
# no error if in exception list
continue
err.append({"class": 3040, "subclass": stablehash64(k), "text": T_("Bad value for %(key)s=%(val)s", {"key": k, "val": tags[k]})})
keys = set(keyss) & self.check_list_closed
for k in keys:
if tags[k] not in self.allow_closed[k]:
err.append({"class": 3040, "subclass": stablehash64(k), "text": T_("Bad value for %(key)s=%(val)s", {"key": k, "val": tags[k]})})
return err
def node(self, data, tags):
return self.check(data, tags, self.check_list_open_node)
def way(self, data, tags, nds):
return self.check(data, tags, self.check_list_open_way)
def relation(self, data, tags, members):
return self.check(data, tags, self.check_list_open_relation)
###########################################################################
from plugins.Plugin import TestPluginCommon
class Test(TestPluginCommon):
def test(self):
a = TagFix_BadValue(None)
a.init(None)
for t in [{"access": "vor/dme"},
{"barrier": "AEGTO"},
{"barrier": "yes; AEGTO"},
{"aerialway": "ta-bar"},
{"tunnel": "-1st"},
{"area": "a"},
{"oneway": "yes;yes"},
]:
self.check_err(a.node(None, t), t)
self.check_err(a.way(None, t, None), t)
self.check_err(a.relation(None, {"type": "vor/dme"}, None))
for t in [{"type": "vor/dme"},
]:
self.check_err(a.relation(None, t, None), t)
for t in [{"type": "vor"},
{"barrier": "yes"},
{"area": "yes"},
{"aerialway": "t-bar"},
{"oneway": "yes"},
]:
assert not a.node(None, t), t
assert not a.way(None, t, None), t
assert not a.relation(None, t, None), t
for t in [{"type": "vor/dme"},
{"type": "associatedStreet"},
]:
assert not a.node(None, t), t
assert not a.way(None, t, None), t
for t in [{"type": "associatedStreet"},
]:
assert not a.relation(None, t, None), t