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
f87e04d3
Kaydet (Commit)
f87e04d3
authored
Mar 12, 2009
tarafından
Brett Cannon
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Finish properly hiding importlib implementation code.
üst
e9103d26
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
43 additions
and
55 deletions
+43
-55
NOTES
Lib/importlib/NOTES
+0
-9
__init__.py
Lib/importlib/__init__.py
+0
-4
_bootstrap.py
Lib/importlib/_bootstrap.py
+9
-14
test_case_sensitivity.py
Lib/importlib/test/extension/test_case_sensitivity.py
+2
-2
test_finder.py
Lib/importlib/test/extension/test_finder.py
+2
-2
test_loader.py
Lib/importlib/test/extension/test_loader.py
+3
-3
test_path_hook.py
Lib/importlib/test/extension/test_path_hook.py
+2
-2
test_case_sensitivity.py
Lib/importlib/test/source/test_case_sensitivity.py
+2
-2
test_file_loader.py
Lib/importlib/test/source/test_file_loader.py
+15
-9
test_finder.py
Lib/importlib/test/source/test_finder.py
+2
-2
test_path_hook.py
Lib/importlib/test/source/test_path_hook.py
+2
-2
test_source_encoding.py
Lib/importlib/test/source/test_source_encoding.py
+4
-4
No files found.
Lib/importlib/NOTES
Dosyayı görüntüle @
f87e04d3
...
...
@@ -7,15 +7,6 @@ to do
+ Expose function to see if a frozen module is a package.
* Remove ``import *`` from importlib.__init__.
* Remove __all__ from importlib._bootstrap.
* Add leading underscores to all objects in importlib._bootstrap that are not
publicly exposed.
* Reorder importlib/_bootstrap.py so definitions are not in inverted order.
* Make sure that there is documentation *somewhere* fully explaining the
semantics of import that can be referenced from the package's documentation
(even if it is in the package documentation itself, although it might be best
...
...
Lib/importlib/__init__.py
Dosyayı görüntüle @
f87e04d3
...
...
@@ -136,7 +136,3 @@ def import_module(name, package=None):
break
level
+=
1
return
_bootstrap
.
_gcd_import
(
name
[
level
:],
package
,
level
)
# XXX This should go away once the public API is done.
from
._bootstrap
import
*
Lib/importlib/_bootstrap.py
Dosyayı görüntüle @
f87e04d3
...
...
@@ -387,7 +387,7 @@ class PyPycLoader(PyLoader):
return
code_object
class
PyFileLoader
(
PyLoader
):
class
_
PyFileLoader
(
PyLoader
):
"""Load a Python source file."""
...
...
@@ -452,7 +452,7 @@ class PyFileLoader(PyLoader):
return
self
.
_is_pkg
class
PyPycFileLoader
(
PyPycLoader
,
PyFileLoader
):
class
_PyPycFileLoader
(
PyPycLoader
,
_
PyFileLoader
):
"""Load a module from a source or bytecode file."""
...
...
@@ -626,7 +626,7 @@ class _ChainedFinder:
return
None
class
FileFinder
:
class
_
FileFinder
:
"""Base class for file finders.
...
...
@@ -685,12 +685,12 @@ class FileFinder:
return
None
class
PyFileFinder
(
FileFinder
):
class
_PyFileFinder
(
_
FileFinder
):
"""Importer for source/bytecode files."""
_possible_package
=
True
_loader
=
PyFileLoader
_loader
=
_
PyFileLoader
def
__init__
(
self
,
path_entry
):
# Lack of imp during class creation means _suffixes is set here.
...
...
@@ -700,11 +700,11 @@ class PyFileFinder(FileFinder):
super
()
.
__init__
(
path_entry
)
class
PyPycFileFinder
(
PyFileFinder
):
class
_PyPycFileFinder
(
_
PyFileFinder
):
"""Finder for source and bytecode files."""
_loader
=
PyPycFileLoader
_loader
=
_
PyPycFileLoader
def
__init__
(
self
,
path_entry
):
super
()
.
__init__
(
path_entry
)
...
...
@@ -713,7 +713,7 @@ class PyPycFileFinder(PyFileFinder):
class
ExtensionFileFinder
(
FileFinder
):
class
_ExtensionFileFinder
(
_
FileFinder
):
"""Importer for extension files."""
...
...
@@ -750,7 +750,7 @@ def _chained_path_hook(*path_hooks):
return
path_hook
_DEFAULT_PATH_HOOK
=
_chained_path_hook
(
ExtensionFileFinder
,
PyPycFileFinder
)
_DEFAULT_PATH_HOOK
=
_chained_path_hook
(
_ExtensionFileFinder
,
_
PyPycFileFinder
)
class
_DefaultPathFinder
(
PathFinder
):
...
...
@@ -902,8 +902,3 @@ def _import(name, globals={}, locals={}, fromlist=[], level=0):
except
ImportError
:
pass
return
module
# XXX Eventually replace with a proper __all__ value (i.e., don't expose os
# replacements but do expose _ExtensionFileLoader, etc. for testing).
__all__
=
[
obj
for
obj
in
globals
()
.
keys
()
if
not
obj
.
startswith
(
'__'
)]
Lib/importlib/test/extension/test_case_sensitivity.py
Dosyayı görüntüle @
f87e04d3
import
sys
from
test
import
support
import
unittest
import
importlib
from
importlib
import
_bootstrap
from
..
import
util
from
.
import
util
as
ext_util
...
...
@@ -13,7 +13,7 @@ class ExtensionModuleCaseSensitivityTest(unittest.TestCase):
good_name
=
ext_util
.
NAME
bad_name
=
good_name
.
upper
()
assert
good_name
!=
bad_name
finder
=
importlib
.
ExtensionFileFinder
(
ext_util
.
PATH
)
finder
=
_bootstrap
.
_
ExtensionFileFinder
(
ext_util
.
PATH
)
return
finder
.
find_module
(
bad_name
)
def
test_case_sensitive
(
self
):
...
...
Lib/importlib/test/extension/test_finder.py
Dosyayı görüntüle @
f87e04d3
import
importlib
from
importlib
import
_bootstrap
from
..
import
abc
from
.
import
util
...
...
@@ -9,7 +9,7 @@ class FinderTests(abc.FinderTests):
"""Test the finder for extension modules."""
def
find_module
(
self
,
fullname
):
importer
=
importlib
.
ExtensionFileFinder
(
util
.
PATH
)
importer
=
_bootstrap
.
_
ExtensionFileFinder
(
util
.
PATH
)
return
importer
.
find_module
(
fullname
)
def
test_module
(
self
):
...
...
Lib/importlib/test/extension/test_loader.py
Dosyayı görüntüle @
f87e04d3
import
importlib
from
importlib
import
_bootstrap
from
.
import
util
as
ext_util
from
..
import
abc
from
..
import
util
...
...
@@ -12,7 +12,7 @@ class LoaderTests(abc.LoaderTests):
"""Test load_module() for extension modules."""
def
load_module
(
self
,
fullname
):
loader
=
importlib
.
_ExtensionFileLoader
(
ext_util
.
NAME
,
loader
=
_bootstrap
.
_ExtensionFileLoader
(
ext_util
.
NAME
,
ext_util
.
FILEPATH
,
False
)
return
loader
.
load_module
(
fullname
)
...
...
@@ -25,7 +25,7 @@ class LoaderTests(abc.LoaderTests):
self
.
assertEqual
(
getattr
(
module
,
attr
),
value
)
self
.
assert_
(
ext_util
.
NAME
in
sys
.
modules
)
self
.
assert_
(
isinstance
(
module
.
__loader__
,
importlib
.
_ExtensionFileLoader
))
_bootstrap
.
_ExtensionFileLoader
))
def
test_package
(
self
):
# Extensions are not found in packages.
...
...
Lib/importlib/test/extension/test_path_hook.py
Dosyayı görüntüle @
f87e04d3
import
importlib
from
importlib
import
_bootstrap
from
.
import
util
import
collections
...
...
@@ -14,7 +14,7 @@ class PathHookTests(unittest.TestCase):
# XXX Should it only work for directories containing an extension module?
def
hook
(
self
,
entry
):
return
importlib
.
ExtensionFileFinder
(
entry
)
return
_bootstrap
.
_
ExtensionFileFinder
(
entry
)
def
test_success
(
self
):
# Path hook should handle a directory where a known extension module
...
...
Lib/importlib/test/source/test_case_sensitivity.py
Dosyayı görüntüle @
f87e04d3
"""Test case-sensitivity (PEP 235)."""
import
importlib
from
importlib
import
_bootstrap
from
..
import
util
from
.
import
util
as
source_util
import
os
...
...
@@ -19,7 +19,7 @@ class CaseSensitivityTest(unittest.TestCase):
assert
name
!=
name
.
lower
()
def
find
(
self
,
path
):
finder
=
importlib
.
PyPycFileFinder
(
path
)
finder
=
_bootstrap
.
_
PyPycFileFinder
(
path
)
return
finder
.
find_module
(
self
.
name
)
def
sensitivity_test
(
self
):
...
...
Lib/importlib/test/source/test_file_loader.py
Dosyayı görüntüle @
f87e04d3
import
importlib
from
importlib
import
_bootstrap
from
..
import
abc
from
.
import
util
as
source_util
...
...
@@ -19,7 +20,8 @@ class SimpleTest(unittest.TestCase):
# [basic]
def
test_module
(
self
):
with
source_util
.
create_modules
(
'_temp'
)
as
mapping
:
loader
=
importlib
.
PyPycFileLoader
(
'_temp'
,
mapping
[
'_temp'
],
False
)
loader
=
_bootstrap
.
_PyPycFileLoader
(
'_temp'
,
mapping
[
'_temp'
],
False
)
module
=
loader
.
load_module
(
'_temp'
)
self
.
assert_
(
'_temp'
in
sys
.
modules
)
check
=
{
'__name__'
:
'_temp'
,
'__file__'
:
mapping
[
'_temp'
],
...
...
@@ -29,8 +31,9 @@ class SimpleTest(unittest.TestCase):
def
test_package
(
self
):
with
source_util
.
create_modules
(
'_pkg.__init__'
)
as
mapping
:
loader
=
importlib
.
PyPycFileLoader
(
'_pkg'
,
mapping
[
'_pkg.__init__'
],
True
)
loader
=
_bootstrap
.
_PyPycFileLoader
(
'_pkg'
,
mapping
[
'_pkg.__init__'
],
True
)
module
=
loader
.
load_module
(
'_pkg'
)
self
.
assert_
(
'_pkg'
in
sys
.
modules
)
check
=
{
'__name__'
:
'_pkg'
,
'__file__'
:
mapping
[
'_pkg.__init__'
],
...
...
@@ -42,8 +45,8 @@ class SimpleTest(unittest.TestCase):
def
test_lacking_parent
(
self
):
with
source_util
.
create_modules
(
'_pkg.__init__'
,
'_pkg.mod'
)
as
mapping
:
loader
=
importlib
.
PyPycFileLoader
(
'_pkg.mod'
,
mapping
[
'_pkg.mod'
]
,
False
)
loader
=
_bootstrap
.
_PyPycFileLoader
(
'_pkg.mod'
,
mapping
[
'_pkg.mod'
],
False
)
module
=
loader
.
load_module
(
'_pkg.mod'
)
self
.
assert_
(
'_pkg.mod'
in
sys
.
modules
)
check
=
{
'__name__'
:
'_pkg.mod'
,
'__file__'
:
mapping
[
'_pkg.mod'
],
...
...
@@ -57,7 +60,8 @@ class SimpleTest(unittest.TestCase):
def
test_module_reuse
(
self
):
with
source_util
.
create_modules
(
'_temp'
)
as
mapping
:
loader
=
importlib
.
PyPycFileLoader
(
'_temp'
,
mapping
[
'_temp'
],
False
)
loader
=
_bootstrap
.
_PyPycFileLoader
(
'_temp'
,
mapping
[
'_temp'
],
False
)
module
=
loader
.
load_module
(
'_temp'
)
module_id
=
id
(
module
)
module_dict_id
=
id
(
module
.
__dict__
)
...
...
@@ -87,7 +91,8 @@ class SimpleTest(unittest.TestCase):
setattr
(
orig_module
,
attr
,
value
)
with
open
(
mapping
[
name
],
'w'
)
as
file
:
file
.
write
(
'+++ bad syntax +++'
)
loader
=
importlib
.
PyPycFileLoader
(
'_temp'
,
mapping
[
'_temp'
],
False
)
loader
=
_bootstrap
.
_PyPycFileLoader
(
'_temp'
,
mapping
[
'_temp'
],
False
)
self
.
assertRaises
(
SyntaxError
,
loader
.
load_module
,
name
)
for
attr
in
attributes
:
self
.
assertEqual
(
getattr
(
orig_module
,
attr
),
value
)
...
...
@@ -97,7 +102,8 @@ class SimpleTest(unittest.TestCase):
with
source_util
.
create_modules
(
'_temp'
)
as
mapping
:
with
open
(
mapping
[
'_temp'
],
'w'
)
as
file
:
file
.
write
(
'='
)
loader
=
importlib
.
PyPycFileLoader
(
'_temp'
,
mapping
[
'_temp'
],
False
)
loader
=
_bootstrap
.
_PyPycFileLoader
(
'_temp'
,
mapping
[
'_temp'
],
False
)
self
.
assertRaises
(
SyntaxError
,
loader
.
load_module
,
'_temp'
)
self
.
assert_
(
'_temp'
not
in
sys
.
modules
)
...
...
@@ -116,7 +122,7 @@ class BadBytecodeTest(unittest.TestCase):
"""
def
import_
(
self
,
file
,
module_name
):
loader
=
importlib
.
PyPycFileLoader
(
module_name
,
file
,
False
)
loader
=
_bootstrap
.
_
PyPycFileLoader
(
module_name
,
file
,
False
)
module
=
loader
.
load_module
(
module_name
)
self
.
assert_
(
module_name
in
sys
.
modules
)
...
...
Lib/importlib/test/source/test_finder.py
Dosyayı görüntüle @
f87e04d3
import
importlib
from
importlib
import
_bootstrap
from
..
import
abc
from
.
import
util
as
source_util
import
os
...
...
@@ -32,7 +32,7 @@ class FinderTests(abc.FinderTests):
"""
def
import_
(
self
,
root
,
module
):
finder
=
importlib
.
PyPycFileFinder
(
root
)
finder
=
_bootstrap
.
_
PyPycFileFinder
(
root
)
return
finder
.
find_module
(
module
)
def
run_test
(
self
,
test
,
create
=
None
,
*
,
compile_
=
None
,
unlink
=
None
):
...
...
Lib/importlib/test/source/test_path_hook.py
Dosyayı görüntüle @
f87e04d3
import
importlib
from
importlib
import
_bootstrap
from
.
import
util
as
source_util
import
unittest
...
...
@@ -10,7 +10,7 @@ class PathHookTest(unittest.TestCase):
def
test_success
(
self
):
# XXX Only work on existing directories?
with
source_util
.
create_modules
(
'dummy'
)
as
mapping
:
self
.
assert_
(
hasattr
(
importlib
.
FileFinder
(
mapping
[
'.root'
]),
self
.
assert_
(
hasattr
(
_bootstrap
.
_
FileFinder
(
mapping
[
'.root'
]),
'find_module'
))
...
...
Lib/importlib/test/source/test_source_encoding.py
Dosyayı görüntüle @
f87e04d3
import
importlib
from
importlib
import
_bootstrap
from
.
import
util
as
source_util
import
codecs
...
...
@@ -35,7 +35,7 @@ class EncodingTest(unittest.TestCase):
with
source_util
.
create_modules
(
self
.
module_name
)
as
mapping
:
with
open
(
mapping
[
self
.
module_name
],
'wb'
)
as
file
:
file
.
write
(
source
)
loader
=
importlib
.
PyPycFileLoader
(
self
.
module_name
,
loader
=
_bootstrap
.
_
PyPycFileLoader
(
self
.
module_name
,
mapping
[
self
.
module_name
],
False
)
return
loader
.
load_module
(
self
.
module_name
)
...
...
@@ -96,8 +96,8 @@ class LineEndingTest(unittest.TestCase):
with
source_util
.
create_modules
(
module_name
)
as
mapping
:
with
open
(
mapping
[
module_name
],
'wb'
)
as
file
:
file
.
write
(
source
)
loader
=
importlib
.
PyPycFileLoader
(
module_name
,
mapping
[
module_name
]
,
False
)
loader
=
_bootstrap
.
_PyPycFileLoader
(
module_name
,
mapping
[
module_name
],
False
)
return
loader
.
load_module
(
module_name
)
# [cr]
...
...
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