Return the module specified by `module`. In particular: - If `module` is a module, then return module. - If `module` is a string, then import and return the module with that name. - If `module` is None, then return the calling module. The calling module is ass
(module, depth=2)
| 214 | return flags |
| 215 | |
| 216 | def _normalize_module(module, depth=2): |
| 217 | """ |
| 218 | Return the module specified by `module`. In particular: |
| 219 | - If `module` is a module, then return module. |
| 220 | - If `module` is a string, then import and return the |
| 221 | module with that name. |
| 222 | - If `module` is None, then return the calling module. |
| 223 | The calling module is assumed to be the module of |
| 224 | the stack frame at the given depth in the call stack. |
| 225 | """ |
| 226 | if inspect.ismodule(module): |
| 227 | return module |
| 228 | elif isinstance(module, str): |
| 229 | return __import__(module, globals(), locals(), ["*"]) |
| 230 | elif module is None: |
| 231 | try: |
| 232 | try: |
| 233 | return sys.modules[sys._getframemodulename(depth)] |
| 234 | except AttributeError: |
| 235 | return sys.modules[sys._getframe(depth).f_globals['__name__']] |
| 236 | except KeyError: |
| 237 | pass |
| 238 | else: |
| 239 | raise TypeError("Expected a module, string, or None") |
| 240 | |
| 241 | def _newline_convert(data): |
| 242 | # The IO module provides a handy decoder for universal newline conversion |
no test coverage detected