Commit 8943caf7 authored by Georg Brandl's avatar Georg Brandl

Merged revisions...

Merged revisions 70642,70648,70656,70661,70765,70773,70789,70824-70825,70828,70830,70832,70836,70838,70842,70851,70855,70857-70858 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r70642 | georg.brandl | 2009-03-28 01:48:48 +0100 (Sa, 28 Mär 2009) | 1 line

  Fix typo.
........
  r70648 | georg.brandl | 2009-03-28 20:10:37 +0100 (Sa, 28 Mär 2009) | 1 line

  #5324: document __subclasses__().
........
  r70656 | georg.brandl | 2009-03-28 20:33:33 +0100 (Sa, 28 Mär 2009) | 2 lines

  Add a script to fixup rst files if the pre-commit hook rejects them.
........
  r70661 | georg.brandl | 2009-03-28 20:57:36 +0100 (Sa, 28 Mär 2009) | 2 lines

  Add section numbering to some of the larger subdocuments.
........
  r70765 | georg.brandl | 2009-03-31 00:09:34 +0200 (Di, 31 Mär 2009) | 1 line

  #5199: make warning about vars() assignment more visible.
........
  r70773 | georg.brandl | 2009-03-31 00:43:00 +0200 (Di, 31 Mär 2009) | 1 line

  #5039: make it clear that the impl. note refers to CPython.
........
  r70789 | georg.brandl | 2009-03-31 03:25:15 +0200 (Di, 31 Mär 2009) | 1 line

  Fix a wrong struct field assignment (docstring as closure).
........
  r70824 | georg.brandl | 2009-03-31 17:43:20 +0200 (Di, 31 Mär 2009) | 1 line

  #5519: remove reference to Kodos, which seems dead.
........
  r70825 | georg.brandl | 2009-03-31 17:46:30 +0200 (Di, 31 Mär 2009) | 1 line

  #5566: fix versionadded from PyLong ssize_t functions.
........
  r70828 | georg.brandl | 2009-03-31 17:50:16 +0200 (Di, 31 Mär 2009) | 1 line

  #5581: fget argument of abstractproperty is optional as well.
........
  r70830 | georg.brandl | 2009-03-31 18:11:45 +0200 (Di, 31 Mär 2009) | 1 line

  #5529: backport new docs of import semantics written by Brett to 2.x.
........
  r70832 | georg.brandl | 2009-03-31 18:31:11 +0200 (Di, 31 Mär 2009) | 1 line

  #1386675: specify WindowsError as the exception, because it has a winerror attribute that EnvironmentError doesnt have.
........
  r70836 | georg.brandl | 2009-03-31 18:50:25 +0200 (Di, 31 Mär 2009) | 1 line

  #5417: replace references to undocumented functions by ones to documented functions.
........
  r70838 | georg.brandl | 2009-03-31 18:54:38 +0200 (Di, 31 Mär 2009) | 1 line

  #992207: document that the parser only accepts \\n newlines.
........
  r70842 | georg.brandl | 2009-03-31 19:13:06 +0200 (Di, 31 Mär 2009) | 1 line

  #970783: document PyObject_Generic[GS]etAttr.
........
  r70851 | georg.brandl | 2009-03-31 20:26:55 +0200 (Di, 31 Mär 2009) | 1 line

  #837577: note cryptic return value of spawn*e on invalid env dicts.
........
  r70855 | georg.brandl | 2009-03-31 20:30:37 +0200 (Di, 31 Mär 2009) | 1 line

  #5245: note that PyRun_SimpleString doesnt return on SystemExit.
........
  r70857 | georg.brandl | 2009-03-31 20:33:10 +0200 (Di, 31 Mär 2009) | 1 line

  #5227: note that Py_Main doesnt return on SystemExit.
........
  r70858 | georg.brandl | 2009-03-31 20:38:56 +0200 (Di, 31 Mär 2009) | 1 line

  #5241: document missing U in regex howto.
