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.
This commit is contained in:
Barry Warsaw 2003-06-09 22:27:41 +00:00
parent e07b83591f
commit 9caa0d1642
3 changed files with 40 additions and 37 deletions

View file

@ -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):
"""