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
Labels
Merge Requests
139
Merge Requests
139
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
abe49733
Commit
abe49733
authored
Dec 26, 2022
by
Jérome Perrin
Committed by
Arnaud Fontaine
Mar 02, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
File: treat data as bytes, not str
parent
611a8f15
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
18 deletions
+11
-18
bt5/erp5_dms/TestTemplateItem/portal_components/test.erp5.testDms.py
...s/TestTemplateItem/portal_components/test.erp5.testDms.py
+6
-6
product/ERP5/bootstrap/erp5_core/DocumentTemplateItem/portal_components/document.erp5.File.py
...umentTemplateItem/portal_components/document.erp5.File.py
+5
-12
No files found.
bt5/erp5_dms/TestTemplateItem/portal_components/test.erp5.testDms.py
View file @
abe49733
...
...
@@ -589,8 +589,8 @@ class TestDocument(TestDocumentMixin):
def
testTempOOoDocument_get_size
(
self
):
# test get_size on temporary OOoDocument
doc
=
self
.
portal
.
newContent
(
temp_object
=
True
,
portal_type
=
'OOo Document'
,
id
=
'tmp'
)
doc
.
edit
(
data
=
'OOo'
)
self
.
assertEqual
(
len
(
'OOo'
),
doc
.
get_size
())
doc
.
edit
(
data
=
b
'OOo'
)
self
.
assertEqual
(
len
(
b
'OOo'
),
doc
.
get_size
())
def
testOOoDocument_hasData
(
self
):
# test hasData on OOoDocument
...
...
@@ -1279,7 +1279,7 @@ class TestDocument(TestDocumentMixin):
display
=
'thumbnail'
)
self
.
assertEqual
(
mime
,
'image/png'
)
# it's a valid PNG
self
.
assertEqual
(
image_data
[
1
:
4
],
'PNG'
)
self
.
assertEqual
(
image_data
[
1
:
4
],
b
'PNG'
)
def
test_PDFToJpg
(
self
):
upload_file
=
makeFileUpload
(
'REF-en-001.pdf'
)
...
...
@@ -1290,7 +1290,7 @@ class TestDocument(TestDocumentMixin):
frame
=
0
,
display
=
'thumbnail'
)
self
.
assertEqual
(
mime
,
'image/jpeg'
)
self
.
assertEqual
(
image_data
[
6
:
10
],
'JFIF'
)
self
.
assertEqual
(
image_data
[
6
:
10
],
b
'JFIF'
)
def
test_PDFToGif
(
self
):
upload_file
=
makeFileUpload
(
'REF-en-001.pdf'
)
...
...
@@ -1301,7 +1301,7 @@ class TestDocument(TestDocumentMixin):
frame
=
0
,
display
=
'thumbnail'
)
self
.
assertEqual
(
mime
,
'image/gif'
)
self
.
assertEqual
(
image_data
[
0
:
4
],
'GIF8'
)
self
.
assertEqual
(
image_data
[
0
:
4
],
b
'GIF8'
)
def
test_PDFToTiff
(
self
):
upload_file
=
makeFileUpload
(
'REF-en-001.pdf'
)
...
...
@@ -1312,7 +1312,7 @@ class TestDocument(TestDocumentMixin):
frame
=
0
,
display
=
'thumbnail'
)
self
.
assertEqual
(
mime
,
'image/tiff'
)
self
.
assertIn
(
image_data
[
0
:
2
],
(
'II'
,
'MM'
))
self
.
assertIn
(
image_data
[
0
:
2
],
(
b'II'
,
b
'MM'
))
def
test_PDF_content_information
(
self
):
...
...
product/ERP5/bootstrap/erp5_core/DocumentTemplateItem/portal_components/document.erp5.File.py
View file @
abe49733
...
...
@@ -38,13 +38,6 @@ from OFS.Image import File as OFS_File
from
Products.ERP5Type.Utils
import
deprecated
def
_unpackData
(
data
):
"""
Unpack Pdata into string
OBSOLETED. use str(data) instead, because Pdata.__str__ is defined.
"""
return
str
(
data
)
_MARKER
=
object
()
class
File
(
Document
,
OFS_File
):
...
...
@@ -147,7 +140,7 @@ class File(Document, OFS_File):
if
data
is
None
:
return
if
self
.
hasData
():
if
str
(
data
.
read
())
==
str
(
self
.
getData
()):
if
bytes
(
data
.
read
())
==
bytes
(
self
.
getData
()):
# Same data as previous, no need to change its content
return
else
:
...
...
@@ -180,13 +173,13 @@ class File(Document, OFS_File):
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getData'
)
def
getData
(
self
,
default
=
None
):
"""return Data as
str
."""
"""return Data as
bytes
."""
self
.
_checkConversionFormatPermission
(
None
)
data
=
self
.
_baseGetData
()
if
data
is
None
:
return
None
else
:
return
str
(
data
)
return
bytes
(
data
)
# DAV Support
security
.
declareProtected
(
Permissions
.
ModifyPortalContent
,
'PUT'
)
...
...
@@ -226,8 +219,8 @@ class File(Document, OFS_File):
elif
getattr
(
self
,
'getBaseData'
,
None
)
is
not
None
:
content
=
self
.
getBaseData
()
if
content
and
not
isinstance
(
content
,
str
):
content
=
str
(
content
)
if
content
and
not
isinstance
(
content
,
bytes
):
content
=
bytes
(
content
)
return
(
mime_type
,
content
)
...
...
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