assert other == other2
+def test_RodelbahnboxValidator():
+ v = wrpylib.wrmwmarkup.RodelbahnboxValidator()
+ wikitext = u'''{{Rodelbahnbox
+ | Position = 47.309820 N 9.986508 E
+ | Position oben =
+ | Höhe oben = 1244
+ | Position unten =
+ | Höhe unten = 806
+ | Länge = 5045
+ | Schwierigkeit =
+ | Lawinen = gelegentlich
+ | Betreiber =
+ | Öffentliche Anreise = Ja
+ | Aufstieg möglich = Nein
+ | Aufstieg getrennt = Nein
+ | Gehzeit = 105
+ | Aufstiegshilfe = Nein
+ | Beleuchtungsanlage = Nein
+ | Beleuchtungstage =
+ | Rodelverleih = Ja
+ | Gütesiegel =
+ | Webauskunft =
+ | Telefonauskunft = +43-664-1808482 (Bergkristallhütte)
+ | Bild = Rodelbahn Bergkristallhütte 2009-03-03.jpg
+ | In Übersichtskarte = Ja
+ | Forumid = 72
+ }}'''
+ sledrun = v.to_python(wikitext)
+ wikitext2 = v.from_python(sledrun)
+ assert wikitext == wikitext2
+ wikitext = u'''{{Rodelbahnbox
+ | Position =
+ | Position oben =
+ | Höhe oben =
+ | Position unten =
+ | Höhe unten =
+ | Länge =
+ | Schwierigkeit =
+ | Lawinen =
+ | Betreiber =
+ | Öffentliche Anreise =
+ | Aufstieg möglich =
+ | Aufstieg getrennt =
+ | Gehzeit =
+ | Aufstiegshilfe =
+ | Beleuchtungsanlage =
+ | Beleuchtungstage =
+ | Rodelverleih =
+ | Gütesiegel =
+ | Webauskunft =
+ | Telefonauskunft =
+ | Bild =
+ | In Übersichtskarte =
+ | Forumid =
+ }}'''
+ sledrun = v.to_python(wikitext)
+ wikitext2 = v.from_python(sledrun)
+ assert wikitext == wikitext2
+
+
def test_gasthausbox_to_inn():
wikitext = u'''{{Gasthausbox
| Position = 47.295549 N 9.986970 E
return r
+class RodelbahnboxTemplateDict(formencode.Validator):
+ """Private helper class for RodelbahnboxValidator"""
+ def to_python(self, value, state):
+ title, anonym_params, named_params = value
+ if title != u'Rodelbahnbox':
+ raise Invalud('Template title has to be "Rodelbahnbox".', value, state)
+ if len(anonym_params) > 0:
+ raise Invalid('No anonymous parameters are allowed in "Rodelbahnbox".', value, state)
+ return named_params
+
+ def from_python(self, value, state):
+ return u'Rodelbahnbox', [], value
+
+
+class RodelbahnboxValidator(wrpylib.wrvalidators.RodelbahnboxDictValidator):
+ def __init__(self):
+ wrpylib.wrvalidators.RodelbahnboxDictValidator.__init__(self)
+ self.pre_validators=[wrpylib.mwmarkup.TemplateValidator(), RodelbahnboxTemplateDict()]
+ self.chained_validators = [RodelbahnboxDictConverter()]
+
+
def sledrun_to_rodelbahnbox(sledrun, version):
"""Converts a sledrun class to the {{Rodelbahnbox}} representation.
The sledrun class has to have properties like position_latitude, ...
class OrderedSchema(formencode.Schema):
def _convert_to_python(self, value, state):
- result = formencode.Schema._convert_to_python(self, value, state)
- ordered_result = collections.OrderedDict()
- for key in value.iterkeys():
- ordered_result[key] = result[key]
+ pre_validators = self.pre_validators
+ chained_validators = self.chained_validators
+ for validator in pre_validators:
+ value = validator.to_python(value, state)
+ self.pre_validators = []
+ self.chained_validators = []
+ try:
+ result = formencode.Schema._convert_to_python(self, value, state)
+ ordered_result = collections.OrderedDict()
+ for key in value.iterkeys():
+ ordered_result[key] = result[key]
+ for validator in chained_validators:
+ ordered_result = validator.to_python(ordered_result, state)
+ finally:
+ self.pre_validators = pre_validators
+ self.chained_validators = chained_validators
return ordered_result