#!/usr/bin/python3.4
-# -*- coding: utf-8 -*-
# $Id$
# $HeadURL$
"""
import re
from collections import OrderedDict, namedtuple
-import mwparserfromhell
+import mwparserfromhell # https://github.com/earwig/mwparserfromhell
-from wrpylib.mwmarkup import template_to_table
+from wrpylib.mwmarkup import format_template_table
# FromToConverter type
pass
-def wikibox_from_template(template, name, converter_dict):
- if template.name.strip() != name:
- raise ValueError('Box name has to be "{}"'.format(name))
+def wikibox_from_template(template, converter_dict):
+ """Returns an ordered dict."""
result = OrderedDict()
exceptions_dict = OrderedDict()
# check values
def template_from_str(value, name):
wikicode = mwparserfromhell.parse(value)
- template_list = wikicode.filter_templates(name)
- if len(name) == 0:
+ template_list = [template for template in wikicode.filter_templates(name) if template.name.strip() == name]
+ if len(template_list) == 0:
raise ValueError('No "{}" template was found'.format(name))
if len(template_list) > 1:
raise ValueError('{} "{}" templates were found'.format(len(template_list), name))
def wikibox_from_str(value, name, converter_dict):
template = template_from_str(value, name)
- return wikibox_from_template(template, name, converter_dict)
+ return wikibox_from_template(template, converter_dict)
def wikibox_to_str(value, name, converter_dict):
def rodelbahnbox_from_template(template):
- return wikibox_from_template(template, RODELBAHNBOX_TEMPLATE_NAME, RODELBAHNBOX_DICT)
+ """Returns an ordered dict."""
+ return wikibox_from_template(template, RODELBAHNBOX_DICT)
def rodelbahnbox_to_template(value):
def rodelbahnbox_from_str(value):
+ """Returns an ordered dict."""
return wikibox_from_str(value, RODELBAHNBOX_TEMPLATE_NAME, RODELBAHNBOX_DICT)
def rodelbahnbox_to_str(value):
template = rodelbahnbox_to_template(value)
- template_to_table(template, 20)
+ format_template_table(template, 20)
return str(template)
def gasthausbox_from_template(template):
+ """Returns an ordered dict."""
return wikibox_from_template(template, GASTHAUSBOX_TEMPLATE_NAME, GASTHAUSBOX_DICT)
def gasthausbox_from_str(value):
+ """Returns an ordered dict."""
return wikibox_from_str(value, GASTHAUSBOX_TEMPLATE_NAME, GASTHAUSBOX_DICT)
def gasthausbox_to_str(value):
template = gasthausbox_to_template(value)
- template_to_table(template, 17)
+ format_template_table(template, 17)
return str(template)