Skip to content

Commit

Permalink
replaced tabs with spaces in order to fix codemod failure (#1999)
Browse files Browse the repository at this point in the history
* replaced tabs with spaces in order to fix codemod failure

* fix bandit security warning

* more bandit security fix

* run pre-commit to fix format
  • Loading branch information
rshraga authored Dec 6, 2022
1 parent 1020fae commit 49930ef
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
14 changes: 7 additions & 7 deletions packaging/install_torchdata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ if [ "$package_type" = "wheel" ]; then
TORCHDATA_VERSION="$(pip show torchdata | grep ^Version: | sed 's/Version: *//' | sed 's/+.\+//')"
else
TORCHDATA_VERSION="$(conda search --json 'torchdata[channel=pytorch-'"${channel}"] | \
python -c "import json, os, re, sys; \
cuver = 'cpu'; \
pyver = os.environ.get('PYTHON_VERSION').replace('.', ''); \
print(re.sub(r'\\+.*$', '',
[x['version'] for x in json.load(sys.stdin)['torchdata'] \
if 'py' + pyver in x['fn']][-1]))"
)"
python -c "import json, os, re, sys; \
cuver = 'cpu'; \
pyver = os.environ.get('PYTHON_VERSION').replace('.', ''); \
print(re.sub(r'\\+.*$', '',
[x['version'] for x in json.load(sys.stdin)['torchdata'] \
if 'py' + pyver in x['fn']][-1]))"
)"
echo "export CONDA_TORCHDATA_CONSTRAINT='- torchdata==${TORCHDATA_VERSION}'" >> "${BUILD_ENV_FILE}"
fi

Expand Down
4 changes: 2 additions & 2 deletions test/torchtext_unittest/datasets/test_cnndm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _get_mock_dataset(root_dir):
stories = []
for i in range(5):
url = "_".join([source, split, str(i)])
h = hashlib.sha1()
h = hashlib.new("sha1", usedforsecurity=False)
h.update(url.encode())
filename = h.hexdigest() + ".story"
txt_file = os.path.join(source_dir, filename)
Expand Down Expand Up @@ -74,7 +74,7 @@ def _mock_split_list(source, split):
story_fnames = []
for i in range(5):
url = "_".join([source, split, str(i)])
h = hashlib.sha1()
h = hashlib.new("sha1", usedforsecurity=False)
h.update(url.encode())
filename = h.hexdigest() + ".story"
story_fnames.append(filename)
Expand Down
2 changes: 1 addition & 1 deletion torchtext/datasets/cnndm.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _hash_urls(s: tuple):
Code is inspired from https://github.com/abisee/cnn-dailymail/blob/master/make_datafiles.py
"""
url = s[1]
h = hashlib.sha1()
h = hashlib.new("sha1", usedforsecurity=False)
h.update(url)
url_hash = h.hexdigest()
story_fname = url_hash + ".story"
Expand Down
6 changes: 2 additions & 4 deletions torchtext/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ def validate_file(file_obj, hash_value, hash_type="sha256"):
bool: return True if its a valid file, else False.
"""

if hash_type == "sha256":
hash_func = hashlib.sha256()
elif hash_type == "md5":
hash_func = hashlib.md5()
if hash_type in ("sha256", "md5"):
hash_func = hashlib.new(hash_type, usedforsecurity=False)
else:
raise ValueError

Expand Down

0 comments on commit 49930ef

Please sign in to comment.