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

Use only one parameter for WordList init.

parent d420f32b
No related branches found
No related tags found
No related merge requests found
......@@ -133,9 +133,19 @@ def get_wordlist_path(name):
basename = 'wordlist_%s.txt' % name
return os.path.join(WORDLISTS_DIR, basename)
try:
basestring
except NameError:
basestring = str
class WordList(object):
"""A word list contains words for building passphrases.
"""
def __init__(self, opened_file=None, path=None):
pass
def __init__(self, path_or_filelike=None):
self.path = None
if isinstance(path_or_filelike, basestring):
self.path = path_or_filelike
self.fd = open(self.path, "r")
else:
self.fd = path_or_filelike
......@@ -199,3 +199,21 @@ class TestWordList(object):
in_file.write("foo\n")
w_list = WordList(str(in_file))
assert w_list is not None
assert hasattr(w_list, "path")
assert hasattr(w_list, "fd")
def test_create_opens_file(self, tmpdir):
# if we pass-in a path, the file will be opened for reading.
in_file = tmpdir.mkdir("work").join("mywordlist")
in_file.write("foo\n")
w_list = WordList(str(in_file))
assert w_list.fd is not None
def test_create_accepts_open_file(self, tmpdir):
# if we pass in an open file, it will be used
in_file = tmpdir.mkdir("work").join("mywordlist")
in_file.write("foo\n")
with open(str(in_file), "w") as my_open_file:
w_list = WordList(my_open_file)
assert w_list.fd is not None
assert w_list.path is None
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