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
1d333f3f
Commit
1d333f3f
authored
Jan 05, 2024
by
Jérome Perrin
Committed by
Kazuhiko Shiozaki
Jul 11, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: enable print_function in checkPythonSourceCodeAsJSON
This flags python2 style usage of print as a statement
parent
3b89c4b8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
5 deletions
+21
-5
product/ERP5/bootstrap/erp5_core/ExtensionTemplateItem/portal_components/extension.erp5.PythonCodeUtils.py
...eItem/portal_components/extension.erp5.PythonCodeUtils.py
+21
-5
No files found.
product/ERP5/bootstrap/erp5_core/ExtensionTemplateItem/portal_components/extension.erp5.PythonCodeUtils.py
View file @
1d333f3f
from
six
import
string_types
as
basestring
import
re
import
json
from
Products.ERP5Type.Utils
import
checkPythonSourceCode
match_PEP263
=
re
.
compile
(
r'^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)'
).
match
def
checkPythonSourceCodeAsJSON
(
self
,
data
,
REQUEST
=
None
):
"""
Check Python source suitable for Source Code Editor and return a JSON object
...
...
@@ -24,8 +29,19 @@ def checkPythonSourceCodeAsJSON(self, data, REQUEST=None):
signature_parts
+=
[
data
[
'params'
]]
signature
=
", "
.
join
(
signature_parts
)
function_name
=
"function_name"
body
=
"def %s(%s):
\
n
%s"
%
(
function_name
,
# keep the PEP263 magic comment
pep263_comment
=
'#'
lines
=
data
[
'code'
].
splitlines
()
+
[
''
,
''
]
for
line
in
lines
[
0
],
lines
[
1
]:
m
=
match_PEP263
(
line
)
if
m
:
pep263_comment
=
'# coding='
+
m
.
groups
()[
0
]
break
body
=
"%s
\
n
"
\
"from __future__ import print_function
\
n
"
\
"def function_name(%s):
\
n
%s"
%
(
pep263_comment
,
signature
,
indent
(
data
[
'code'
])
or
" pass"
)
else
:
...
...
@@ -34,7 +50,7 @@ def checkPythonSourceCodeAsJSON(self, data, REQUEST=None):
message_list
=
checkPythonSourceCode
(
body
.
encode
(
'utf8'
),
data
.
get
(
'portal_type'
))
for
message_dict
in
message_list
:
if
is_script
:
message_dict
[
'row'
]
=
message_dict
[
'row'
]
-
2
message_dict
[
'row'
]
=
message_dict
[
'row'
]
-
4
else
:
message_dict
[
'row'
]
=
message_dict
[
'row'
]
-
1
...
...
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