Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
17098a54
Kaydet (Commit)
17098a54
authored
May 04, 2012
tarafından
Brett Cannon
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Properly mark names in importlib._bootstrap as private.
üst
fbd85a0f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
37 deletions
+37
-37
imp.py
Lib/imp.py
+6
-6
_bootstrap.py
Lib/importlib/_bootstrap.py
+31
-31
No files found.
Lib/imp.py
Dosyayı görüntüle @
17098a54
...
...
@@ -15,8 +15,8 @@ from _imp import get_magic, get_tag
# Can (probably) move to importlib
from
_imp
import
get_suffixes
from
importlib._bootstrap
import
_new_module
as
new_module
from
importlib._bootstrap
import
_cache_from_source
as
cache_from_source
from
importlib._bootstrap
import
new_module
from
importlib._bootstrap
import
cache_from_source
from
importlib
import
_bootstrap
import
os
...
...
@@ -48,14 +48,14 @@ def source_from_cache(path):
"""
head
,
pycache_filename
=
os
.
path
.
split
(
path
)
head
,
pycache
=
os
.
path
.
split
(
head
)
if
pycache
!=
_bootstrap
.
PYCACHE
:
if
pycache
!=
_bootstrap
.
_
PYCACHE
:
raise
ValueError
(
'{} not bottom-level directory in '
'{!r}'
.
format
(
_bootstrap
.
PYCACHE
,
path
))
'{!r}'
.
format
(
_bootstrap
.
_
PYCACHE
,
path
))
if
pycache_filename
.
count
(
'.'
)
!=
2
:
raise
ValueError
(
'expected only 2 dots in '
'{!r}'
.
format
(
pycache_filename
))
base_filename
=
pycache_filename
.
partition
(
'.'
)[
0
]
return
os
.
path
.
join
(
head
,
base_filename
+
_bootstrap
.
SOURCE_SUFFIXES
[
0
])
return
os
.
path
.
join
(
head
,
base_filename
+
_bootstrap
.
_
SOURCE_SUFFIXES
[
0
])
class
NullImporter
:
...
...
@@ -185,7 +185,7 @@ def find_module(name, path=None):
for
entry
in
path
:
package_directory
=
os
.
path
.
join
(
entry
,
name
)
for
suffix
in
[
'.py'
,
_bootstrap
.
BYTECODE_SUFFIX
]:
for
suffix
in
[
'.py'
,
_bootstrap
.
_
BYTECODE_SUFFIX
]:
package_file_name
=
'__init__'
+
suffix
file_path
=
os
.
path
.
join
(
package_directory
,
package_file_name
)
if
os
.
path
.
isfile
(
file_path
):
...
...
Lib/importlib/_bootstrap.py
Dosyayı görüntüle @
17098a54
...
...
@@ -26,11 +26,11 @@ work. One should use importlib as the public-facing version of this module.
# Bootstrap-related code ######################################################
CASE_INSENSITIVE_PLATFORMS
=
'win'
,
'cygwin'
,
'darwin'
_
CASE_INSENSITIVE_PLATFORMS
=
'win'
,
'cygwin'
,
'darwin'
def
_make_relax_case
():
if
sys
.
platform
.
startswith
(
CASE_INSENSITIVE_PLATFORMS
):
if
sys
.
platform
.
startswith
(
_
CASE_INSENSITIVE_PLATFORMS
):
def
_relax_case
():
"""True if filenames must be checked case-insensitively."""
return
b
'PYTHONCASEOK'
in
_os
.
environ
...
...
@@ -179,10 +179,10 @@ def _wrap(new, old):
new
.
__dict__
.
update
(
old
.
__dict__
)
code_type
=
type
(
_wrap
.
__code__
)
_
code_type
=
type
(
_wrap
.
__code__
)
def
_
new_module
(
name
):
def
new_module
(
name
):
"""Create a new module.
The module is not entered into sys.modules.
...
...
@@ -193,15 +193,15 @@ def _new_module(name):
# Finder/loader utility code ##################################################
PYCACHE
=
'__pycache__'
_
PYCACHE
=
'__pycache__'
SOURCE_SUFFIXES
=
[
'.py'
]
# _setup() adds .pyw as needed.
_
SOURCE_SUFFIXES
=
[
'.py'
]
# _setup() adds .pyw as needed.
DEBUG_BYTECODE_SUFFIX
=
'.pyc'
OPT_BYTECODE_SUFFIX
=
'.pyo'
BYTECODE_SUFFIX
=
DEBUG_BYTECODE_SUFFIX
if
__debug__
else
OPT_BYTECODE_SUFFIX
_
DEBUG_BYTECODE_SUFFIX
=
'.pyc'
_
OPT_BYTECODE_SUFFIX
=
'.pyo'
_BYTECODE_SUFFIX
=
_DEBUG_BYTECODE_SUFFIX
if
__debug__
else
_
OPT_BYTECODE_SUFFIX
def
_
cache_from_source
(
path
,
debug_override
=
None
):
def
cache_from_source
(
path
,
debug_override
=
None
):
"""Given the path to a .py file, return the path to its .pyc/.pyo file.
The .py file does not need to exist; this simply returns the path to the
...
...
@@ -213,14 +213,14 @@ def _cache_from_source(path, debug_override=None):
"""
debug
=
__debug__
if
debug_override
is
None
else
debug_override
suffix
=
DEBUG_BYTECODE_SUFFIX
if
debug
else
OPT_BYTECODE_SUFFIX
suffix
=
_DEBUG_BYTECODE_SUFFIX
if
debug
else
_
OPT_BYTECODE_SUFFIX
head
,
tail
=
_path_split
(
path
)
base_filename
,
sep
,
_
=
tail
.
partition
(
'.'
)
filename
=
''
.
join
([
base_filename
,
sep
,
_TAG
,
suffix
])
return
_path_join
(
head
,
PYCACHE
,
filename
)
return
_path_join
(
head
,
_
PYCACHE
,
filename
)
def
verbose_message
(
message
,
*
args
):
def
_
verbose_message
(
message
,
*
args
):
"""Print the message to stderr if -v/PYTHONVERBOSE is turned on."""
if
sys
.
flags
.
verbose
:
if
not
message
.
startswith
((
'#'
,
'import '
)):
...
...
@@ -277,7 +277,7 @@ def module_for_loader(fxn):
# This must be done before open() is called as the 'io' module
# implicitly imports 'locale' and would otherwise trigger an
# infinite loop.
module
=
_
new_module
(
fullname
)
module
=
new_module
(
fullname
)
sys
.
modules
[
fullname
]
=
module
module
.
__loader__
=
self
try
:
...
...
@@ -472,11 +472,11 @@ class _LoaderBasics:
raise
ImportError
(
msg
,
name
=
fullname
,
path
=
bytecode_path
)
elif
len
(
raw_timestamp
)
!=
4
:
message
=
'bad timestamp in {}'
.
format
(
fullname
)
verbose_message
(
message
)
_
verbose_message
(
message
)
raise
EOFError
(
message
)
elif
len
(
raw_size
)
!=
4
:
message
=
'bad size in {}'
.
format
(
fullname
)
verbose_message
(
message
)
_
verbose_message
(
message
)
raise
EOFError
(
message
)
if
source_stats
is
not
None
:
try
:
...
...
@@ -486,7 +486,7 @@ class _LoaderBasics:
else
:
if
_r_long
(
raw_timestamp
)
!=
source_mtime
:
message
=
'bytecode is stale for {}'
.
format
(
fullname
)
verbose_message
(
message
)
_
verbose_message
(
message
)
raise
ImportError
(
message
,
name
=
fullname
,
path
=
bytecode_path
)
try
:
...
...
@@ -510,7 +510,7 @@ class _LoaderBasics:
code_object
=
self
.
get_code
(
name
)
module
.
__file__
=
self
.
get_filename
(
name
)
if
not
sourceless
:
module
.
__cached__
=
_
cache_from_source
(
module
.
__file__
)
module
.
__cached__
=
cache_from_source
(
module
.
__file__
)
else
:
module
.
__cached__
=
module
.
__file__
module
.
__package__
=
name
...
...
@@ -573,7 +573,7 @@ class SourceLoader(_LoaderBasics):
"""
source_path
=
self
.
get_filename
(
fullname
)
bytecode_path
=
_
cache_from_source
(
source_path
)
bytecode_path
=
cache_from_source
(
source_path
)
source_mtime
=
None
if
bytecode_path
is
not
None
:
try
:
...
...
@@ -594,12 +594,12 @@ class SourceLoader(_LoaderBasics):
except
(
ImportError
,
EOFError
):
pass
else
:
verbose_message
(
'{} matches {}'
,
bytecode_path
,
_
verbose_message
(
'{} matches {}'
,
bytecode_path
,
source_path
)
found
=
marshal
.
loads
(
bytes_data
)
if
isinstance
(
found
,
code_type
):
if
isinstance
(
found
,
_
code_type
):
_imp
.
_fix_co_filename
(
found
,
source_path
)
verbose_message
(
'code object from {}'
,
_
verbose_message
(
'code object from {}'
,
bytecode_path
)
return
found
else
:
...
...
@@ -609,7 +609,7 @@ class SourceLoader(_LoaderBasics):
source_bytes
=
self
.
get_data
(
source_path
)
code_object
=
compile
(
source_bytes
,
source_path
,
'exec'
,
dont_inherit
=
True
)
verbose_message
(
'code object from {}'
,
source_path
)
_
verbose_message
(
'code object from {}'
,
source_path
)
if
(
not
sys
.
dont_write_bytecode
and
bytecode_path
is
not
None
and
source_mtime
is
not
None
):
data
=
bytearray
(
_MAGIC_NUMBER
)
...
...
@@ -618,7 +618,7 @@ class SourceLoader(_LoaderBasics):
data
.
extend
(
marshal
.
dumps
(
code_object
))
try
:
self
.
set_data
(
bytecode_path
,
data
)
verbose_message
(
'wrote {!r}'
,
bytecode_path
)
_
verbose_message
(
'wrote {!r}'
,
bytecode_path
)
except
NotImplementedError
:
pass
return
code_object
...
...
@@ -687,7 +687,7 @@ class SourceFileLoader(FileLoader, SourceLoader):
return
try
:
_write_atomic
(
path
,
data
)
verbose_message
(
'created {!r}'
,
path
)
_
verbose_message
(
'created {!r}'
,
path
)
except
(
PermissionError
,
FileExistsError
):
# Don't worry if you can't write bytecode or someone is writing
# it at the same time.
...
...
@@ -706,8 +706,8 @@ class SourcelessFileLoader(FileLoader, _LoaderBasics):
data
=
self
.
get_data
(
path
)
bytes_data
=
self
.
_bytes_from_bytecode
(
fullname
,
data
,
path
,
None
)
found
=
marshal
.
loads
(
bytes_data
)
if
isinstance
(
found
,
code_type
):
verbose_message
(
'code object from {!r}'
,
path
)
if
isinstance
(
found
,
_
code_type
):
_
verbose_message
(
'code object from {!r}'
,
path
)
return
found
else
:
raise
ImportError
(
"Non-code object in {}"
.
format
(
path
),
...
...
@@ -738,7 +738,7 @@ class ExtensionFileLoader:
is_reload
=
fullname
in
sys
.
modules
try
:
module
=
_imp
.
load_dynamic
(
fullname
,
self
.
path
)
verbose_message
(
'extension module loaded from {!r}'
,
self
.
path
)
_
verbose_message
(
'extension module loaded from {!r}'
,
self
.
path
)
return
module
except
:
if
not
is_reload
and
fullname
in
sys
.
modules
:
...
...
@@ -908,7 +908,7 @@ class FileFinder:
new_name
=
name
lower_suffix_contents
.
add
(
new_name
)
self
.
_path_cache
=
lower_suffix_contents
if
sys
.
platform
.
startswith
(
CASE_INSENSITIVE_PLATFORMS
):
if
sys
.
platform
.
startswith
(
_
CASE_INSENSITIVE_PLATFORMS
):
self
.
_relaxed_path_cache
=
set
(
fn
.
lower
()
for
fn
in
contents
)
@classmethod
...
...
@@ -1013,7 +1013,7 @@ def _find_and_load(name, import_):
elif
name
not
in
sys
.
modules
:
# The parent import may have already imported this module.
loader
.
load_module
(
name
)
verbose_message
(
'import {!r} # {!r}'
,
name
,
loader
)
_
verbose_message
(
'import {!r} # {!r}'
,
name
,
loader
)
# Backwards-compatibility; be nicer to skip the dict lookup.
module
=
sys
.
modules
[
name
]
if
parent
:
...
...
@@ -1185,7 +1185,7 @@ def _setup(sys_module, _imp_module):
setattr
(
self_module
,
'_MAGIC_NUMBER'
,
_imp_module
.
get_magic
())
setattr
(
self_module
,
'_TAG'
,
_imp
.
get_tag
())
if
builtin_os
==
'nt'
:
SOURCE_SUFFIXES
.
append
(
'.pyw'
)
_
SOURCE_SUFFIXES
.
append
(
'.pyw'
)
def
_install
(
sys_module
,
_imp_module
):
...
...
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