summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libmat/archive.py9
-rw-r--r--libmat/exceptions.py1
-rw-r--r--libmat/mat.py5
-rw-r--r--libmat/misc.py1
-rw-r--r--libmat/mutagenstripper.py4
-rw-r--r--libmat/office.py2
-rw-r--r--libmat/parser.py3
7 files changed, 21 insertions, 4 deletions
diff --git a/libmat/archive.py b/libmat/archive.py
index 8a3fee9..426dcf9 100644
--- a/libmat/archive.py
+++ b/libmat/archive.py
@@ -44,6 +44,7 @@ class GenericArchiveStripper(parser.GenericParser):
44 44
45 def is_clean(self, list_unsupported=False): 45 def is_clean(self, list_unsupported=False):
46 """ Virtual method to check for harmul metadata 46 """ Virtual method to check for harmul metadata
47 :param bool list_unsupported:
47 """ 48 """
48 raise NotImplementedError 49 raise NotImplementedError
49 50
@@ -157,6 +158,10 @@ class ZipStripper(GenericArchiveStripper):
157 files starting with "begining_blacklist", or ending with 158 files starting with "begining_blacklist", or ending with
158 "ending_blacklist". This method also add files present in 159 "ending_blacklist". This method also add files present in
159 whitelist to the archive. 160 whitelist to the archive.
161
162 :param list whitelist: Add those files to the produced archive, regardless if they are harmful or not
163 :param list beginning_blacklist: If the file starts with $ending_blacklist, it will _not_ be added
164 :param list ending_blacklist: If the file end with $ending_blacklist, it will _not_ be added
160 """ 165 """
161 if not ending_blacklist: 166 if not ending_blacklist:
162 ending_blacklist = [] 167 ending_blacklist = []
@@ -222,6 +227,8 @@ class TarStripper(GenericArchiveStripper):
222 """ Remove all harmful metadata from the tarfile. 227 """ Remove all harmful metadata from the tarfile.
223 The method will also add every files matching 228 The method will also add every files matching
224 whitelist in the produced archive. 229 whitelist in the produced archive.
230 :param list whitelist: Files to add the to produced archive,
231 regardless if they are considered harmfull.
225 """ 232 """
226 if not whitelist: 233 if not whitelist:
227 whitelist = [] 234 whitelist = []
@@ -257,6 +264,7 @@ class TarStripper(GenericArchiveStripper):
257 @staticmethod 264 @staticmethod
258 def is_file_clean(current_file): 265 def is_file_clean(current_file):
259 """ Check metadatas added by tarfile 266 """ Check metadatas added by tarfile
267 :param tarfile.TarInfo current_file:
260 """ 268 """
261 if current_file.mtime != 0: 269 if current_file.mtime != 0:
262 return False 270 return False
@@ -275,6 +283,7 @@ class TarStripper(GenericArchiveStripper):
275 When list_unsupported is True, the method returns a list 283 When list_unsupported is True, the method returns a list
276 of all non-supported/archives files contained in the 284 of all non-supported/archives files contained in the
277 archive. 285 archive.
286 :param bool list_unsupported:
278 """ 287 """
279 ret_list = [] 288 ret_list = []
280 tarin = tarfile.open(self.filename, 'r' + self.compression) 289 tarin = tarfile.open(self.filename, 'r' + self.compression)
diff --git a/libmat/exceptions.py b/libmat/exceptions.py
index e71c398..d982d2d 100644
--- a/libmat/exceptions.py
+++ b/libmat/exceptions.py
@@ -7,6 +7,7 @@ class UnableToRemoveFile(Exception):
7 """ 7 """
8 pass 8 pass
9 9
10
10class UnableToWriteFile(Exception): 11class UnableToWriteFile(Exception):
11 """This exception is raised when a file 12 """This exception is raised when a file
12 can could not be chmod +w 13 can could not be chmod +w
diff --git a/libmat/mat.py b/libmat/mat.py
index 5b5a83c..3947606 100644
--- a/libmat/mat.py
+++ b/libmat/mat.py
@@ -9,7 +9,6 @@ import os
9import platform 9import platform
10import subprocess 10import subprocess
11import xml.sax 11import xml.sax
12import mimetypes
13 12
14import hachoir_core.cmd_line 13import hachoir_core.cmd_line
15import hachoir_parser 14import hachoir_parser
@@ -46,7 +45,8 @@ def get_logo():
46 45
47 46
48def get_datafile_path(filename): 47def get_datafile_path(filename):
49 """ Return the path to the given ressource 48 """ Return the path to $filename
49 :param string filename:
50 """ 50 """
51 if os.path.isfile(os.path.join(os.path.curdir, 'data', filename)): 51 if os.path.isfile(os.path.join(os.path.curdir, 'data', filename)):
52 return os.path.join(os.path.curdir, 'data', filename) 52 return os.path.join(os.path.curdir, 'data', filename)
@@ -82,6 +82,7 @@ class XMLParser(xml.sax.handler.ContentHandler):
82 """ 82 """
83 83
84 def __init__(self): 84 def __init__(self):
85 xml.sax.handler.ContentHandler.__init__(self)
85 self.dict = {} 86 self.dict = {}
86 self.list = [] 87 self.list = []
87 self.content, self.key = '', '' 88 self.content, self.key = '', ''
diff --git a/libmat/misc.py b/libmat/misc.py
index b1a551c..a55b8ed 100644
--- a/libmat/misc.py
+++ b/libmat/misc.py
@@ -64,7 +64,6 @@ class TorrentStripper(parser.GenericParser):
64 def remove_all(self): 64 def remove_all(self):
65 """ Remove all comprimizing fields 65 """ Remove all comprimizing fields
66 """ 66 """
67 decoded = ''
68 with open(self.filename, 'r') as f: 67 with open(self.filename, 'r') as f:
69 decoded = bencode.bdecode(f.read()) 68 decoded = bencode.bdecode(f.read())
70 69
diff --git a/libmat/mutagenstripper.py b/libmat/mutagenstripper.py
index be89178..7e4beed 100644
--- a/libmat/mutagenstripper.py
+++ b/libmat/mutagenstripper.py
@@ -5,17 +5,21 @@ import parser
5 5
6 6
7class MutagenStripper(parser.GenericParser): 7class MutagenStripper(parser.GenericParser):
8 """ Parser using the (awesome) mutagen library. """
8 def __init__(self, filename, parser, mime, backup, is_writable, **kwargs): 9 def __init__(self, filename, parser, mime, backup, is_writable, **kwargs):
9 super(MutagenStripper, self).__init__(filename, parser, mime, backup, is_writable, **kwargs) 10 super(MutagenStripper, self).__init__(filename, parser, mime, backup, is_writable, **kwargs)
11 self.mfile = None # This will be instanciated in self._create_mfile()
10 self._create_mfile() 12 self._create_mfile()
11 13
12 def _create_mfile(self): 14 def _create_mfile(self):
13 raise NotImplementedError 15 raise NotImplementedError
14 16
15 def is_clean(self): 17 def is_clean(self):
18 """ Check if the file is clean. """
16 return not self.mfile.tags 19 return not self.mfile.tags
17 20
18 def remove_all(self): 21 def remove_all(self):
22 """ Remove all harmful metadata. """
19 if self.backup: 23 if self.backup:
20 self.create_backup_copy() 24 self.create_backup_copy()
21 self.mfile.delete() 25 self.mfile.delete()
diff --git a/libmat/office.py b/libmat/office.py
index bd4bd97..5a57b57 100644
--- a/libmat/office.py
+++ b/libmat/office.py
@@ -77,6 +77,8 @@ class OpenXmlStripper(archive.TerminalZipStripper):
77 """ 77 """
78 78
79 def remove_all(self): 79 def remove_all(self):
80 """ Remove harmful metadata, by deleting everything that doesn't end with '.rels' in the
81 'docProps' folder. """
80 return super(OpenXmlStripper, self).remove_all( 82 return super(OpenXmlStripper, self).remove_all(
81 beginning_blacklist='docProps/', whitelist='.rels') 83 beginning_blacklist='docProps/', whitelist='.rels')
82 84
diff --git a/libmat/parser.py b/libmat/parser.py
index 43de6d6..c6ba0a4 100644
--- a/libmat/parser.py
+++ b/libmat/parser.py
@@ -85,7 +85,8 @@ class GenericParser(object):
85 except: 85 except:
86 return False 86 return False
87 87
88 def _remove(self, fieldset, field): 88 @staticmethod
89 def _remove(fieldset, field):
89 """ Delete the given field 90 """ Delete the given field
90 """ 91 """
91 del fieldset[field] 92 del fieldset[field]