Fix some pep8 issues spotted by pyflakes
This commit is contained in:
parent
f49aa5cab7
commit
8c21006e6c
@ -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',
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
4
mat2
4
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
|
||||
|
Loading…
Reference in New Issue
Block a user