summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2001-10-25 21:49:18 (GMT)
committerBarry Warsaw <barry@python.org>2001-10-25 21:49:18 (GMT)
commit107771a228ee73b4683242cb696e3024f93b74d5 (patch)
tree34e96a4adcd53b74dfda667434b31b784095961a /Lib/test
parent9cd0efcee9d7ee29cd87eb0d1072351fbb986e08 (diff)
downloadcpython-107771a228ee73b4683242cb696e3024f93b74d5.zip
cpython-107771a228ee73b4683242cb696e3024f93b74d5.tar.gz
cpython-107771a228ee73b4683242cb696e3024f93b74d5.tar.bz2
Applying proposed patch for bug #474583, optional support for
non-standard but common types. Including Martin's suggestion to add rejected non-standard types from patch #438790. Specifically, guess_type(), guess_extension(): Both the functions and the methods grow an optional "strict" flag, defaulting to true, which determines whether to recognize non-standard, but commonly found types or not. Also, I sorted, reformatted, and culled duplicates from the big types_map dictionary. Note that there are a few non-equivalent duplicates (e.g. .cdf and .xls) for which the first will just get thrown away. I didn't remove those though. Finally, use of the module as a script as grown the -l and -e options to toggle strictness and to do guess_extension(), respectively. Doc and unittest updates too.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_mimetypes.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_mimetypes.py b/Lib/test/test_mimetypes.py
index 8735e27..bca5766 100644
--- a/Lib/test/test_mimetypes.py
+++ b/Lib/test/test_mimetypes.py
@@ -38,6 +38,18 @@ class MimeTypesTestCase(unittest.TestCase):
self.assertEqual(self.db.guess_extension("x-application/x-unittest"),
".pyunit")
+ def test_non_standard_types(self):
+ # First try strict
+ self.assertEqual(self.db.guess_type('foo.xul', strict=1),
+ (None, None))
+ self.assertEqual(self.db.guess_extension('image/jpg', strict=1),
+ None)
+ # And then non-strict
+ self.assertEqual(self.db.guess_type('foo.xul', strict=0),
+ ('text/xul', None))
+ self.assertEqual(self.db.guess_extension('image/jpg', strict=0),
+ '.jpg')
+
def test_main():
test_support.run_unittest(MimeTypesTestCase)