ToastFreeware
/
philipp
/
winterrodeln
/
wrpylib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Moved dbkey_to_title from mwapi to mwmarkup.
[philipp/winterrodeln/wrpylib.git]
/
wrpylib
/
wrvalidators.py
diff --git
a/wrpylib/wrvalidators.py
b/wrpylib/wrvalidators.py
index cb9d826691e02ffefdedb163e9fda2831e43dabd..c827d5e48f5a2400f92e1133158518b95232eec3 100644
(file)
--- a/
wrpylib/wrvalidators.py
+++ b/
wrpylib/wrvalidators.py
@@
-304,7
+304,7
@@
opt_tristate_german_converter = FromToConverter(opt_tristate_german_from_str, op
# -------------------------------
def opt_tristate_german_comment_from_str(value):
# -------------------------------
def opt_tristate_german_comment_from_str(value):
- """Ja, Nein or
Vielleicht
, optionally with comment in parenthesis."""
+ """Ja, Nein or
Teilweise
, optionally with comment in parenthesis."""
return value_comment_from_str(value, opt_tristate_german_from_str, opt_str_from_str, True)
return value_comment_from_str(value, opt_tristate_german_from_str, opt_str_from_str, True)
@@
-335,6
+335,14
@@
def url_to_str(value):
# ---------------------
def webauskunft_from_str(value):
# ---------------------
def webauskunft_from_str(value):
+ """Converts a URL or 'Nein' to a tuple
+ 'http://www.example.com/' -> (True, 'http://www.example.com/')
+ 'Nein' -> (False, None)
+ '' -> (None, None)
+
+ :param value: URL or 'Nein'
+ :return: tuple
+ """
return opt_no_german_from_str(value, url_from_str)
return opt_no_german_from_str(value, url_from_str)
@@
-354,7
+362,7
@@
def wikipage_from_str(value):
An empty string is an error.
'[[Birgitzer Alm]]' => '[[Birgitzer Alm]]'
"""
An empty string is an error.
'[[Birgitzer Alm]]' => '[[Birgitzer Alm]]'
"""
- if
not value.startswith('[[') or not value.endswith(']]')
:
+ if
re.match(r'\[\[[^\[\]]+\]\]$', value) is None
:
raise ValueError('No valid wiki page name "{}"'.format(value))
return value
raise ValueError('No valid wiki page name "{}"'.format(value))
return value
@@
-699,7
+707,7
@@
def wikibox_to_template(value, name, converter_dict):
def template_from_str(value, name):
wikicode = mwparserfromhell.parse(value)
def template_from_str(value, name):
wikicode = mwparserfromhell.parse(value)
- template_list =
[template for template in wikicode.filter_templates(name) if template.name.strip() == name]
+ template_list =
wikicode.filter_templates(recursive=False, matches=lambda t: t.name.strip() == name)
if len(template_list) == 0:
raise ValueError('No "{}" template was found'.format(name))
if len(template_list) > 1:
if len(template_list) == 0:
raise ValueError('No "{}" template was found'.format(name))
if len(template_list) > 1: