module.pxd 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. from .object cimport PyObject
  2. cdef extern from "Python.h":
  3. ctypedef struct _inittab
  4. #####################################################################
  5. # 5.3 Importing Modules
  6. #####################################################################
  7. object PyImport_ImportModule(const char *name)
  8. # Return value: New reference.
  9. # This is a simplified interface to PyImport_ImportModuleEx()
  10. # below, leaving the globals and locals arguments set to
  11. # NULL. When the name argument contains a dot (when it specifies a
  12. # submodule of a package), the fromlist argument is set to the
  13. # list ['*'] so that the return value is the named module rather
  14. # than the top-level package containing it as would otherwise be
  15. # the case. (Unfortunately, this has an additional side effect
  16. # when name in fact specifies a subpackage instead of a submodule:
  17. # the submodules specified in the package's __all__ variable are
  18. # loaded.) Return a new reference to the imported module, or NULL
  19. # with an exception set on failure.
  20. object PyImport_ImportModuleEx(const char *name, object globals, object locals, object fromlist)
  21. # Return value: New reference.
  22. # Import a module. This is best described by referring to the
  23. # built-in Python function __import__(), as the standard
  24. # __import__() function calls this function directly.
  25. # The return value is a new reference to the imported module or
  26. # top-level package, or NULL with an exception set on failure
  27. # (before Python 2.4, the module may still be created in this
  28. # case). Like for __import__(), the return value when a submodule
  29. # of a package was requested is normally the top-level package,
  30. # unless a non-empty fromlist was given. Changed in version 2.4:
  31. # failing imports remove incomplete module objects.
  32. object PyImport_ImportModuleLevel(char *name, object globals, object locals, object fromlist, int level)
  33. # Return value: New reference.
  34. # Import a module. This is best described by referring to the
  35. # built-in Python function __import__(), as the standard
  36. # __import__() function calls this function directly.
  37. # The return value is a new reference to the imported module or
  38. # top-level package, or NULL with an exception set on failure. Like
  39. # for __import__(), the return value when a submodule of a package
  40. # was requested is normally the top-level package, unless a
  41. # non-empty fromlist was given.
  42. object PyImport_Import(object name)
  43. # Return value: New reference.
  44. # This is a higher-level interface that calls the current ``import
  45. # hook function''. It invokes the __import__() function from the
  46. # __builtins__ of the current globals. This means that the import
  47. # is done using whatever import hooks are installed in the current
  48. # environment, e.g. by rexec or ihooks.
  49. object PyImport_ReloadModule(object m)
  50. # Return value: New reference.
  51. # Reload a module. This is best described by referring to the
  52. # built-in Python function reload(), as the standard reload()
  53. # function calls this function directly. Return a new reference to
  54. # the reloaded module, or NULL with an exception set on failure
  55. # (the module still exists in this case).
  56. PyObject* PyImport_AddModule(const char *name) except NULL
  57. # Return value: Borrowed reference.
  58. # Return the module object corresponding to a module name. The
  59. # name argument may be of the form package.module. First check the
  60. # modules dictionary if there's one there, and if not, create a
  61. # new one and insert it in the modules dictionary. Return NULL
  62. # with an exception set on failure. Note: This function does not
  63. # load or import the module; if the module wasn't already loaded,
  64. # you will get an empty module object. Use PyImport_ImportModule()
  65. # or one of its variants to import a module. Package structures
  66. # implied by a dotted name for name are not created if not already
  67. # present.
  68. object PyImport_ExecCodeModule(char *name, object co)
  69. # Return value: New reference.
  70. # Given a module name (possibly of the form package.module) and a
  71. # code object read from a Python bytecode file or obtained from
  72. # the built-in function compile(), load the module. Return a new
  73. # reference to the module object, or NULL with an exception set if
  74. # an error occurred. Name is removed from sys.modules in error
  75. # cases, and even if name was already in sys.modules on entry to
  76. # PyImport_ExecCodeModule(). Leaving incompletely initialized
  77. # modules in sys.modules is dangerous, as imports of such modules
  78. # have no way to know that the module object is an unknown (and
  79. # probably damaged with respect to the module author's intents)
  80. # state.
  81. # This function will reload the module if it was already
  82. # imported. See PyImport_ReloadModule() for the intended way to
  83. # reload a module.
  84. # If name points to a dotted name of the form package.module, any
  85. # package structures not already created will still not be
  86. # created.
  87. long PyImport_GetMagicNumber()
  88. # Return the magic number for Python bytecode files (a.k.a. .pyc
  89. # and .pyo files). The magic number should be present in the first
  90. # four bytes of the bytecode file, in little-endian byte order.
  91. PyObject* PyImport_GetModuleDict() except NULL
  92. # Return value: Borrowed reference.
  93. # Return the dictionary used for the module administration
  94. # (a.k.a. sys.modules). Note that this is a per-interpreter
  95. # variable.
  96. int PyImport_ImportFrozenModule(char *name) except -1
  97. # Load a frozen module named name. Return 1 for success, 0 if the
  98. # module is not found, and -1 with an exception set if the
  99. # initialization failed. To access the imported module on a
  100. # successful load, use PyImport_ImportModule(). (Note the misnomer
  101. # -- this function would reload the module if it was already
  102. # imported.)
  103. int PyImport_ExtendInittab(_inittab *newtab) except -1
  104. # Add a collection of modules to the table of built-in
  105. # modules. The newtab array must end with a sentinel entry which
  106. # contains NULL for the name field; failure to provide the
  107. # sentinel value can result in a memory fault. Returns 0 on
  108. # success or -1 if insufficient memory could be allocated to
  109. # extend the internal table. In the event of failure, no modules
  110. # are added to the internal table. This should be called before
  111. # Py_Initialize().
  112. #####################################################################
  113. # 7.5.5 Module Objects
  114. #####################################################################
  115. # PyTypeObject PyModule_Type
  116. #
  117. # This instance of PyTypeObject represents the Python module
  118. # type. This is exposed to Python programs as types.ModuleType.
  119. bint PyModule_Check(object p)
  120. # Return true if p is a module object, or a subtype of a module
  121. # object.
  122. bint PyModule_CheckExact(object p)
  123. # Return true if p is a module object, but not a subtype of PyModule_Type.
  124. object PyModule_New(const char *name)
  125. # Return value: New reference.
  126. # Return a new module object with the __name__ attribute set to
  127. # name. Only the module's __doc__ and __name__ attributes are
  128. # filled in; the caller is responsible for providing a __file__
  129. # attribute.
  130. PyObject* PyModule_GetDict(object module) except NULL
  131. # Return value: Borrowed reference.
  132. # Return the dictionary object that implements module's namespace;
  133. # this object is the same as the __dict__ attribute of the module
  134. # object. This function never fails. It is recommended extensions
  135. # use other PyModule_*() and PyObject_*() functions rather than
  136. # directly manipulate a module's __dict__.
  137. char* PyModule_GetName(object module) except NULL
  138. # Return module's __name__ value. If the module does not provide
  139. # one, or if it is not a string, SystemError is raised and NULL is
  140. # returned.
  141. char* PyModule_GetFilename(object module) except NULL
  142. # Return the name of the file from which module was loaded using
  143. # module's __file__ attribute. If this is not defined, or if it is
  144. # not a string, raise SystemError and return NULL.
  145. int PyModule_AddObject(object module, const char *name, object value) except -1
  146. # Add an object to module as name. This is a convenience function
  147. # which can be used from the module's initialization
  148. # function. This steals a reference to value. Return -1 on error,
  149. # 0 on success.
  150. int PyModule_AddIntConstant(object module, const char *name, long value) except -1
  151. # Add an integer constant to module as name. This convenience
  152. # function can be used from the module's initialization
  153. # function. Return -1 on error, 0 on success.
  154. int PyModule_AddStringConstant(object module, const char *name, const char *value) except -1
  155. # Add a string constant to module as name. This convenience
  156. # function can be used from the module's initialization
  157. # function. The string value must be null-terminated. Return -1 on
  158. # error, 0 on success.