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
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
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexander Emmerich
erp5
Commits
86981105
Commit
86981105
authored
Dec 26, 2022
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
File: treat data as bytes, not str
parent
85681613
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 @
86981105
...
@@ -589,8 +589,8 @@ class TestDocument(TestDocumentMixin):
...
@@ -589,8 +589,8 @@ class TestDocument(TestDocumentMixin):
def
testTempOOoDocument_get_size
(
self
):
def
testTempOOoDocument_get_size
(
self
):
# test get_size on temporary OOoDocument
# test get_size on temporary OOoDocument
doc
=
self
.
portal
.
newContent
(
temp_object
=
True
,
portal_type
=
'OOo Document'
,
id
=
'tmp'
)
doc
=
self
.
portal
.
newContent
(
temp_object
=
True
,
portal_type
=
'OOo Document'
,
id
=
'tmp'
)
doc
.
edit
(
data
=
'OOo'
)
doc
.
edit
(
data
=
b
'OOo'
)
self
.
assertEqual
(
len
(
'OOo'
),
doc
.
get_size
())
self
.
assertEqual
(
len
(
b
'OOo'
),
doc
.
get_size
())
def
testOOoDocument_hasData
(
self
):
def
testOOoDocument_hasData
(
self
):
# test hasData on OOoDocument
# test hasData on OOoDocument
...
@@ -1279,7 +1279,7 @@ class TestDocument(TestDocumentMixin):
...
@@ -1279,7 +1279,7 @@ class TestDocument(TestDocumentMixin):
display
=
'thumbnail'
)
display
=
'thumbnail'
)
self
.
assertEqual
(
mime
,
'image/png'
)
self
.
assertEqual
(
mime
,
'image/png'
)
# it's a valid 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
):
def
test_PDFToJpg
(
self
):
upload_file
=
makeFileUpload
(
'REF-en-001.pdf'
)
upload_file
=
makeFileUpload
(
'REF-en-001.pdf'
)
...
@@ -1290,7 +1290,7 @@ class TestDocument(TestDocumentMixin):
...
@@ -1290,7 +1290,7 @@ class TestDocument(TestDocumentMixin):
frame
=
0
,
frame
=
0
,
display
=
'thumbnail'
)
display
=
'thumbnail'
)
self
.
assertEqual
(
mime
,
'image/jpeg'
)
self
.
assertEqual
(
mime
,
'image/jpeg'
)
self
.
assertEqual
(
image_data
[
6
:
10
],
'JFIF'
)
self
.
assertEqual
(
image_data
[
6
:
10
],
b
'JFIF'
)
def
test_PDFToGif
(
self
):
def
test_PDFToGif
(
self
):
upload_file
=
makeFileUpload
(
'REF-en-001.pdf'
)
upload_file
=
makeFileUpload
(
'REF-en-001.pdf'
)
...
@@ -1301,7 +1301,7 @@ class TestDocument(TestDocumentMixin):
...
@@ -1301,7 +1301,7 @@ class TestDocument(TestDocumentMixin):
frame
=
0
,
frame
=
0
,
display
=
'thumbnail'
)
display
=
'thumbnail'
)
self
.
assertEqual
(
mime
,
'image/gif'
)
self
.
assertEqual
(
mime
,
'image/gif'
)
self
.
assertEqual
(
image_data
[
0
:
4
],
'GIF8'
)
self
.
assertEqual
(
image_data
[
0
:
4
],
b
'GIF8'
)
def
test_PDFToTiff
(
self
):
def
test_PDFToTiff
(
self
):
upload_file
=
makeFileUpload
(
'REF-en-001.pdf'
)
upload_file
=
makeFileUpload
(
'REF-en-001.pdf'
)
...
@@ -1312,7 +1312,7 @@ class TestDocument(TestDocumentMixin):
...
@@ -1312,7 +1312,7 @@ class TestDocument(TestDocumentMixin):
frame
=
0
,
frame
=
0
,
display
=
'thumbnail'
)
display
=
'thumbnail'
)
self
.
assertEqual
(
mime
,
'image/tiff'
)
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
):
def
test_PDF_content_information
(
self
):
...
...
product/ERP5/bootstrap/erp5_core/DocumentTemplateItem/portal_components/document.erp5.File.py
View file @
86981105
...
@@ -38,13 +38,6 @@ from OFS.Image import File as OFS_File
...
@@ -38,13 +38,6 @@ from OFS.Image import File as OFS_File
from
Products.ERP5Type.Utils
import
deprecated
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
()
_MARKER
=
object
()
class
File
(
Document
,
OFS_File
):
class
File
(
Document
,
OFS_File
):
...
@@ -147,7 +140,7 @@ class File(Document, OFS_File):
...
@@ -147,7 +140,7 @@ class File(Document, OFS_File):
if
data
is
None
:
if
data
is
None
:
return
return
if
self
.
hasData
():
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
# Same data as previous, no need to change its content
return
return
else
:
else
:
...
@@ -180,13 +173,13 @@ class File(Document, OFS_File):
...
@@ -180,13 +173,13 @@ class File(Document, OFS_File):
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getData'
)
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getData'
)
def
getData
(
self
,
default
=
None
):
def
getData
(
self
,
default
=
None
):
"""return Data as
str
."""
"""return Data as
bytes
."""
self
.
_checkConversionFormatPermission
(
None
)
self
.
_checkConversionFormatPermission
(
None
)
data
=
self
.
_baseGetData
()
data
=
self
.
_baseGetData
()
if
data
is
None
:
if
data
is
None
:
return
None
return
None
else
:
else
:
return
str
(
data
)
return
bytes
(
data
)
# DAV Support
# DAV Support
security
.
declareProtected
(
Permissions
.
ModifyPortalContent
,
'PUT'
)
security
.
declareProtected
(
Permissions
.
ModifyPortalContent
,
'PUT'
)
...
@@ -226,8 +219,8 @@ class File(Document, OFS_File):
...
@@ -226,8 +219,8 @@ class File(Document, OFS_File):
elif
getattr
(
self
,
'getBaseData'
,
None
)
is
not
None
:
elif
getattr
(
self
,
'getBaseData'
,
None
)
is
not
None
:
content
=
self
.
getBaseData
()
content
=
self
.
getBaseData
()
if
content
and
not
isinstance
(
content
,
str
):
if
content
and
not
isinstance
(
content
,
bytes
):
content
=
str
(
content
)
content
=
bytes
(
content
)
return
(
mime_type
,
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