Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
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
Kirill Smelkov
gevent
Commits
dde3100c
Commit
dde3100c
authored
Aug 05, 2015
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compatibility with the future library.
parent
47426f27
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
7 deletions
+30
-7
gevent/builtins.py
gevent/builtins.py
+14
-7
greentest/test__monkey_builtins_future.py
greentest/test__monkey_builtins_future.py
+16
-0
No files found.
gevent/builtins.py
View file @
dde3100c
...
...
@@ -5,14 +5,21 @@ from __future__ import absolute_import
import
imp
import
sys
import
gevent.lock
try
:
import
builtins
allowed_module_name_types
=
(
str
,)
__target__
=
'builtins'
except
ImportError
:
# Py2
# Normally we'd have the "expected" case inside the try
# (Python 3, because Python 3 is the way forward). But
# under Python 2, the popular `future` library *also* provides
# a `builtins` module---which lacks the __import__ attribute.
# So we test for the old, deprecated version first
try
:
# Py2
import
__builtin__
as
builtins
allowed_module_name_types
=
(
basestring
,)
_
allowed_module_name_types
=
(
basestring
,)
__target__
=
'__builtin__'
except
ImportError
:
import
builtins
_allowed_module_name_types
=
(
str
,)
__target__
=
'builtins'
_import
=
builtins
.
__import__
...
...
@@ -30,7 +37,7 @@ def __import__(*args, **kwargs):
wraps the normal __import__ functionality in a recursive lock, ensuring that
we're protected against greenlet import concurrency as well.
"""
if
len
(
args
)
>
0
and
not
issubclass
(
type
(
args
[
0
]),
allowed_module_name_types
):
if
len
(
args
)
>
0
and
not
issubclass
(
type
(
args
[
0
]),
_
allowed_module_name_types
):
# if a builtin has been acquired as a bound instance method,
# python knows not to pass 'self' when the method is called.
# No such protection exists for monkey-patched builtins,
...
...
greentest/test__monkey_builtins_future.py
0 → 100644
View file @
dde3100c
# Under Python 2, if the `future` module is installed, we get
# a `builtins` module, which mimics the `builtins` module from
# Python 3, but does not have the __import__ and some other functions.
# Make sure we can still run in that case.
import
sys
try
:
# fake out a "broken" builtins module
import
builtins
except
ImportError
:
class
builtins
(
object
):
pass
sys
.
modules
[
'builtins'
]
=
builtins
()
if
not
hasattr
(
builtins
,
'__import__'
):
import
gevent.monkey
gevent
.
monkey
.
patch_builtins
()
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