Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9d7219a9
Commit
9d7219a9
authored
Feb 08, 2012
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move setup code from importlib.__init__ to
importlib._bootstrap._setup().
parent
82296101
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
27 deletions
+47
-27
Lib/importlib/__init__.py
Lib/importlib/__init__.py
+3
-27
Lib/importlib/_bootstrap.py
Lib/importlib/_bootstrap.py
+44
-0
No files found.
Lib/importlib/__init__.py
View file @
9d7219a9
...
@@ -22,9 +22,6 @@ __all__ = ['__import__', 'import_module']
...
@@ -22,9 +22,6 @@ __all__ = ['__import__', 'import_module']
from
.
import
_bootstrap
from
.
import
_bootstrap
import
os
import
re
import
tokenize
# To simplify imports in test code
# To simplify imports in test code
_w_long
=
_bootstrap
.
_w_long
_w_long
=
_bootstrap
.
_w_long
...
@@ -32,31 +29,10 @@ _r_long = _bootstrap._r_long
...
@@ -32,31 +29,10 @@ _r_long = _bootstrap._r_long
# Bootstrap help #####################################################
# Bootstrap help #####################################################
import
imp
import
sys
# Required built-in modules.
_bootstrap
.
_setup
(
sys
,
imp
)
try
:
import
posix
as
_os
except
ImportError
:
try
:
import
nt
as
_os
except
ImportError
:
try
:
import
os2
as
_os
except
ImportError
:
raise
ImportError
(
'posix, nt, or os2 module required for importlib'
)
_bootstrap
.
_os
=
_os
import
imp
,
sys
,
marshal
,
_io
_bootstrap
.
imp
=
imp
_bootstrap
.
sys
=
sys
_bootstrap
.
marshal
=
marshal
_bootstrap
.
_io
=
_io
import
_warnings
_bootstrap
.
_warnings
=
_warnings
from
os
import
sep
# For os.path.join replacement; pull from Include/osdefs.h:SEP .
_bootstrap
.
path_sep
=
sep
# Public API #########################################################
# Public API #########################################################
...
...
Lib/importlib/_bootstrap.py
View file @
9d7219a9
...
@@ -995,3 +995,47 @@ def __import__(name, globals={}, locals={}, fromlist=[], level=0):
...
@@ -995,3 +995,47 @@ def __import__(name, globals={}, locals={}, fromlist=[], level=0):
except
ImportError
:
except
ImportError
:
pass
pass
return
module
return
module
def
_setup
(
sys_module
,
imp_module
):
"""Setup importlib by importing needed built-in modules and injecting them
into the global namespace.
As sys is needed for sys.modules access and imp is needed to load built-in
modules those two modules must be explicitly passed in.
"""
global
imp
,
sys
imp
=
imp_module
sys
=
sys_module
for
module
in
(
imp
,
sys
):
if
not
hasattr
(
module
,
'__loader__'
):
module
.
__loader__
=
BuiltinImporter
self_module
=
sys
.
modules
[
__name__
]
for
builtin_name
in
(
'_io'
,
'_warnings'
,
'builtins'
,
'marshal'
):
if
builtin_name
not
in
sys
.
modules
:
builtin_module
=
BuiltinImporter
.
load_module
(
builtin_name
)
else
:
builtin_module
=
sys
.
modules
[
builtin_name
]
setattr
(
self_module
,
builtin_name
,
builtin_module
)
for
builtin_os
,
path_sep
in
[(
'posix'
,
'/'
),
(
'nt'
,
'
\
\
'
),
(
'os2'
,
'
\
\
'
)]:
if
builtin_os
in
sys
.
modules
:
os_module
=
sys
.
modules
[
builtin_os
]
break
else
:
try
:
os_module
=
BuiltinImporter
.
load_module
(
builtin_os
)
# TODO: rip out os2 code after 3.3 is released as per PEP 11
if
builtin_os
==
'os2'
and
'EMX GCC'
in
sys
.
version
:
path_sep
=
'/'
break
except
ImportError
:
continue
else
:
raise
ImportError
(
'importlib requires posix or nt'
)
setattr
(
self_module
,
'_os'
,
os_module
)
setattr
(
self_module
,
'path_sep'
,
path_sep
)
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