Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mitogen
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
mitogen
Commits
b543b84e
Commit
b543b84e
authored
Feb 15, 2018
by
David Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
importer: share blacklist logic between master/parent
parent
8ec6ae1d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
4 deletions
+10
-4
mitogen/core.py
mitogen/core.py
+6
-2
mitogen/master.py
mitogen/master.py
+4
-2
No files found.
mitogen/core.py
View file @
b543b84e
...
...
@@ -167,6 +167,11 @@ def restart(func, *args):
raise
def
is_blacklisted_import
(
importer
,
fullname
):
return
((
not
any
(
fullname
.
startswith
(
s
)
for
s
in
importer
.
whitelist
))
or
(
any
(
fullname
.
startswith
(
s
)
for
s
in
importer
.
blacklist
)))
def
set_cloexec
(
fd
):
flags
=
fcntl
.
fcntl
(
fd
,
fcntl
.
F_GETFD
)
fcntl
.
fcntl
(
fd
,
fcntl
.
F_SETFD
,
flags
|
fcntl
.
FD_CLOEXEC
)
...
...
@@ -461,8 +466,7 @@ class Importer(object):
del
_tls
.
running
def
_refuse_imports
(
self
,
fullname
):
if
((
not
any
(
fullname
.
startswith
(
s
)
for
s
in
self
.
whitelist
))
or
(
any
(
fullname
.
startswith
(
s
)
for
s
in
self
.
blacklist
))):
if
is_blacklisted_import
(
self
,
fullname
):
raise
ImportError
(
'Refused'
)
f
=
sys
.
_getframe
(
2
)
...
...
mitogen/master.py
View file @
b543b84e
...
...
@@ -442,7 +442,7 @@ class ModuleResponder(object):
self
.
_finder
=
ModuleFinder
()
self
.
_cache
=
{}
# fullname -> pickled
self
.
blacklist
=
[]
self
.
whitelist
=
[]
self
.
whitelist
=
[
''
]
router
.
add_handler
(
self
.
_on_get_module
,
mitogen
.
core
.
GET_MODULE
)
def
__repr__
(
self
):
...
...
@@ -451,6 +451,8 @@ class ModuleResponder(object):
MAIN_RE
=
re
.
compile
(
r'^if\
s+__
name__\
s*==
\s*.__main__.\
s*:
', re.M)
def whitelist_prefix(self, fullname):
if self.whitelist == ['']:
self.whitelist = ['
mitogen
']
self.whitelist.append(fullname)
def blacklist_prefix(self, fullname):
...
...
@@ -466,7 +468,7 @@ class ModuleResponder(object):
return src
def _build_tuple(self, fullname):
if
fullname in self._blacklist
:
if
mitogen.core.is_blacklisted_import(self, fullname)
:
raise ImportError('
blacklisted
')
if fullname in self._cache:
...
...
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