Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
cloudooo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
cloudooo
Commits
fbd8591e
Commit
fbd8591e
authored
Apr 23, 2023
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util: reimplement parseContentType with something python3 compatible
parent
f0be8d52
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
12 additions
and
16 deletions
+12
-16
cloudooo/handler/ooo/handler.py
cloudooo/handler/ooo/handler.py
+1
-1
cloudooo/handler/pdf/handler.py
cloudooo/handler/pdf/handler.py
+1
-1
cloudooo/handler/wkhtmltopdf/handler.py
cloudooo/handler/wkhtmltopdf/handler.py
+1
-1
cloudooo/handler/x2t/handler.py
cloudooo/handler/x2t/handler.py
+1
-1
cloudooo/manager.py
cloudooo/manager.py
+1
-1
cloudooo/util.py
cloudooo/util.py
+7
-11
No files found.
cloudooo/handler/ooo/handler.py
View file @
fbd8591e
...
@@ -248,7 +248,7 @@ class Handler:
...
@@ -248,7 +248,7 @@ class Handler:
# XXX please never guess extension from mimetype
# XXX please never guess extension from mimetype
output_set
=
set
()
output_set
=
set
()
if
"/"
in
source_mimetype
:
if
"/"
in
source_mimetype
:
parsed_mimetype_type
=
parseContentType
(
source_mimetype
).
gettype
()
parsed_mimetype_type
=
parseContentType
(
source_mimetype
).
get
_content_
type
()
# here `guess_all_extensions` never handles mimetype parameters
# here `guess_all_extensions` never handles mimetype parameters
# (even for `text/plain;charset=UTF-8` which is standard)
# (even for `text/plain;charset=UTF-8` which is standard)
extension_list
=
mimetypes
.
guess_all_extensions
(
parsed_mimetype_type
)
# XXX never guess
extension_list
=
mimetypes
.
guess_all_extensions
(
parsed_mimetype_type
)
# XXX never guess
...
...
cloudooo/handler/pdf/handler.py
View file @
fbd8591e
...
@@ -127,7 +127,7 @@ class Handler:
...
@@ -127,7 +127,7 @@ class Handler:
...
...
]
]
"""
"""
source_mimetype
=
parseContentType
(
source_mimetype
).
gettype
()
source_mimetype
=
parseContentType
(
source_mimetype
).
get
_content_
type
()
if
source_mimetype
in
(
"application/pdf"
,
"pdf"
):
if
source_mimetype
in
(
"application/pdf"
,
"pdf"
):
return
[(
"text/plain"
,
"Plain Text"
)]
return
[(
"text/plain"
,
"Plain Text"
)]
return
[]
return
[]
cloudooo/handler/wkhtmltopdf/handler.py
View file @
fbd8591e
...
@@ -109,7 +109,7 @@ class Handler:
...
@@ -109,7 +109,7 @@ class Handler:
...
...
]
]
"""
"""
source_mimetype
=
parseContentType
(
source_mimetype
).
gettype
()
source_mimetype
=
parseContentType
(
source_mimetype
).
get
_content_
type
()
if
source_mimetype
in
(
"text/html"
,
"htm"
,
"html"
):
if
source_mimetype
in
(
"text/html"
,
"htm"
,
"html"
):
return
[(
"application/pdf"
,
"PDF - Portable Document Format"
)]
return
[(
"application/pdf"
,
"PDF - Portable Document Format"
)]
return
[]
return
[]
...
...
cloudooo/handler/x2t/handler.py
View file @
fbd8591e
...
@@ -338,7 +338,7 @@ class Handler:
...
@@ -338,7 +338,7 @@ class Handler:
...
...
]
]
"""
"""
source_mimetype
=
parseContentType
(
source_mimetype
).
gettype
()
source_mimetype
=
parseContentType
(
source_mimetype
).
get
_content_
type
()
if
source_mimetype
in
(
"docy"
,
"application/x-asc-text"
):
if
source_mimetype
in
(
"docy"
,
"application/x-asc-text"
):
return
[
return
[
(
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
,
"Word 2007 Document"
),
(
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
,
"Word 2007 Document"
),
...
...
cloudooo/manager.py
View file @
fbd8591e
...
@@ -93,7 +93,7 @@ def BBB_guess_extension(mimetype, title=None):
...
@@ -93,7 +93,7 @@ def BBB_guess_extension(mimetype, title=None):
"text/html"
:
".html"
,
"text/html"
:
".html"
,
"text/plain"
:
".txt"
,
"text/plain"
:
".txt"
,
"image/jpeg"
:
".jpg"
,
"image/jpeg"
:
".jpg"
,
}.
get
(
parseContentType
(
mimetype
).
gettype
(),
None
)
or
guess_extension
(
mimetype
)
}.
get
(
parseContentType
(
mimetype
).
get
_content_
type
(),
None
)
or
guess_extension
(
mimetype
)
@
implementer
(
IManager
,
IERP5Compatibility
,
ITableGranulator
,
IImageGranulator
,
@
implementer
(
IManager
,
IERP5Compatibility
,
ITableGranulator
,
IImageGranulator
,
ITextGranulator
)
ITextGranulator
)
...
...
cloudooo/util.py
View file @
fbd8591e
...
@@ -28,12 +28,12 @@
...
@@ -28,12 +28,12 @@
#
#
##############################################################################
##############################################################################
import
email
import
email.message
import
logging
import
logging
import
mimetypes
import
mimetypes
import
pkg_resources
import
pkg_resources
import
os
import
os
import
mimetools
import
cStringIO
from
zipfile
import
ZipFile
,
ZIP_DEFLATED
from
zipfile
import
ZipFile
,
ZIP_DEFLATED
logger
=
logging
.
getLogger
(
'Cloudooo'
)
logger
=
logging
.
getLogger
(
'Cloudooo'
)
...
@@ -126,17 +126,13 @@ def unzip(source, destination):
...
@@ -126,17 +126,13 @@ def unzip(source, destination):
with
ZipFile
(
source
)
as
zipfile
:
with
ZipFile
(
source
)
as
zipfile
:
zipfile
.
extractall
(
destination
)
zipfile
.
extractall
(
destination
)
def
parseContentType
(
content_type
)
:
def
parseContentType
(
content_type
:
str
)
->
email
.
message
.
EmailMessage
:
"""Parses `text/plain;charset="utf-8"` to a
mimetools.Message
object.
"""Parses `text/plain;charset="utf-8"` to a
n email
object.
Note: Content type or MIME type are built like `maintype/subtype[;params]`.
Note: Content type or MIME type are built like `maintype/subtype[;params]`.
parsed_content_type = parseContentType('text/plain;charset="utf-8"')
parsed_content_type = parseContentType('text/plain;charset="utf-8"')
parsed_content_type.gettype() -> 'text/plain'
parsed_content_type.get_content_type() -> 'text/plain'
parsed_content_type.getmaintype() -> 'text'
parsed_content_type.get_charset() -> 'utf-8'
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
"
)
))
return
email
.
message_from_string
(
"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