OLD | NEW |
1 :mod:`imp` --- Access the :keyword:`import` internals | 1 :mod:`imp` --- Access the :keyword:`import` internals |
2 ===================================================== | 2 ===================================================== |
3 | 3 |
4 .. module:: imp | 4 .. module:: imp |
5 :synopsis: Access the implementation of the import statement. | 5 :synopsis: Access the implementation of the import statement. |
6 | 6 |
7 | 7 |
8 .. index:: statement: import | 8 .. index:: statement: import |
9 | 9 |
10 This module provides an interface to the mechanisms used to implement the | 10 This module provides an interface to the mechanisms used to implement the |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 be used by import hooks to ensure thread-safety when importing modules. On | 197 be used by import hooks to ensure thread-safety when importing modules. On |
198 platforms without threads, this function does nothing. | 198 platforms without threads, this function does nothing. |
199 | 199 |
200 | 200 |
201 .. function:: release_lock() | 201 .. function:: release_lock() |
202 | 202 |
203 Release the interpreter's import lock. On platforms without threads, this | 203 Release the interpreter's import lock. On platforms without threads, this |
204 function does nothing. | 204 function does nothing. |
205 | 205 |
206 | 206 |
207 The following constants with integer values, defined in this module, are used to | 207 The following functions and data provide conveniences for handling :pep:`3147` |
208 indicate the search result of :func:`find_module`. | 208 byte-compiled file paths. |
| 209 |
| 210 .. versionadded:: 3.2 |
| 211 |
| 212 .. function:: cache_from_source(path, debug_override=None) |
| 213 |
| 214 Return the PEP 3147 path to the byte-compiled file associated with the |
| 215 source *path*. For example, if *path* is ``/foo/bar/baz.py`` the return |
| 216 value would be ``/foo/bar/__pycache__/baz.cpython-32.pyc`` for Python 3.2. |
| 217 The ``cpython-32`` string comes from the current magic tag (see |
| 218 :func:`get_tag`). The returned path will end in ``.pyc`` when |
| 219 ``__debug__`` is True or ``.pyo`` for an optimized Python |
| 220 (i.e. ``__debug__`` is False). By passing in True or False for |
| 221 *debug_override* you can override the system's value for ``__debug__`` for |
| 222 extension selection. |
| 223 |
| 224 *path* need not exist. |
| 225 |
| 226 .. function:: source_from_cache(path) |
| 227 |
| 228 Given the *path* to a PEP 3147 file name, return the associated source code |
| 229 file path. For example, if *path* is |
| 230 ``/foo/bar/__pycache__/baz.cpython-32.pyc`` the returned path would be |
| 231 ``/foo/bar/baz.py``. *path* need not exist, however if it does not conform |
| 232 to PEP 3147 format, a ``ValueError`` is raised. |
| 233 |
| 234 .. function:: get_tag() |
| 235 |
| 236 Return the PEP 3147 magic tag string matching this version of Python's |
| 237 magic number, as returned by :func:`get_magic`. |
| 238 |
| 239 |
| 240 The following constants with integer values, defined in this module, are used |
| 241 to indicate the search result of :func:`find_module`. |
209 | 242 |
210 | 243 |
211 .. data:: PY_SOURCE | 244 .. data:: PY_SOURCE |
212 | 245 |
213 The module was found as a source file. | 246 The module was found as a source file. |
214 | 247 |
215 | 248 |
216 .. data:: PY_COMPILED | 249 .. data:: PY_COMPILED |
217 | 250 |
218 The module was found as a compiled code object file. | 251 The module was found as a compiled code object file. |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 # Since we may exit via an exception, close fp explicitly. | 402 # Since we may exit via an exception, close fp explicitly. |
370 if fp: | 403 if fp: |
371 fp.close() | 404 fp.close() |
372 | 405 |
373 .. index:: module: knee | 406 .. index:: module: knee |
374 | 407 |
375 A more complete example that implements hierarchical module names and includes a | 408 A more complete example that implements hierarchical module names and includes a |
376 :func:`reload` function can be found in the module :mod:`knee`. The :mod:`knee` | 409 :func:`reload` function can be found in the module :mod:`knee`. The :mod:`knee` |
377 module can be found in :file:`Demo/imputil/` in the Python source distribution. | 410 module can be found in :file:`Demo/imputil/` in the Python source distribution. |
378 | 411 |
OLD | NEW |