diff options
| author | Jonathan Lange <jml@mumak.net> | 2015-11-02 19:29:49 +0000 |
|---|---|---|
| committer | Jonathan Lange <jml@mumak.net> | 2015-11-09 13:24:01 +0000 |
| commit | 131161fa7a7c348d56aa61614890a2ec4beed7ce (patch) | |
| tree | 4671c1b28cba62a19f9f61c41a06a143a8144079 | |
| parent | 37afc36a952e07c9484cd380d1dcdd6597b50716 (diff) | |
| download | testtools-131161fa7a7c348d56aa61614890a2ec4beed7ce.tar.gz | |
Extract _make_content_type
| -rw-r--r-- | testtools/testresult/real.py | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/testtools/testresult/real.py b/testtools/testresult/real.py index 176f019..62b9716 100644 --- a/testtools/testresult/real.py +++ b/testtools/testresult/real.py @@ -713,20 +713,7 @@ class StreamToDict(StreamResult): case['timestamps'][1] = timestamp if file_name is not None: if file_name not in case['details']: - - if mime_type is None: - mime_type = 'application/octet-stream' - - primary, sub, parameters = parse_mime_type(mime_type) - if 'charset' in parameters: - if ',' in parameters['charset']: - # testtools was emitting a bad encoding, workaround it, - # Though this does lose data - probably want to drop - # this in a few releases. - parameters['charset'] = parameters['charset'][ - :parameters['charset'].find(',')] - - content_type = ContentType(primary, sub, parameters) + content_type = _make_content_type(mime_type) content_bytes = [] case['details'][file_name] = Content( content_type, lambda: content_bytes) @@ -763,6 +750,27 @@ class StreamToDict(StreamResult): return key +def _make_content_type(mime_type=None): + """Return ContentType for a given mime type. + + testtools was emitting a bad encoding, and this works around it. + Unfortunately, is also loses data - probably want to drop this in a few + releases. + """ + # XXX: Not sure what release this was added, so "in a few releases" is + # unactionable. + if mime_type is None: + mime_type = 'application/octet-stream' + + primary, sub, parameters = parse_mime_type(mime_type) + if 'charset' in parameters: + if ',' in parameters['charset']: + parameters['charset'] = parameters['charset'][ + :parameters['charset'].find(',')] + + return ContentType(primary, sub, parameters) + + _status_map = { 'inprogress': 'addFailure', 'unknown': 'addFailure', |
