Matthew Schinckel avatar Matthew Schinckel committed 85129ca


Comments (0)

Files changed (1)


 import gzip
+import os
 import random
-MALE_NAMES ='data/male-names.gz').read().strip().split('\n')
-FEMALE_NAMES ='data/female-names.gz').read().strip().split('\n')
-LAST_NAMES ='data/Family-names.gz').read().strip().split('\n')
+data = os.path.join(os.path.dirname(__file__), 'data')
-WORDS ='data/Unabr.dict.gz').read().strip().split('\n')
+def read(filename):
+    return, filename)).read().strip().split('\n')
+MALE_NAMES = read('male-names.gz')
+FEMALE_NAMES = read('female-names.gz')
+LAST_NAMES = read('Family-names.gz')
+WORDS = read('Unabr.dict.gz')
-    'animal':'data/animals.gz').read().strip().split('\n'),
-    'plant':'data/plants.gz').read().strip().split('\n'),
-    'colour':'data/colours.gz').read().strip().split('\n'),
-    'shape':'data/shapes.gz').read().strip().split('\n'),
-    'verb':'data/verbs.gz').read().strip().split('\n'),
+    'animal': read('animals.gz'),
+    'plant': read('plants.gz'),
+    'colour': read('colours.gz'),
+    'shape': read('shapes.gz'),
+    'verb': read('verbs.gz'),
     'female': FEMALE_NAMES
+_WORDS = {}
 def digits(length=3):
     result = []
     for i in range(length):
 def generate_full_name(gender=None):
     return first_name(gender) + ' ' + last_name()
-def generate_passphrase(words=4):
+def generate_passphrase(words=4, length=None):
+    if length:
+        if length not in _WORDS:
+            _WORDS[length] = [x for x in WORDS if len(x) <= length]
+        source = _WORDS[length]
+    else:
+        source = WORDS
     result = []
     for i in range(words):
-        result.append(random.choice(WORDS))
+        result.append(random.choice(source))
     return " ".join(result)
 def generate_nice_passphrase(*terms):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.