summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjvoisin2019-03-06 21:20:39 +0100
committerjvoisin2019-03-06 21:25:06 +0100
commit457d171cd48bf4809d3809fc9511836795972bf5 (patch)
tree1469ba539371703008abc659c0af87dd215e9930
parent769bafac0acdf3e0b41f42a60df1029d6e0e3829 (diff)
Improve the display of supported formats
- Show the extension instead of the mimetype - Sort the results
-rw-r--r--main.py5
-rw-r--r--tests.py4
2 files changed, 6 insertions, 3 deletions
diff --git a/main.py b/main.py
index 033d8b6..1a99ad4 100644
--- a/main.py
+++ b/main.py
@@ -1,6 +1,7 @@
1import os 1import os
2import hashlib 2import hashlib
3import hmac 3import hmac
4import mimetypes as mtype
4 5
5from libmat2 import parser_factory 6from libmat2 import parser_factory
6 7
@@ -60,7 +61,9 @@ def upload_file():
60 61
61 mimetypes = set() 62 mimetypes = set()
62 for parser in parser_factory._get_parsers(): 63 for parser in parser_factory._get_parsers():
63 mimetypes = mimetypes | parser.mimetypes 64 mimetypes |= set(map(mtype.guess_extension, parser.mimetypes))
65 # since `guess_extension` might return `None`, we need to filter it out
66 mimetypes = sorted(filter(None, mimetypes))
64 67
65 if request.method == 'POST': 68 if request.method == 'POST':
66 if 'file' not in request.files: # check if the post request has the file part 69 if 'file' not in request.files: # check if the post request has the file part
diff --git a/tests.py b/tests.py
index 0289755..4c85a74 100644
--- a/tests.py
+++ b/tests.py
@@ -21,8 +21,8 @@ class FlaskrTestCase(unittest.TestCase):
21 21
22 def test_check_mimetypes(self): 22 def test_check_mimetypes(self):
23 rv = self.app.get('/') 23 rv = self.app.get('/')
24 self.assertIn(b'application/zip', rv.data) 24 self.assertIn(b'.torrent', rv.data)
25 self.assertIn(b'audio/x-flac', rv.data) 25 self.assertIn(b'.ods', rv.data)
26 26
27 def test_get_download_dangerous_file(self): 27 def test_get_download_dangerous_file(self):
28 rv = self.app.get('/download/1337/\..\filename') 28 rv = self.app.get('/download/1337/\..\filename')