Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Commit 49930ef

Browse files
authored
replaced tabs with spaces in order to fix codemod failure (#1999)
* replaced tabs with spaces in order to fix codemod failure * fix bandit security warning * more bandit security fix * run pre-commit to fix format
1 parent 1020fae commit 49930ef

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

packaging/install_torchdata.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ if [ "$package_type" = "wheel" ]; then
3434
TORCHDATA_VERSION="$(pip show torchdata | grep ^Version: | sed 's/Version: *//' | sed 's/+.\+//')"
3535
else
3636
TORCHDATA_VERSION="$(conda search --json 'torchdata[channel=pytorch-'"${channel}"] | \
37-
python -c "import json, os, re, sys; \
38-
cuver = 'cpu'; \
39-
pyver = os.environ.get('PYTHON_VERSION').replace('.', ''); \
40-
print(re.sub(r'\\+.*$', '',
41-
[x['version'] for x in json.load(sys.stdin)['torchdata'] \
42-
if 'py' + pyver in x['fn']][-1]))"
43-
)"
37+
python -c "import json, os, re, sys; \
38+
cuver = 'cpu'; \
39+
pyver = os.environ.get('PYTHON_VERSION').replace('.', ''); \
40+
print(re.sub(r'\\+.*$', '',
41+
[x['version'] for x in json.load(sys.stdin)['torchdata'] \
42+
if 'py' + pyver in x['fn']][-1]))"
43+
)"
4444
echo "export CONDA_TORCHDATA_CONSTRAINT='- torchdata==${TORCHDATA_VERSION}'" >> "${BUILD_ENV_FILE}"
4545
fi
4646

test/torchtext_unittest/datasets/test_cnndm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _get_mock_dataset(root_dir):
2929
stories = []
3030
for i in range(5):
3131
url = "_".join([source, split, str(i)])
32-
h = hashlib.sha1()
32+
h = hashlib.new("sha1", usedforsecurity=False)
3333
h.update(url.encode())
3434
filename = h.hexdigest() + ".story"
3535
txt_file = os.path.join(source_dir, filename)
@@ -74,7 +74,7 @@ def _mock_split_list(source, split):
7474
story_fnames = []
7575
for i in range(5):
7676
url = "_".join([source, split, str(i)])
77-
h = hashlib.sha1()
77+
h = hashlib.new("sha1", usedforsecurity=False)
7878
h.update(url.encode())
7979
filename = h.hexdigest() + ".story"
8080
story_fnames.append(filename)

torchtext/datasets/cnndm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _hash_urls(s: tuple):
7575
Code is inspired from https://github.com/abisee/cnn-dailymail/blob/master/make_datafiles.py
7676
"""
7777
url = s[1]
78-
h = hashlib.sha1()
78+
h = hashlib.new("sha1", usedforsecurity=False)
7979
h.update(url)
8080
url_hash = h.hexdigest()
8181
story_fname = url_hash + ".story"

torchtext/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ def validate_file(file_obj, hash_value, hash_type="sha256"):
4747
bool: return True if its a valid file, else False.
4848
"""
4949

50-
if hash_type == "sha256":
51-
hash_func = hashlib.sha256()
52-
elif hash_type == "md5":
53-
hash_func = hashlib.md5()
50+
if hash_type in ("sha256", "md5"):
51+
hash_func = hashlib.new(hash_type, usedforsecurity=False)
5452
else:
5553
raise ValueError
5654

0 commit comments

Comments
 (0)