forked from osm-fr/osmose-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Josm_relation.py
129 lines (113 loc) · 7.77 KB
/
Josm_relation.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
#-*- coding: utf-8 -*-
from __future__ import unicode_literals
import modules.mapcss_lib as mapcss
import regex as re
from plugins.Plugin import Plugin, with_options
class Josm_relation(Plugin):
def init(self, logger):
Plugin.init(self, logger)
tags = capture_tags = {}
self.errors[9007001] = {'item': 9007, 'level': 3, 'tag': ["tag", "relation"], 'desc': mapcss.tr(u'missing tag')}
self.errors[9007002] = {'item': 9007, 'level': 2, 'tag': ["tag", "relation"], 'desc': mapcss.tr(u'relation without type')}
self.re_67b11051 = re.compile(r'^restriction')
def relation(self, data, tags, members):
capture_tags = {}
keys = tags.keys()
err = []
# relation[!type]
if True:
match = False
if not match:
capture_tags = {}
try: match = (not mapcss._tag_capture(capture_tags, 0, tags, u'type'))
except mapcss.RuleAbort: pass
if match:
# throwError:tr("relation without type")
# assertMatch:"relation name=Foo"
# assertNoMatch:"relation type=route name=Foo"
err.append({'class': 9007002, 'subclass': 1457279320, 'text': mapcss.tr(u'relation without type')})
# relation[type=route][!route]
# relation[type=route_master][!route_master]
# relation[type=restriction][!/^restriction/]
# relation[type=boundary][!boundary]
# relation[type=public_transport][!public_transport]
# relation[type=waterway][!waterway]
# relation[type=enforcement][!enforcement]
if (u'type' in keys):
match = False
if not match:
capture_tags = {}
try: match = (mapcss._tag_capture(capture_tags, 0, tags, u'type') == mapcss._value_capture(capture_tags, 0, u'route') and not mapcss._tag_capture(capture_tags, 1, tags, u'route'))
except mapcss.RuleAbort: pass
if not match:
capture_tags = {}
try: match = (mapcss._tag_capture(capture_tags, 0, tags, u'type') == mapcss._value_capture(capture_tags, 0, u'route_master') and not mapcss._tag_capture(capture_tags, 1, tags, u'route_master'))
except mapcss.RuleAbort: pass
if not match:
capture_tags = {}
try: match = (mapcss._tag_capture(capture_tags, 0, tags, u'type') == mapcss._value_capture(capture_tags, 0, u'restriction') and not mapcss._tag_capture(capture_tags, 1, tags, self.re_67b11051))
except mapcss.RuleAbort: pass
if not match:
capture_tags = {}
try: match = (mapcss._tag_capture(capture_tags, 0, tags, u'type') == mapcss._value_capture(capture_tags, 0, u'boundary') and not mapcss._tag_capture(capture_tags, 1, tags, u'boundary'))
except mapcss.RuleAbort: pass
if not match:
capture_tags = {}
try: match = (mapcss._tag_capture(capture_tags, 0, tags, u'type') == mapcss._value_capture(capture_tags, 0, u'public_transport') and not mapcss._tag_capture(capture_tags, 1, tags, u'public_transport'))
except mapcss.RuleAbort: pass
if not match:
capture_tags = {}
try: match = (mapcss._tag_capture(capture_tags, 0, tags, u'type') == mapcss._value_capture(capture_tags, 0, u'waterway') and not mapcss._tag_capture(capture_tags, 1, tags, u'waterway'))
except mapcss.RuleAbort: pass
if not match:
capture_tags = {}
try: match = (mapcss._tag_capture(capture_tags, 0, tags, u'type') == mapcss._value_capture(capture_tags, 0, u'enforcement') and not mapcss._tag_capture(capture_tags, 1, tags, u'enforcement'))
except mapcss.RuleAbort: pass
if match:
# group:tr("missing tag")
# throwWarning:tr("{0} relation without {0} tag","{1.key}")
# assertNoMatch:"relation type=boundary boundary=administrative"
# assertMatch:"relation type=boundary"
# assertNoMatch:"relation type=enforcement enforcement=maxspeed"
# assertMatch:"relation type=enforcement"
# assertNoMatch:"relation type=public_transport public_transport=stop_area"
# assertMatch:"relation type=public_transport"
# assertNoMatch:"relation type=restriction restriction=no_left_turn"
# assertMatch:"relation type=restriction"
# assertNoMatch:"relation type=route route=train"
# assertMatch:"relation type=route"
# assertNoMatch:"relation type=route_master route_master=train"
# assertMatch:"relation type=route_master"
# assertNoMatch:"relation type=site site=administrative"
# assertNoMatch:"relation type=waterway waterway=river"
# assertMatch:"relation type=waterway"
err.append({'class': 9007001, 'subclass': 881372982, 'text': mapcss.tr(u'{0} relation without {0} tag', mapcss._tag_uncapture(capture_tags, u'{1.key}'))})
return err
from plugins.Plugin import TestPluginCommon
class Test(TestPluginCommon):
def test(self):
n = Josm_relation(None)
class _config:
options = {"country": None, "language": None}
class father:
config = _config()
n.father = father()
n.init(None)
data = {'id': 0, 'lat': 0, 'lon': 0}
self.check_err(n.relation(data, {u'name': u'Foo'}, []), expected={'class': 9007002, 'subclass': 1457279320})
self.check_not_err(n.relation(data, {u'name': u'Foo', u'type': u'route'}, []), expected={'class': 9007002, 'subclass': 1457279320})
self.check_not_err(n.relation(data, {u'boundary': u'administrative', u'type': u'boundary'}, []), expected={'class': 9007001, 'subclass': 881372982})
self.check_err(n.relation(data, {u'type': u'boundary'}, []), expected={'class': 9007001, 'subclass': 881372982})
self.check_not_err(n.relation(data, {u'enforcement': u'maxspeed', u'type': u'enforcement'}, []), expected={'class': 9007001, 'subclass': 881372982})
self.check_err(n.relation(data, {u'type': u'enforcement'}, []), expected={'class': 9007001, 'subclass': 881372982})
self.check_not_err(n.relation(data, {u'public_transport': u'stop_area', u'type': u'public_transport'}, []), expected={'class': 9007001, 'subclass': 881372982})
self.check_err(n.relation(data, {u'type': u'public_transport'}, []), expected={'class': 9007001, 'subclass': 881372982})
self.check_not_err(n.relation(data, {u'restriction': u'no_left_turn', u'type': u'restriction'}, []), expected={'class': 9007001, 'subclass': 881372982})
self.check_err(n.relation(data, {u'type': u'restriction'}, []), expected={'class': 9007001, 'subclass': 881372982})
self.check_not_err(n.relation(data, {u'route': u'train', u'type': u'route'}, []), expected={'class': 9007001, 'subclass': 881372982})
self.check_err(n.relation(data, {u'type': u'route'}, []), expected={'class': 9007001, 'subclass': 881372982})
self.check_not_err(n.relation(data, {u'route_master': u'train', u'type': u'route_master'}, []), expected={'class': 9007001, 'subclass': 881372982})
self.check_err(n.relation(data, {u'type': u'route_master'}, []), expected={'class': 9007001, 'subclass': 881372982})
self.check_not_err(n.relation(data, {u'site': u'administrative', u'type': u'site'}, []), expected={'class': 9007001, 'subclass': 881372982})
self.check_not_err(n.relation(data, {u'type': u'waterway', u'waterway': u'river'}, []), expected={'class': 9007001, 'subclass': 881372982})
self.check_err(n.relation(data, {u'type': u'waterway'}, []), expected={'class': 9007001, 'subclass': 881372982})