diff options
| author | jvoisin | 2018-07-06 00:42:09 +0200 |
|---|---|---|
| committer | jvoisin | 2018-07-06 00:42:09 +0200 |
| commit | 53271495f74bde7fde2329b7c5c938654a36b7dc (patch) | |
| tree | 1a4b73671b53b3da6a20694d77c54ef40cdecb72 | |
| parent | 0638b9bbbbe9fa5de50c01ea160a53f0e7162d59 (diff) | |
Add support for .txt files
| -rw-r--r-- | libmat2/__init__.py | 2 | ||||
| -rw-r--r-- | libmat2/harmless.py | 7 | ||||
| -rw-r--r-- | tests/data/dirty.txt | 1 | ||||
| -rw-r--r-- | tests/test_corrupted_files.py | 8 | ||||
| -rw-r--r-- | tests/test_libmat2.py | 24 |
5 files changed, 30 insertions, 12 deletions
diff --git a/libmat2/__init__.py b/libmat2/__init__.py index 91a51d8..190abe5 100644 --- a/libmat2/__init__.py +++ b/libmat2/__init__.py | |||
| @@ -12,8 +12,6 @@ unsupported_extensions = { | |||
| 12 | '.pot', | 12 | '.pot', |
| 13 | '.rdf', | 13 | '.rdf', |
| 14 | '.srt', | 14 | '.srt', |
| 15 | '.text', | ||
| 16 | '.txt', | ||
| 17 | '.wsdl', | 15 | '.wsdl', |
| 18 | '.xpdl', | 16 | '.xpdl', |
| 19 | '.xsd', | 17 | '.xsd', |
diff --git a/libmat2/harmless.py b/libmat2/harmless.py index 2878571..9032caf 100644 --- a/libmat2/harmless.py +++ b/libmat2/harmless.py | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | import shutil | ||
| 1 | from typing import Dict | 2 | from typing import Dict |
| 2 | from . import abstract | 3 | from . import abstract |
| 3 | 4 | ||
| @@ -6,13 +7,9 @@ class HarmlessParser(abstract.AbstractParser): | |||
| 6 | """ This is the parser for filetypes that do not contain metadata. """ | 7 | """ This is the parser for filetypes that do not contain metadata. """ |
| 7 | mimetypes = {'text/plain', } | 8 | mimetypes = {'text/plain', } |
| 8 | 9 | ||
| 9 | def __init__(self, filename: str) -> None: | ||
| 10 | super().__init__(filename) | ||
| 11 | self.filename = filename | ||
| 12 | self.output_filename = filename | ||
| 13 | |||
| 14 | def get_meta(self) -> Dict[str, str]: | 10 | def get_meta(self) -> Dict[str, str]: |
| 15 | return dict() | 11 | return dict() |
| 16 | 12 | ||
| 17 | def remove_all(self) -> bool: | 13 | def remove_all(self) -> bool: |
| 14 | shutil.copy(self.filename, self.output_filename) | ||
| 18 | return True | 15 | return True |
diff --git a/tests/data/dirty.txt b/tests/data/dirty.txt new file mode 100644 index 0000000..952975e --- /dev/null +++ b/tests/data/dirty.txt | |||
| @@ -0,0 +1 @@ | |||
| I'm a file that can't have metadata, but I'm supposed to be supported anyway. \ No newline at end of file | |||
diff --git a/tests/test_corrupted_files.py b/tests/test_corrupted_files.py index b784b0e..4b2243d 100644 --- a/tests/test_corrupted_files.py +++ b/tests/test_corrupted_files.py | |||
| @@ -18,11 +18,11 @@ class TestUnsupportedFiles(unittest.TestCase): | |||
| 18 | 18 | ||
| 19 | class TestExplicitelyUnsupportedFiles(unittest.TestCase): | 19 | class TestExplicitelyUnsupportedFiles(unittest.TestCase): |
| 20 | def test_pdf(self): | 20 | def test_pdf(self): |
| 21 | shutil.copy('./tests/test_libmat2.py', './tests/clean.txt') | 21 | shutil.copy('./tests/test_libmat2.py', './tests/data/clean.py') |
| 22 | parser, mimetype = parser_factory.get_parser('./tests/data/clean.txt') | 22 | parser, mimetype = parser_factory.get_parser('./tests/data/clean.py') |
| 23 | self.assertEqual(mimetype, 'text/plain') | 23 | self.assertEqual(mimetype, 'text/x-python') |
| 24 | self.assertEqual(parser, None) | 24 | self.assertEqual(parser, None) |
| 25 | os.remove('./tests/clean.txt') | 25 | os.remove('./tests/data/clean.py') |
| 26 | 26 | ||
| 27 | 27 | ||
| 28 | class TestCorruptedFiles(unittest.TestCase): | 28 | class TestCorruptedFiles(unittest.TestCase): |
diff --git a/tests/test_libmat2.py b/tests/test_libmat2.py index 4df6385..90f37a8 100644 --- a/tests/test_libmat2.py +++ b/tests/test_libmat2.py | |||
| @@ -6,7 +6,7 @@ import os | |||
| 6 | import zipfile | 6 | import zipfile |
| 7 | import tempfile | 7 | import tempfile |
| 8 | 8 | ||
| 9 | from libmat2 import pdf, images, audio, office, parser_factory, torrent | 9 | from libmat2 import pdf, images, audio, office, parser_factory, torrent, harmless |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | class TestParserFactory(unittest.TestCase): | 12 | class TestParserFactory(unittest.TestCase): |
| @@ -104,6 +104,12 @@ class TestGetMeta(unittest.TestCase): | |||
| 104 | self.assertEqual(meta['meta:creation-date'], '2011-07-26T03:27:48') | 104 | self.assertEqual(meta['meta:creation-date'], '2011-07-26T03:27:48') |
| 105 | self.assertEqual(meta['meta:generator'], 'LibreOffice/3.3$Unix LibreOffice_project/330m19$Build-202') | 105 | self.assertEqual(meta['meta:generator'], 'LibreOffice/3.3$Unix LibreOffice_project/330m19$Build-202') |
| 106 | 106 | ||
| 107 | def test_txt(self): | ||
| 108 | p, mimetype = parser_factory.get_parser('./tests/data/dirty.txt') | ||
| 109 | self.assertEqual(mimetype, 'text/plain') | ||
| 110 | meta = p.get_meta() | ||
| 111 | self.assertEqual(meta, {}) | ||
| 112 | |||
| 107 | 113 | ||
| 108 | class TestRemovingThumbnails(unittest.TestCase): | 114 | class TestRemovingThumbnails(unittest.TestCase): |
| 109 | def test_odt(self): | 115 | def test_odt(self): |
| @@ -473,3 +479,19 @@ class TestCleaning(unittest.TestCase): | |||
| 473 | 479 | ||
| 474 | os.remove('./tests/data/clean.odg') | 480 | os.remove('./tests/data/clean.odg') |
| 475 | os.remove('./tests/data/clean.cleaned.odg') | 481 | os.remove('./tests/data/clean.cleaned.odg') |
| 482 | |||
| 483 | def test_txt(self): | ||
| 484 | shutil.copy('./tests/data/dirty.txt', './tests/data/clean.txt') | ||
| 485 | p = harmless.HarmlessParser('./tests/data/clean.txt') | ||
| 486 | |||
| 487 | meta = p.get_meta() | ||
| 488 | self.assertEqual(meta, {}) | ||
| 489 | |||
| 490 | ret = p.remove_all() | ||
| 491 | self.assertTrue(ret) | ||
| 492 | |||
| 493 | p = harmless.HarmlessParser('./tests/data/clean.cleaned.txt') | ||
| 494 | self.assertEqual(p.get_meta(), {}) | ||
| 495 | |||
| 496 | os.remove('./tests/data/clean.txt') | ||
| 497 | os.remove('./tests/data/clean.cleaned.txt') | ||
