1
0
mirror of synced 2024-11-22 09:14:23 +01:00

Improve a bit the formatting of the code thanks to pyflakes3

This commit is contained in:
jvoisin 2018-07-02 00:22:05 +02:00
parent 11008f8fd4
commit 893f58554a
6 changed files with 39 additions and 41 deletions

View File

@ -10,11 +10,7 @@ class MutagenParser(abstract.AbstractParser):
super().__init__(filename) super().__init__(filename)
try: try:
mutagen.File(self.filename) mutagen.File(self.filename)
except mutagen.flac.MutagenError: except mutagen.MutagenError:
raise ValueError
except mutagen.mp3.MutagenError:
raise ValueError
except mutagen.ogg.MutagenError:
raise ValueError raise ValueError
def get_meta(self): def get_meta(self):
@ -47,4 +43,4 @@ class OGGParser(MutagenParser):
class FLACParser(MutagenParser): class FLACParser(MutagenParser):
mimetypes = {'audio/flac', 'audio/x-flac' } mimetypes = {'audio/flac', 'audio/x-flac'}

View File

@ -15,9 +15,9 @@ from gi.repository import GdkPixbuf
from . import abstract from . import abstract
class __ImageParser(abstract.AbstractParser): class _ImageParser(abstract.AbstractParser):
@staticmethod @staticmethod
def __handle_problematic_filename(filename:str, callback) -> str: def __handle_problematic_filename(filename: str, callback) -> str:
""" This method takes a filename with a problematic name, """ This method takes a filename with a problematic name,
and safely applies it a `callback`.""" and safely applies it a `callback`."""
tmpdirname = tempfile.mkdtemp() tmpdirname = tempfile.mkdtemp()
@ -42,7 +42,7 @@ class __ImageParser(abstract.AbstractParser):
meta.pop(key, None) meta.pop(key, None)
return meta return meta
class PNGParser(__ImageParser): class PNGParser(_ImageParser):
mimetypes = {'image/png', } mimetypes = {'image/png', }
meta_whitelist = {'SourceFile', 'ExifToolVersion', 'FileName', meta_whitelist = {'SourceFile', 'ExifToolVersion', 'FileName',
'Directory', 'FileSize', 'FileModifyDate', 'Directory', 'FileSize', 'FileModifyDate',
@ -65,7 +65,7 @@ class PNGParser(__ImageParser):
return True return True
class GdkPixbufAbstractParser(__ImageParser): class GdkPixbufAbstractParser(_ImageParser):
""" GdkPixbuf can handle a lot of surfaces, so we're rending images on it, """ GdkPixbuf can handle a lot of surfaces, so we're rending images on it,
this has the side-effect of removing metadata completely. this has the side-effect of removing metadata completely.
""" """

View File

@ -26,7 +26,7 @@ def _parse_xml(full_path: str):
ns = parse_map(full_path) ns = parse_map(full_path)
# Register the namespaces # Register the namespaces
for k,v in ns.items(): for k, v in ns.items():
ET.register_namespace(k, v) ET.register_namespace(k, v)
return ET.parse(full_path), ns return ET.parse(full_path), ns
@ -48,7 +48,7 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser):
except zipfile.BadZipFile: except zipfile.BadZipFile:
raise ValueError raise ValueError
def _specific_cleanup(self, full_path:str) -> bool: def _specific_cleanup(self, full_path: str) -> bool:
""" This method can be used to apply specific treatment """ This method can be used to apply specific treatment
to files present in the archive.""" to files present in the archive."""
return True return True
@ -140,7 +140,7 @@ class MSOfficeParser(ArchiveBasedAbstractParser):
'^docProps/', '^docProps/',
})) }))
def __remove_revisions(self, full_path:str) -> bool: def __remove_revisions(self, full_path: str) -> bool:
""" In this function, we're changing the XML """ In this function, we're changing the XML
document in two times, since we don't want document in two times, since we don't want
to change the tree we're iterating on.""" to change the tree we're iterating on."""
@ -152,7 +152,7 @@ class MSOfficeParser(ArchiveBasedAbstractParser):
elif tree.find('.//w:ins', ns) is None: elif tree.find('.//w:ins', ns) is None:
return True return True
parent_map = {c:p for p in tree.iter( ) for c in p} parent_map = {c:p for p in tree.iter() for c in p}
elements = list([element for element in tree.iterfind('.//w:del', ns)]) elements = list([element for element in tree.iterfind('.//w:del', ns)])
for element in elements: for element in elements:
@ -174,7 +174,7 @@ class MSOfficeParser(ArchiveBasedAbstractParser):
return True return True
def _specific_cleanup(self, full_path:str) -> bool: def _specific_cleanup(self, full_path: str) -> bool:
if full_path.endswith('/word/document.xml'): if full_path.endswith('/word/document.xml'):
return self.__remove_revisions(full_path) return self.__remove_revisions(full_path)
return True return True
@ -222,13 +222,13 @@ class LibreOfficeParser(ArchiveBasedAbstractParser):
'styles.xml', 'styles.xml',
} }
files_to_omit = set(map(re.compile, { # type: ignore files_to_omit = set(map(re.compile, { # type: ignore
'^meta\.xml$', r'^meta\.xml$',
'^Configurations2/', '^Configurations2/',
'^Thumbnails/', '^Thumbnails/',
})) }))
def __remove_revisions(self, full_path:str) -> bool: def __remove_revisions(self, full_path: str) -> bool:
tree, ns = _parse_xml(full_path) tree, ns = _parse_xml(full_path)
if 'office' not in ns.keys(): # no revisions in the current file if 'office' not in ns.keys(): # no revisions in the current file
@ -242,7 +242,7 @@ class LibreOfficeParser(ArchiveBasedAbstractParser):
return True return True
def _specific_cleanup(self, full_path:str) -> bool: def _specific_cleanup(self, full_path: str) -> bool:
if os.path.basename(full_path) == 'content.xml': if os.path.basename(full_path) == 'content.xml':
return self.__remove_revisions(full_path) return self.__remove_revisions(full_path)
return True return True

View File

@ -37,10 +37,10 @@ def get_parser(filename: str) -> Tuple[Optional[T], Optional[str]]:
if extension in unsupported_extensions: if extension in unsupported_extensions:
return None, mtype return None, mtype
for c in _get_parsers(): # type: ignore for parser_class in _get_parsers(): # type: ignore
if mtype in c.mimetypes: if mtype in parser_class.mimetypes:
try: try:
return c(filename), mtype return parser_class(filename), mtype
except ValueError: except ValueError:
return None, mtype return None, mtype
return None, mtype return None, mtype

View File

@ -83,7 +83,9 @@ class PDFParser(abstract.AbstractParser):
page_width, page_height = page.get_size() page_width, page_height = page.get_size()
logging.info("Rendering page %d/%d", pagenum + 1, pages_count) logging.info("Rendering page %d/%d", pagenum + 1, pages_count)
img_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(page_width) * self.__scale, int(page_height) * self.__scale) width = int(page_width) * self.__scale
height = int(page_height) * self.__scale
img_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
img_context = cairo.Context(img_surface) img_context = cairo.Context(img_surface)
img_context.scale(self.__scale, self.__scale) img_context.scale(self.__scale, self.__scale)

View File

@ -125,7 +125,7 @@ class _BencodeHandler(object):
try: try:
r, l = self.__decode_func[s[0]](s) r, l = self.__decode_func[s[0]](s)
except (IndexError, KeyError, ValueError) as e: except (IndexError, KeyError, ValueError) as e:
logging.debug("Not a valid bencoded string: %s" % e) logging.debug("Not a valid bencoded string: %s", e)
return None return None
if l != b'': if l != b'':
logging.debug("Invalid bencoded value (data after valid prefix)") logging.debug("Invalid bencoded value (data after valid prefix)")