From 8c21006e6c2959a55ce8cb80758564eeea2ebde8 Mon Sep 17 00:00:00 2001
From: jvoisin <julien.voisin@dustri.org>
Date: Sun, 8 Jul 2018 22:40:36 +0200
Subject: [PATCH] Fix some pep8 issues spotted by pyflakes

---
 libmat2/__init__.py       |  2 +-
 libmat2/images.py         |  5 +++++
 libmat2/office.py         |  2 +-
 libmat2/parser_factory.py |  4 ++--
 libmat2/torrent.py        | 40 +++++++++++++++++++--------------------
 mat2                      |  4 ++--
 6 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/libmat2/__init__.py b/libmat2/__init__.py
index 190abe5..d910215 100644
--- a/libmat2/__init__.py
+++ b/libmat2/__init__.py
@@ -1,7 +1,7 @@
 #!/bin/env python3
 
 # A set of extension that aren't supported, despite matching a supported mimetype
-unsupported_extensions = {
+UNSUPPORTED_EXTENSIONS = {
     '.asc',
     '.bat',
     '.brf',
diff --git a/libmat2/images.py b/libmat2/images.py
index 311186d..f9171e5 100644
--- a/libmat2/images.py
+++ b/libmat2/images.py
@@ -5,6 +5,7 @@ import os
 import shutil
 import tempfile
 import re
+from typing import Set
 
 import cairo
 
@@ -14,8 +15,12 @@ from gi.repository import GdkPixbuf
 
 from . import abstract
 
+# Make pyflakes happy
+assert Set
 
 class _ImageParser(abstract.AbstractParser):
+    meta_whitelist = set()  # type: Set[str]
+
     @staticmethod
     def __handle_problematic_filename(filename: str, callback) -> str:
         """ This method takes a filename with a problematic name,
diff --git a/libmat2/office.py b/libmat2/office.py
index e0ee6d2..75d6744 100644
--- a/libmat2/office.py
+++ b/libmat2/office.py
@@ -21,7 +21,7 @@ def _parse_xml(full_path: str):
     """ This function parse XML with namespace support. """
     def parse_map(f):  # etree support for ns is a bit rough
         ns_map = dict()
-        for event, (k, v) in ET.iterparse(f, ("start-ns", )):
+        for _, (k, v) in ET.iterparse(f, ("start-ns", )):
             ns_map[k] = v
         return ns_map
 
diff --git a/libmat2/parser_factory.py b/libmat2/parser_factory.py
index 7d4f43f..bd442b8 100644
--- a/libmat2/parser_factory.py
+++ b/libmat2/parser_factory.py
@@ -4,7 +4,7 @@ import mimetypes
 import importlib
 from typing import TypeVar, List, Tuple, Optional
 
-from . import abstract, unsupported_extensions
+from . import abstract, UNSUPPORTED_EXTENSIONS
 
 assert Tuple  # make pyflakes happy
 
@@ -34,7 +34,7 @@ def get_parser(filename: str) -> Tuple[Optional[T], Optional[str]]:
     mtype, _ = mimetypes.guess_type(filename)
 
     _, extension = os.path.splitext(filename)
-    if extension in unsupported_extensions:
+    if extension in UNSUPPORTED_EXTENSIONS:
         return None, mtype
 
     for parser_class in _get_parsers():  # type: ignore
diff --git a/libmat2/torrent.py b/libmat2/torrent.py
index 0f122b0..ca7715a 100644
--- a/libmat2/torrent.py
+++ b/libmat2/torrent.py
@@ -17,17 +17,17 @@ class TorrentParser(abstract.AbstractParser):
 
     def get_meta(self) -> Dict[str, str]:
         metadata = {}
-        for k, v in self.dict_repr.items():
-            if k not in self.whitelist:
-                metadata[k.decode('utf-8')] = v
+        for key, value in self.dict_repr.items():
+            if key not in self.whitelist:
+                metadata[key.decode('utf-8')] = value
         return metadata
 
 
     def remove_all(self) -> bool:
         cleaned = dict()
-        for k, v in self.dict_repr.items():
-            if k in self.whitelist:
-                cleaned[k] = v
+        for key, value in self.dict_repr.items():
+            if key in self.whitelist:
+                cleaned[key] = value
         with open(self.output_filename, 'wb') as f:
             f.write(_BencodeHandler().bencode(cleaned))
         self.dict_repr = cleaned  # since we're stateful
@@ -78,20 +78,20 @@ class _BencodeHandler(object):
         return s[colon:colon+str_len], s[colon+str_len:]
 
     def __decode_list(self, s: bytes) -> Tuple[list, bytes]:
-        r = list()
+        ret = list()
         s = s[1:]  # skip leading `l`
         while s[0] != ord('e'):
-            v, s = self.__decode_func[s[0]](s)
-            r.append(v)
-        return r, s[1:]
+            value, s = self.__decode_func[s[0]](s)
+            ret.append(value)
+        return ret, s[1:]
 
     def __decode_dict(self, s: bytes) -> Tuple[dict, bytes]:
-        r = dict()
+        ret = dict()
         s = s[1:]  # skip leading `d`
         while s[0] != ord(b'e'):
-            k, s = self.__decode_string(s)
-            r[k], s = self.__decode_func[s[0]](s)
-        return r, s[1:]
+            key, s = self.__decode_string(s)
+            ret[key], s = self.__decode_func[s[0]](s)
+        return ret, s[1:]
 
     @staticmethod
     def __encode_int(x: bytes) -> bytes:
@@ -109,9 +109,9 @@ class _BencodeHandler(object):
 
     def __encode_dict(self, x: dict) -> bytes:
         ret = b''
-        for k, v in sorted(x.items()):
-            ret += self.__encode_func[type(k)](k)
-            ret += self.__encode_func[type(v)](v)
+        for key, value in sorted(x.items()):
+            ret += self.__encode_func[type(key)](key)
+            ret += self.__encode_func[type(value)](value)
         return b'd' + ret + b'e'
 
     def bencode(self, s: Union[dict, list, bytes, int]) -> bytes:
@@ -119,11 +119,11 @@ class _BencodeHandler(object):
 
     def bdecode(self, s: bytes) -> Union[dict, None]:
         try:
-            r, l = self.__decode_func[s[0]](s)
+            ret, trail = self.__decode_func[s[0]](s)
         except (IndexError, KeyError, ValueError) as e:
             logging.debug("Not a valid bencoded string: %s", e)
             return None
-        if l != b'':
+        if trail != b'':
             logging.debug("Invalid bencoded value (data after valid prefix)")
             return None
-        return r
+        return ret
diff --git a/mat2 b/mat2
index 3fef8a0..d2a083a 100755
--- a/mat2
+++ b/mat2
@@ -9,7 +9,7 @@ import argparse
 import multiprocessing
 
 try:
-    from libmat2 import parser_factory, unsupported_extensions
+    from libmat2 import parser_factory, UNSUPPORTED_EXTENSIONS
 except ValueError as e:
     print(e)
     sys.exit(1)
@@ -84,7 +84,7 @@ def show_parsers():
         for mtype in parser.mimetypes:
             extensions = set()
             for extension in mimetypes.guess_all_extensions(mtype):
-                if extension[1:] not in unsupported_extensions:  # skip the dot
+                if extension[1:] not in UNSUPPORTED_EXTENSIONS:  # skip the dot
                     extensions.add(extension)
             if not extensions:
                 # we're not supporting a single extension in the current
-- 
GitLab