summaryrefslogtreecommitdiffstats
path: root/Lib/mimetypes.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2003-06-09 22:27:41 (GMT)
committerBarry Warsaw <barry@python.org>2003-06-09 22:27:41 (GMT)
commit9caa0d1642b79020a1665560e6efaedabfadfba3 (patch)
treef0d7a3303445d8777eff6e152fa6ada997a50402 /Lib/mimetypes.py
parente07b83591fe4c9e6dec9b9e94b97bb536985a2ff (diff)
downloadcpython-9caa0d1642b79020a1665560e6efaedabfadfba3.zip
cpython-9caa0d1642b79020a1665560e6efaedabfadfba3.tar.gz
cpython-9caa0d1642b79020a1665560e6efaedabfadfba3.tar.bz2
guess_all_extensions(): Return the empty list instead of None when
there are no matching types. Updated the docs and docstrings. Added some unit tests.
Diffstat (limited to 'Lib/mimetypes.py')
-rw-r--r--Lib/mimetypes.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py
index a909366..5784e23 100644
--- a/Lib/mimetypes.py
+++ b/Lib/mimetypes.py
@@ -148,10 +148,8 @@ class MimeTypes:
Return value is a list of strings giving the possible filename
extensions, including the leading dot ('.'). The extension is not
- guaranteed to have been associated with any particular data
- stream, but would be mapped to the MIME type `type' by
- guess_type(). If no extension can be guessed for `type', None
- is returned.
+ guaranteed to have been associated with any particular data stream,
+ but would be mapped to the MIME type `type' by guess_type().
Optional `strict' argument when false adds a bunch of commonly found,
but non-standard types.
@@ -162,8 +160,7 @@ class MimeTypes:
for ext in self.types_map_inv[False].get(type, []):
if ext not in extensions:
extensions.append(ext)
- if len(extensions):
- return extensions
+ return extensions
def guess_extension(self, type, strict=True):
"""Guess the extension for a file based on its MIME type.
@@ -179,9 +176,9 @@ class MimeTypes:
but non-standard types.
"""
extensions = self.guess_all_extensions(type, strict)
- if extensions is not None:
- extensions = extensions[0]
- return extensions
+ if not extensions:
+ return None
+ return extensions[0]
def read(self, filename, strict=True):
"""