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
7a840e8d
Commit
7a840e8d
authored
Oct 12, 1998
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for dotted module names to readmodule().
parent
1c5fb1cd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
18 deletions
+26
-18
Lib/pyclbr.py
Lib/pyclbr.py
+26
-18
No files found.
Lib/pyclbr.py
View file @
7a840e8d
...
...
@@ -65,13 +65,22 @@ class Class:
def
_addmethod
(
self
,
name
,
lineno
):
self
.
methods
[
name
]
=
lineno
def
readmodule
(
module
,
path
=
[]
):
def
readmodule
(
module
,
path
=
[],
inpackage
=
0
):
'''Read a module file and return a dictionary of classes.
Search for MODULE in PATH and sys.path, read and parse the
module and return a dictionary with one entry for each class
found in the module.'''
i
=
string
.
rfind
(
module
,
'.'
)
if
i
>=
0
:
# Dotted module name
package
=
module
[:
i
]
submodule
=
module
[
i
+
1
:]
parent
=
readmodule
(
package
,
path
,
inpackage
)
child
=
readmodule
(
submodule
,
parent
[
'__path__'
],
1
)
return
child
if
_modules
.
has_key
(
module
):
# we've seen this module before...
return
_modules
[
module
]
...
...
@@ -83,21 +92,20 @@ def readmodule(module, path = []):
# search the path for the module
f
=
None
suffixes
=
imp
.
get_suffixes
()
for
dir
in
path
+
sys
.
path
:
for
suff
,
mode
,
type
in
suffixes
:
file
=
os
.
path
.
join
(
dir
,
module
+
suff
)
try
:
f
=
open
(
file
,
mode
)
except
IOError
:
pass
else
:
# found the module
break
if
f
:
break
if
not
f
:
raise
IOError
,
'module '
+
module
+
' not found'
if
inpackage
:
try
:
f
,
file
,
(
suff
,
mode
,
type
)
=
\
imp
.
find_module
(
module
,
path
)
except
ImportError
:
f
=
None
if
f
is
None
:
fullpath
=
path
+
sys
.
path
f
,
file
,
(
suff
,
mode
,
type
)
=
imp
.
find_module
(
module
,
fullpath
)
if
type
==
imp
.
PKG_DIRECTORY
:
dict
=
{
'__path__'
:
[
file
]}
_modules
[
module
]
=
dict
# XXX Should we recursively look for submodules?
return
dict
if
type
!=
imp
.
PY_SOURCE
:
# not Python source, can't do anything with this module
f
.
close
()
...
...
@@ -130,7 +138,7 @@ def readmodule(module, path = []):
try
:
# recursively read the
# imported module
d
=
readmodule
(
n
,
path
)
d
=
readmodule
(
n
,
path
,
inpackage
)
except
:
print
'module'
,
n
,
'not found'
pass
...
...
@@ -142,7 +150,7 @@ def readmodule(module, path = []):
names
=
string
.
splitfields
(
res
.
group
(
'imp'
),
','
)
try
:
# recursively read the imported module
d
=
readmodule
(
mod
,
path
)
d
=
readmodule
(
mod
,
path
,
inpackage
)
except
:
print
'module'
,
mod
,
'not found'
continue
...
...
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