(self, prefix='')
| 226 | return ImpLoader(fullname, file, filename, etc) |
| 227 | |
| 228 | def iter_modules(self, prefix=''): |
| 229 | if self.path is None or not os.path.isdir(self.path): |
| 230 | return |
| 231 | |
| 232 | yielded = {} |
| 233 | import inspect |
| 234 | try: |
| 235 | filenames = os.listdir(self.path) |
| 236 | except OSError: |
| 237 | # ignore unreadable directories like import does |
| 238 | filenames = [] |
| 239 | filenames.sort() # handle packages before same-named modules |
| 240 | |
| 241 | for fn in filenames: |
| 242 | modname = inspect.getmodulename(fn) |
| 243 | if modname=='__init__' or modname in yielded: |
| 244 | continue |
| 245 | |
| 246 | path = os.path.join(self.path, fn) |
| 247 | ispkg = False |
| 248 | |
| 249 | if not modname and os.path.isdir(path) and '.' not in fn: |
| 250 | modname = fn |
| 251 | try: |
| 252 | dircontents = os.listdir(path) |
| 253 | except OSError: |
| 254 | # ignore unreadable directories like import does |
| 255 | dircontents = [] |
| 256 | for fn in dircontents: |
| 257 | subname = inspect.getmodulename(fn) |
| 258 | if subname=='__init__': |
| 259 | ispkg = True |
| 260 | break |
| 261 | else: |
| 262 | continue # not a package |
| 263 | |
| 264 | if modname and '.' not in modname: |
| 265 | yielded[modname] = 1 |
| 266 | yield prefix + modname, ispkg |
| 267 | |
| 268 | |
| 269 | class ImpLoader: |
no test coverage detected