diff options
| author | jvoisin | 2013-10-30 18:44:02 +0000 |
|---|---|---|
| committer | jvoisin | 2013-10-30 18:44:02 +0000 |
| commit | ff431ae30521f294ce4d97d31b19db93cb7c0195 (patch) | |
| tree | 1ba0af34082607a318e74a068ed95bc3dd455271 /MAT | |
| parent | a646ebbd3a0f54b43fc610134d2ebb39b5c4c732 (diff) | |
More pep8 conformance
Diffstat (limited to 'MAT')
| -rw-r--r-- | MAT/images.py | 6 | ||||
| -rw-r--r-- | MAT/mat.py | 8 | ||||
| -rw-r--r-- | MAT/misc.py | 8 | ||||
| -rw-r--r-- | MAT/parser.py | 10 |
4 files changed, 18 insertions, 14 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): | |||
| 42 | ''' | 42 | ''' |
| 43 | field_list = frozenset([ | 43 | field_list = frozenset([ |
| 44 | 'id', | 44 | 'id', |
| 45 | 'header', # PNG header | 45 | 'header', # PNG header |
| 46 | 'physical', # the intended pixel size or aspect ratio | 46 | 'physical', # the intended pixel size or aspect ratio |
| 47 | 'end']) # end of the image | 47 | 'end']) # end of the image |
| 48 | if field.name in field_list: | 48 | if field.name in field_list: |
| 49 | return False | 49 | return False |
| 50 | if field.name.startswith('data['): # data | 50 | if field.name.startswith('data['): # data |
| @@ -31,6 +31,7 @@ logging.basicConfig(filename=fname, level=LOGGING_LEVEL) | |||
| 31 | 31 | ||
| 32 | import strippers # this is loaded here because we need LOGGING_LEVEL | 32 | import strippers # this is loaded here because we need LOGGING_LEVEL |
| 33 | 33 | ||
| 34 | |||
| 34 | def get_logo(): | 35 | def get_logo(): |
| 35 | ''' Return the path to the logo | 36 | ''' Return the path to the logo |
| 36 | ''' | 37 | ''' |
| @@ -41,6 +42,7 @@ def get_logo(): | |||
| 41 | elif os.path.isfile('/usr/local/share/pixmaps/mat.png'): | 42 | elif os.path.isfile('/usr/local/share/pixmaps/mat.png'): |
| 42 | return '/usr/local/share/pixmaps/mat.png' | 43 | return '/usr/local/share/pixmaps/mat.png' |
| 43 | 44 | ||
| 45 | |||
| 44 | def get_datadir(): | 46 | def get_datadir(): |
| 45 | ''' Return the path to the data directory | 47 | ''' Return the path to the data directory |
| 46 | ''' | 48 | ''' |
| @@ -51,6 +53,7 @@ def get_datadir(): | |||
| 51 | elif os.path.isdir('/usr/share/mat/'): | 53 | elif os.path.isdir('/usr/share/mat/'): |
| 52 | return '/usr/share/mat/' | 54 | return '/usr/share/mat/' |
| 53 | 55 | ||
| 56 | |||
| 54 | def list_supported_formats(): | 57 | def list_supported_formats(): |
| 55 | ''' Return a list of all locally supported fileformat. | 58 | ''' Return a list of all locally supported fileformat. |
| 56 | It parses that FORMATS file, and removes locally | 59 | It parses that FORMATS file, and removes locally |
| @@ -70,6 +73,7 @@ def list_supported_formats(): | |||
| 70 | 73 | ||
| 71 | return localy_supported | 74 | return localy_supported |
| 72 | 75 | ||
| 76 | |||
| 73 | class XMLParser(xml.sax.handler.ContentHandler): | 77 | class XMLParser(xml.sax.handler.ContentHandler): |
| 74 | ''' Parse the supported format xml, and return a corresponding | 78 | ''' Parse the supported format xml, and return a corresponding |
| 75 | list of dict | 79 | list of dict |
| @@ -132,7 +136,7 @@ def create_class_file(name, backup, **kwargs): | |||
| 132 | logging.error('%s is not a valid file' % name) | 136 | logging.error('%s is not a valid file' % name) |
| 133 | return None | 137 | return None |
| 134 | 138 | ||
| 135 | if not os.access(name, os.R_OK): #check read permissions | 139 | if not os.access(name, os.R_OK): # check read permissions |
| 136 | logging.error('%s is is not readable' % name) | 140 | logging.error('%s is is not readable' % name) |
| 137 | return None | 141 | return None |
| 138 | 142 | ||
| @@ -156,7 +160,7 @@ def create_class_file(name, backup, **kwargs): | |||
| 156 | 160 | ||
| 157 | if mime == 'application/zip': # some formats are zipped stuff | 161 | if mime == 'application/zip': # some formats are zipped stuff |
| 158 | if mimetypes.guess_type(name)[0]: | 162 | if mimetypes.guess_type(name)[0]: |
| 159 | mime = mimetypes.guess_type(name)[0] | 163 | mime = mimetypes.guess_type(name)[0] |
| 160 | 164 | ||
| 161 | if mime.startswith('application/vnd.oasis.opendocument'): | 165 | if mime.startswith('application/vnd.oasis.opendocument'): |
| 162 | mime = 'application/opendocument' # opendocument fileformat | 166 | 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): | |||
| 19 | ''' Get recursively all keys from a dict and | 19 | ''' Get recursively all keys from a dict and |
| 20 | its subdicts | 20 | its subdicts |
| 21 | ''' | 21 | ''' |
| 22 | for (i,j) in list(dictionary.items()): | 22 | for i, j in list(dictionary.items()): |
| 23 | if isinstance(j, dict): | 23 | if isinstance(j, dict): |
| 24 | return set([i]).union(self.__get_key_recursively(j)) | 24 | return set([i]).union(self.__get_key_recursively(j)) |
| 25 | return set([i]) | 25 | return set([i]) |
| @@ -35,7 +35,7 @@ class TorrentStripper(parser.GenericParser): | |||
| 35 | ''' Get recursively all harmful metadata | 35 | ''' Get recursively all harmful metadata |
| 36 | ''' | 36 | ''' |
| 37 | d = dict() | 37 | d = dict() |
| 38 | for(i,j) in list(dictionary.items()): | 38 | for i, j in list(dictionary.items()): |
| 39 | if i not in self.fields: | 39 | if i not in self.fields: |
| 40 | d[i] = j | 40 | d[i] = j |
| 41 | elif isinstance(j, dict): | 41 | elif isinstance(j, dict): |
| @@ -53,7 +53,7 @@ class TorrentStripper(parser.GenericParser): | |||
| 53 | ''' Remove recursively all compromizing fields | 53 | ''' Remove recursively all compromizing fields |
| 54 | ''' | 54 | ''' |
| 55 | d = dict() | 55 | d = dict() |
| 56 | for (i,j) in [i for i in list(dictionary.items()) if i in self.fields]: | 56 | for i, j in [i for i in list(dictionary.items()) if i in self.fields]: |
| 57 | if isinstance(j, dict): | 57 | if isinstance(j, dict): |
| 58 | d = dict(list(d.items()) + list(self.__get_meta_recursively(j).items())) | 58 | d = dict(list(d.items()) + list(self.__get_meta_recursively(j).items())) |
| 59 | else: | 59 | else: |
| @@ -67,7 +67,7 @@ class TorrentStripper(parser.GenericParser): | |||
| 67 | with open(self.filename, 'r') as f: | 67 | with open(self.filename, 'r') as f: |
| 68 | decoded = bencode.bdecode(f.read()) | 68 | decoded = bencode.bdecode(f.read()) |
| 69 | 69 | ||
| 70 | cleaned = {i:j for i,j in list(decoded.items()) if i in self.fields} | 70 | cleaned = {i: j for i, j in list(decoded.items()) if i in self.fields} |
| 71 | 71 | ||
| 72 | with open(self.output, 'w') as f: # encode the decoded torrent | 72 | with open(self.output, 'w') as f: # encode the decoded torrent |
| 73 | f.write(bencode.bencode(cleaned)) # and write it in self.output | 73 | 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 | |||
| 11 | import mat | 11 | import mat |
| 12 | 12 | ||
| 13 | NOMETA = frozenset(( | 13 | NOMETA = frozenset(( |
| 14 | '.bmp', # "raw" image | 14 | '.bmp', # "raw" image |
| 15 | '.rdf', # text | 15 | '.rdf', # text |
| 16 | '.txt', # plain text | 16 | '.txt', # plain text |
| 17 | '.xml', # formated text (XML) | 17 | '.xml', # formated text (XML) |
| 18 | '.rels', # openXML formated text | 18 | '.rels', # openXML formated text |
| 19 | )) | 19 | )) |
| 20 | 20 | ||
| 21 | FIELD = object() | 21 | FIELD = object() |
