Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Eteri
erp5
Commits
0d617cbf
Commit
0d617cbf
authored
Apr 29, 2022
by
Arnaud Fontaine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PortalTransforms: mimetools has been deprecated since Python 2.3 in favor of email package.
parent
a17bb910
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
16 deletions
+11
-16
product/PortalTransforms/TransformEngine.py
product/PortalTransforms/TransformEngine.py
+3
-1
product/PortalTransforms/utils.py
product/PortalTransforms/utils.py
+8
-15
No files found.
product/PortalTransforms/TransformEngine.py
View file @
0d617cbf
...
...
@@ -666,7 +666,9 @@ class TransformTool(UniqueObject, ActionProviderBase, Folder):
# clean up mimetype from its useless characters
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
input_output_dict
=
{}
# {"application/pdf": set(["text/html", "application/msword", ...])}
...
...
product/PortalTransforms/utils.py
View file @
0d617cbf
...
...
@@ -2,8 +2,12 @@
"""some common utilities
"""
import
mimetools
import
cStringIO
import
six
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
):
pass
...
...
@@ -30,16 +34,5 @@ def safeToInt(value):
return
0
def
parseContentType
(
content_type
):
"""Parses `text/plain;charset="utf-8"` to a mimetools.Message object.
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
"
)))
"""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
"
)))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment