#!/usr/bin/python2.7
# -*- coding: iso-8859-15 -*-
+import collections
import wrpylib.wrvalidators
import formencode
def test_RodelbahnboxDictValidator():
v = wrpylib.wrvalidators.RodelbahnboxDictValidator()
- other = {
- u'Position': u'47.309820 N 9.986508 E',
- u'Position oben': u'',
- u'Höhe oben': u'1244',
- u'Position unten': u'',
- u'Höhe unten': u'806',
- u'Länge': u'5045',
- u'Schwierigkeit': u'',
- u'Lawinen': u'gelegentlich',
- u'Betreiber': u'',
- u'Öffentliche Anreise': u'Ja',
- u'Gehzeit': u'105',
- u'Aufstieg möglich': u'Ja',
- u'Aufstieg getrennt': u'Nein',
- u'Aufstiegshilfe': u'Nein',
- u'Beleuchtungsanlage': u'Nein',
- u'Beleuchtungstage': u'',
- u'Rodelverleih': u'Ja',
- u'Gütesiegel': u'',
- u'Webauskunft': u'',
- u'Telefonauskunft': u'+43-664-1808482 (Bergkristallhütte)',
- u'Bild': u'Rodelbahn Bergkristallhütte 2009-03-03.jpg',
- u'In Übersichtskarte': u'Ja',
- u'Forumid': u'72'}
+ other = collections.OrderedDict([
+ (u'Position', u'47.309820 N 9.986508 E'),
+ (u'Position oben', u''),
+ (u'Höhe oben', u'1244'),
+ (u'Position unten', u''),
+ (u'Höhe unten', u'806'),
+ (u'Länge', u'5045'),
+ (u'Schwierigkeit', u''),
+ (u'Lawinen', u'gelegentlich'),
+ (u'Betreiber', u''),
+ (u'Öffentliche Anreise', u'Ja'),
+ (u'Aufstieg möglich', u'Ja'),
+ (u'Aufstieg getrennt', u'Nein'),
+ (u'Gehzeit', u'105'),
+ (u'Aufstiegshilfe', u'Nein'),
+ (u'Beleuchtungsanlage', u'Nein'),
+ (u'Beleuchtungstage', u''),
+ (u'Rodelverleih', u'Ja'),
+ (u'Gütesiegel', u''),
+ (u'Webauskunft', u''),
+ (u'Telefonauskunft', u'+43-664-1808482 (Bergkristallhütte)'),
+ (u'Bild', u'Rodelbahn Bergkristallhütte 2009-03-03.jpg'),
+ (u'In Übersichtskarte', u'Ja'),
+ (u'Forumid', u'72')])
python = v.to_python(other, None)
other2 = v.from_python(python, None)
assert other == other2
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):
+ result = formencode.Schema._convert_to_python(self, value, state)
+ ordered_result = collections.OrderedDict()
+ for key in value.iterkeys():
+ ordered_result[key] = result[key]
+ 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):
BoolUnicodeTupleValidator.__init__(self, Loop(ValueCommentList()))
-class RodelbahnboxDictValidator(formencode.Schema):
+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'