........
parent 19f13d54
......@@ -54,7 +54,7 @@ Long Integer Objects
Return a new :ctype:`PyLongObject` object from a C :ctype:`Py_ssize_t`, or
*NULL* on failure.
.. versionadded:: 2.5
.. versionadded:: 2.6
.. cfunction:: PyObject* PyLong_FromSize_t(size_t v)
......@@ -62,7 +62,7 @@ Long Integer Objects
Return a new :ctype:`PyLongObject` object from a C :ctype:`size_t`, or
*NULL* on failure.
.. versionadded:: 2.5
.. versionadded:: 2.6
.. cfunction:: PyObject* PyLong_FromLongLong(PY_LONG_LONG v)
......@@ -139,7 +139,7 @@ Long Integer Objects
*pylong* is greater than :const:`PY_SSIZE_T_MAX`, an :exc:`OverflowError` is raised
and ``-1`` will be returned.
.. versionadded:: 2.5
.. versionadded:: 2.6
.. cfunction:: unsigned long PyLong_AsUnsignedLong(PyObject *pylong)
......
......@@ -42,6 +42,16 @@ Object Protocol
expression ``o.attr_name``.
.. cfunction:: PyObject* PyObject_GenericGetAttr(PyObject *o, PyObject *name)
Generic attribute getter function that is meant to be put into a type
object's ``tp_getattro`` slot. It looks for a descriptor in the dictionary
of classes in the object's MRO as well as an attribute in the object's
:attr:`__dict__` (if present). As outlined in :ref:`descriptors`, data
descriptors take preference over instance attributes, while non-data
descriptors don't. Otherwise, an :exc:`AttributeError` is raised.
.. cfunction:: int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v)
Set the value of the attribute named *attr_name*, for object *o*, to the value
......@@ -56,6 +66,17 @@ Object Protocol
``o.attr_name = v``.
.. cfunction:: int PyObject_GenericSetAttr(PyObject *o, PyObject *name, PyObject
*value)
Generic attribute setter function that is meant to be put into a type
object's ``tp_setattro`` slot. It looks for a data descriptor in the
dictionary of classes in the object's MRO, and if found it takes preference
over setting the attribute in the instance dictionary. Otherwise, the
attribute is set in the object's :attr:`__dict__` (if present). Otherwise,
an :exc:`AttributeError` is raised and ``-1`` is returned.
.. cfunction:: int PyObject_DelAttr(PyObject *o, PyObject *attr_name)
Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure.
......
......@@ -36,6 +36,10 @@ the same library that the Python runtime is using.
interpreter exits due to an exception, or ``2`` if the parameter list does not
represent a valid Python command line.
Note that if an otherwise unhandled :exc:`SystemError` is raised, this
function will not return ``1``, but exit the process, as long as
``Py_InspectFlag`` is not set.
.. cfunction:: int PyRun_AnyFile(FILE *fp, const char *filename)
......@@ -78,6 +82,10 @@ the same library that the Python runtime is using.
there was an error, there is no way to get the exception information. For the
meaning of *flags*, see below.
Note that if an otherwise unhandled :exc:`SystemError` is raised, this
function will not return ``-1``, but exit the process, as long as
``Py_InspectFlag`` is not set.
.. cfunction:: int PyRun_SimpleFile(FILE *fp, const char *filename)
......
......@@ -16,6 +16,7 @@ very little overhead for build/release/install mechanics.
.. toctree::
:maxdepth: 2
:numbered:
introduction.rst
setupscript.rst
......
......@@ -23,6 +23,7 @@ to write reStructuredText if you're not so inclined; plain text contributions
are more than welcome as well.
.. toctree::
:numbered:
intro.rst
style.rst
......
......@@ -465,10 +465,10 @@ reference count of an object and are safe in the presence of *NULL* pointers
(but note that *temp* will not be *NULL* in this context). More info on them
in section :ref:`refcounts`.
.. index:: single: PyEval_CallObject()
.. index:: single: PyObject_CallObject()
Later, when it is time to call the function, you call the C function
:cfunc:`PyEval_CallObject`. This function has two arguments, both pointers to
:cfunc:`PyObject_CallObject`. This function has two arguments, both pointers to
arbitrary Python objects: the Python function, and the argument list. The
argument list must always be a tuple object, whose length is the number of
arguments. To call the Python function with no arguments, pass in NULL, or
......@@ -484,16 +484,16 @@ or more format codes between parentheses. For example::
...
/* Time to call the callback */
arglist = Py_BuildValue("(i)", arg);
result = PyEval_CallObject(my_callback, arglist);
result = PyObject_CallObject(my_callback, arglist);
Py_DECREF(arglist);
:cfunc:`PyEval_CallObject` returns a Python object pointer: this is the return
value of the Python function. :cfunc:`PyEval_CallObject` is
:cfunc:`PyObject_CallObject` returns a Python object pointer: this is the return
value of the Python function. :cfunc:`PyObject_CallObject` is
"reference-count-neutral" with respect to its arguments. In the example a new
tuple was created to serve as the argument list, which is :cfunc:`Py_DECREF`\
-ed immediately after the call.
The return value of :cfunc:`PyEval_CallObject` is "new": either it is a brand
The return value of :cfunc:`PyObject_CallObject` is "new": either it is a brand
new object, or it is an existing object whose reference count has been
incremented. So, unless you want to save it in a global variable, you should
somehow :cfunc:`Py_DECREF` the result, even (especially!) if you are not
......@@ -501,7 +501,7 @@ interested in its value.
Before you do this, however, it is important to check that the return value
isn't *NULL*. If it is, the Python function terminated by raising an exception.
If the C code that called :cfunc:`PyEval_CallObject` is called from Python, it
If the C code that called :cfunc:`PyObject_CallObject` is called from Python, it
should now return an error indication to its Python caller, so the interpreter
can print a stack trace, or the calling Python code can handle the exception.
If this is not possible or desirable, the exception should be cleared by calling
......@@ -513,7 +513,7 @@ If this is not possible or desirable, the exception should be cleared by calling
Py_DECREF(result);
Depending on the desired interface to the Python callback function, you may also
have to provide an argument list to :cfunc:`PyEval_CallObject`. In some cases
have to provide an argument list to :cfunc:`PyObject_CallObject`. In some cases
the argument list is also provided by the Python program, through the same
interface that specified the callback function. It can then be saved and used
in the same manner as the function object. In other cases, you may have to
......@@ -524,7 +524,7 @@ event code, you might use the following code::
PyObject *arglist;
...
arglist = Py_BuildValue("(l)", eventcode);
result = PyEval_CallObject(my_callback, arglist);
result = PyObject_CallObject(my_callback, arglist);
Py_DECREF(arglist);
if (result == NULL)
return NULL; /* Pass error back */
......@@ -536,19 +536,20 @@ the error check! Also note that strictly speaking this code is not complete:
:cfunc:`Py_BuildValue` may run out of memory, and this should be checked.
You may also call a function with keyword arguments by using
:cfunc:`PyEval_CallObjectWithKeywords`. As in the above example, we use
:cfunc:`Py_BuildValue` to construct the dictionary. ::
:cfunc:`PyObject_Call`, which supports arguments and keyword arguments. As in
the above example, we use :cfunc:`Py_BuildValue` to construct the dictionary. ::
PyObject *dict;
...
dict = Py_BuildValue("{s:i}", "name", val);
result = PyEval_CallObjectWithKeywords(my_callback, NULL, dict);
result = PyObject_Call(my_callback, NULL, dict);
Py_DECREF(dict);
if (result == NULL)
return NULL; /* Pass error back */
/* Here maybe use the result */
Py_DECREF(result);
.. _parsetuple:
Extracting Parameters in Extension Functions
......
......@@ -26,6 +26,7 @@ For a detailed description of the whole Python/C API, see the separate
.. toctree::
:maxdepth: 2
:numbered:
extending.rst
newtypes.rst
......
......@@ -185,6 +185,11 @@ Glossary
A module written in C or C++, using Python's C API to interact with the core and
with user code.
finder
An object that tries to find the :term:`loader` for a module. It must
implement a method named :meth:`find_module`. See :pep:`302` for
details.
function
A series of statements which returns some value to a caller. It can also
be passed zero or more arguments which may be used in the execution of
......@@ -288,6 +293,10 @@ Glossary
fraction. Integer division can be forced by using the ``//`` operator
instead of the ``/`` operator. See also :term:`__future__`.
importer
An object that both finds and loads a module; both a
:term:`finder` and :term:`loader` object.
interactive
Python has an interactive interpreter which means you can enter
statements and expressions at the interpreter prompt, immediately
......@@ -368,6 +377,11 @@ Glossary
clause is optional. If omitted, all elements in ``range(256)`` are
processed.
loader
An object that loads a module. It must define a method named
:meth:`load_module`. A loader is typically returned by a
:term:`finder`. See :pep:`302` for details.
mapping
A container object (such as :class:`dict`) which supports arbitrary key
lookups using the special method :meth:`__getitem__`.
......
......@@ -540,6 +540,10 @@ of each one.
| :const:`VERBOSE`, :const:`X` | Enable verbose REs, which can be organized |
| | more cleanly and understandably. |
+---------------------------------+--------------------------------------------+
| :const:`UNICODE`, :const:`U` | Makes several escapes like ``\w``, ``\b``, |
| | ``\s`` and ``\d`` dependent on the Unicode |
| | character database. |
+---------------------------------+--------------------------------------------+
.. data:: I
......@@ -594,6 +598,14 @@ of each one.
newline; without this flag, ``'.'`` will match anything *except* a newline.
.. data:: U
UNICODE
:index:
Make ``\w``, ``\W``, ``\b``, ``\B``, ``\d``, ``\D``, ``\s`` and ``\S``
dependent on the Unicode character properties database.
.. data:: X
VERBOSE
:noindex:
......
:mod:`_winreg` -- Windows registry access
=========================================
......@@ -47,8 +46,8 @@ This module offers the following functions:
*key* is the predefined handle to connect to.
The return value is the handle of the opened key. If the function fails, an
:exc:`EnvironmentError` exception is raised.
The return value is the handle of the opened key. If the function fails, a
:exc:`WindowsError` exception is raised.
.. function:: CreateKey(key, sub_key)
......@@ -65,8 +64,8 @@ This module offers the following functions:
If the key already exists, this function opens the existing key.
The return value is the handle of the opened key. If the function fails, an
:exc:`EnvironmentError` exception is raised.
The return value is the handle of the opened key. If the function fails, a
:exc:`WindowsError` exception is raised.
.. function:: DeleteKey(key, sub_key)
......@@ -82,7 +81,7 @@ This module offers the following functions:
*This method can not delete keys with subkeys.*
If the method succeeds, the entire key, including all of its values, is removed.
If the method fails, an :exc:`EnvironmentError` exception is raised.
If the method fails, a :exc:`WindowsError` exception is raised.
.. function:: DeleteValue(key, value)
......@@ -105,7 +104,7 @@ This module offers the following functions:
*index* is an integer that identifies the index of the key to retrieve.
The function retrieves the name of one subkey each time it is called. It is
typically called repeatedly until an :exc:`EnvironmentError` exception is
typically called repeatedly until a :exc:`WindowsError` exception is
raised, indicating, no more values are available.
......@@ -119,7 +118,7 @@ This module offers the following functions:
*index* is an integer that identifies the index of the value to retrieve.
The function retrieves the name of one subkey each time it is called. It is
typically called repeatedly, until an :exc:`EnvironmentError` exception is
typically called repeatedly, until a :exc:`WindowsError` exception is
raised, indicating no more values.
The result is a tuple of 3 items:
......@@ -209,7 +208,7 @@ This module offers the following functions:
The result is a new handle to the specified key.
If the function fails, :exc:`EnvironmentError` is raised.
If the function fails, :exc:`WindowsError` is raised.
.. function:: OpenKeyEx()
......
......@@ -161,7 +161,7 @@ It also provides the following decorators:
multiple-inheritance.
.. function:: abstractproperty(fget[, fset[, fdel[, doc]]])
.. function:: abstractproperty([fget[, fset[, fdel[, doc]]]])
A subclass of the built-in :func:`property`, indicating an abstract property.
......@@ -189,6 +189,7 @@ It also provides the following decorators:
def setx(self, value): ...
x = abstractproperty(getx, setx)
.. rubric:: Footnotes
.. [#] C++ programmers should note that Python's virtual base class
......
......@@ -1344,8 +1344,12 @@ available. They are listed here in alphabetical order.
Without arguments, return a dictionary corresponding to the current local symbol
table. With a module, class or class instance object as argument (or anything
else that has a :attr:`__dict__` attribute), returns a dictionary corresponding
to the object's symbol table. The returned dictionary should not be modified:
the effects on the corresponding symbol table are undefined. [#]_
to the object's symbol table.
.. warning::
The returned dictionary should not be modified:
the effects on the corresponding symbol table are undefined. [#]_
.. function:: xrange([start,] stop[, step])
......
......@@ -38,6 +38,7 @@ the `Python Package Index <http://pypi.python.org/pypi>`_.
.. toctree::
:maxdepth: 2
:numbered:
intro.rst
functions.rst
......
......@@ -1751,7 +1751,9 @@ written in Python, such as a mail server's external command delivery program.
which is used to define the environment variables for the new process (they are
used instead of the current process' environment); the functions
:func:`spawnl`, :func:`spawnlp`, :func:`spawnv`, and :func:`spawnvp` all cause
the new process to inherit the environment of the current process.
the new process to inherit the environment of the current process. Note that
keys and values in the *env* dictionary must be strings; invalid keys or
values will cause the function to fail, with a return value of ``127``.
As an example, the following calls to :func:`spawnlp` and :func:`spawnvpe` are
equivalent::
......
......@@ -8,12 +8,9 @@
.. sectionauthor:: Andrew M. Kuchling <amk@amk.ca>
This module provides regular expression matching operations similar to
those found in Perl. Both patterns and strings to be searched can be
Unicode strings as well as 8-bit strings. The :mod:`re` module is
always available.
Unicode strings as well as 8-bit strings.
Regular expressions use the backslash character (``'\'``) to indicate
special forms or to allow special characters to be used without invoking
......@@ -43,9 +40,6 @@ fine-tuning parameters.
second edition of the book no longer covers Python at all, but the first
edition covered writing good regular expression patterns in great detail.
`Kodos <http://kodos.sf.net/>`_
is a graphical regular expression debugger written in Python.
.. _re-syntax:
......
......@@ -2652,6 +2652,17 @@ types, where they are relevant. Some of these are not reported by the
The name of the class or type.
.. method:: class.__subclasses__
:term:`New-style class`\ es keep a list of weak references to their immediate
subclasses. This method returns a list of all those references still alive.
Example::
>>> int.__subclasses__()
[<type 'bool'>]
.. rubric:: Footnotes
.. [#] Additional information on these special methods may be found in the Python
......
......@@ -535,6 +535,22 @@ always available.
characters are stored as UCS-2 or UCS-4.
.. data:: meta_path
A list of :term:`finder` objects that have their :meth:`find_module`
methods called to see if one of the objects can find the module to be
imported. The :meth:`find_module` method is called at least with the
absolute name of the module being imported. If the module to be imported is
contained in package then the parent package's :attr:`__path__` attribute
is passed in as a second argument. The method returns :keyword:`None` if
the module cannot be found, else returns a :term:`loader`.
:data:`sys.meta_path` is searched before any implicit default finders or
:data:`sys.path`.
See :pep:`302` for the original specification.
.. data:: modules
.. index:: builtin: reload
......@@ -571,6 +587,27 @@ always available.
:data:`sys.path`.
.. data:: path_hooks
A list of callables that take a path argument to try to create a
:term:`finder` for the path. If a finder can be created, it is to be
returned by the callable, else raise :exc:`ImportError`.
Originally specified in :pep:`302`.
.. data:: path_importer_cache
A dictionary acting as a cache for :term:`finder` objects. The keys are
paths that have been passed to :data:`sys.path_hooks` and the values are
the finders that are found. If a path is a valid file system path but no
explicit finder is found on :data:`sys.path_hooks` then :keyword:`None` is
stored to represent the implicit default finder should be used. If the path
is not an existing path then :class:`imp.NullImporter` is set.
Originally specified in :pep:`302`.
.. data:: platform
This string contains a platform identifier that can be used to append
......
......@@ -56,12 +56,13 @@ Objects are never explicitly destroyed; however, when they become unreachable
they may be garbage-collected. An implementation is allowed to postpone garbage
collection or omit it altogether --- it is a matter of implementation quality
how garbage collection is implemented, as long as no objects are collected that
are still reachable. (Implementation note: the current implementation uses a
are still reachable. (Implementation note: CPython currently uses a
reference-counting scheme with (optional) delayed detection of cyclically linked
garbage, which collects most objects as soon as they become unreachable, but is
not guaranteed to collect garbage containing circular references. See the
documentation of the :mod:`gc` module for information on controlling the
collection of cyclic garbage.)
collection of cyclic garbage. Other implementations act differently and CPython
may change.)
Note that the use of the implementation's tracing or debugging facilities may
keep objects alive that would normally be collectable. Also note that catching
......
......@@ -18,6 +18,7 @@ interfaces available to C/C++ programmers in detail.
.. toctree::
:maxdepth: 2
:numbered:
introduction.rst
lexical_analysis.rst
......
This diff is collapsed.
......@@ -44,6 +44,7 @@ various Python library modules described in the Python Library Reference.
The :ref:`glossary` is also worth going through.
.. toctree::
:numbered:
appetite.rst
interpreter.rst
......
......@@ -11,6 +11,7 @@ interpreter and things that make working with Python easier.
.. toctree::
:numbered:
cmdline.rst
unix.rst
......
......@@ -162,7 +162,7 @@ class StrictVersion (Version):
# The rules according to Greg Stein:
# 1) a version number has 1 or more numbers separate by a period or by
# 1) a version number has 1 or more numbers separated by a period or by
# sequences of letters. If only periods, then these are compared
# left-to-right to determine an ordering.
# 2) sequences of letters are part of the tuple for comparison and are
......
......@@ -306,7 +306,7 @@ PyDoc_STRVAR(gen__name__doc__,
"Return the name of the generator's associated code object.");
static PyGetSetDef gen_getsetlist[] = {
{"__name__", (getter)gen_get_name, NULL, NULL, gen__name__doc__},
{"__name__", (getter)gen_get_name, NULL, gen__name__doc__},
{NULL}
};
......
#!/usr/bin/env python
# Make a reST file compliant to our pre-commit hook.
# Currently just remove trailing whitespace.
from __future__ import with_statement
import sys, re, shutil
ws_re = re.compile(r'\s+(\r?\n)$')
def main(argv=sys.argv):
rv = 0
for filename in argv[1:]:
try:
with open(filename, 'rb') as f:
lines = f.readlines()
new_lines = [ws_re.sub(r'\1', line) for line in lines]
if new_lines != lines:
print 'Fixing %s...' % filename
shutil.copyfile(filename, filename + '.bak')
with open(filename, 'wb') as f:
f.writelines(new_lines)
except Exception, err:
print 'Cannot fix %s: %s' % (filename, err)
rv = 1
return rv
if __name__ == '__main__':
sys.exit(main())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment