Commit 0d617cbf authored by Arnaud Fontaine's avatar Arnaud Fontaine

PortalTransforms: mimetools has been deprecated since Python 2.3 in favor of email package.

parent a17bb910
...@@ -666,7 +666,9 @@ class TransformTool(UniqueObject, ActionProviderBase, Folder): ...@@ -666,7 +666,9 @@ class TransformTool(UniqueObject, ActionProviderBase, Folder):
# clean up mimetype from its useless characters # clean up mimetype from its useless characters
source_mimetype = parseContentType(source_mimetype) source_mimetype = parseContentType(source_mimetype)
source_mimetype = ";".join([source_mimetype.gettype()] + source_mimetype.getplist()) source_mimetype = ';'.join(
[source_mimetype.get_content_type()] +
["%s=%s" % (p, v) for (p, v) in source_mimetype.get_params()[1:]])
# fill dict that will contain all possible conversion for each mimetype # fill dict that will contain all possible conversion for each mimetype
input_output_dict = {} # {"application/pdf": set(["text/html", "application/msword", ...])} input_output_dict = {} # {"application/pdf": set(["text/html", "application/msword", ...])}
......
...@@ -2,8 +2,12 @@ ...@@ -2,8 +2,12 @@
"""some common utilities """some common utilities
""" """
import mimetools import six
import cStringIO if six.PY2:
from email import message_from_file as message_from_bytes
else:
from email import message_from_bytes
from six.moves import cStringIO as StringIO
class TransformException(Exception): class TransformException(Exception):
pass pass
...@@ -30,16 +34,5 @@ def safeToInt(value): ...@@ -30,16 +34,5 @@ def safeToInt(value):
return 0 return 0
def parseContentType(content_type): def parseContentType(content_type):
"""Parses `text/plain;charset="utf-8"` to a mimetools.Message object. """Parses `text/plain;charset="utf-8"` to a email.Message object"""
return message_from_bytes(StringIO("Content-Type:" + content_type.replace("\r\n", "\r\n\t")))
Note: Content type or MIME type are built like `maintype/subtype[;params]`.
parsed_content_type = parseContentType('text/plain;charset="utf-8"')
parsed_content_type.gettype() -> 'text/plain'
parsed_content_type.getmaintype() -> 'text'
parsed_content_type.getsubtype() -> 'plain'
parsed_content_type.getplist() -> 'charset="utf-8"'
parsed_content_type.getparam('charset') -> 'utf-8'
parsed_content_type.typeheader -> 'text/plain;charset="utf-8"'
"""
return mimetools.Message(cStringIO.StringIO("Content-Type:" + content_type.replace("\r\n", "\r\n\t")))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment