-#!/usr/bin/python2.6
+#!/usr/bin/python3.4
# -*- coding: iso-8859-15 -*-
# $Id$
# $HeadURL$
of properties used in the "Rodelbahnbox" and "Gasthausbox".
The "to_python" method has to get a unicode argument.
"""
-import formencode
-import formencode.national
import datetime
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.keys():
+ 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.keys():
+ 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):
self.validator = validator
self.python_none = python_none
- def to_python(self, value):
- self.assert_string(value, None)
- if value == u'': return self.python_none
- return self.validator.to_python(value)
+ def to_python(self, value, state=None):
+ self.assert_string(value, state)
+ if value == '': return self.python_none
+ return self.validator.to_python(value, state)
- def from_python(self, value):
- if value == self.python_none: return u''
- return self.validator.from_python(value)
+ def from_python(self, value, state=None):
+ if value == self.python_none: return ''
+ return self.validator.from_python(value, state)
class NeinValidator(formencode.FancyValidator):
>>> v.to_python(u'Nein')
u'Nein'
"""
- def __init__(self, validator, python_no=u'Nein'):
+ def __init__(self, validator, python_no='Nein'):
self.validator = validator
self.python_no = python_no
- def to_python(self, value):
- self.assert_string(value, None)
- if value == u'Nein': return self.python_no
- return self.validator.to_python(value)
+ def to_python(self, value, state=None):
+ self.assert_string(value, state)
+ if value == 'Nein': return self.python_no
+ return self.validator.to_python(value, state)
- def from_python(self, value):
- if value == self.python_no: return u'Nein'
- return self.validator.from_python(value)
+ def from_python(self, value, state=None):
+ if value == self.python_no: return 'Nein'
+ return self.validator.from_python(value, state)
class Unicode(formencode.FancyValidator):
"""Converts an unicode string to an unicode string:
u'any string' <=> u'any string'"""
- def to_python(self, value):
- self.assert_string(value, None)
- return unicode(value)
+ def to_python(self, value, state=None):
+ self.assert_string(value, state)
+ return str(value)
- def from_python(self, value):
- return unicode(value)
+ def from_python(self, value, state=None):
+ return str(value)
class UnicodeNone(NoneValidator):
def __init__(self, max=None):
self.iv = formencode.validators.Int(min=0, max=max)
- def to_python(self, value):
- self.assert_string(value, None)
- return self.iv.to_python(value)
+ def to_python(self, value, state=None):
+ self.assert_string(value, state)
+ return self.iv.to_python(value, state)
- def from_python(self, value):
- return unicode(value)
+ def from_python(self, value, state=None):
+ return str(value)
class UnsignedNone(NoneValidator):
def __init__(self, validator):
self.validator = validator
- def to_python(self, value):
- self.assert_string(value, None)
- return self.validator.from_python(self.validator.to_python(value))
+ def to_python(self, value, state=None):
+ self.assert_string(value, state)
+ return self.validator.from_python(self.validator.to_python(value, state))
- def from_python(self, value):
+ def from_python(self, value, state=None):
# we don't call self.validator.to_python(self.validator.from_python(value))
- # here because our to_python implementation basically leaves the input untouches
+ # here because our to_python implementation basically leaves the input untouched
# and so should from_python do.
- return self.validator.from_python(self.validator.to_python(value))
+ return self.validator.from_python(self.validator.to_python(value, state))
class DictValidator(formencode.FancyValidator):
def __init__(self, dict):
self.dict = dict
- def to_python(self, value):
- self.assert_string(value, None)
- if not self.dict.has_key(value): raise formencode.Invalid("Key not found in dict.", value, None)
+ def to_python(self, value, state=None):
+ self.assert_string(value, state)
+ if value not in self.dict: raise formencode.Invalid("Key not found in dict.", value, state)
return self.dict[value]
- def from_python(self, value):
- for k, v in self.dict.iteritems():
- if type(v) == type(value) and v == value: return k
- raise formencode.Invalid('Invalid value', value, None)
+ def from_python(self, value, state=None):
+ for k, v in self.dict.items():
+ if v == value:
+ return k
+ raise formencode.Invalid('Invalid value', value, state)
class GermanBoolNone(DictValidator):
u'Nein' <=> False
"""
def __init__(self):
- DictValidator.__init__(self, {u'': None, u'Ja': True, u'Nein': False})
+ DictValidator.__init__(self, {'': None, 'Ja': True, 'Nein': False})
class GermanTristateTuple(DictValidator):
u'Teilweise' <=> (True, True)
u'Nein' <=> (False, True)"""
def __init__(self, yes_python = (True, False), no_python = (False, True), partly_python = (True, True), none_python = (None, None)):
- DictValidator.__init__(self, {u'': none_python, u'Ja': yes_python, u'Nein': no_python, u'Teilweise': partly_python})
+ DictValidator.__init__(self, {'': none_python, 'Ja': yes_python, 'Nein': no_python, 'Teilweise': partly_python})
class GermanTristateFloat(GermanTristateTuple):
class ValueComment(formencode.FancyValidator):
- """Converts value with a potentially optional comment to a python tuple:
- u'' <=> (None, None)
- u'value' <=> (u'value', None)
- u'value (comment)' <=> (u'value', u'comment')"""
+ """Converts value with a potentially optional comment to a python tuple. If a comment is present, the
+ closing bracket has to be the rightmost character.
+ u'' <=> (None, None)
+ u'value' <=> (u'value', None)
+ u'value (comment)' <=> (u'value', u'comment')
+ u'[[link (linkcomment)]]' <=> (u'[[link (linkcomment)]]', None)
+ u'[[link (linkcomment)]] (comment)' <=> (u'[[link (linkcomment)]]', comment)
+ """
def __init__(self, value_validator=UnicodeNone(), comment_validator=UnicodeNone(), comment_is_optional=True):
self.value_validator = value_validator
self.comment_validator = comment_validator
self.comment_is_optional = comment_is_optional
- def to_python(self, value):
- self.assert_string(value, None)
- if value == u'':
+ def to_python(self, value, state=None):
+ self.assert_string(value, state)
+ if value == '':
v = value
c = value
else:
- left = value.find('(')
right = value.rfind(')')
- if left < 0 and right < 0:
- if not self.comment_is_optional: raise formencode.Invalid(u'Mandatory comment not present', value, None)
+ if right+1 != len(value):
+ if not self.comment_is_optional: raise formencode.Invalid('Mandatory comment not present', value, state)
v = value
- c = u''
- elif left >= 0 and right >= 0 and left < right:
+ c = ''
+ else:
+ left = value.rfind('(')
+ if left < 0: raise formencode.Invalid('Invalid format', value, state)
v = value[:left].strip()
c = value[left+1:right].strip()
- else: raise formencode.Invalid(u'Invalid format', value, None)
- return self.value_validator.to_python(v), self.comment_validator.to_python(c)
+ return self.value_validator.to_python(v, state), self.comment_validator.to_python(c, state)
- def from_python(self, value):
+ def from_python(self, value, state=None):
assert len(value) == 2
- v = self.value_validator.from_python(value[0])
- c = self.comment_validator.from_python(value[1])
+ v = self.value_validator.from_python(value[0], state)
+ c = self.comment_validator.from_python(value[1], state)
if len(c) > 0:
- if len(v) > 0: return u'%s (%s)' % (v, c)
- else: return u'(%s)' % c
+ if len(v) > 0: return '%s (%s)' % (v, c)
+ else: return '(%s)' % c
return v
def __init__(self, validator=Unicode()):
self.validator = validator
- def to_python(self, value):
- self.assert_string(value, None)
- return [self.validator.to_python(s.strip()) for s in value.split(';')]
+ def to_python(self, value, state=None):
+ self.assert_string(value, state)
+ return [self.validator.to_python(s.strip(), state) for s in value.split(';')]
- def from_python(self, value):
- return "; ".join([self.validator.from_python(s) for s in value])
+ def from_python(self, value, state=None):
+ return "; ".join([self.validator.from_python(s, state) for s in value])
class ValueCommentList(SemicolonList):
self.date_time_format = date_time_format
def to_python(self, value, state=None):
- self.assert_string(value, None)
+ self.assert_string(value, state)
try: return datetime.datetime.strptime(value, self.date_time_format)
- except ValueError, e: raise formencode.Invalid(str(e), value, None)
+ except ValueError as e: raise formencode.Invalid(str(e), value, state)
def from_python(self, value, state=None):
return value.strftime(self.date_time_format)
class Geo(formencode.FancyValidator):
"""Formats to coordinates '47.076207 N 11.453553 E' to the (latitude, longitude) tuplet."""
- def to_python(self, value):
- self.assert_string(value, None)
- r = re.match(u'(\d+\.\d+) N (\d+\.\d+) E', value)
- if r is None: raise formencode.Invalid(u"Coordinates '%s' have not a format like '47.076207 N 11.453553 E'" % value, value, None)
+ def to_python(self, value, state=None):
+ self.assert_string(value, state)
+ r = re.match('(\d+\.\d+) N (\d+\.\d+) E', value)
+ if r is None: raise formencode.Invalid("Coordinates '%s' have not a format like '47.076207 N 11.453553 E'" % value, value, state)
return (float(r.groups()[0]), float(r.groups()[1]))
- def from_python(self, value):
+ def from_python(self, value, state=None):
latitude, longitude = value
- return u'%.6f N %.6f E' % (latitude, longitude)
+ return '%.6f N %.6f E' % (latitude, longitude)
class GeoNone(NoneValidator):
self.output_format = output_format
formencode.FancyValidator.__init__(self, if_empty = (None, None, None), **keywords)
- def to_python(self, value):
- self.assert_string(value, None)
+ def to_python(self, value, state=None):
+ self.assert_string(value, state)
input_format = self.input_format
if not input_format in [self.FORMAT_GUESS, self.FORMAT_GEOCACHING, self.FORMAT_WINTERRODELN, self.FORMAT_GMAPPLUGIN, self.FORMAT_GPX]:
- raise formencode.Invalid(u"input_format %d is not recognized" % input_format, value, None) # Shouldn't it be an other type of runtime error?
+ raise formencode.Invalid("input_format %d is not recognized" % input_format, value, state) # Shouldn't it be an other type of runtime error?
lines = [line.strip() for line in value.split("\n") if len(line.strip()) > 0]
result = []
for line in lines:
if input_format == self.FORMAT_GUESS or input_format == self.FORMAT_GEOCACHING:
- r = re.match(u'N ?(\d+)° ?(\d+\.\d+) +E ?(\d+)° ?(\d+\.\d+)', line)
+ r = re.match('N ?(\d+)° ?(\d+\.\d+) +E ?(\d+)° ?(\d+\.\d+)', line)
if not r is None:
g = r.groups()
result.append((float(g[0]) + float(g[1])/60, float(g[2]) + float(g[3])/60, None))
continue
if input_format == self.FORMAT_GUESS or input_format == self.FORMAT_WINTERRODELN:
- r = re.match(u'(\d+\.\d+) N (\d+\.\d+) E', line)
+ r = re.match('(\d+\.\d+) N (\d+\.\d+) E', line)
if not r is None:
result.append((float(r.groups()[0]), float(r.groups()[1]), None))
last_input_format = self.FORMAT_WINTERRODELN
continue
if input_format == self.FORMAT_GUESS or input_format == self.FORMAT_GMAPPLUGIN:
- r = re.match(u'(\d+\.\d+), ?(\d+\.\d+)', line)
+ r = re.match('(\d+\.\d+), ?(\d+\.\d+)', line)
if not r is None:
result.append((float(r.groups()[0]), float(r.groups()[1]), None))
last_input_format = self.FORMAT_GMAPPLUGIN
continue
except (ExpatError, IndexError, ValueError): pass
- raise formencode.Invalid(u"Coordinates '%s' have no known format" % line, value, None)
+ raise formencode.Invalid("Coordinates '%s' have no known format" % line, value, state)
return result
- def from_python(self, value):
+ def from_python(self, value, state=None):
output_format = self.output_format
result = []
for latitude, longitude, height in value:
if output_format == self.FORMAT_GEOCACHING:
degree = latitude
- result.append(u'N %02d° %02.3f E %03d° %02.3f' % (latitude, latitude % 1 * 60, longitude, longitude % 1 * 60))
+ result.append('N %02d° %02.3f E %03d° %02.3f' % (latitude, latitude % 1 * 60, longitude, longitude % 1 * 60))
elif output_format == self.FORMAT_WINTERRODELN:
- result.append(u'%.6f N %.6f E' % (latitude, longitude))
+ result.append('%.6f N %.6f E' % (latitude, longitude))
elif output_format == self.FORMAT_GMAPPLUGIN:
- result.append(u'%.6f, %.6f' % (latitude, longitude))
+ result.append('%.6f, %.6f' % (latitude, longitude))
elif output_format == self.FORMAT_GPX:
- if not height is None: result.append(u'<trkpt lat="%.6f" lon="%.6f"><ele>%.2f</ele></trkpt>' % (latitude, longitude, height))
- else: result.append(u'<trkpt lat="%.6f" lon="%.6f"/>' % (latitude, longitude))
+ if not height is None: result.append('<trkpt lat="%.6f" lon="%.6f"><ele>%.2f</ele></trkpt>' % (latitude, longitude, height))
+ else: result.append('<trkpt lat="%.6f" lon="%.6f"/>' % (latitude, longitude))
else:
- raise formencode.Invalid(u"output_format %d is not recognized" % output_format, value, None) # Shouldn't it be an other type of runtime error?
+ raise formencode.Invalid("output_format %d is not recognized" % output_format, value, state) # Shouldn't it be an other type of runtime error?
return "\n".join(result)
default_cc = 43 # Default country code
messages = {'phoneFormat': "'%%(value)s' is an invalid format. Please enter a number in the form +43/###/####### or 0###/########."}
- def to_python(self, value):
- self.assert_string(value, None)
- m = re.match(u'^(?:\+(\d+)/)?([\d/]+)(?:-(\d+))?$', value)
+ def to_python(self, value, state=None):
+ self.assert_string(value, state)
+ m = re.match('^(?:\+(\d+)/)?([\d/]+)(?:-(\d+))?$', value)
# This will separate
# u'+43/512/1234567-89' => (u'43', u'512/1234567', u'89')
# u'+43/512/1234/567-89' => (u'43', u'512/1234/567', u'89')
# u'+43/512/1234/567' => (u'43', u'512/1234/567', None)
# u'0512/1234567' => (None, u'0512/1234567', None)
- if m is None: raise formencode.Invalid(self.message('phoneFormat', None) % {'value': value}, value, None)
+ if m is None: raise formencode.Invalid(self.message('phoneFormat', None) % {'value': value}, value, state)
(country, phone, extension) = m.groups()
# Phone
- if phone.find(u'//') > -1 or phone.count('/') == 0: raise formencode.Invalid(self.message('phoneFormat', None) % {'value': value}, value, None)
+ if phone.find('//') > -1 or phone.count('/') == 0: raise formencode.Invalid(self.message('phoneFormat', None) % {'value': value}, value, state)
# Country
if country is None:
- if phone[0] != '0': raise formencode.Invalid(self.message('phoneFormat', None) % {'value': value}, value, None)
+ if phone[0] != '0': raise formencode.Invalid(self.message('phoneFormat', None) % {'value': value}, value, state)
phone = phone[1:]
- country = unicode(self.default_cc)
+ country = str(self.default_cc)
if extension is None: return '+%s/%s' % (country, phone)
return '+%s/%s-%s' % (country, phone, extension)
u'mittel' <=> 2
u'schwer' <=> 3"""
def __init__(self):
- DictValidator.__init__(self, {u'': None, u'leicht': 1, u'mittel': 2, u'schwer': 3})
+ DictValidator.__init__(self, {'': None, 'leicht': 1, 'mittel': 2, 'schwer': 3})
class GermanAvalanches(DictValidator):
u'gelegentlich' <=> 3
u'häufig' <=> 4"""
def __init__(self):
- DictValidator.__init__(self, {u'': None, u'kaum': 1, u'selten': 2, u'gelegentlich': 3, u'häufig': 4})
+ DictValidator.__init__(self, {'': None, 'kaum': 1, 'selten': 2, 'gelegentlich': 3, 'häufig': 4})
class GermanPublicTransport(DictValidator):
u'Nein' <=> 5
u'Ja' <=> 6"""
def __init__(self):
- DictValidator.__init__(self, {u'': None, u'Sehr gut': 1, u'Gut': 2, u'Mittelmäßig': 3, u'Schlecht': 4, u'Nein': 5, u'Ja': 6})
+ DictValidator.__init__(self, {'': None, 'Sehr gut': 1, 'Gut': 2, 'Mittelmäßig': 3, 'Schlecht': 4, 'Nein': 5, 'Ja': 6})
class GermanTristateFloatComment(ValueComment):
u'' <=> None
u'Nein' <=> 'Nein'
u'Tiroler Naturrodelbahn-Gütesiegel 2009 mittel' <=> u'Tiroler Naturrodelbahn-Gütesiegel 2009 mittel'"""
- def to_python(self, value):
- self.assert_string(value, None)
- if value == u'': return None
- elif value == u'Nein': return value
- elif value.startswith(u'Tiroler Naturrodelbahn-Gütesiegel '):
+ def to_python(self, value, state=None):
+ self.assert_string(value, state)
+ if value == '': return None
+ elif value == 'Nein': return value
+ elif value.startswith('Tiroler Naturrodelbahn-Gütesiegel '):
p = value.split(" ")
- Unsigned().to_python(p[2]) # check if year can be parsed
- if not p[3] in ['leicht', 'mittel', 'schwer']: raise formencode.Invalid("Unbekannter Schwierigkeitsgrad", value, None)
+ Unsigned().to_python(p[2], state) # check if year can be parsed
+ if not p[3] in ['leicht', 'mittel', 'schwer']: raise formencode.Invalid("Unbekannter Schwierigkeitsgrad", value, state)
return value
- else: raise formencode.Invalid(u"Unbekanntes Gütesiegel", value, None)
+ else: raise formencode.Invalid("Unbekanntes Gütesiegel", value, state)
- def from_python(self, value):
- if value == None: return u''
- assert value != u''
- return self.to_python(value)
+ def from_python(self, value, state=None):
+ if value is None: return ''
+ assert value != ''
+ return self.to_python(value, state)
class Url(formencode.FancyValidator):
"""Validates an URL. In contrast to fromencode.validators.URL, umlauts are allowed."""
+ # formencode 1.2.5 to formencode 1.3.0a1 sometimes raise ValueError instead of Invalid exceptions
+ # https://github.com/formencode/formencode/pull/61
urlv = formencode.validators.URL()
- def to_python(self, value):
- self.assert_string(value, None)
+
+ def to_python(self, value, state=None):
+ self.assert_string(value, state)
v = value
- v = v.replace(u'ä', u'a')
- v = v.replace(u'ö', u'o')
- v = v.replace(u'ü', u'u')
- v = v.replace(u'ß', u'ss')
- v = self.urlv.to_python(v)
+ v = v.replace('ä', 'a')
+ v = v.replace('ö', 'o')
+ v = v.replace('ü', 'u')
+ v = v.replace('ß', 'ss')
+ v = self.urlv.to_python(v, state)
return value
- def from_python(self, value):
+ def from_python(self, value, state=None):
return value
def __init__(self, default_cc=43):
self.validator = formencode.national.InternationalPhoneNumber(default_cc=lambda: default_cc)
- def to_python(self, value):
- return unicode(self.validator.to_python(value))
+ def to_python(self, value, state=None):
+ return str(self.validator.to_python(value, state))
- def from_python(self, value):
- return self.validator.from_python(value)
+ def from_python(self, value, state=None):
+ return self.validator.from_python(value, state)
class PhoneCommentListNeinLoopNone(NoneValidator):
NoneValidator.__init__(self, NeinValidator(Loop(ValueCommentList(PhoneNumber(default_cc=43), comments_are_optional=comments_are_optional))))
+class MaskedEmail(formencode.FancyValidator):
+ """A masked email address as defined here is an email address that has the `@` character replacted by the text `(at)`.
+ So instead of `abd.def@example.com` it would be `abc.def(at)example.com`.
+ This validator takes either a normal or a masked email address in it's to_python method and returns the normal email address as well
+ as a bool indicating whether the email address was masked.
+ u'' <=> (None, None)
+ u'abc.def@example.com' <=> (u'abc.def@example.com', False)
+ u'abc.def(at)example.com' <=> (u'abc.def@example.com', True)
+
+ """
+ def __init__(self, *args, **kw):
+ if 'strip' not in kw: kw['strip'] = True
+ if 'not_empty' not in kw: kw['not_empty'] = False
+ if 'if_empty' not in kw: kw['if_empty'] = (None, None)
+ self.at = '(at)'
+ formencode.FancyValidator.__init__(self, *args, **kw)
+
+ def _to_python(self, value, state=None):
+ email = value.replace(self.at, '@')
+ masked = value != email
+ val_email = formencode.validators.Email()
+ return val_email.to_python(email, state), masked
+
+ def _from_python(self, value, state=None):
+ email, masked = value
+ if email is None: return ''
+ val_email = formencode.validators.Email()
+ email = val_email.from_python(email, state)
+ if masked: email = email.replace('@', self.at)
+ return email
+
+
class EmailCommentListNeinLoopNone(NoneValidator):
"""Converts a semicolon-separated list of email addresses with optional comments to itself.
The special value of u'Nein' indicates that there are no email addresses.
u'Nein' <=> u'Nein'
u'first@example.com' <=> u'first@example.com'
u'first@example.com (Nur Winter); second@example.com' <=> u'first@example.com (Nur Winter); second@example.com'
+
+ If the parameter allow_masked_email is true, the following gives no error:
+ u'abc.def(at)example.com (comment)' <=> u'abc.def(at)example.com (comment)'
"""
- def __init__(self):
- NoneValidator.__init__(self, NeinValidator(Loop(ValueCommentList(formencode.validators.Email()))))
+ def __init__(self, allow_masked_email=False):
+ NoneValidator.__init__(self, NeinValidator(Loop(ValueCommentList(MaskedEmail() if allow_masked_email else formencode.validators.Email()))))
class WikiPage(formencode.FancyValidator):
An empty string is an error.
u'[[Birgitzer Alm]]' <=> u'[[Birgitzer Alm]]'
"""
- def to_python(self, value):
- self.assert_string(value, None)
+ def to_python(self, value, state=None):
+ self.assert_string(value, state)
if not value.startswith('[[') or not value.endswith(']]'):
- raise formencode.Invalid('No valid wiki page name', value, None)
+ raise formencode.Invalid('No valid wiki page name', value, state)
return value
- def from_python(self, value):
+ def from_python(self, value, state=None):
return value
self.first = first
self.validator = validator
- def to_python(self, value):
- self.assert_string(value, None)
- return self.first, self.validator.to_python(value)
+ def to_python(self, value, state=None):
+ self.assert_string(value, state)
+ return self.first, self.validator.to_python(value, state)
- def from_python(self, value):
+ def from_python(self, value, state=None):
assert value[0] == self.first
- return self.validator.from_python(value[1])
+ return self.validator.from_python(value[1], state)
class BoolUnicodeTupleValidator(NoneValidator):
u'Sessellift (Wochenende); Taxi (6 Euro)' <=> (True, u'Sessellift (Wochenende); Taxi (6 Euro)')
"""
def __init__(self):
- BoolUnicodeTupleValidator.__init__(self, Loop(ValueCommentList(DictValidator({u'Sessellift': u'Sessellift', u'Gondel': u'Gondel', u'Linienbus': u'Linienbus', u'Taxi': u'Taxi', u'Sonstige': u'Sonstige'}))))
+ BoolUnicodeTupleValidator.__init__(self, Loop(ValueCommentList(DictValidator({'Sessellift': 'Sessellift', 'Gondel': 'Gondel', 'Linienbus': 'Linienbus', 'Taxi': 'Taxi', 'Sonstige': 'Sonstige'}))))
class SledRental(BoolUnicodeTupleValidator):
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('Position', GeoNone()) # '47.583333 N 15.75 E'
+ self.add_field('Position oben', GeoNone()) # '47.583333 N 15.75 E'
+ self.add_field('Höhe oben', UnsignedNone()) # '2000'
+ self.add_field('Position unten', GeoNone()) # '47.583333 N 15.75 E'
+ self.add_field('Höhe unten', UnsignedNone()) # '1200'
+ self.add_field('Länge', UnsignedNone()) # 3500
+ self.add_field('Schwierigkeit', GermanDifficulty()) # 'mittel'
+ self.add_field('Lawinen', GermanAvalanches()) # 'kaum'
+ self.add_field('Betreiber', UnicodeNone()) # 'Max Mustermann'
+ self.add_field('Öffentliche Anreise', GermanPublicTransport()) # 'Mittelmäßig'
+ self.add_field('Aufstieg möglich', GermanBoolNone()) # 'Ja'
+ self.add_field('Aufstieg getrennt', GermanTristateFloatComment()) # 'Ja'
+ self.add_field('Gehzeit', UnsignedNone()) # 90
+ self.add_field('Aufstiegshilfe', GermanLift()) # 'Gondel (unterer Teil)'
+ self.add_field('Beleuchtungsanlage', GermanTristateFloatComment())
+ self.add_field('Beleuchtungstage', UnsignedCommentNone(7)) # '3 (Montag, Mittwoch, Freitag)'
+ self.add_field('Rodelverleih', SledRental()) # 'Talstation Serlesbahnan'
+ self.add_field('Gütesiegel', GermanCachet()) # 'Tiroler Naturrodelbahn-Gütesiegel 2009 mittel'
+ self.add_field('Webauskunft', UrlNeinNone()) # 'http://www.nösslachhütte.at/page9.php'
+ self.add_field('Telefonauskunft', PhoneCommentListNeinLoopNone(comments_are_optional=False)) # '+43-664-5487520 (Mitterer Alm)'
+ self.add_field('Bild', UnicodeNone())
+ self.add_field('In Übersichtskarte', GermanBoolNone())
+ self.add_field('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('Position', GeoNone()) # '47.583333 N 15.75 E'
+ self.add_field('Höhe', UnsignedNone())
+ self.add_field('Betreiber', UnicodeNone())
+ self.add_field('Sitzplätze', UnsignedNone())
+ self.add_field('Übernachtung', BoolUnicodeTupleValidator())
+ self.add_field('Rauchfrei', GermanTristateTuple())
+ self.add_field('Rodelverleih', BoolUnicodeTupleValidator())
+ self.add_field('Handyempfang', ValueCommentListNeinLoopNone())
+ self.add_field('Homepage', UrlNeinNone())
+ self.add_field('E-Mail', EmailCommentListNeinLoopNone(allow_masked_email=True))
+ self.add_field('Telefon', PhoneCommentListNeinLoopNone(comments_are_optional=True))
+ self.add_field('Bild', UnicodeNone())
+ self.add_field('Rodelbahnen', WikiPageListLoopNone())
+
+
+def sledrun_page_title_to_pretty_url(page_title):
+ """Converts a page_title from the page_title column of wrsledruncache to name_url.
+ name_url is not used by MediaWiki but by new applications like wrweb."""
+ return page_title.lower().replace(' ', '-').replace('_', '-').replace('(', '').replace(')', '')