forked from fuzzitdev/pythonfuzz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary.py
More file actions
28 lines (23 loc) · 702 Bytes
/
Copy pathdictionary.py
File metadata and controls
28 lines (23 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import random
import re
import os
class Dictionary:
line_re = re.compile('"(.+)"$')
def __init__(self, dict_path=None):
if not dict_path or not os.path.exists(dict_path):
self._dict = list()
return
_dict = set()
with open(dict_path) as f:
for line in f:
line = line.lstrip()
if line.startswith('#'):
continue
word = self.line_re.search(line)
if word:
_dict.add(word.group(1))
self._dict = list(_dict)
def get_word(self):
if not self._dict:
return None
return random.choice(self._dict)