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
1dae0c68
Commit
1dae0c68
authored
Sep 25, 2015
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #25186: Remove duplicated function from importlib._bootstrap_external
parent
b5bb6f3a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2502 additions
and
2523 deletions
+2502
-2523
Lib/importlib/_bootstrap_external.py
Lib/importlib/_bootstrap_external.py
+22
-26
Python/importlib_external.h
Python/importlib_external.h
+2480
-2497
No files found.
Lib/importlib/_bootstrap_external.py
View file @
1dae0c68
...
@@ -360,14 +360,6 @@ def _calc_mode(path):
...
@@ -360,14 +360,6 @@ def _calc_mode(path):
return
mode
return
mode
def
_verbose_message
(
message
,
*
args
,
verbosity
=
1
):
"""Print the message to stderr if -v/PYTHONVERBOSE is turned on."""
if
sys
.
flags
.
verbose
>=
verbosity
:
if
not
message
.
startswith
((
'#'
,
'import '
)):
message
=
'# '
+
message
print
(
message
.
format
(
*
args
),
file
=
sys
.
stderr
)
def
_check_name
(
method
):
def
_check_name
(
method
):
"""Decorator to verify that the module being requested matches the one the
"""Decorator to verify that the module being requested matches the one the
loader can handle.
loader can handle.
...
@@ -437,15 +429,15 @@ def _validate_bytecode_header(data, source_stats=None, name=None, path=None):
...
@@ -437,15 +429,15 @@ def _validate_bytecode_header(data, source_stats=None, name=None, path=None):
raw_size
=
data
[
8
:
12
]
raw_size
=
data
[
8
:
12
]
if
magic
!=
MAGIC_NUMBER
:
if
magic
!=
MAGIC_NUMBER
:
message
=
'bad magic number in {!r}: {!r}'
.
format
(
name
,
magic
)
message
=
'bad magic number in {!r}: {!r}'
.
format
(
name
,
magic
)
_verbose_message
(
message
)
_
bootstrap
.
_
verbose_message
(
message
)
raise
ImportError
(
message
,
**
exc_details
)
raise
ImportError
(
message
,
**
exc_details
)
elif
len
(
raw_timestamp
)
!=
4
:
elif
len
(
raw_timestamp
)
!=
4
:
message
=
'reached EOF while reading timestamp in {!r}'
.
format
(
name
)
message
=
'reached EOF while reading timestamp in {!r}'
.
format
(
name
)
_verbose_message
(
message
)
_
bootstrap
.
_
verbose_message
(
message
)
raise
EOFError
(
message
)
raise
EOFError
(
message
)
elif
len
(
raw_size
)
!=
4
:
elif
len
(
raw_size
)
!=
4
:
message
=
'reached EOF while reading size of source in {!r}'
.
format
(
name
)
message
=
'reached EOF while reading size of source in {!r}'
.
format
(
name
)
_verbose_message
(
message
)
_
bootstrap
.
_
verbose_message
(
message
)
raise
EOFError
(
message
)
raise
EOFError
(
message
)
if
source_stats
is
not
None
:
if
source_stats
is
not
None
:
try
:
try
:
...
@@ -455,7 +447,7 @@ def _validate_bytecode_header(data, source_stats=None, name=None, path=None):
...
@@ -455,7 +447,7 @@ def _validate_bytecode_header(data, source_stats=None, name=None, path=None):
else
:
else
:
if
_r_long
(
raw_timestamp
)
!=
source_mtime
:
if
_r_long
(
raw_timestamp
)
!=
source_mtime
:
message
=
'bytecode is stale for {!r}'
.
format
(
name
)
message
=
'bytecode is stale for {!r}'
.
format
(
name
)
_verbose_message
(
message
)
_
bootstrap
.
_
verbose_message
(
message
)
raise
ImportError
(
message
,
**
exc_details
)
raise
ImportError
(
message
,
**
exc_details
)
try
:
try
:
source_size
=
source_stats
[
'size'
]
&
0xFFFFFFFF
source_size
=
source_stats
[
'size'
]
&
0xFFFFFFFF
...
@@ -472,7 +464,7 @@ def _compile_bytecode(data, name=None, bytecode_path=None, source_path=None):
...
@@ -472,7 +464,7 @@ def _compile_bytecode(data, name=None, bytecode_path=None, source_path=None):
"""Compile bytecode as returned by _validate_bytecode_header()."""
"""Compile bytecode as returned by _validate_bytecode_header()."""
code
=
marshal
.
loads
(
data
)
code
=
marshal
.
loads
(
data
)
if
isinstance
(
code
,
_code_type
):
if
isinstance
(
code
,
_code_type
):
_verbose_message
(
'code object from {!r}'
,
bytecode_path
)
_
bootstrap
.
_
verbose_message
(
'code object from {!r}'
,
bytecode_path
)
if
source_path
is
not
None
:
if
source_path
is
not
None
:
_imp
.
_fix_co_filename
(
code
,
source_path
)
_imp
.
_fix_co_filename
(
code
,
source_path
)
return
code
return
code
...
@@ -755,21 +747,21 @@ class SourceLoader(_LoaderBasics):
...
@@ -755,21 +747,21 @@ class SourceLoader(_LoaderBasics):
except
(
ImportError
,
EOFError
):
except
(
ImportError
,
EOFError
):
pass
pass
else
:
else
:
_verbose_message
(
'{} matches {}'
,
bytecode_path
,
_
bootstrap
.
_
verbose_message
(
'{} matches {}'
,
bytecode_path
,
source_path
)
source_path
)
return
_compile_bytecode
(
bytes_data
,
name
=
fullname
,
return
_compile_bytecode
(
bytes_data
,
name
=
fullname
,
bytecode_path
=
bytecode_path
,
bytecode_path
=
bytecode_path
,
source_path
=
source_path
)
source_path
=
source_path
)
source_bytes
=
self
.
get_data
(
source_path
)
source_bytes
=
self
.
get_data
(
source_path
)
code_object
=
self
.
source_to_code
(
source_bytes
,
source_path
)
code_object
=
self
.
source_to_code
(
source_bytes
,
source_path
)
_verbose_message
(
'code object from {}'
,
source_path
)
_
bootstrap
.
_
verbose_message
(
'code object from {}'
,
source_path
)
if
(
not
sys
.
dont_write_bytecode
and
bytecode_path
is
not
None
and
if
(
not
sys
.
dont_write_bytecode
and
bytecode_path
is
not
None
and
source_mtime
is
not
None
):
source_mtime
is
not
None
):
data
=
_code_to_bytecode
(
code_object
,
source_mtime
,
data
=
_code_to_bytecode
(
code_object
,
source_mtime
,
len
(
source_bytes
))
len
(
source_bytes
))
try
:
try
:
self
.
_cache_bytecode
(
source_path
,
bytecode_path
,
data
)
self
.
_cache_bytecode
(
source_path
,
bytecode_path
,
data
)
_verbose_message
(
'wrote {!r}'
,
bytecode_path
)
_
bootstrap
.
_
verbose_message
(
'wrote {!r}'
,
bytecode_path
)
except
NotImplementedError
:
except
NotImplementedError
:
pass
pass
return
code_object
return
code_object
...
@@ -849,14 +841,16 @@ class SourceFileLoader(FileLoader, SourceLoader):
...
@@ -849,14 +841,16 @@ class SourceFileLoader(FileLoader, SourceLoader):
except
OSError
as
exc
:
except
OSError
as
exc
:
# Could be a permission error, read-only filesystem: just forget
# Could be a permission error, read-only filesystem: just forget
# about writing the data.
# about writing the data.
_verbose_message
(
'could not create {!r}: {!r}'
,
parent
,
exc
)
_bootstrap
.
_verbose_message
(
'could not create {!r}: {!r}'
,
parent
,
exc
)
return
return
try
:
try
:
_write_atomic
(
path
,
data
,
_mode
)
_write_atomic
(
path
,
data
,
_mode
)
_verbose_message
(
'created {!r}'
,
path
)
_
bootstrap
.
_
verbose_message
(
'created {!r}'
,
path
)
except
OSError
as
exc
:
except
OSError
as
exc
:
# Same as above: just don't write the bytecode.
# Same as above: just don't write the bytecode.
_verbose_message
(
'could not create {!r}: {!r}'
,
path
,
exc
)
_bootstrap
.
_verbose_message
(
'could not create {!r}: {!r}'
,
path
,
exc
)
class
SourcelessFileLoader
(
FileLoader
,
_LoaderBasics
):
class
SourcelessFileLoader
(
FileLoader
,
_LoaderBasics
):
...
@@ -901,14 +895,14 @@ class ExtensionFileLoader(FileLoader, _LoaderBasics):
...
@@ -901,14 +895,14 @@ class ExtensionFileLoader(FileLoader, _LoaderBasics):
"""Create an unitialized extension module"""
"""Create an unitialized extension module"""
module
=
_bootstrap
.
_call_with_frames_removed
(
module
=
_bootstrap
.
_call_with_frames_removed
(
_imp
.
create_dynamic
,
spec
)
_imp
.
create_dynamic
,
spec
)
_verbose_message
(
'extension module {!r} loaded from {!r}'
,
_
bootstrap
.
_
verbose_message
(
'extension module {!r} loaded from {!r}'
,
spec
.
name
,
self
.
path
)
spec
.
name
,
self
.
path
)
return
module
return
module
def
exec_module
(
self
,
module
):
def
exec_module
(
self
,
module
):
"""Initialize an extension module"""
"""Initialize an extension module"""
_bootstrap
.
_call_with_frames_removed
(
_imp
.
exec_dynamic
,
module
)
_bootstrap
.
_call_with_frames_removed
(
_imp
.
exec_dynamic
,
module
)
_verbose_message
(
'extension module {!r} executed from {!r}'
,
_
bootstrap
.
_
verbose_message
(
'extension module {!r} executed from {!r}'
,
self
.
name
,
self
.
path
)
self
.
name
,
self
.
path
)
def
is_package
(
self
,
fullname
):
def
is_package
(
self
,
fullname
):
...
@@ -1023,7 +1017,8 @@ class _NamespaceLoader:
...
@@ -1023,7 +1017,8 @@ class _NamespaceLoader:
"""
"""
# The import system never calls this method.
# The import system never calls this method.
_verbose_message
(
'namespace module loaded with path {!r}'
,
self
.
_path
)
_bootstrap
.
_verbose_message
(
'namespace module loaded with path {!r}'
,
self
.
_path
)
return
_bootstrap
.
_load_module_shim
(
self
,
fullname
)
return
_bootstrap
.
_load_module_shim
(
self
,
fullname
)
...
@@ -1243,12 +1238,13 @@ class FileFinder:
...
@@ -1243,12 +1238,13 @@ class FileFinder:
# Check for a file w/ a proper suffix exists.
# Check for a file w/ a proper suffix exists.
for
suffix
,
loader_class
in
self
.
_loaders
:
for
suffix
,
loader_class
in
self
.
_loaders
:
full_path
=
_path_join
(
self
.
path
,
tail_module
+
suffix
)
full_path
=
_path_join
(
self
.
path
,
tail_module
+
suffix
)
_
verbose_message
(
'trying {}'
.
format
(
full_path
)
,
verbosity
=
2
)
_
bootstrap
.
_verbose_message
(
'trying {}'
,
full_path
,
verbosity
=
2
)
if
cache_module
+
suffix
in
cache
:
if
cache_module
+
suffix
in
cache
:
if
_path_isfile
(
full_path
):
if
_path_isfile
(
full_path
):
return
self
.
_get_spec
(
loader_class
,
fullname
,
full_path
,
None
,
target
)
return
self
.
_get_spec
(
loader_class
,
fullname
,
full_path
,
None
,
target
)
if
is_namespace
:
if
is_namespace
:
_
verbose_message
(
'possible namespace for {}'
.
format
(
base_path
)
)
_
bootstrap
.
_verbose_message
(
'possible namespace for {}'
,
base_path
)
spec
=
_bootstrap
.
ModuleSpec
(
fullname
,
None
)
spec
=
_bootstrap
.
ModuleSpec
(
fullname
,
None
)
spec
.
submodule_search_locations
=
[
base_path
]
spec
.
submodule_search_locations
=
[
base_path
]
return
spec
return
spec
...
...
Python/importlib_external.h
View file @
1dae0c68
This source diff could not be displayed because it is too large. You can
view the blob
instead.
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