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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Iliya Manolov
erp5
Commits
7a1d2f7f
Commit
7a1d2f7f
authored
Aug 04, 2017
by
Iliya Manolov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a module whitelist to Jupyter and an error message to go with it.
parent
583ed6e7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.py
...teItem/portal_components/extension.erp5.JupyterCompile.py
+53
-0
No files found.
bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterCompile.py
View file @
7a1d2f7f
...
...
@@ -311,6 +311,18 @@ def Base_runJupyterCode(self, jupyter_code, old_notebook_context):
tree
=
ast
.
parse
(
warning
)
tree
.
body
[
0
].
lineno
=
ast_node
.
body
[
-
1
].
lineno
+
5
ast_node
.
body
.
append
(
tree
.
body
[
0
])
# Whenever we have new imports we need to warn the user about the
# environment
if
(
import_fixer
.
whitelist_breach_names
!=
[]):
warning
=
(
"print '"
"ERROR: You imported %s, which is not in the module whitelist. "
"If you think that you should be able to use that module "
"please contact the team at Nexedi. "
"'"
)
%
(
import_fixer
.
whitelist_breach_names
[
0
])
tree
=
ast
.
parse
(
warning
)
tree
.
body
[
0
].
lineno
=
ast_node
.
body
[
-
1
].
lineno
+
5
ast_node
.
body
.
append
(
tree
.
body
[
0
])
ast_node
=
print_fixer
.
visit
(
ast_node
)
ast
.
fix_missing_locations
(
ast_node
)
...
...
@@ -774,6 +786,7 @@ class ImportFixer(ast.NodeTransformer):
def
__init__
(
self
):
self
.
import_func_dict
=
{}
self
.
warning_module_names
=
[]
self
.
whitelist_breach_names
=
[]
def
visit_FunctionDef
(
self
,
node
):
"""
...
...
@@ -810,6 +823,39 @@ class ImportFixer(ast.NodeTransformer):
root_module_name
=
""
module_names
=
[]
module_whitelist
=
[
'scipy'
,
'matplotlib'
,
'sklearn'
,
'math'
,
'pickle'
,
'keras'
,
'statsmodels'
,
'zipfile'
,
'sympy'
,
'functools'
,
'pylab'
,
'ftplib'
,
'openpyxl'
,
'pandas'
,
'numpy'
,
'datetime'
,
'wendelin.bigarray.array_zodb'
]
# check if all the modules we're importing from are whitelisted
source_modules
=
[]
if
isinstance
(
node
,
ast
.
Import
):
for
name
in
node
.
names
:
source_modules
.
append
(
name
.
name
)
elif
isinstance
(
node
,
ast
.
ImportFrom
):
source_modules
.
append
(
node
.
module
)
for
name
in
source_modules
:
if
name
not
in
module_whitelist
:
self
.
whitelist_breach_names
.
append
(
name
)
return
node
if
getattr
(
node
,
"module"
,
None
)
is
not
None
:
# case when 'from <module_name> import <something>'
...
...
@@ -944,6 +990,13 @@ class ImportFixer(ast.NodeTransformer):
modules.
"""
self
.
warning_module_names
.
append
(
module_name
)
def
newWhitelistBreachCall
(
self
,
module_name
):
"""
Called when a non-whitelisted module is imported and calls for an error
message.
"""
self
.
whitelist_breach_names
.
append
(
module_name
)
def
renderAsHtml
(
self
,
renderable_object
):
...
...
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