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
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
Jérome Perrin
erp5
Commits
6ee44e70
Commit
6ee44e70
authored
Sep 30, 2022
by
Kazuhiko Shiozaki
Committed by
Jérome Perrin
May 27, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py2/py3: handle bytes correctly in Python3.
parent
eff321fa
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
19 deletions
+20
-19
product/CMFActivity/Activity/SQLBase.py
product/CMFActivity/Activity/SQLBase.py
+16
-17
product/CMFActivity/ActivityTool.py
product/CMFActivity/ActivityTool.py
+1
-1
product/ERP5Type/Utils.py
product/ERP5Type/Utils.py
+1
-1
product/ZSQLCatalog/Utils.py
product/ZSQLCatalog/Utils.py
+2
-0
No files found.
product/CMFActivity/Activity/SQLBase.py
View file @
6ee44e70
...
@@ -29,7 +29,7 @@ from __future__ import absolute_import
...
@@ -29,7 +29,7 @@ from __future__ import absolute_import
from
six
import
string_types
as
basestring
from
six
import
string_types
as
basestring
from
six.moves
import
xrange
from
six.moves
import
xrange
from
Products.ERP5Type.Utils
import
ensure_list
,
str2bytes
from
Products.ERP5Type.Utils
import
bytes2str
,
ensure_list
,
str2bytes
from
collections
import
defaultdict
from
collections
import
defaultdict
from
contextlib
import
contextmanager
from
contextlib
import
contextmanager
from
itertools
import
product
,
chain
from
itertools
import
product
,
chain
...
@@ -398,10 +398,10 @@ CREATE TABLE %s (
...
@@ -398,10 +398,10 @@ CREATE TABLE %s (
for
line
in
result
]
for
line
in
result
]
def
countMessageSQL
(
self
,
quote
,
**
kw
):
def
countMessageSQL
(
self
,
quote
,
**
kw
):
return
"SELECT count(*) FROM %s WHERE processing_node > %d AND %s"
%
(
return
b
"SELECT count(*) FROM %s WHERE processing_node > %d AND %s"
%
(
s
elf
.
sql_table
,
DEPENDENCY_IGNORED_ERROR_STATE
,
" AND "
.
join
(
s
tr2bytes
(
self
.
sql_table
),
DEPENDENCY_IGNORED_ERROR_STATE
,
b
" AND "
.
join
(
sqltest_dict
[
k
](
v
,
quote
)
for
(
k
,
v
)
in
six
.
iteritems
(
kw
)
if
v
sqltest_dict
[
k
](
v
,
quote
)
for
(
k
,
v
)
in
six
.
iteritems
(
kw
)
if
v
)
or
"1"
)
)
or
b
"1"
)
def
hasActivitySQL
(
self
,
quote
,
only_valid
=
False
,
only_invalid
=
False
,
**
kw
):
def
hasActivitySQL
(
self
,
quote
,
only_valid
=
False
,
only_invalid
=
False
,
**
kw
):
where
=
[
sqltest_dict
[
k
](
v
,
quote
)
for
(
k
,
v
)
in
six
.
iteritems
(
kw
)
if
v
]
where
=
[
sqltest_dict
[
k
](
v
,
quote
)
for
(
k
,
v
)
in
six
.
iteritems
(
kw
)
if
v
]
...
@@ -426,7 +426,7 @@ CREATE TABLE %s (
...
@@ -426,7 +426,7 @@ CREATE TABLE %s (
0
,
0
,
)[
1
]
)[
1
]
else
:
else
:
subquery
=
(
b"("
subquery
=
lambda
*
a
,
**
k
:
str2bytes
(
bytes2str
(
b"("
b"SELECT 3*priority{} AS effective_priority, date"
b"SELECT 3*priority{} AS effective_priority, date"
b" FROM %s"
b" FROM %s"
b" WHERE"
b" WHERE"
...
@@ -435,7 +435,7 @@ CREATE TABLE %s (
...
@@ -435,7 +435,7 @@ CREATE TABLE %s (
b" date <= UTC_TIMESTAMP(6)"
b" date <= UTC_TIMESTAMP(6)"
b" ORDER BY priority, date"
b" ORDER BY priority, date"
b" LIMIT 1"
b" LIMIT 1"
b")"
%
s
elf
.
sql_table
).
format
b")"
%
s
tr2bytes
(
self
.
sql_table
)).
format
(
*
a
,
**
k
))
result
=
query
(
result
=
query
(
b"SELECT *"
b"SELECT *"
b" FROM (%s) AS t"
b" FROM (%s) AS t"
...
@@ -444,11 +444,11 @@ CREATE TABLE %s (
...
@@ -444,11 +444,11 @@ CREATE TABLE %s (
b" UNION ALL "
.
join
(
b" UNION ALL "
.
join
(
chain
(
chain
(
(
(
subquery
(
b'-1'
,
b
'node = %i'
%
processing_node
),
subquery
(
'-1'
,
'node = %i'
%
processing_node
),
subquery
(
b''
,
b
'node=0'
),
subquery
(
''
,
'node=0'
),
),
),
(
(
subquery
(
b'-1'
,
b
'node = %i'
%
x
)
subquery
(
'-1'
,
'node = %i'
%
x
)
for
x
in
node_set
for
x
in
node_set
),
),
),
),
...
@@ -465,7 +465,7 @@ CREATE TABLE %s (
...
@@ -465,7 +465,7 @@ CREATE TABLE %s (
# sorted set to filter negative node values.
# sorted set to filter negative node values.
# This is why this query is only executed when the previous one
# This is why this query is only executed when the previous one
# did not find anything.
# did not find anything.
result
=
query
(
subquery
(
b'+1'
,
b
'node>0'
),
0
)[
1
]
result
=
query
(
subquery
(
'+1'
,
'node>0'
),
0
)[
1
]
if
result
:
if
result
:
return
result
[
0
]
return
result
[
0
]
return
Queue
.
getPriority
(
self
,
activity_tool
,
processing_node
,
node_set
)
return
Queue
.
getPriority
(
self
,
activity_tool
,
processing_node
,
node_set
)
...
@@ -780,7 +780,7 @@ CREATE TABLE %s (
...
@@ -780,7 +780,7 @@ CREATE TABLE %s (
0
,
0
,
))
))
else
:
else
:
subquery
=
(
b"("
subquery
=
lambda
*
a
,
**
k
:
str2bytes
(
bytes2str
(
b"("
b"SELECT *, 3*priority{} AS effective_priority"
b"SELECT *, 3*priority{} AS effective_priority"
b" FROM %s"
b" FROM %s"
b" WHERE"
b" WHERE"
...
@@ -789,8 +789,7 @@ CREATE TABLE %s (
...
@@ -789,8 +789,7 @@ CREATE TABLE %s (
b" %s%s"
b" %s%s"
b" ORDER BY priority, date"
b" ORDER BY priority, date"
b" LIMIT %i"
b" LIMIT %i"
b" FOR UPDATE"
b")"
%
args
).
format
(
*
a
,
*
k
))
b")"
%
args
).
format
result
=
Results
(
query
(
result
=
Results
(
query
(
b"SELECT *"
b"SELECT *"
b" FROM (%s) AS t"
b" FROM (%s) AS t"
...
@@ -799,11 +798,11 @@ CREATE TABLE %s (
...
@@ -799,11 +798,11 @@ CREATE TABLE %s (
b" UNION ALL "
.
join
(
b" UNION ALL "
.
join
(
chain
(
chain
(
(
(
subquery
(
b'-1'
,
b
'node = %i'
%
processing_node
),
subquery
(
'-1'
,
'node = %i'
%
processing_node
),
subquery
(
b''
,
b
'node=0'
),
subquery
(
''
,
'node=0'
),
),
),
(
(
subquery
(
b'-1'
,
b
'node = %i'
%
x
)
subquery
(
'-1'
,
'node = %i'
%
x
)
for
x
in
node_set
for
x
in
node_set
),
),
),
),
...
@@ -821,7 +820,7 @@ CREATE TABLE %s (
...
@@ -821,7 +820,7 @@ CREATE TABLE %s (
# sorted set to filter negative node values.
# sorted set to filter negative node values.
# This is why this query is only executed when the previous one
# This is why this query is only executed when the previous one
# did not find anything.
# did not find anything.
result
=
Results
(
query
(
subquery
(
b'+1'
,
b
'node>0'
),
0
))
result
=
Results
(
query
(
subquery
(
'+1'
,
'node>0'
),
0
))
if
result
:
if
result
:
# Reserve messages.
# Reserve messages.
uid_list
=
[
x
.
uid
for
x
in
result
]
uid_list
=
[
x
.
uid
for
x
in
result
]
...
...
product/CMFActivity/ActivityTool.py
View file @
6ee44e70
...
@@ -1811,7 +1811,7 @@ class ActivityTool (BaseTool):
...
@@ -1811,7 +1811,7 @@ class ActivityTool (BaseTool):
"""
"""
db
=
self
.
getSQLConnection
()
db
=
self
.
getSQLConnection
()
quote
=
db
.
string_literal
quote
=
db
.
string_literal
return
sum
(
x
for
x
,
in
db
.
query
(
"(%s)"
%
") UNION ALL ("
.
join
(
return
sum
(
x
for
x
,
in
db
.
query
(
b"(%s)"
%
b
") UNION ALL ("
.
join
(
activity
.
countMessageSQL
(
quote
,
**
kw
)
activity
.
countMessageSQL
(
quote
,
**
kw
)
for
activity
in
six
.
itervalues
(
activity_dict
)))[
1
])
for
activity
in
six
.
itervalues
(
activity_dict
)))[
1
])
...
...
product/ERP5Type/Utils.py
View file @
6ee44e70
...
@@ -375,7 +375,7 @@ def getTranslationStringWithContext(self, msg_id, context, context_id):
...
@@ -375,7 +375,7 @@ def getTranslationStringWithContext(self, msg_id, context, context_id):
result
=
localizer
.
erp5_ui
.
gettext
(
msg_id_context
,
default
=
''
)
result
=
localizer
.
erp5_ui
.
gettext
(
msg_id_context
,
default
=
''
)
if
result
==
''
:
if
result
==
''
:
result
=
localizer
.
erp5_ui
.
gettext
(
msg_id
)
result
=
localizer
.
erp5_ui
.
gettext
(
msg_id
)
return
result
.
encode
(
'utf8'
)
return
unicode2str
(
result
)
def
Email_parseAddressHeader
(
text
):
def
Email_parseAddressHeader
(
text
):
"""
"""
...
...
product/ZSQLCatalog/Utils.py
View file @
6ee44e70
...
@@ -31,6 +31,8 @@ def sqlquote(value):
...
@@ -31,6 +31,8 @@ def sqlquote(value):
# (ex: ZMySQLDA.DA.Connection.sql_quote__).
# (ex: ZMySQLDA.DA.Connection.sql_quote__).
# Duplicating such code is error-prone, and makes us rely on a specific SQL
# Duplicating such code is error-prone, and makes us rely on a specific SQL
# dialect...
# dialect...
if
str
!=
bytes
and
isinstance
(
value
,
bytes
):
# six.PY3
value
=
value
.
decode
()
return
"'"
+
(
value
return
"'"
+
(
value
.
replace
(
'
\
x5c
'
,
r'\\'
)
.
replace
(
'
\
x5c
'
,
r'\\'
)
.
replace
(
'
\
x00
'
,
r'\0'
)
.
replace
(
'
\
x00
'
,
r'\0'
)
...
...
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