summaryrefslogtreecommitdiff
path: root/MAT/parser.py
diff options
context:
space:
mode:
authorjvoisin2012-12-27 17:01:30 +0100
committerjvoisin2012-12-27 17:01:30 +0100
commitcffdcc1b1e78d48cad62c54432a9d8ce41f4d616 (patch)
treef07e10cdbfb6fa1a5de4edb84435f10cb50ee191 /MAT/parser.py
parenta36f48b460f7638052f2e8ac3f9ddde8232cf339 (diff)
Refactor the archive parser
Refactoring of the archive and office parser, in order to simplify the code and reduce abstraction
Diffstat (limited to 'MAT/parser.py')
-rw-r--r--MAT/parser.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/MAT/parser.py b/MAT/parser.py
index 6be2b03..e5acbf8 100644
--- a/MAT/parser.py
+++ b/MAT/parser.py
@@ -59,7 +59,7 @@ class GenericParser(object):
59 59
60 def remove_all(self): 60 def remove_all(self):
61 ''' 61 '''
62 Remove all the files that are compromizing 62 Remove all compromising fields
63 ''' 63 '''
64 state = self._remove_all(self.editor) 64 state = self._remove_all(self.editor)
65 hachoir_core.field.writeIntoFile(self.editor, self.output) 65 hachoir_core.field.writeIntoFile(self.editor, self.output)
@@ -67,6 +67,9 @@ class GenericParser(object):
67 return state 67 return state
68 68
69 def _remove_all(self, fieldset): 69 def _remove_all(self, fieldset):
70 '''
71 Recursive way to handle tree metadatas
72 '''
70 try: 73 try:
71 for field in fieldset: 74 for field in fieldset:
72 remove = self._should_remove(field) 75 remove = self._should_remove(field)
@@ -93,6 +96,9 @@ class GenericParser(object):
93 return metadata 96 return metadata
94 97
95 def _get_meta(self, fieldset, metadata): 98 def _get_meta(self, fieldset, metadata):
99 '''
100 Recursive way to handle tree metadatas
101 '''
96 for field in fieldset: 102 for field in fieldset:
97 remove = self._should_remove(field) 103 remove = self._should_remove(field)
98 if remove is True: 104 if remove is True:
@@ -101,11 +107,11 @@ class GenericParser(object):
101 except: 107 except:
102 metadata[field.name] = 'harmful content' 108 metadata[field.name] = 'harmful content'
103 if remove is FIELD: 109 if remove is FIELD:
104 self._get_meta(field) 110 self._get_meta(field, None)
105 111
106 def _should_remove(self, key): 112 def _should_remove(self, key):
107 ''' 113 '''
108 return True if the field is compromizing 114 return True if the field is compromising
109 abstract method 115 abstract method
110 ''' 116 '''
111 raise NotImplementedError 117 raise NotImplementedError
@@ -115,6 +121,6 @@ class GenericParser(object):
115 Do a backup of the file if asked, 121 Do a backup of the file if asked,
116 and change his creation/access date 122 and change his creation/access date
117 ''' 123 '''
118 if self.backup is False: 124 if not self.backup:
119 mat.secure_remove(self.filename) 125 mat.secure_remove(self.filename)
120 os.rename(self.output, self.filename) 126 os.rename(self.output, self.filename)