| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 938144e commit 04a29bf
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,8 @@ | |||
| 23 | 23 | read_mime_types(file) -- parse one file, return a dictionary or None | |
| 24 | 24 | """ | |
| 25 | 25 | ||
| 26 | + import sys | ||
| 27 | + | ||
| 26 | 28 | try: | |
| 27 | 29 | from _winapi import _mimetypes_read_windows_registry | |
| 28 | 30 | except ImportError: | |
@@ -40,17 +42,23 @@ | |||
| 40 | 42 | "suffix_map", "encodings_map", "types_map", "common_types" | |
| 41 | 43 | ] | |
| 42 | 44 | ||
| 43 | - knownfiles = [ | ||
| 44 | - "/etc/mime.types", | ||
| 45 | - "/etc/httpd/mime.types", # Mac OS X | ||
| 46 | - "/etc/httpd/conf/mime.types", # Apache | ||
| 47 | - "/etc/apache/mime.types", # Apache 1 | ||
| 48 | - "/etc/apache2/mime.types", # Apache 2 | ||
| 49 | - "/usr/local/etc/httpd/conf/mime.types", | ||
| 50 | - "/usr/local/lib/netscape/mime.types", | ||
| 51 | - "/usr/local/etc/httpd/conf/mime.types", # Apache 1.2 | ||
| 52 | - "/usr/local/etc/mime.types", # Apache 1.3 | ||
| 53 | - ] | ||
| 45 | + if sys.platform == "win32": | ||
| 46 | + # The default paths would resolve to the root of the current drive on Windows | ||
| 47 | + # (e.g. C:\etc\mime.types), which unprivileged users can usually create. | ||
| 48 | + # Only the registry is used by default. | ||
| 49 | + knownfiles = [] | ||
| 50 | + else: | ||
| 51 | + knownfiles = [ | ||
| 52 | + "/etc/mime.types", | ||
| 53 | + "/etc/httpd/mime.types", # Mac OS X | ||
| 54 | + "/etc/httpd/conf/mime.types", # Apache | ||
| 55 | + "/etc/apache/mime.types", # Apache 1 | ||
| 56 | + "/etc/apache2/mime.types", # Apache 2 | ||
| 57 | + "/usr/local/etc/httpd/conf/mime.types", | ||
| 58 | + "/usr/local/lib/netscape/mime.types", | ||
| 59 | + "/usr/local/etc/httpd/conf/mime.types", # Apache 1.2 | ||
| 60 | + "/usr/local/etc/mime.types", # Apache 1.3 | ||
| 61 | + ] | ||
| 54 | 62 | ||
| 55 | 63 | inited = False | |
| 56 | 64 | _db = None | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -271,6 +271,10 @@ def test_init_knownfiles(self): | |||
| 271 | 271 | mimetypes.init() | |
| 272 | 272 | self.assertEqual(guess_file_type("file.test2")[0], "testing/test2") | |
| 273 | 273 | ||
| 274 | + @unittest.skipIf(sys.platform == "win32", "non-Windows only") | ||
| 275 | + def test_default_knownfiles(self): | ||
| 276 | + self.assertIn("/etc/mime.types", knownfiles) | ||
| 277 | + | ||
| 274 | 278 | def test_added_types_are_used(self): | |
| 275 | 279 | mimetypes.add_type('testing/default-type', '') | |
| 276 | 280 | mime_type, _ = mimetypes.guess_type('') | |
@@ -555,6 +559,9 @@ def test_registry_parsing(self): | |||
| 555 | 559 | eq(self.db.guess_type("image.jpg"), ("image/jpeg", None)) | |
| 556 | 560 | eq(self.db.guess_type("image.png"), ("image/png", None)) | |
| 557 | 561 | ||
| 562 | + def test_default_knownfiles(self): | ||
| 563 | + self.assertEqual(knownfiles, []) | ||
| 564 | + | ||
| 558 | 565 | @unittest.skipIf(not hasattr(_winapi, "_mimetypes_read_windows_registry"), | |
| 559 | 566 | "read_windows_registry accelerator unavailable") | |
| 560 | 567 | def test_registry_accelerator(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + :mod:`mimetypes` no longer reads the files listed in :data:`mimetypes.knownfiles` | ||
| 2 | + by default on Windows, and uses only the registry. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments