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
Frederic Thoma
erp5
Commits
db633b6f
Commit
db633b6f
authored
Oct 14, 2021
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make some dependencies optional: pandas, wendelin
parent
4426de1b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
53 deletions
+67
-53
product/ERP5Type/patches/Restricted.py
product/ERP5Type/patches/Restricted.py
+57
-47
product/ERP5Type/patches/pylint.py
product/ERP5Type/patches/pylint.py
+10
-6
No files found.
product/ERP5Type/patches/Restricted.py
View file @
db633b6f
...
@@ -402,8 +402,7 @@ ModuleSecurityInfo('os').declarePublic('urandom')
...
@@ -402,8 +402,7 @@ ModuleSecurityInfo('os').declarePublic('urandom')
#
#
# backport from wendelin
# backport from wendelin
#
#
# we neeed to allow access to numpy's internal types
# we need to allow access to numpy's internal types
import
pandas
as
pd
import
numpy
as
np
import
numpy
as
np
allow_module
(
'numpy'
)
allow_module
(
'numpy'
)
allow_module
(
'numpy.lib.recfunctions'
)
allow_module
(
'numpy.lib.recfunctions'
)
...
@@ -427,55 +426,66 @@ allow_type(np.timedelta64)
...
@@ -427,55 +426,66 @@ allow_type(np.timedelta64)
allow_type
(
type
(
np
.
c_
))
allow_type
(
type
(
np
.
c_
))
allow_type
(
type
(
np
.
dtype
(
'int16'
)))
allow_type
(
type
(
np
.
dtype
(
'int16'
)))
allow_module
(
'pandas'
)
# Modify 'safetype' dict in full_write_guard function of RestrictedPython
# (closure) directly to allow write access to ndarray
# (and pandas DataFrame below).
allow_type
(
pd
.
Series
)
from
RestrictedPython.Guards
import
full_write_guard
allow_type
(
pd
.
Timestamp
)
safetype
=
full_write_guard
.
func_closure
[
1
].
cell_contents
.
__self__
allow_type
(
pd
.
DatetimeIndex
)
safetype
.
update
(
dict
.
fromkeys
((
# XXX: pd.DataFrame has its own security thus disable until we can fully integrate it
np
.
ndarray
,
#allow_type(pd.DataFrame)
np
.
core
.
records
.
recarray
,
allow_type
(
pd
.
MultiIndex
)
np
.
core
.
records
.
record
,
allow_type
(
pd
.
indexes
.
range
.
RangeIndex
)
),
True
))
allow_type
(
pd
.
indexes
.
numeric
.
Int64Index
)
allow_type
(
pd
.
core
.
groupby
.
DataFrameGroupBy
)
allow_type
(
pd
.
core
.
groupby
.
SeriesGroupBy
)
allow_class
(
pd
.
DataFrame
)
def
restrictedMethod
(
s
,
name
):
def
restrictedMethod
(
s
,
name
):
def
dummyMethod
(
*
args
,
**
kw
):
def
dummyMethod
(
*
args
,
**
kw
):
raise
Unauthorized
(
name
)
raise
Unauthorized
(
name
)
return
dummyMethod
return
dummyMethod
# Note: These black_list methods are for pandas 0.19.2
try
:
series_black_list
=
[
'to_csv'
,
'to_json'
,
'to_pickle'
,
'to_hdf'
,
import
pandas
as
pd
'to_sql'
,
'to_msgpack'
]
except
ImportError
:
series_black_list_dict
=
{
m
:
restrictedMethod
for
m
in
series_black_list
}
pass
ContainerAssertions
[
pd
.
Series
]
=
_check_access_wrapper
(
pd
.
Series
,
else
:
series_black_list_dict
)
allow_module
(
'pandas'
)
allow_type
(
pd
.
Series
)
pandas_black_list
=
[
'read_csv'
,
'read_json'
,
'read_pickle'
,
'read_hdf'
,
'read_fwf'
,
allow_type
(
pd
.
Timestamp
)
'read_excel'
,
'read_html'
,
'read_msgpack'
,
allow_type
(
pd
.
DatetimeIndex
)
'read_gbq'
,
'read_sas'
,
'read_stata'
]
# XXX: pd.DataFrame has its own security thus disable
ModuleSecurityInfo
(
'pandas'
).
declarePrivate
(
*
pandas_black_list
)
# until we can fully integrate it
#allow_type(pd.DataFrame)
dataframe_black_list
=
[
'to_csv'
,
'to_json'
,
'to_pickle'
,
'to_hdf'
,
allow_type
(
pd
.
MultiIndex
)
'to_excel'
,
'to_html'
,
'to_sql'
,
'to_msgpack'
,
allow_type
(
pd
.
indexes
.
range
.
RangeIndex
)
'to_latex'
,
'to_gbq'
,
'to_stata'
]
allow_type
(
pd
.
indexes
.
numeric
.
Int64Index
)
dataframe_black_list_dict
=
{
m
:
restrictedMethod
for
m
in
dataframe_black_list
}
allow_type
(
pd
.
core
.
groupby
.
DataFrameGroupBy
)
ContainerAssertions
[
pd
.
DataFrame
]
=
_check_access_wrapper
(
allow_type
(
pd
.
core
.
groupby
.
SeriesGroupBy
)
pd
.
DataFrame
,
dataframe_black_list_dict
)
allow_class
(
pd
.
DataFrame
)
# Modify 'safetype' dict in full_write_guard function
# Note: These black_list methods are for pandas 0.19.2
# of RestrictedPython (closure) directly to allow
ContainerAssertions
[
pd
.
Series
]
=
_check_access_wrapper
(
# write access to ndarray and pandas DataFrame.
pd
.
Series
,
dict
.
fromkeys
((
from
RestrictedPython.Guards
import
full_write_guard
'to_csv'
,
'to_json'
,
'to_pickle'
,
'to_hdf'
,
'to_sql'
,
'to_msgpack'
,
full_write_guard
.
func_closure
[
1
].
cell_contents
.
__self__
[
np
.
ndarray
]
=
True
),
restrictedMethod
))
full_write_guard
.
func_closure
[
1
].
cell_contents
.
__self__
[
np
.
core
.
records
.
recarray
]
=
True
full_write_guard
.
func_closure
[
1
].
cell_contents
.
__self__
[
np
.
core
.
records
.
record
]
=
True
ModuleSecurityInfo
(
'pandas'
).
declarePrivate
(
full_write_guard
.
func_closure
[
1
].
cell_contents
.
__self__
[
pd
.
DataFrame
]
=
True
'read_csv'
,
'read_json'
,
'read_pickle'
,
'read_hdf'
,
'read_fwf'
,
full_write_guard
.
func_closure
[
1
].
cell_contents
.
__self__
[
pd
.
Series
]
=
True
'read_excel'
,
'read_html'
,
'read_msgpack'
,
full_write_guard
.
func_closure
[
1
].
cell_contents
.
__self__
[
pd
.
tseries
.
index
.
DatetimeIndex
]
=
True
'read_gbq'
,
'read_sas'
,
'read_stata'
,
full_write_guard
.
func_closure
[
1
].
cell_contents
.
__self__
[
pd
.
core
.
indexing
.
_iLocIndexer
]
=
True
)
full_write_guard
.
func_closure
[
1
].
cell_contents
.
__self__
[
pd
.
core
.
indexing
.
_LocIndexer
]
=
True
full_write_guard
.
func_closure
[
1
].
cell_contents
.
__self__
[
pd
.
MultiIndex
]
=
True
ContainerAssertions
[
pd
.
DataFrame
]
=
_check_access_wrapper
(
full_write_guard
.
func_closure
[
1
].
cell_contents
.
__self__
[
pd
.
Index
]
=
True
pd
.
DataFrame
,
dict
.
fromkeys
((
'to_csv'
,
'to_json'
,
'to_pickle'
,
'to_hdf'
,
'to_excel'
,
'to_html'
,
'to_sql'
,
'to_msgpack'
,
'to_latex'
,
'to_gbq'
,
'to_stata'
,
),
restrictedMethod
))
safetype
.
update
(
dict
.
fromkeys
((
pd
.
DataFrame
,
pd
.
Series
,
pd
.
tseries
.
index
.
DatetimeIndex
,
pd
.
core
.
indexing
.
_iLocIndexer
,
pd
.
core
.
indexing
.
_LocIndexer
,
pd
.
MultiIndex
,
pd
.
Index
,
),
True
))
product/ERP5Type/patches/pylint.py
View file @
db633b6f
...
@@ -335,12 +335,16 @@ for filename in os.listdir(os.path.dirname(lxml.__file__)):
...
@@ -335,12 +335,16 @@ for filename in os.listdir(os.path.dirname(lxml.__file__)):
# with `No name 'bigarray' in module 'wendelin' (no-name-in-module)`.
# with `No name 'bigarray' in module 'wendelin' (no-name-in-module)`.
#
#
# -> Teach pylint to properly understand wendelin package nature.
# -> Teach pylint to properly understand wendelin package nature.
import
wendelin
try
:
def
wendelin_transform
(
node
):
import
wendelin
m
=
AstroidBuilder
(
MANAGER
).
string_build
(
'__path__ = %r'
%
wendelin
.
__path__
)
except
ImportError
:
m
.
package
=
True
pass
return
m
else
:
MANAGER
.
register_transform
(
Module
,
wendelin_transform
,
lambda
node
:
node
.
name
==
'wendelin'
)
def
wendelin_transform
(
node
):
m
=
AstroidBuilder
(
MANAGER
).
string_build
(
'__path__ = %r'
%
wendelin
.
__path__
)
m
.
package
=
True
return
m
MANAGER
.
register_transform
(
Module
,
wendelin_transform
,
lambda
node
:
node
.
name
==
'wendelin'
)
# Properly search for namespace packages: original astroid (as of 1.3.8) only
# Properly search for namespace packages: original astroid (as of 1.3.8) only
# checks at top-level and it doesn't work for Shared.DC.ZRDB (defined in
# checks at top-level and it doesn't work for Shared.DC.ZRDB (defined in
...
...
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