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
(module, depth=2)
| 193 | return flags |
| 194 | |
| 195 | def _normalize_module(module, depth=2): |
| 196 | """ |
| 197 | Return the module specified by `module`. In particular: |
| 198 | - If `module` is a module, then return module. |
| 199 | - If `module` is a string, then import and return the |
| 200 | module with that name. |
| 201 | - If `module` is None, then return the calling module. |
| 202 | The calling module is assumed to be the module of |
| 203 | the stack frame at the given depth in the call stack. |
| 204 | """ |
| 205 | if inspect.ismodule(module): |
| 206 | return module |
| 207 | elif isinstance(module, str): |
| 208 | return __import__(module, globals(), locals(), ["*"]) |
| 209 | elif module is None: |
| 210 | return sys.modules[sys._getframe(depth).f_globals['__name__']] |
| 211 | else: |
| 212 | raise TypeError("Expected a module, string, or None") |
| 213 | |
| 214 | def _newline_convert(data): |
| 215 | # The IO module provides a handy decoder for universal newline conversion |
no test coverage detected