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
Titouan Soulard
erp5
Commits
92344d10
Commit
92344d10
authored
Jul 29, 2023
by
Emmy Vouriot
Committed by
Jérome Perrin
Aug 21, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
str to bytes WIP
parent
884a012b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
14 deletions
+20
-14
bt5/erp5_dms/DocumentTemplateItem/portal_components/document.erp5.PDFDocument.py
...mplateItem/portal_components/document.erp5.PDFDocument.py
+4
-4
product/ERP5/bootstrap/erp5_core/DocumentTemplateItem/portal_components/document.erp5.EmailDocument.py
...lateItem/portal_components/document.erp5.EmailDocument.py
+6
-2
product/ERP5/bootstrap/erp5_core/MixinTemplateItem/portal_components/mixin.erp5.MailMessageMixin.py
...lateItem/portal_components/mixin.erp5.MailMessageMixin.py
+3
-1
product/ERP5OOo/tests/testIngestion.py
product/ERP5OOo/tests/testIngestion.py
+7
-7
No files found.
bt5/erp5_dms/DocumentTemplateItem/portal_components/document.erp5.PDFDocument.py
View file @
92344d10
...
@@ -32,7 +32,7 @@ import zope.interface
...
@@ -32,7 +32,7 @@ import zope.interface
from
AccessControl
import
ClassSecurityInfo
from
AccessControl
import
ClassSecurityInfo
from
Products.ERP5Type
import
Permissions
,
PropertySheet
from
Products.ERP5Type
import
Permissions
,
PropertySheet
from
Products.ERP5Type.Utils
import
bytes2str
from
Products.ERP5Type.Utils
import
bytes2str
,
str2bytes
from
erp5.component.interface.IWatermarkable
import
IWatermarkable
from
erp5.component.interface.IWatermarkable
import
IWatermarkable
from
erp5.component.document.Image
import
Image
from
erp5.component.document.Image
import
Image
from
erp5.component.document.Document
import
ConversionError
from
erp5.component.document.Document
import
ConversionError
...
@@ -291,10 +291,10 @@ class PDFDocument(Image):
...
@@ -291,10 +291,10 @@ class PDFDocument(Image):
finally
:
finally
:
tmp
.
close
()
tmp
.
close
()
# Quick hack to remove bg color - XXX
# Quick hack to remove bg color - XXX
h
=
command_result
.
replace
(
'<BODY bgcolor="#A0A0A0"'
,
'<BODY '
)
h
=
command_result
.
replace
(
b'<BODY bgcolor="#A0A0A0"'
,
b
'<BODY '
)
# Make links relative
# Make links relative
h
=
h
.
replace
(
'href="%s.html'
%
tmp
.
name
.
split
(
os
.
sep
)[
-
1
]
,
h
=
h
.
replace
(
str2bytes
(
'href="%s.html'
%
tmp
.
name
.
split
(
os
.
sep
)[
-
1
])
,
'href="asEntireHTML'
)
b
'href="asEntireHTML'
)
return
h
return
h
security
.
declarePrivate
(
'_convertToDJVU'
)
security
.
declarePrivate
(
'_convertToDJVU'
)
...
...
product/ERP5/bootstrap/erp5_core/DocumentTemplateItem/portal_components/document.erp5.EmailDocument.py
View file @
92344d10
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
##############################################################################
##############################################################################
import
re
import
re
import
six
from
DateTime
import
DateTime
from
DateTime
import
DateTime
from
AccessControl
import
ClassSecurityInfo
from
AccessControl
import
ClassSecurityInfo
from
Products.ERP5Type.Accessor.Constant
import
PropertyGetter
as
ConstantGetter
from
Products.ERP5Type.Accessor.Constant
import
PropertyGetter
as
ConstantGetter
...
@@ -47,7 +48,10 @@ except ImportError:
...
@@ -47,7 +48,10 @@ except ImportError:
not installed yet.
not installed yet.
"""
"""
from
email
import
message_from_string
if
six
.
PY2
:
from
email
import
message_from_string
as
message_from_x
else
:
from
email
import
message_from_bytes
as
message_from_x
from
email.utils
import
parsedate_tz
,
mktime_tz
from
email.utils
import
parsedate_tz
,
mktime_tz
DEFAULT_TEXT_FORMAT
=
'text/html'
DEFAULT_TEXT_FORMAT
=
'text/html'
...
@@ -170,7 +174,7 @@ class EmailDocument(TextDocument, MailMessageMixin):
...
@@ -170,7 +174,7 @@ class EmailDocument(TextDocument, MailMessageMixin):
content_type
=
self
.
getContentType
(),
content_type
=
self
.
getContentType
(),
embedded_file_list
=
self
.
getAggregateValueList
(
portal_type
=
document_type_list
),
embedded_file_list
=
self
.
getAggregateValueList
(
portal_type
=
document_type_list
),
)
)
result
=
message_from_
string
(
data
)
result
=
message_from_
x
(
data
)
self
.
_v_message
=
result
self
.
_v_message
=
result
return
result
return
result
...
...
product/ERP5/bootstrap/erp5_core/MixinTemplateItem/portal_components/mixin.erp5.MailMessageMixin.py
View file @
92344d10
...
@@ -35,6 +35,7 @@ from zLOG import LOG, INFO
...
@@ -35,6 +35,7 @@ from zLOG import LOG, INFO
from
email.header
import
decode_header
,
HeaderParseError
from
email.header
import
decode_header
,
HeaderParseError
import
re
import
re
import
six
filename_regexp
=
'name="([^"]*)"'
filename_regexp
=
'name="([^"]*)"'
...
@@ -43,6 +44,7 @@ def testCharsetAndConvert(text_content, content_type, encoding):
...
@@ -43,6 +44,7 @@ def testCharsetAndConvert(text_content, content_type, encoding):
if
encoding
is
not
None
:
if
encoding
is
not
None
:
text_content
=
text_content
.
decode
(
encoding
).
encode
(
'utf-8'
)
text_content
=
text_content
.
decode
(
encoding
).
encode
(
'utf-8'
)
else
:
else
:
if
six
.
PY2
:
text_content
=
text_content
.
decode
().
encode
(
'utf-8'
)
text_content
=
text_content
.
decode
().
encode
(
'utf-8'
)
except
(
UnicodeDecodeError
,
LookupError
):
except
(
UnicodeDecodeError
,
LookupError
):
encoding
=
guessEncodingFromText
(
text_content
,
content_type
)
encoding
=
guessEncodingFromText
(
text_content
,
content_type
)
...
...
product/ERP5OOo/tests/testIngestion.py
View file @
92344d10
...
@@ -36,7 +36,7 @@ from cgi import FieldStorage
...
@@ -36,7 +36,7 @@ from cgi import FieldStorage
from
lxml
import
etree
from
lxml
import
etree
from
AccessControl.SecurityManagement
import
newSecurityManager
from
AccessControl.SecurityManagement
import
newSecurityManager
from
DateTime
import
DateTime
from
DateTime
import
DateTime
from
Products.ERP5Type.Utils
import
convertToUpperCase
from
Products.ERP5Type.Utils
import
convertToUpperCase
,
str2bytes
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
(
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
(
ERP5TypeTestCase
,
_getConversionServerUrlList
)
ERP5TypeTestCase
,
_getConversionServerUrlList
)
from
Products.ERP5Type.tests.Sequence
import
SequenceList
from
Products.ERP5Type.tests.Sequence
import
SequenceList
...
@@ -1937,7 +1937,7 @@ return result
...
@@ -1937,7 +1937,7 @@ return result
module
=
self
.
portal
.
document_module
module
=
self
.
portal
.
document_module
document
=
module
.
newContent
(
portal_type
=
'File'
,
document
=
module
.
newContent
(
portal_type
=
'File'
,
property_which_doesnot_exists
=
'Foo'
,
property_which_doesnot_exists
=
'Foo'
,
data
=
'Hello World!'
,
data
=
b
'Hello World!'
,
filename
=
'toto.txt'
)
filename
=
'toto.txt'
)
document
.
publish
()
document
.
publish
()
self
.
tic
()
self
.
tic
()
...
@@ -1952,7 +1952,7 @@ return result
...
@@ -1952,7 +1952,7 @@ return result
self
.
assertEqual
(
new_doc
.
getTitle
(),
'One title'
)
self
.
assertEqual
(
new_doc
.
getTitle
(),
'One title'
)
self
.
assertEqual
(
new_doc
.
getReference
(),
'EFAA'
)
self
.
assertEqual
(
new_doc
.
getReference
(),
'EFAA'
)
self
.
assertEqual
(
new_doc
.
getValidationState
(),
'published'
)
self
.
assertEqual
(
new_doc
.
getValidationState
(),
'published'
)
self
.
assertEqual
(
new_doc
.
getData
(),
'Hello World!'
)
self
.
assertEqual
(
new_doc
.
getData
(),
b
'Hello World!'
)
# Migrate a document with url property
# Migrate a document with url property
url
=
new_doc
.
absolute_url
()
+
'/getData'
url
=
new_doc
.
absolute_url
()
+
'/getData'
...
@@ -1964,7 +1964,7 @@ return result
...
@@ -1964,7 +1964,7 @@ return result
new_doc
=
document
.
migratePortalType
(
'File'
)
new_doc
=
document
.
migratePortalType
(
'File'
)
self
.
assertEqual
(
new_doc
.
getPortalType
(),
'File'
)
self
.
assertEqual
(
new_doc
.
getPortalType
(),
'File'
)
self
.
assertEqual
(
new_doc
.
asURL
(),
url
)
self
.
assertEqual
(
new_doc
.
asURL
(),
url
)
self
.
assertEqual
(
new_doc
.
getData
(),
'Hello World!'
)
self
.
assertEqual
(
new_doc
.
getData
(),
b
'Hello World!'
)
self
.
assertEqual
(
new_doc
.
getValidationState
(),
'submitted'
)
self
.
assertEqual
(
new_doc
.
getValidationState
(),
'submitted'
)
def
test_User_Portal_Type_parameter_is_honoured
(
self
):
def
test_User_Portal_Type_parameter_is_honoured
(
self
):
...
@@ -2024,14 +2024,14 @@ return result
...
@@ -2024,14 +2024,14 @@ return result
uri
=
'%(protocol)s://%(hostname)s'
%
url_dict
uri
=
'%(protocol)s://%(hostname)s'
%
url_dict
push_url
=
'%s%s/newContent'
%
(
uri
,
self
.
portal
.
portal_contributions
.
getPath
(),)
push_url
=
'%s%s/newContent'
%
(
uri
,
self
.
portal
.
portal_contributions
.
getPath
(),)
request
=
six
.
moves
.
urllib
.
request
.
Request
(
push_url
,
six
.
moves
.
urllib
.
parse
.
urlencode
(
request
=
six
.
moves
.
urllib
.
request
.
Request
(
push_url
,
s
tr2bytes
(
s
ix
.
moves
.
urllib
.
parse
.
urlencode
(
{
'data'
:
data
,
{
'data'
:
data
,
'filename'
:
filename
,
'filename'
:
filename
,
'reference'
:
reference
,
'reference'
:
reference
,
'disable_cookie_login__'
:
1
,
'disable_cookie_login__'
:
1
,
}),
headers
=
{
})
)
,
headers
=
{
'Authorization'
:
'Basic %s'
%
'Authorization'
:
'Basic %s'
%
base64
.
b64encode
(
'ERP5TypeTestCase:'
)
base64
.
b64encode
(
b
'ERP5TypeTestCase:'
)
})
})
# disable_cookie_login__ is required to force zope to raise Unauthorized (401)
# disable_cookie_login__ is required to force zope to raise Unauthorized (401)
# then HTTPDigestAuthHandler can perform HTTP Authentication
# then HTTPDigestAuthHandler can perform HTTP Authentication
...
...
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