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
16475adc
Commit
16475adc
authored
Apr 16, 2012
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #13959: Re-implement imp.load_source() in imp.py.
parent
4132368d
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
391 deletions
+28
-391
Lib/imp.py
Lib/imp.py
+28
-1
Python/import.c
Python/import.c
+0
-390
No files found.
Lib/imp.py
View file @
16475adc
...
...
@@ -14,7 +14,7 @@ from _imp import (lock_held, acquire_lock, release_lock, reload,
from
_imp
import
(
get_magic
,
get_tag
,
get_suffixes
,
cache_from_source
,
source_from_cache
)
# Should be re-implemented here (and mostly deprecated)
from
_imp
import
(
find_module
,
load_compiled
,
load_source
,
NullImporter
,
from
_imp
import
(
find_module
,
load_compiled
,
NullImporter
,
SEARCH_ERROR
,
PY_SOURCE
,
PY_COMPILED
,
C_EXTENSION
,
PY_RESOURCE
,
PKG_DIRECTORY
,
C_BUILTIN
,
PY_FROZEN
,
PY_CODERESOURCE
,
IMP_HOOK
)
...
...
@@ -25,6 +25,33 @@ from importlib import _bootstrap
import
os
class
_LoadSourceCompatibility
(
_bootstrap
.
_SourceFileLoader
):
"""Compatibility support for implementing load_source()."""
def
__init__
(
self
,
fullname
,
path
,
file
=
None
):
super
().
__init__
(
fullname
,
path
)
self
.
file
=
file
def
get_data
(
self
,
path
):
"""Gross hack to contort SourceFileLoader to deal w/ load_source()'s bad
API."""
if
path
==
self
.
_path
:
with
self
.
file
:
# Technically should be returning bytes, but
# SourceLoader.get_code() just passed what is returned to
# compile() which can handle str. And converting to bytes would
# require figuring out the encoding to decode to and
# tokenize.detect_encoding() only accepts bytes.
return
self
.
file
.
read
()
else
:
return
super
().
get_data
(
path
)
def
load_source
(
name
,
pathname
,
file
=
None
):
return
_LoadSourceCompatibility
(
name
,
pathname
,
file
).
load_module
(
name
)
def
load_package
(
name
,
path
):
if
os
.
path
.
isdir
(
path
):
extensions
=
_bootstrap
.
_suffix_list
(
PY_SOURCE
)
...
...
Python/import.c
View file @
16475adc
This diff is collapsed.
Click to expand it.
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