Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
diceware-debian
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drebs
diceware-debian
Commits
dc4161a0
Commit
dc4161a0
authored
9 years ago
by
ulif
Browse files
Options
Downloads
Patches
Plain Diff
Use only one parameter for WordList init.
parent
d420f32b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
diceware/wordlist.py
+12
-2
12 additions, 2 deletions
diceware/wordlist.py
tests/test_wordlist.py
+18
-0
18 additions, 0 deletions
tests/test_wordlist.py
with
30 additions
and
2 deletions
diceware/wordlist.py
+
12
−
2
View file @
dc4161a0
...
...
@@ -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
This diff is collapsed.
Click to expand it.
tests/test_wordlist.py
+
18
−
0
View file @
dc4161a0
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment