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
501d0bb7
Kaydet (Commit)
501d0bb7
authored
Eyl 09, 1997
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
*** empty log message ***
üst
a86f77d4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
115 additions
and
0 deletions
+115
-0
knee.py
Lib/knee.py
+115
-0
No files found.
Lib/knee.py
0 → 100644
Dosyayı görüntüle @
501d0bb7
# More structured (slower) alternative to mini
import
sys
,
imp
,
__builtin__
,
string
# Replacement for __import__()
def
import_hook
(
name
,
globals
=
None
,
locals
=
None
,
fromlist
=
None
):
parent
=
determine_parent
(
globals
)
q
,
tail
=
find_head_package
(
parent
,
name
)
m
=
load_tail
(
q
,
tail
)
if
not
fromlist
:
return
q
if
hasattr
(
m
,
"__path__"
):
ensure_fromlist
(
m
,
fromlist
)
return
m
def
determine_parent
(
globals
):
if
not
globals
or
not
globals
.
has_key
(
"__name__"
):
return
None
pname
=
globals
[
'__name__'
]
if
globals
.
has_key
(
"__path__"
):
parent
=
sys
.
modules
[
pname
]
assert
globals
is
parent
.
__dict__
return
parent
if
'.'
in
pname
:
i
=
string
.
rfind
(
pname
,
'.'
)
pname
=
pname
[:
i
]
parent
=
sys
.
modules
[
pname
]
assert
parent
.
__name__
==
pname
return
parent
return
None
def
find_head_package
(
parent
,
name
):
if
'.'
in
name
:
i
=
string
.
find
(
name
,
'.'
)
head
=
name
[:
i
]
tail
=
name
[
i
+
1
:]
else
:
head
=
name
tail
=
""
if
parent
:
qname
=
"
%
s.
%
s"
%
(
parent
.
__name__
,
head
)
else
:
qname
=
head
q
=
import_module
(
head
,
qname
,
parent
)
if
q
:
return
q
,
tail
if
parent
:
qname
=
head
parent
=
None
q
=
import_module
(
head
,
qname
,
parent
)
if
q
:
return
q
,
tail
raise
ImportError
,
"No module named "
+
qname
def
load_tail
(
q
,
tail
):
m
=
q
while
tail
:
i
=
string
.
find
(
tail
,
'.'
)
if
i
<
0
:
i
=
len
(
tail
)
head
,
tail
=
tail
[:
i
],
tail
[
i
+
1
:]
mname
=
"
%
s.
%
s"
%
(
m
.
__name__
,
head
)
m
=
import_module
(
head
,
mname
,
m
)
if
not
m
:
raise
ImportError
,
"No module named "
+
mname
return
m
def
ensure_fromlist
(
m
,
fromlist
):
for
sub
in
fromlist
:
if
sub
!=
"*"
and
not
hasattr
(
m
,
sub
):
subname
=
"
%
s.
%
s"
%
(
m
.
__name__
,
sub
)
submod
=
import_module
(
sub
,
subname
,
m
)
## if not submod:
## raise ImportError, "No module named " + subname
def
import_module
(
partname
,
fqname
,
parent
):
try
:
return
sys
.
modules
[
fqname
]
except
KeyError
:
pass
try
:
fp
,
pathname
,
stuff
=
imp
.
find_module
(
partname
,
parent
and
parent
.
__path__
)
except
ImportError
:
return
None
try
:
m
=
imp
.
load_module
(
fqname
,
fp
,
pathname
,
stuff
)
finally
:
if
fp
:
fp
.
close
()
if
parent
:
setattr
(
parent
,
partname
,
m
)
return
m
# Replacement for reload()
def
reload_hook
(
module
):
name
=
module
.
__name__
if
'.'
not
in
name
:
return
import_module
(
name
,
name
,
None
)
i
=
string
.
rfind
(
name
,
'.'
)
pname
=
name
[:
i
]
parent
=
sys
.
modules
[
pname
]
return
import_module
(
name
[
i
+
1
:],
name
,
parent
)
# Save the original hooks
original_import
=
__builtin__
.
__import__
original_reload
=
__builtin__
.
reload
# Now install our hooks
__builtin__
.
__import__
=
import_hook
__builtin__
.
reload
=
reload_hook
# pretend we're ni, too
sys
.
modules
[
'ni'
]
=
sys
.
modules
[
__name__
]
def
ni
():
pass
def
install
():
pass
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