import re
import xml.dom.minidom as minidom
from xml.parsers.expat import ExpatError
+import collections
import formencode
import formencode.national
+class OrderedSchema(formencode.Schema):
+ def _convert_to_python(self, value, state):
+ 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
+
+ def _convert_from_python(self, value, state):
+ # store original pre- and chained validators
+ pre_validators = self.pre_validators
+ chained_validators = self.chained_validators[:]
+ # apply chained validators
+ chained = chained_validators[:]
+ chained.reverse()
+ for validator in chained:
+ value = validator.from_python(value, state)
+ # tempoarly remove pre- and chained validators
+ self.pre_validators = []
+ self.chained_validators = []
+ # apply original _convert_from_python method
+ try:
+ result = formencode.Schema._convert_from_python(self, value, state)
+ ordered_result = collections.OrderedDict()
+ for key in value.iterkeys():
+ ordered_result[key] = result[key]
+ # apply pre_validators
+ pre = pre_validators[:]
+ pre.reverse()
+ for validator in pre:
+ ordered_result = validator.from_python(ordered_result, state)
+ finally:
+ # resore original pre- and chained_validators
+ self.pre_validators = pre_validators
+ self.chained_validators = chained_validators
+ return ordered_result
+
+
class NoneValidator(formencode.FancyValidator):
"""Takes a validator and makes it possible that empty strings are mapped to None."""
def __init__(self, validator, python_none=None):
u'Talstation (nur mit Ticket); Schneealm' <=> (True, u'Talstation (nur mit Ticket); Schneealm')"""
def __init__(self):
BoolUnicodeTupleValidator.__init__(self, Loop(ValueCommentList()))
+
+
+class RodelbahnboxDictValidator(OrderedSchema):
+ """Takes the fields of the Rodelbahnbox as dict of strings and returns them as dict of appropriet types."""
+ def __init__(self):
+ self.add_field(u'Position', GeoNone()) # '47.583333 N 15.75 E'
+ self.add_field(u'Position oben', GeoNone()) # '47.583333 N 15.75 E'
+ self.add_field(u'Höhe oben', UnsignedNone()) # '2000'
+ self.add_field(u'Position unten', GeoNone()) # '47.583333 N 15.75 E'
+ self.add_field(u'Höhe unten', UnsignedNone()) # '1200'
+ self.add_field(u'Länge', UnsignedNone()) # 3500
+ self.add_field(u'Schwierigkeit', GermanDifficulty()) # 'mittel'
+ self.add_field(u'Lawinen', GermanAvalanches()) # 'kaum'
+ self.add_field(u'Betreiber', UnicodeNone()) # 'Max Mustermann'
+ self.add_field(u'Öffentliche Anreise', GermanPublicTransport()) # 'Mittelmäßig'
+ self.add_field(u'Aufstieg möglich', GermanBoolNone()) # 'Ja'
+ self.add_field(u'Aufstieg getrennt', GermanTristateFloatComment()) # 'Ja'
+ self.add_field(u'Gehzeit', UnsignedNone()) # 90
+ self.add_field(u'Aufstiegshilfe', GermanLift()) # 'Gondel (unterer Teil)'
+ self.add_field(u'Beleuchtungsanlage', GermanTristateFloatComment())
+ self.add_field(u'Beleuchtungstage', UnsignedCommentNone(7)) # '3 (Montag, Mittwoch, Freitag)'
+ self.add_field(u'Rodelverleih', SledRental()) # 'Talstation Serlesbahnan'
+ self.add_field(u'Gütesiegel', GermanCachet()) # 'Tiroler Naturrodelbahn-Gütesiegel 2009 mittel'
+ self.add_field(u'Webauskunft', UrlNeinNone()) # 'http://www.nösslachhütte.at/page9.php'
+ self.add_field(u'Telefonauskunft', PhoneCommentListNeinLoopNone(comments_are_optional=False)) # '+43-664-5487520 (Mitterer Alm)'
+ self.add_field(u'Bild', UnicodeNone())
+ self.add_field(u'In Übersichtskarte', GermanBoolNone())
+ self.add_field(u'Forumid', UnsignedNeinNone())
+
+
+class GasthausboxDictValidator(OrderedSchema):
+ """Takes the fields of the Gasthausbox as dict of strings and returns them as dict of appropriet types."""
+ def __init__(self):
+ self.add_field(u'Position', GeoNone()) # '47.583333 N 15.75 E'
+ self.add_field(u'Höhe', UnsignedNone())
+ self.add_field(u'Betreiber', UnicodeNone())
+ self.add_field(u'Sitzplätze', UnsignedNone())
+ self.add_field(u'Übernachtung', BoolUnicodeTupleValidator())
+ self.add_field(u'Rauchfrei', GermanTristateTuple())
+ self.add_field(u'Rodelverleih', BoolUnicodeTupleValidator())
+ self.add_field(u'Handyempfang', ValueCommentListNeinLoopNone())
+ self.add_field(u'Homepage', UrlNeinNone())
+ self.add_field(u'E-Mail', EmailCommentListNeinLoopNone(allow_masked_email=True))
+ self.add_field(u'Telefon', PhoneCommentListNeinLoopNone(comments_are_optional=True))
+ self.add_field(u'Bild', UnicodeNone())
+ self.add_field(u'Rodelbahnen', WikiPageListLoopNone())