From 3d80f9752481b8967616698bb3c0c014e6f1527a Mon Sep 17 00:00:00 2001
From: jvoisin <julien.voisin@dustri.org>
Date: Fri, 6 Jul 2018 00:49:17 +0200
Subject: [PATCH] Simplify BMP handling

---
 libmat2/harmless.py           |  2 +-
 libmat2/images.py             | 16 ----------------
 tests/test_corrupted_files.py |  5 ++---
 tests/test_libmat2.py         |  4 ++--
 4 files changed, 5 insertions(+), 22 deletions(-)

diff --git a/libmat2/harmless.py b/libmat2/harmless.py
index 9032caf..336873c 100644
--- a/libmat2/harmless.py
+++ b/libmat2/harmless.py
@@ -5,7 +5,7 @@ from . import abstract
 
 class HarmlessParser(abstract.AbstractParser):
     """ This is the parser for filetypes that do not contain metadata. """
-    mimetypes = {'text/plain', }
+    mimetypes = {'text/plain', 'image/x-ms-bmp'}
 
     def get_meta(self) -> Dict[str, str]:
         return dict()
diff --git a/libmat2/images.py b/libmat2/images.py
index 74533b5..311186d 100644
--- a/libmat2/images.py
+++ b/libmat2/images.py
@@ -110,19 +110,3 @@ class TiffParser(GdkPixbufAbstractParser):
                       'FilePermissions', 'FileSize', 'FileType',
                       'FileTypeExtension', 'ImageHeight', 'ImageSize',
                       'ImageWidth', 'MIMEType', 'Megapixels', 'SourceFile'}
-
-
-class BMPParser(GdkPixbufAbstractParser):
-    _type = 'bmp'
-    mimetypes = {'image/x-ms-bmp'}
-    meta_whitelist = {'SourceFile', 'ExifToolVersion', 'FileName', 'Directory',
-                      'FileSize', 'FileModifyDate', 'FileAccessDate',
-                      'FileInodeChangeDate', 'FilePermissions', 'FileType',
-                      'FileTypeExtension', 'MIMEType', 'BMPVersion',
-                      'ImageWidth', 'ImageHeight', 'Planes', 'BitDepth',
-                      'Compression', 'ImageLength', 'PixelsPerMeterX',
-                      'PixelsPerMeterY', 'NumColors', 'NumImportantColors',
-                      'RedMask', 'GreenMask', 'BlueMask', 'AlphaMask',
-                      'ColorSpace', 'RedEndpoint', 'GreenEndpoint',
-                      'BlueEndpoint', 'GammaRed', 'GammaGreen', 'GammaBlue',
-                      'ImageSize', 'Megapixels'}
diff --git a/tests/test_corrupted_files.py b/tests/test_corrupted_files.py
index 4b2243d..1beb2ba 100644
--- a/tests/test_corrupted_files.py
+++ b/tests/test_corrupted_files.py
@@ -4,7 +4,7 @@ import unittest
 import shutil
 import os
 
-from libmat2 import pdf, images, audio, office, parser_factory, torrent
+from libmat2 import pdf, images, audio, office, parser_factory, torrent, harmless
 
 
 class TestUnsupportedFiles(unittest.TestCase):
@@ -65,8 +65,7 @@ class TestCorruptedFiles(unittest.TestCase):
 
     def test_bmp(self):
         shutil.copy('./tests/data/dirty.png', './tests/data/clean.bmp')
-        with self.assertRaises(ValueError):
-             images.BMPParser('./tests/data/clean.bmp')
+        harmless.HarmlessParser('./tests/data/clean.bmp')
         os.remove('./tests/data/clean.bmp')
 
     def test_docx(self):
diff --git a/tests/test_libmat2.py b/tests/test_libmat2.py
index 90f37a8..512efe8 100644
--- a/tests/test_libmat2.py
+++ b/tests/test_libmat2.py
@@ -417,7 +417,7 @@ class TestCleaning(unittest.TestCase):
 
     def test_bmp(self):
         shutil.copy('./tests/data/dirty.bmp', './tests/data/clean.bmp')
-        p = images.BMPParser('./tests/data/clean.bmp')
+        p = harmless.HarmlessParser('./tests/data/clean.bmp')
 
         meta = p.get_meta()
         self.assertEqual(meta, {})  # bmp has no meta :)
@@ -425,7 +425,7 @@ class TestCleaning(unittest.TestCase):
         ret = p.remove_all()
         self.assertTrue(ret)
 
-        p = images.BMPParser('./tests/data/clean.cleaned.bmp')
+        p = harmless.HarmlessParser('./tests/data/clean.cleaned.bmp')
         self.assertEqual(p.get_meta(), {})
 
         os.remove('./tests/data/clean.bmp')
-- 
GitLab