1
0
mirror of synced 2024-11-25 18:54:22 +01:00

Simplify BMP handling

This commit is contained in:
jvoisin 2018-07-06 00:49:17 +02:00
parent 53271495f7
commit 3d80f97524
4 changed files with 5 additions and 22 deletions

View File

@ -5,7 +5,7 @@ from . import abstract
class HarmlessParser(abstract.AbstractParser): class HarmlessParser(abstract.AbstractParser):
""" This is the parser for filetypes that do not contain metadata. """ """ 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]: def get_meta(self) -> Dict[str, str]:
return dict() return dict()

View File

@ -110,19 +110,3 @@ class TiffParser(GdkPixbufAbstractParser):
'FilePermissions', 'FileSize', 'FileType', 'FilePermissions', 'FileSize', 'FileType',
'FileTypeExtension', 'ImageHeight', 'ImageSize', 'FileTypeExtension', 'ImageHeight', 'ImageSize',
'ImageWidth', 'MIMEType', 'Megapixels', 'SourceFile'} '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'}

View File

@ -4,7 +4,7 @@ import unittest
import shutil import shutil
import os 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): class TestUnsupportedFiles(unittest.TestCase):
@ -65,8 +65,7 @@ class TestCorruptedFiles(unittest.TestCase):
def test_bmp(self): def test_bmp(self):
shutil.copy('./tests/data/dirty.png', './tests/data/clean.bmp') shutil.copy('./tests/data/dirty.png', './tests/data/clean.bmp')
with self.assertRaises(ValueError): harmless.HarmlessParser('./tests/data/clean.bmp')
images.BMPParser('./tests/data/clean.bmp')
os.remove('./tests/data/clean.bmp') os.remove('./tests/data/clean.bmp')
def test_docx(self): def test_docx(self):

View File

@ -417,7 +417,7 @@ class TestCleaning(unittest.TestCase):
def test_bmp(self): def test_bmp(self):
shutil.copy('./tests/data/dirty.bmp', './tests/data/clean.bmp') 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() meta = p.get_meta()
self.assertEqual(meta, {}) # bmp has no meta :) self.assertEqual(meta, {}) # bmp has no meta :)
@ -425,7 +425,7 @@ class TestCleaning(unittest.TestCase):
ret = p.remove_all() ret = p.remove_all()
self.assertTrue(ret) self.assertTrue(ret)
p = images.BMPParser('./tests/data/clean.cleaned.bmp') p = harmless.HarmlessParser('./tests/data/clean.cleaned.bmp')
self.assertEqual(p.get_meta(), {}) self.assertEqual(p.get_meta(), {})
os.remove('./tests/data/clean.bmp') os.remove('./tests/data/clean.bmp')