From ff431ae30521f294ce4d97d31b19db93cb7c0195 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 30 Oct 2013 18:44:02 +0000 Subject: More pep8 conformance --- MAT/images.py | 6 +++--- MAT/mat.py | 8 ++++++-- MAT/misc.py | 8 ++++---- MAT/parser.py | 10 +++++----- nautilus/nautilus-mat.py | 12 +++++------- test/libtest.py | 1 + test/test.py | 3 ++- 7 files changed, 26 insertions(+), 22 deletions(-) diff --git a/MAT/images.py b/MAT/images.py index dc96e6a..67c710f 100644 --- a/MAT/images.py +++ b/MAT/images.py @@ -42,9 +42,9 @@ class PngStripper(parser.GenericParser): ''' field_list = frozenset([ 'id', - 'header', # PNG header - 'physical', # the intended pixel size or aspect ratio - 'end']) # end of the image + 'header', # PNG header + 'physical', # the intended pixel size or aspect ratio + 'end']) # end of the image if field.name in field_list: return False if field.name.startswith('data['): # data diff --git a/MAT/mat.py b/MAT/mat.py index 092ef48..0359dd0 100644 --- a/MAT/mat.py +++ b/MAT/mat.py @@ -31,6 +31,7 @@ logging.basicConfig(filename=fname, level=LOGGING_LEVEL) import strippers # this is loaded here because we need LOGGING_LEVEL + def get_logo(): ''' Return the path to the logo ''' @@ -41,6 +42,7 @@ def get_logo(): elif os.path.isfile('/usr/local/share/pixmaps/mat.png'): return '/usr/local/share/pixmaps/mat.png' + def get_datadir(): ''' Return the path to the data directory ''' @@ -51,6 +53,7 @@ def get_datadir(): elif os.path.isdir('/usr/share/mat/'): return '/usr/share/mat/' + def list_supported_formats(): ''' Return a list of all locally supported fileformat. It parses that FORMATS file, and removes locally @@ -70,6 +73,7 @@ def list_supported_formats(): return localy_supported + class XMLParser(xml.sax.handler.ContentHandler): ''' Parse the supported format xml, and return a corresponding list of dict @@ -132,7 +136,7 @@ def create_class_file(name, backup, **kwargs): logging.error('%s is not a valid file' % name) return None - if not os.access(name, os.R_OK): #check read permissions + if not os.access(name, os.R_OK): # check read permissions logging.error('%s is is not readable' % name) return None @@ -156,7 +160,7 @@ def create_class_file(name, backup, **kwargs): if mime == 'application/zip': # some formats are zipped stuff if mimetypes.guess_type(name)[0]: - mime = mimetypes.guess_type(name)[0] + mime = mimetypes.guess_type(name)[0] if mime.startswith('application/vnd.oasis.opendocument'): mime = 'application/opendocument' # opendocument fileformat diff --git a/MAT/misc.py b/MAT/misc.py index 3f24ece..450f381 100644 --- a/MAT/misc.py +++ b/MAT/misc.py @@ -19,7 +19,7 @@ class TorrentStripper(parser.GenericParser): ''' Get recursively all keys from a dict and its subdicts ''' - for (i,j) in list(dictionary.items()): + for i, j in list(dictionary.items()): if isinstance(j, dict): return set([i]).union(self.__get_key_recursively(j)) return set([i]) @@ -35,7 +35,7 @@ class TorrentStripper(parser.GenericParser): ''' Get recursively all harmful metadata ''' d = dict() - for(i,j) in list(dictionary.items()): + for i, j in list(dictionary.items()): if i not in self.fields: d[i] = j elif isinstance(j, dict): @@ -53,7 +53,7 @@ class TorrentStripper(parser.GenericParser): ''' Remove recursively all compromizing fields ''' d = dict() - for (i,j) in [i for i in list(dictionary.items()) if i in self.fields]: + for i, j in [i for i in list(dictionary.items()) if i in self.fields]: if isinstance(j, dict): d = dict(list(d.items()) + list(self.__get_meta_recursively(j).items())) else: @@ -67,7 +67,7 @@ class TorrentStripper(parser.GenericParser): with open(self.filename, 'r') as f: decoded = bencode.bdecode(f.read()) - cleaned = {i:j for i,j in list(decoded.items()) if i in self.fields} + cleaned = {i: j for i, j in list(decoded.items()) if i in self.fields} with open(self.output, 'w') as f: # encode the decoded torrent f.write(bencode.bencode(cleaned)) # and write it in self.output diff --git a/MAT/parser.py b/MAT/parser.py index 8ef5aba..1765da8 100644 --- a/MAT/parser.py +++ b/MAT/parser.py @@ -11,11 +11,11 @@ import hachoir_editor import mat NOMETA = frozenset(( - '.bmp', # "raw" image - '.rdf', # text - '.txt', # plain text - '.xml', # formated text (XML) - '.rels', # openXML formated text + '.bmp', # "raw" image + '.rdf', # text + '.txt', # plain text + '.xml', # formated text (XML) + '.rels', # openXML formated text )) FIELD = object() diff --git a/nautilus/nautilus-mat.py b/nautilus/nautilus-mat.py index 2a84600..19b601e 100644 --- a/nautilus/nautilus-mat.py +++ b/nautilus/nautilus-mat.py @@ -1,12 +1,11 @@ #! /usr/bin/python ''' This file is an extension for the Nautilus - file manager, to provide a contextual menu to - clean metadata + file manager, to provide a contextual menu to + clean metadata ''' import logging -import os import urllib try: import gettext @@ -15,13 +14,12 @@ except: logging.warning("Failed to initialise gettext") _ = lambda x: x -import xml.sax - from gi.repository import Nautilus, GObject, Gtk import MAT.mat import MAT.strippers + class MatExtension(GObject.GObject, Nautilus.MenuProvider): def __init__(self): logging.debug("nautilus-mat: initialising") @@ -44,7 +42,7 @@ class MatExtension(GObject.GObject, Nautilus.MenuProvider): logging.debug("%s files not supported by MAT" % file.get_uri_scheme()) return - # MAT can not clean non-writable files + # MAT can not clean non-writable files if not file.can_write(): logging.debug("%s is not writable by MAT" % file.get_uri_scheme()) return @@ -56,7 +54,7 @@ class MatExtension(GObject.GObject, Nautilus.MenuProvider): item.connect('activate', self.menu_activate_cb, file) return item, - def show_message(self, message, type = Gtk.MessageType.INFO): + def show_message(self, message, type=Gtk.MessageType.INFO): dialog = Gtk.MessageDialog(parent=None, flags=Gtk.DialogFlags.MODAL, type=type, diff --git a/test/libtest.py b/test/libtest.py index acf8659..f92d933 100644 --- a/test/libtest.py +++ b/test/libtest.py @@ -84,6 +84,7 @@ class TestFileAttributes(unittest.TestCase): ''' test MAT's behaviour on empty file''' self.assertFalse(MAT.mat.create_class_file('empty_file', False, add2archive=True)) + class TestSecureRemove(unittest.TestCase): ''' Test the secure_remove function ''' diff --git a/test/test.py b/test/test.py index 0b7996b..1641f88 100644 --- a/test/test.py +++ b/test/test.py @@ -8,12 +8,12 @@ - remove the copy on end ''' + import shutil import os import glob import tempfile import unittest -import subprocess VERBOSITY = 15 @@ -39,6 +39,7 @@ except ImportError: FILE_LIST.remove(('clean é.mp3', 'dirty é.mp3')) FILE_LIST.remove(('clean é.flac', 'dirty é.flac')) + class MATTest(unittest.TestCase): ''' Parent class of all test-functions -- cgit v1.3