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
138
Merge Requests
138
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
09ee5c6e
Commit
09ee5c6e
authored
Mar 15, 2023
by
Jérome Perrin
Committed by
Arnaud Fontaine
Jul 05, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
web_shadir: PY3 compatibility
parent
4154ddd0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
10 deletions
+22
-10
bt5/erp5_web_shacache/ExtensionTemplateItem/portal_components/extension.erp5.ShaCache.py
...TemplateItem/portal_components/extension.erp5.ShaCache.py
+7
-4
bt5/erp5_web_shadir/ExtensionTemplateItem/portal_components/extension.erp5.ShaDir.py
...onTemplateItem/portal_components/extension.erp5.ShaDir.py
+15
-6
No files found.
bt5/erp5_web_shacache/ExtensionTemplateItem/portal_components/extension.erp5.ShaCache.py
View file @
09ee5c6e
...
@@ -26,8 +26,9 @@
...
@@ -26,8 +26,9 @@
#
#
##############################################################################
##############################################################################
import
hashlib
import
hashlib
,
six
.
moves
.
http_client
import
six
import
six.moves.http_client
from
Products.ERP5Type.UnrestrictedMethod
import
super_user
from
Products.ERP5Type.UnrestrictedMethod
import
super_user
...
@@ -77,7 +78,7 @@ def File_viewAsWeb(self):
...
@@ -77,7 +78,7 @@ def File_viewAsWeb(self):
# Shortcut if the file is not a Pdata.
# Shortcut if the file is not a Pdata.
data
=
self
.
data
data
=
self
.
data
if
isinstance
(
data
,
str
):
if
isinstance
(
data
,
bytes
):
# Do this way instead of 'return data'
# Do this way instead of 'return data'
# to bypass default caching policy manager.
# to bypass default caching policy manager.
RESPONSE
.
write
(
data
)
RESPONSE
.
write
(
data
)
...
@@ -85,7 +86,9 @@ def File_viewAsWeb(self):
...
@@ -85,7 +86,9 @@ def File_viewAsWeb(self):
# For Pdata type, we must iterate and send chunk by chunk.
# For Pdata type, we must iterate and send chunk by chunk.
# And no need to continue if the client closed the connection.
# And no need to continue if the client closed the connection.
while
data
and
not
RESPONSE
.
stdout
.
_channel
.
closed
:
while
data
:
if
six
.
PY2
and
RESPONSE
.
stdout
.
_channel
.
closed
:
break
# Send data to the client.
# Send data to the client.
RESPONSE
.
write
(
data
.
data
)
RESPONSE
.
write
(
data
.
data
)
# Load next object without keeping previous chunks in memory.
# Load next object without keeping previous chunks in memory.
...
...
bt5/erp5_web_shadir/ExtensionTemplateItem/portal_components/extension.erp5.ShaDir.py
View file @
09ee5c6e
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
#
#
##############################################################################
##############################################################################
import
six
import
hashlib
import
hashlib
from
base64
import
b64decode
from
base64
import
b64decode
from
binascii
import
a2b_hex
from
binascii
import
a2b_hex
...
@@ -33,6 +34,7 @@ from json import dumps, loads
...
@@ -33,6 +34,7 @@ from json import dumps, loads
from
zExceptions
import
BadRequest
from
zExceptions
import
BadRequest
from
DateTime
import
DateTime
from
DateTime
import
DateTime
from
Products.ERP5Type.UnrestrictedMethod
import
super_user
from
Products.ERP5Type.UnrestrictedMethod
import
super_user
from
Products.ERP5Type.Utils
import
unicode2str
,
str2bytes
def
WebSection_getDocumentValue
(
self
,
key
,
portal
=
None
,
language
=
None
,
\
def
WebSection_getDocumentValue
(
self
,
key
,
portal
=
None
,
language
=
None
,
\
...
@@ -67,10 +69,9 @@ def WebSection_getDocumentValue(self, key, portal=None, language=None,\
...
@@ -67,10 +69,9 @@ def WebSection_getDocumentValue(self, key, portal=None, language=None,\
validation_state
=
'published'
)]
validation_state
=
'published'
)]
temp_file
=
self
.
newContent
(
temp_object
=
True
,
portal_type
=
'File'
,
id
=
'%s.txt'
%
key
)
temp_file
=
self
.
newContent
(
temp_object
=
True
,
portal_type
=
'File'
,
id
=
'%s.txt'
%
key
)
temp_file
.
setData
(
dumps
(
document_list
))
temp_file
.
setData
(
str2bytes
(
dumps
(
document_list
)
))
temp_file
.
setContentType
(
'application/json'
)
temp_file
.
setContentType
(
'application/json'
)
return
temp_file
.
getObject
()
return
temp_file
.
getObject
()
return
None
return
None
def
WebSection_setObject
(
self
,
id
,
ob
,
**
kw
):
def
WebSection_setObject
(
self
,
id
,
ob
,
**
kw
):
...
@@ -78,12 +79,14 @@ def WebSection_setObject(self, id, ob, **kw):
...
@@ -78,12 +79,14 @@ def WebSection_setObject(self, id, ob, **kw):
Make any change related to the file uploaded.
Make any change related to the file uploaded.
"""
"""
portal
=
self
.
getPortalObject
()
portal
=
self
.
getPortalObject
()
ob
=
ob
.
getOriginalDocument
()
data
=
self
.
REQUEST
.
get
(
'BODY'
)
data
=
self
.
REQUEST
.
get
(
'BODY'
)
try
:
try
:
metadata
,
signature
=
loads
(
data
)
metadata
,
signature
=
loads
(
data
)
metadata
=
loads
(
metadata
)
metadata
=
loads
(
metadata
)
# a few basic checks
# a few basic checks
b64decode
(
s
ignature
)
b64decode
(
s
tr2bytes
(
signature
)
)
if
len
(
a2b_hex
(
metadata
[
'sha512'
]))
!=
64
:
if
len
(
a2b_hex
(
metadata
[
'sha512'
]))
!=
64
:
raise
Exception
(
'sha512: invalid length'
)
raise
Exception
(
'sha512: invalid length'
)
except
Exception
as
e
:
except
Exception
as
e
:
...
@@ -126,7 +129,13 @@ def WebSection_putFactory(self, name, typ, body):
...
@@ -126,7 +129,13 @@ def WebSection_putFactory(self, name, typ, body):
document
=
portal
.
portal_contributions
.
newContent
(
data
=
body
,
document
=
portal
.
portal_contributions
.
newContent
(
data
=
body
,
filename
=
name
,
filename
=
name
,
discover_metadata
=
False
)
discover_metadata
=
False
)
return
document
# return a document for which getId() returns the name for _setObject to be
# called with id=name ( for WebSection_setObject ), but for which
# getRelativeUrl returns the relative url of the real document, for
# VirtualFolderMixin transactional variable cache between _setObject and
# _getOb
return
document
.
asContext
(
getId
=
lambda
:
name
)
# The following scripts are helpers to search & clean up shadir entries.
# The following scripts are helpers to search & clean up shadir entries.
# XXX: Due to lack of View skin for shadir, external methods are currently
# XXX: Due to lack of View skin for shadir, external methods are currently
...
@@ -217,10 +226,10 @@ def ShaDir_search(self, filename, summary, delete=False):
...
@@ -217,10 +226,10 @@ def ShaDir_search(self, filename, summary, delete=False):
document_list
.
append
(
document
)
document_list
.
append
(
document
)
metadata
=
loads
(
loads
(
document
.
getData
())[
0
])
metadata
=
loads
(
loads
(
document
.
getData
())[
0
])
del
metadata
[
u"sha512"
]
del
metadata
[
u"sha512"
]
x
[
';'
.
join
(
'%s=%r'
%
(
k
,
v
.
encode
(
'utf-8'
)
if
type
(
v
)
is
unicode
else
v
)
x
[
';'
.
join
(
'%s=%r'
%
(
k
,
unicode2str
(
v
)
)
for
k
,
v
in
sorted
(
metadata
.
iteritems
()))].
append
(
for
k
,
v
in
sorted
(
metadata
.
iteritems
()))].
append
(
document
.
getId
())
document
.
getId
())
r
=
'
\
n
'
.
join
(
'%s %s'
%
(
k
,
sorted
(
v
))
for
k
,
v
in
sorted
(
x
.
iteritems
(
)))
r
=
'
\
n
'
.
join
(
'%s %s'
%
(
k
,
sorted
(
v
))
for
k
,
v
in
sorted
(
six
.
iteritems
(
x
)))
if
delete
:
if
delete
:
r
+=
'
\
n
'
+
_deleteDocumentList
(
self
,
document_list
)
r
+=
'
\
n
'
+
_deleteDocumentList
(
self
,
document_list
)
return
r
return
r
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