• Home
  • Raw
  • Download

Lines Matching +full:module +full:- +full:importer

2 /* Module definition and import implementation */
6 #include "Python-ast.h"
39 -U interpeter flag will cause MAGIC+1 being used. They have been
64 Python 2.5a0: 62081 (ast-branch)
97 /* these tables define the module suffixes that Python recognizes */
122 * "e:\\shared\\" and "\\\\whiterab-c2znlh\\shared" as dirs. in isdir()
160 for (scan = _PyImport_DynLoadFiletab; scan->suffix != NULL; ++scan) in _PyImport_Init()
163 for (scan = _PyImport_StandardFiletab; scan->suffix != NULL; ++scan) in _PyImport_Init()
180 for (; filetab->suffix != NULL; filetab++) { in _PyImport_Init()
182 if (strcmp(filetab->suffix, ".pyc") == 0) in _PyImport_Init()
183 filetab->suffix = ".pyo"; in _PyImport_Init()
185 if (strcmp(filetab->suffix, "/pyc") == 0) in _PyImport_Init()
186 filetab->suffix = "/pyo"; in _PyImport_Init()
193 using the all-Unicode method doesn't interfere with in _PyImport_Init()
241 PyErr_Clear(); /* No zip import module -- okay */ in _PyImportHooks_Init()
250 PyErr_Clear(); /* No zipimporter object -- okay */ in _PyImportHooks_Init()
279 /* Locking primitives to prevent parallel imports of the same module
280 in different threads to return with a partially loaded module.
288 static long import_lock_thread = -1;
295 if (me == -1) in _PyImport_AcquireLock()
306 if (import_lock_thread != -1 || !PyThread_acquire_lock(import_lock, 0)) in _PyImport_AcquireLock()
320 if (me == -1 || import_lock == NULL) in _PyImport_ReleaseLock()
323 return -1; in _PyImport_ReleaseLock()
324 import_lock_level--; in _PyImport_ReleaseLock()
326 import_lock_thread = -1; in _PyImport_ReleaseLock()
346 import_lock_thread = -1; in _PyImport_ReInitLock()
356 return PyBool_FromLong(import_lock_thread != -1); in imp_lock_held()
389 PyInterpreterState *interp = PyThreadState_Get()->interp; in imp_modules_reloading_clear()
390 if (interp->modules_reloading != NULL) in imp_modules_reloading_clear()
391 PyDict_Clear(interp->modules_reloading); in imp_modules_reloading_clear()
399 PyInterpreterState *interp = PyThreadState_GET()->interp; in PyImport_GetModuleDict()
400 if (interp->modules == NULL) in PyImport_GetModuleDict()
401 Py_FatalError("PyImport_GetModuleDict: no module dictionary!"); in PyImport_GetModuleDict()
402 return interp->modules; in PyImport_GetModuleDict()
425 /* Un-initialize things, as good as we can */
433 PyInterpreterState *interp = PyThreadState_GET()->interp; in PyImport_Cleanup()
434 PyObject *modules = interp->modules; in PyImport_Cleanup()
490 when it's not referenced as a module, its dictionary is in PyImport_Cleanup()
491 referenced by almost every module's __builtins__. Since in PyImport_Cleanup()
492 deleting a module clears its dictionary (even if there are in PyImport_Cleanup()
494 module last. Likewise, we don't delete sys until the very in PyImport_Cleanup()
501 re-imported. */ in PyImport_Cleanup()
509 if (value->ob_refcnt != 1) in PyImport_Cleanup()
575 interp->modules = NULL; in PyImport_Cleanup()
577 Py_CLEAR(interp->modules_reloading); in PyImport_Cleanup()
581 /* Helper for pythonrun.c -- return magic number */
590 /* Magic for extension modules (built-in as well as dynamically
591 loaded). To prevent initializing an extension module more than
592 once, we keep a static dictionary 'extensions' keyed by module name
593 (for built-in modules) or by filename (for dynamically loaded
594 modules), containing these modules. A copy of the module's
596 immediately after the module initialization function succeeds. A
613 "_PyImport_FixupExtension: module %.200s not loaded", name); in _PyImport_FixupExtension()
651 /* Get the module object corresponding to a module name.
687 PyObject *nameobj, *module; in PyImport_AddModule() local
691 module = _PyImport_AddModuleObject(nameobj); in PyImport_AddModule()
693 return module; in PyImport_AddModule()
708 /* Execute a code object in a module and return the module object
710 * removed from sys.modules, to avoid leaving damaged module objects
712 * module object (if any) in this case; PyImport_ReloadModule is an
730 /* If the module is being reloaded, we get the old module back in PyImport_ExecCodeModuleEx()
731 and re-use its dict to exec the new code. */ in PyImport_ExecCodeModuleEx()
746 v = ((PyCodeObject *)co)->co_filename; in PyImport_ExecCodeModuleEx()
760 "Loaded module %.200s not found in sys.modules", in PyImport_ExecCodeModuleEx()
790 if (len >= 4 && strcmp(&pathname[len-4], ".pyw") == 0) in make_compiled_pathname()
791 --len; /* pretend 'w' isn't there */ in make_compiled_pathname()
850 "Non-code object in %.200s", cpathname); in read_compiled_module()
858 /* Load a module from a compiled file, execute it, and return its
859 module object WITH INCREMENTED REFERENCE COUNT */
939 /* Best we can do -- on Windows this can't happen anyway */ in open_exclusive()
945 /* Write a compiled module to a file, placing the time of last
955 mode_t mode = srcstat->st_mode & ~S_IEXEC; in write_compiled_module()
963 mode_t mode = srcstat->st_mode & ~S_IXUSR & ~S_IXGRP & ~S_IXOTH; in write_compiled_module()
985 /* Now write the true mtime (as a 32-bit field) */ in write_compiled_module()
1001 if (!_PyString_Eq(co->co_filename, oldname)) in update_code_filenames()
1004 tmp = co->co_filename; in update_code_filenames()
1005 co->co_filename = newname; in update_code_filenames()
1006 Py_INCREF(co->co_filename); in update_code_filenames()
1009 constants = co->co_consts; in update_code_filenames()
1024 if (strcmp(PyString_AsString(co->co_filename), pathname) == 0) in update_compiled_module()
1029 return -1; in update_compiled_module()
1031 oldname = co->co_filename; in update_compiled_module()
1059 return -1; in win32_mtime()
1065 return filetime / 10000000 - secs_between_epochs; in win32_mtime()
1071 /* Load a source module from a given file and return its module
1073 byte-compiled file, use that instead. */
1095 if (mtime == (time_t)-1 && PyErr_Occurred()) in load_source_module()
1162 /* Load a package and return its module object WITH INCREMENTED
1210 m = load_module(name, fp, buf, fdp->type, NULL); in load_package()
1226 /* Helper to test for built-in module */
1235 return -1; in is_builtin()
1244 /* Return an importer object for a sys.path/pkg.__path__ item 'p',
1256 PyObject *importer; in get_path_importer() local
1267 importer = PyDict_GetItem(path_importer_cache, p); in get_path_importer()
1268 if (importer != NULL) in get_path_importer()
1269 return importer; in get_path_importer()
1279 importer = PyObject_CallFunctionObjArgs(hook, p, NULL); in get_path_importer()
1280 if (importer != NULL) in get_path_importer()
1288 if (importer == NULL) { in get_path_importer()
1289 importer = PyObject_CallFunctionObjArgs( in get_path_importer()
1292 if (importer == NULL) { in get_path_importer()
1299 if (importer != NULL) { in get_path_importer()
1300 int err = PyDict_SetItem(path_importer_cache, p, importer); in get_path_importer()
1301 Py_DECREF(importer); in get_path_importer()
1305 return importer; in get_path_importer()
1310 PyObject *importer=NULL, *path_importer_cache=NULL, *path_hooks=NULL; in PyImport_GetImporter() local
1314 importer = get_path_importer(path_importer_cache, in PyImport_GetImporter()
1318 Py_XINCREF(importer); /* get_path_importer returns a borrowed reference */ in PyImport_GetImporter()
1319 return importer; in PyImport_GetImporter()
1322 /* Search the path (default sys.path) for a module. Return the
1324 pathname and an open file. Return NULL if the module is not found. */
1359 "module name is too long"); in find_module()
1410 "full frozen module name too long"); in find_module()
1501 PyObject *importer; in find_module() local
1503 importer = get_path_importer(path_importer_cache, in find_module()
1505 if (importer == NULL) { in find_module()
1509 /* Note: importer is a borrowed reference */ in find_module()
1510 if (importer != Py_None) { in find_module()
1512 loader = PyObject_CallMethod(importer, in find_module()
1530 if (len > 0 && buf[len-1] != SEP in find_module()
1532 && buf[len-1] != ALTSEP in find_module()
1540 and there's an __init__ module in that directory */ in find_module()
1561 /* take a snapshot of the module spec for restoration in find_module()
1568 for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) { in find_module()
1573 * dynamically loaded module we're going to try, in find_module()
1580 while (scan->suffix != NULL) { in find_module()
1581 if (!strcmp(scan->suffix, fdp->suffix)) in find_module()
1586 if (scan->suffix != NULL) { in find_module()
1589 len -= strlen(subname) - namelen; in find_module()
1594 strcpy(buf+len, fdp->suffix); in find_module()
1597 filemode = fdp->mode; in find_module()
1617 /* don't need/want the module name snapshot anymore */ in find_module()
1630 "No module named %.200s", name); in find_module()
1643 * Find the source file corresponding to a named module
1655 return fd->type == PY_SOURCE || fd->type == PY_COMPILED; in _PyImport_IsScript()
1662 * |--------------------- buf ---------------------|
1663 * |------------------- len ------------------|
1664 * |------ name -------|
1665 * |----- namelen -----|
1667 * extension. name is the module name, also exclusive of extension.
1670 * there's some match, possibly case-insensitive.
1672 * case_ok() is to return 1 if there's a case-sensitive match for
1676 * case_ok() is used to implement case-sensitive import semantics even
1677 * on platforms with case-insensitive filesystems. It's trivial to implement
1678 * for case-sensitive filesystems. It's pretty much a cross-platform
1679 * nightmare for systems with case-insensitive filesystems.
1682 /* First we may need a pile of platform-specific header files; the sequence
1708 /* Pick a platform-specific implementation; the sequence of #if's here should in case_ok()
1723 "Can't find file for module %.100s\n(filename %.300s)", in case_ok()
1741 "Can't find file for module %.100s\n(filename %.300s)", in case_ok()
1747 /* new-fangled macintosh (macosx) or Cygwin */ in case_ok()
1752 const int dirlen = len - namelen - 1; /* don't want trailing SEP */ in case_ok()
1770 char *nameWithExt = buf + len - namelen; in case_ok()
1774 dp->d_namlen; in case_ok()
1776 strlen(dp->d_name); in case_ok()
1779 strcmp(dp->d_name, nameWithExt) == 0) { in case_ok()
1792 char *nameWithExt = buf+len-namelen; in case_ok()
1805 canonlen = MAXPATHLEN+1-canonlen; in case_ok()
1808 if (strcmp(nameWithExt, canon+canonlen-strlen(nameWithExt))==0) in case_ok()
1833 /* assuming it's a case-sensitive filesystem, so there's nothing to do! */ in case_ok()
1854 * |--------------------- buf ---------------------| in find_init_module()
1855 * |------------------- len ------------------| in find_init_module()
1856 * |------ name -------| in find_init_module()
1857 * |----- namelen -----| in find_init_module()
1925 /* Load an external module using the default search path and return
1926 its module object WITH INCREMENTED REFERENCE COUNT */
1979 "Purported %s module %.200s not found", in load_module()
1990 "%s module %.200s not properly initialized", in load_module()
2021 /* Initialize a built-in module.
2022 Return 1 for success, 0 if the module is not found, and -1 with
2033 for (p = PyImport_Inittab; p->name != NULL; p++) { in init_builtin()
2034 if (strcmp(name, p->name) == 0) { in init_builtin()
2035 if (p->initfunc == NULL) { in init_builtin()
2037 "Cannot re-init internal module %.200s", in init_builtin()
2039 return -1; in init_builtin()
2043 (*p->initfunc)(); in init_builtin()
2045 return -1; in init_builtin()
2047 return -1; in init_builtin()
2063 if (p->name == NULL) in find_frozen()
2065 if (strcmp(p->name, name) == 0) in find_frozen()
2083 if (p->code == NULL) { in get_frozen_object()
2089 size = p->size; in get_frozen_object()
2091 size = -size; in get_frozen_object()
2092 return PyMarshal_ReadObjectFromString((char *)p->code, size); in get_frozen_object()
2095 /* Initialize a frozen module.
2096 Return 1 for succes, 0 if the module is not found, and -1 with
2111 if (p->code == NULL) { in PyImport_ImportFrozenModule()
2115 return -1; in PyImport_ImportFrozenModule()
2117 size = p->size; in PyImport_ImportFrozenModule()
2120 size = -size; in PyImport_ImportFrozenModule()
2124 co = PyMarshal_ReadObjectFromString((char *)p->code, size); in PyImport_ImportFrozenModule()
2126 return -1; in PyImport_ImportFrozenModule()
2157 return -1; in PyImport_ImportFrozenModule()
2161 /* Import a module, either built-in, frozen, or external, and return
2162 its module object WITH INCREMENTED REFERENCE COUNT */
2178 /* Import a module without blocking
2180 * At first it tries to fetch the module from sys.modules. If the module was
2185 * Returns the module object with incremented ref count.
2196 /* Try to get the module from sys.modules[name] */ in PyImport_ImportModuleNoBlock()
2211 * me might be -1 but I ignore the error here, the lock function in PyImport_ImportModuleNoBlock()
2214 if (import_lock_thread == -1 || import_lock_thread == me) { in PyImport_ImportModuleNoBlock()
2240 /* The Magnum Opus of dotted-name import :-) */
2288 an empty module name: someone called __import__("") or in import_module_level()
2293 "Empty module name"); in import_module_level()
2345 from the module foo.bar.bat (not itself a package), this returns the
2352 If globals doesn't come from a package or a module in a package, or a
2392 "__package__ set to non-string"); in get_parent()
2399 "Attempted relative import in non-package"); in get_parent()
2423 "Module name too long"); in get_parent()
2434 /* Normal module, so work out the package name if any */ in get_parent()
2441 "Attempted relative import in non-package"); in get_parent()
2453 len = lastdot - start; in get_parent()
2456 "Module name too long"); in get_parent()
2474 while (--level > 0) { in get_parent()
2491 "Parent module '%.200s' not found " in get_parent()
2505 "Parent module '%.200s' not loaded, " in get_parent()
2511 - parent.__name__ == buf in get_parent()
2512 - parent.__dict__ is globals in get_parent()
2528 /* completely empty module name should only happen in in load_next()
2541 len = dot-name; in load_next()
2545 "Empty module name"); in load_next()
2552 if (p+len-buf >= MAXPATHLEN) { in load_next()
2554 "Module name too long"); in load_next()
2559 *p_buflen = p+len-buf; in load_next()
2582 "No module named %.200s", name); in load_next()
2618 Py_TYPE(item)->tp_name); in ensure_fromlist()
2646 "Module name too long"); in ensure_fromlist()
2673 reference to it in the parent package module. A copy gets in add_submodule()
2676 load failed with a SyntaxError -- then there's no trace in in add_submodule()
2747 m = load_module(fullname, fp, buf, fdp->type, loader); in import_submodule()
2762 /* Re-import a module of any kind and return its module object, WITH
2768 PyInterpreterState *interp = PyThreadState_Get()->interp; in PyImport_ReloadModule()
2769 PyObject *modules_reloading = interp->modules_reloading; in PyImport_ReloadModule()
2786 "reload() argument must be module"); in PyImport_ReloadModule()
2794 "reload(): module %.200s not in sys.modules", in PyImport_ReloadModule()
2800 /* Due to a recursive reload, this module is already in PyImport_ReloadModule()
2813 parentname = PyString_FromStringAndSize(name, (subname-name)); in PyImport_ReloadModule()
2849 newm = load_module(name, fp, buf, fdp->type, loader); in PyImport_ReloadModule()
2856 * the error. Put back the original module object. We're in PyImport_ReloadModule()
2868 /* Higher-level import emulator which emulates the "import" statement
2869 more accurately -- it invokes the __import__() function from the
2875 will return <module "gencache"> instead of <module "win32com">. */
2910 /* No globals -- use standard builtins, and fake globals */ in PyImport_Import()
2945 /* Module 'imp' provides Python access to the primitives used for
2971 for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) { in imp_get_suffixes()
2973 fdp->suffix, fdp->mode, fdp->type); in imp_get_suffixes()
3010 fob = PyFile_FromFile(fp, pathname, fdp->mode, fclose); in call_find_module()
3021 fob, pathname, fdp->suffix, fdp->mode, fdp->type); in call_find_module()
3104 return PyBool_FromLong((long) (p == NULL ? 0 : p->size)); in imp_is_frozen()
3261 "This module provides the components needed to build your own\n\
3265 "reload(module) -> module\n\
3267 Reload the module. The module must have been successfully imported before.");
3270 "find_module(name, [path]) -> (file, filename, (suffix, mode, type))\n\
3271 Search for a module. If path is omitted or None, search for a\n\
3272 built-in, frozen or special module and continue search in sys.path.\n\
3273 The module name cannot contain '.'; to search for a submodule of a\n\
3277 "load_module(name, file, filename, (suffix, mode, type)) -> module\n\
3278 Load a module, given information returned by find_module().\n\
3279 The module name must include the full package name, if any.");
3282 "get_magic() -> string\n\
3286 "get_suffixes() -> [(suffix, mode, type), ...]\n\
3291 "new_module(name) -> module\n\
3292 Create a new module. Do not enter it in sys.modules.\n\
3293 The module name must include the full package name, if any.");
3296 "lock_held() -> boolean\n\
3301 "acquire_lock() -> None\n\
3303 This lock should be used by import hooks to ensure thread-safety\n\
3308 "release_lock() -> None\n\
3360 return -1; in NullImporter_init()
3364 return -1; in NullImporter_init()
3369 return -1; in NullImporter_init()
3374 return -1; in NullImporter_init()
3415 "Null importer object", /* tp_doc */
3471 to the table of built-in modules. This should normally be called
3472 *before* Py_Initialize(). When the table resize fails, -1 is
3496 return -1; in PyImport_ExtendInittab()