diff options
author | Bastien Nocera <hadess@hadess.net> | 2022-06-23 16:12:11 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2022-06-27 14:36:12 +0200 |
commit | 267f18b5b70575fe5e6a86ac1e0c45e9129463de (patch) | |
tree | 6fc5a2af8aeb29d378bfc6ca1ef751a3ac864c32 | |
parent | 1e7655dac34bcb802668105216cbb5f3ecc47b5f (diff) | |
download | totem-267f18b5b70575fe5e6a86ac1e0c45e9129463de.tar.gz |
opensubtitles: Fix some pylint warnings
src/plugins/opensubtitles/hash.py:44:19: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
src/plugins/opensubtitles/hash.py:24:18: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)•
-rw-r--r-- | src/plugins/opensubtitles/hash.py | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/plugins/opensubtitles/hash.py b/src/plugins/opensubtitles/hash.py index f28341658..f780519c5 100644 --- a/src/plugins/opensubtitles/hash.py +++ b/src/plugins/opensubtitles/hash.py @@ -21,26 +21,24 @@ def hash_file (name): if filesize < 65536 * 2: return SIZE_ERROR, 0 - file_handle = open (file_to_hash.get_path (), "rb") + with open (file_to_hash.get_path (), "rb") as file_handle: + for _ in range(int(65536 / bytesize)): + buf = file_handle.read (bytesize) + (l_value,) = struct.unpack (longlongformat, buf) + file_hash += l_value + file_hash = file_hash & 0xFFFFFFFFFFFFFFFF #to remain as 64bit number - for _ in range(int(65536 / bytesize)): - buf = file_handle.read (bytesize) - (l_value,) = struct.unpack (longlongformat, buf) - file_hash += l_value - file_hash = file_hash & 0xFFFFFFFFFFFFFFFF #to remain as 64bit number + file_handle.seek (max (0, filesize - 65536), os.SEEK_SET) - file_handle.seek (max (0, filesize - 65536), os.SEEK_SET) + if file_handle.tell() != max (0, filesize - 65536): + return SEEK_ERROR, 0 - if file_handle.tell() != max (0, filesize - 65536): - return SEEK_ERROR, 0 + for _ in range(int(65536/bytesize)): + buf = file_handle.read (bytesize) + (l_value,) = struct.unpack (longlongformat, buf) + file_hash += l_value + file_hash = file_hash & 0xFFFFFFFFFFFFFFFF - for _ in range(int(65536/bytesize)): - buf = file_handle.read (bytesize) - (l_value,) = struct.unpack (longlongformat, buf) - file_hash += l_value - file_hash = file_hash & 0xFFFFFFFFFFFFFFFF - - file_handle.close () - returnedhash = "%016x" % file_hash + returnedhash = f"{file_hash:%016x}" return returnedhash, filesize |