| 1 | \section{\module{new} ---
|
|---|
| 2 | Creation of runtime internal objects}
|
|---|
| 3 |
|
|---|
| 4 | \declaremodule{builtin}{new}
|
|---|
| 5 | \sectionauthor{Moshe Zadka}{[email protected]}
|
|---|
| 6 | \modulesynopsis{Interface to the creation of runtime implementation objects.}
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 | The \module{new} module allows an interface to the interpreter object
|
|---|
| 10 | creation functions. This is for use primarily in marshal-type functions,
|
|---|
| 11 | when a new object needs to be created ``magically'' and not by using the
|
|---|
| 12 | regular creation functions. This module provides a low-level interface
|
|---|
| 13 | to the interpreter, so care must be exercised when using this module.
|
|---|
| 14 | It is possible to supply non-sensical arguments which crash the
|
|---|
| 15 | interpreter when the object is used.
|
|---|
| 16 |
|
|---|
| 17 | The \module{new} module defines the following functions:
|
|---|
| 18 |
|
|---|
| 19 | \begin{funcdesc}{instance}{class\optional{, dict}}
|
|---|
| 20 | This function creates an instance of \var{class} with dictionary
|
|---|
| 21 | \var{dict} without calling the \method{__init__()} constructor. If
|
|---|
| 22 | \var{dict} is omitted or \code{None}, a new, empty dictionary is
|
|---|
| 23 | created for the new instance. Note that there are no guarantees that
|
|---|
| 24 | the object will be in a consistent state.
|
|---|
| 25 | \end{funcdesc}
|
|---|
| 26 |
|
|---|
| 27 | \begin{funcdesc}{instancemethod}{function, instance, class}
|
|---|
| 28 | This function will return a method object, bound to \var{instance}, or
|
|---|
| 29 | unbound if \var{instance} is \code{None}. \var{function} must be
|
|---|
| 30 | callable.
|
|---|
| 31 | \end{funcdesc}
|
|---|
| 32 |
|
|---|
| 33 | \begin{funcdesc}{function}{code, globals\optional{, name\optional{,
|
|---|
| 34 | argdefs\optional{, closure}}}}
|
|---|
| 35 | Returns a (Python) function with the given code and globals. If
|
|---|
| 36 | \var{name} is given, it must be a string or \code{None}. If it is a
|
|---|
| 37 | string, the function will have the given name, otherwise the function
|
|---|
| 38 | name will be taken from \code{\var{code}.co_name}. If
|
|---|
| 39 | \var{argdefs} is given, it must be a tuple and will be used to
|
|---|
| 40 | determine the default values of parameters. If \var{closure} is given,
|
|---|
| 41 | it must be \code{None} or a tuple of cell objects containing objects
|
|---|
| 42 | to bind to the names in \code{\var{code}.co_freevars}.
|
|---|
| 43 | \end{funcdesc}
|
|---|
| 44 |
|
|---|
| 45 | \begin{funcdesc}{code}{argcount, nlocals, stacksize, flags, codestring,
|
|---|
| 46 | constants, names, varnames, filename, name, firstlineno,
|
|---|
| 47 | lnotab}
|
|---|
| 48 | This function is an interface to the \cfunction{PyCode_New()} C
|
|---|
| 49 | function.
|
|---|
| 50 | %XXX This is still undocumented!!!!!!!!!!!
|
|---|
| 51 | \end{funcdesc}
|
|---|
| 52 |
|
|---|
| 53 | \begin{funcdesc}{module}{name[, doc]}
|
|---|
| 54 | This function returns a new module object with name \var{name}.
|
|---|
| 55 | \var{name} must be a string.
|
|---|
| 56 | The optional \var{doc} argument can have any type.
|
|---|
| 57 | \end{funcdesc}
|
|---|
| 58 |
|
|---|
| 59 | \begin{funcdesc}{classobj}{name, baseclasses, dict}
|
|---|
| 60 | This function returns a new class object, with name \var{name}, derived
|
|---|
| 61 | from \var{baseclasses} (which should be a tuple of classes) and with
|
|---|
| 62 | namespace \var{dict}.
|
|---|
| 63 | \end{funcdesc}
|
|---|