[totem/wip/hadess/re-enable-pylint: 4/10] opensubtitles: Fix some pylint warnings
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem/wip/hadess/re-enable-pylint: 4/10] opensubtitles: Fix some pylint warnings
- Date: Mon, 27 Jun 2022 12:36:19 +0000 (UTC)
commit 267f18b5b70575fe5e6a86ac1e0c45e9129463de
Author: Bastien Nocera <hadess hadess net>
Date: Thu Jun 23 16:12:11 2022 +0200
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)•
src/plugins/opensubtitles/hash.py | 32 +++++++++++++++-----------------
1 file 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]