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
7c11c4d6
Commit
7c11c4d6
authored
9 years ago
by
ulif
Browse files
Options
Downloads
Patches
Plain Diff
Add func to get all local wordlists names.
parent
53ce3f01
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/__init__.py
+18
-0
18 additions, 0 deletions
diceware/__init__.py
tests/test_diceware.py
+7
-0
7 additions, 0 deletions
tests/test_diceware.py
with
25 additions
and
0 deletions
diceware/__init__.py
+
18
−
0
View file @
7c11c4d6
...
...
@@ -124,6 +124,24 @@ def handle_options(args):
return
args
def
get_wordlist_names
():
"""
Get a all names of wordlists stored locally.
"""
result
=
[]
filenames
=
os
.
listdir
(
WORDLISTS_DIR
)
for
filename
in
filenames
:
if
not
os
.
path
.
isfile
(
os
.
path
.
join
(
WORDLISTS_DIR
,
filename
)):
continue
if
not
"
_
"
in
filename
:
continue
if
not
"
.
"
in
filename
:
continue
basename
=
filename
.
split
(
"
.
"
)[
0
]
name
=
basename
.
split
(
"
_
"
,
1
)[
1
]
result
.
append
(
name
)
return
sorted
(
result
)
def
get_wordlist
(
file_descriptor
):
"""
Parse file in `file_descriptor` and build a word list of it.
...
...
This diff is collapsed.
Click to expand it.
tests/test_diceware.py
+
7
−
0
View file @
7c11c4d6
...
...
@@ -8,6 +8,7 @@ from diceware import (
WORDLISTS_DIR
,
RE_WORDLIST_NAME
,
SPECIAL_CHARS
,
get_wordlist
,
get_wordlist_path
,
insert_special_char
,
get_passphrase
,
handle_options
,
main
,
__version__
,
print_version
,
get_random_sources
,
get_wordlist_names
,
)
...
...
@@ -120,6 +121,12 @@ class TestDicewareModule(object):
assert
exc_info
.
value
.
args
[
0
].
startswith
(
'
Not a valid wordlist name
'
)
def
test_get_wordlist_names
(
self
,
wordlists_dir
):
# we can get wordlist names also if directory is empty.
wlist_path
=
wordlists_dir
.
join
(
'
mywordlist_en_8k.txt
'
)
wlist_path
.
write
(
"
some
\n
irrelevant
\n
words
"
)
assert
get_wordlist_names
()
==
[
'
en_8k
'
]
def
test_insert_special_char
(
self
):
# we can insert special chars in words.
fake_rnd
=
FakeRandom
()
...
...
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