From f59ab82ee0348f51ddb99a5d104902ea50eb02cc Mon Sep 17 00:00:00 2001 From: Stefan Wojcik Date: Tue, 26 Jan 2016 20:40:47 -0800 Subject: raise an exception when the header cannot be parsed + better handling of unit tests --- mimeparse.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'mimeparse.py') diff --git a/mimeparse.py b/mimeparse.py index 9f2788e..c8047e7 100755 --- a/mimeparse.py +++ b/mimeparse.py @@ -26,6 +26,10 @@ __license__ = 'MIT License' __credits__ = '' +class MimeTypeParseException(Exception): + pass + + def parse_mime_type(mime_type): """Parses a mime-type into its component parts. @@ -45,6 +49,10 @@ def parse_mime_type(mime_type): # single '*'. Turn it into a legal wildcard. if full_type == '*': full_type = '*/*' + + if '/' not in full_type: + raise MimeTypeParseException(u"Can't parse type \"{}\"".format(full_type)) + (type, subtype) = full_type.split('/') return (type.strip(), subtype.strip(), params) -- cgit v1.2.1