Skip to content
Snippets Groups Projects
Commit 1e20a8c4 authored by ulif's avatar ulif
Browse files

Update get_wordlist_path(name).

Also this method now handles names instead of language codes.
parent 3eb7f54c
No related branches found
No related tags found
No related merge requests found
......@@ -142,15 +142,16 @@ def get_wordlist(file_descriptor):
return result
def get_wordlist_path(lang):
"""Get path to a wordlist file for language `lang`.
def get_wordlist_path(name):
"""Get path to a wordlist file for a wordlist named `name`.
The `lang` string is a 2-char country code. Invalid codes raise a
ValueError.
The `name` string must not contain special chars beside ``-``,
``_``, regular chars ``A-Z`` (upper or lower case) or
numbers. Invalid names raise a ValueError.
"""
if not RE_WORDLIST_NAME.match(lang):
raise ValueError("Not a valid language code: %s" % lang)
basename = 'wordlist_%s.txt' % lang
if not RE_WORDLIST_NAME.match(name):
raise ValueError("Not a valid wordlist name: %s" % name)
basename = 'wordlist_%s.txt' % name
return os.path.join(WORDLISTS_DIR, basename.lower())
......
......@@ -108,7 +108,7 @@ class TestDicewareModule(object):
with pytest.raises(ValueError) as exc_info:
get_wordlist_path('../../tmp')
assert exc_info.value.args[0].startswith(
'Not a valid language code')
'Not a valid wordlist name')
def test_get_wordlist_path_loweres_country_code(self):
# upper case country codes are lowered
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment