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
0bbbb005
Commit
0bbbb005
authored
Apr 28, 2006
by
Neal Norwitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some whitespace to be more consistent.
parent
076ba212
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
11 deletions
+13
-11
Lib/pkgutil.py
Lib/pkgutil.py
+13
-11
No files found.
Lib/pkgutil.py
View file @
0bbbb005
...
...
@@ -31,7 +31,7 @@ def read_code(stream):
def
simplegeneric
(
func
):
"""Make a trivial single-dispatch generic function"""
registry
=
{}
def
wrapper
(
*
args
,
**
kw
):
def
wrapper
(
*
args
,
**
kw
):
ob
=
args
[
0
]
try
:
cls
=
ob
.
__class__
...
...
@@ -41,18 +41,19 @@ def simplegeneric(func):
mro
=
cls
.
__mro__
except
AttributeError
:
try
:
class
cls
(
cls
,
object
):
pass
class
cls
(
cls
,
object
):
pass
mro
=
cls
.
__mro__
[
1
:]
except
TypeError
:
mro
=
object
,
# must be an ExtensionClass or some such :(
for
t
in
mro
:
if
t
in
registry
:
return
registry
[
t
](
*
args
,
**
kw
)
return
registry
[
t
](
*
args
,
**
kw
)
else
:
return
func
(
*
args
,
**
kw
)
return
func
(
*
args
,
**
kw
)
try
:
wrapper
.
__name__
=
func
.
__name__
except
(
TypeError
,
AttributeError
):
except
(
TypeError
,
AttributeError
):
pass
# Python 2.3 doesn't allow functions to be renamed
def
register
(
typ
,
func
=
None
):
...
...
@@ -70,8 +71,9 @@ def simplegeneric(func):
def
walk_packages
(
path
=
None
,
prefix
=
''
,
onerror
=
None
):
"""Yield submodule names+loaders recursively, for path or sys.path"""
def
seen
(
p
,
m
=
{}):
if
p
in
m
:
return
True
def
seen
(
p
,
m
=
{}):
if
p
in
m
:
return
True
m
[
p
]
=
True
for
importer
,
name
,
ispkg
in
iter_modules
(
path
,
prefix
):
...
...
@@ -110,7 +112,7 @@ def iter_modules(path=None, prefix=''):
#@simplegeneric
def
iter_importer_modules
(
importer
,
prefix
=
''
):
if
not
hasattr
(
importer
,
'iter_modules'
):
if
not
hasattr
(
importer
,
'iter_modules'
):
return
[]
return
importer
.
iter_modules
(
prefix
)
...
...
@@ -336,7 +338,7 @@ def get_importer(path_item):
pass
else
:
importer
=
None
sys
.
path_importer_cache
.
setdefault
(
path_item
,
importer
)
sys
.
path_importer_cache
.
setdefault
(
path_item
,
importer
)
if
importer
is
None
:
try
:
...
...
@@ -377,7 +379,7 @@ def iter_importers(fullname=""):
pkg
=
'.'
.
join
(
fullname
.
split
(
'.'
)[:
-
1
])
if
pkg
not
in
sys
.
modules
:
__import__
(
pkg
)
path
=
getattr
(
sys
.
modules
[
pkg
],
'__path__'
,
None
)
or
[]
path
=
getattr
(
sys
.
modules
[
pkg
],
'__path__'
,
None
)
or
[]
else
:
for
importer
in
sys
.
meta_path
:
yield
importer
...
...
@@ -404,7 +406,7 @@ def get_loader(module_or_name):
module_or_name
=
sys
.
modules
[
module_or_name
]
if
isinstance
(
module_or_name
,
ModuleType
):
module
=
module_or_name
loader
=
getattr
(
module
,
'__loader__'
,
None
)
loader
=
getattr
(
module
,
'__loader__'
,
None
)
if
loader
is
not
None
:
return
loader
fullname
=
module
.
__name__
...
...
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