Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for google app engine #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions zxcvbn/matching.py
@@ -1,5 +1,5 @@
from itertools import groupby
import pkg_resources
import os
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, pkg_resources is better for this purpose because provides support for accessing data files residing in the module even when the module is actually loaded from a zipfile. This request drops that ability.

I imagine that pkg_resources is not available on Google App Engine since it's not standard? But in order to not regress the behavior, could you please modify this pull request to try to import and use the pkg_resources method, and if it fails, fall back to using the filesystem?

import re

try:
Expand All @@ -8,6 +8,8 @@
except ImportError:
import json

MODULE_PATH = os.path.dirname(os.path.abspath(__file__))


GRAPHS = {}
DICTIONARY_MATCHERS = []
Expand Down Expand Up @@ -63,16 +65,14 @@ def _build_ranked_dict(unranked_list):


def _load_frequency_lists():
data = pkg_resources.resource_string(__name__, 'generated/frequency_lists.json')
dicts = json.loads(data)
dicts = json.load(open(os.path.join(MODULE_PATH, 'generated', 'frequency_lists.json'), 'rb'))
for name, wordlist in dicts.items():
DICTIONARY_MATCHERS.append(_build_dict_matcher(name, _build_ranked_dict(wordlist)))


def _load_adjacency_graphs():
global GRAPHS
data = pkg_resources.resource_string(__name__, 'generated/adjacency_graphs.json')
GRAPHS = json.loads(data)
GRAPHS = json.load(open(os.path.join(MODULE_PATH, 'generated', 'adjacency_graphs.json'), 'rb'))


# on qwerty, 'g' has degree 6, being adjacent to 'ftyhbv'. '\' has degree 1.
Expand Down Expand Up @@ -526,7 +526,7 @@ def check_date(day, month, year):
def omnimatch(password, user_inputs=[]):
ranked_user_inputs_dict = {}
for i, user_input in enumerate(user_inputs):
ranked_user_inputs_dict[user_input.lower()] = i+1
ranked_user_inputs_dict[user_input.lower()] = i+1
user_input_matcher = _build_dict_matcher('user_inputs', ranked_user_inputs_dict)
matches = user_input_matcher(password)
for matcher in MATCHERS:
Expand Down