summaryrefslogtreecommitdiff
path: root/mimeparse.py
diff options
context:
space:
mode:
authorStefan Wojcik <wojcikstefan@gmail.com>2016-01-26 20:40:47 -0800
committerStefan Wojcik <wojcikstefan@gmail.com>2016-01-26 20:40:47 -0800
commitf59ab82ee0348f51ddb99a5d104902ea50eb02cc (patch)
treed824d74ecac73a6f54e3de600efaa5085eca15d2 /mimeparse.py
parent2ae1bbeaeb8827e9debfbb3254c732ee0ccff1c3 (diff)
downloadpython-mimeparse-f59ab82ee0348f51ddb99a5d104902ea50eb02cc.tar.gz
raise an exception when the header cannot be parsed + better handling of unit tests
Diffstat (limited to 'mimeparse.py')
-rwxr-xr-xmimeparse.py8
1 files changed, 8 insertions, 0 deletions
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)