Skip to content

Commit 4009c9e

Browse files
committed
Merged revisions 82805-82806,83523-83527,83536,83538,83542,83546-83548,83550-83555,83558,83560 via svnmerge from
svn+ssh://svn.python.org/python/branches/py3k ........ r82805 | georg.brandl | 2010-07-11 11:42:10 +0200 (So, 11 Jul 2010) | 1 line #7935: cross-reference to ast.literal_eval() from eval() docs. ........ r82806 | georg.brandl | 2010-07-11 12:22:44 +0200 (So, 11 Jul 2010) | 1 line #9223: link to Command class reference, and move Command interface docs nearer to class docs. ........ r83523 | georg.brandl | 2010-08-02 14:06:18 +0200 (Mo, 02 Aug 2010) | 1 line #9209 and #7781: fix two crashes in pstats interactive browser. ........ r83524 | georg.brandl | 2010-08-02 14:20:23 +0200 (Mo, 02 Aug 2010) | 1 line #9428: fix running scripts from profile/cProfile with their own name and the right namespace. Same fix as for trace.py in #1690103. ........ r83525 | georg.brandl | 2010-08-02 14:36:24 +0200 (Mo, 02 Aug 2010) | 1 line Get rid of spurious "threading" entries in trace output. ........ r83526 | georg.brandl | 2010-08-02 14:40:22 +0200 (Mo, 02 Aug 2010) | 1 line Fix softspace relic. ........ r83527 | georg.brandl | 2010-08-02 14:48:46 +0200 (Mo, 02 Aug 2010) | 1 line #3821: beginnings of a trace.py unittest. ........ r83536 | georg.brandl | 2010-08-02 19:49:25 +0200 (Mo, 02 Aug 2010) | 1 line #8578: mention danger of not incref'ing weak referenced object. ........ r83538 | georg.brandl | 2010-08-02 20:10:13 +0200 (Mo, 02 Aug 2010) | 1 line #6928: fix class docs w.r.t. new metaclasses. ........ r83542 | georg.brandl | 2010-08-02 20:56:54 +0200 (Mo, 02 Aug 2010) | 1 line Move test_SimpleHTTPServer into test_httpservers. ........ r83546 | georg.brandl | 2010-08-02 21:16:34 +0200 (Mo, 02 Aug 2010) | 1 line #7973: Fix distutils options spelling. ........ r83547 | georg.brandl | 2010-08-02 21:19:26 +0200 (Mo, 02 Aug 2010) | 1 line #7386: add example that shows that trailing path separators are stripped. ........ r83548 | georg.brandl | 2010-08-02 21:23:34 +0200 (Mo, 02 Aug 2010) | 1 line #8172: how does one use a property? ........ r83550 | georg.brandl | 2010-08-02 21:32:43 +0200 (Mo, 02 Aug 2010) | 1 line #9451: strengthen warning about __*__ special name usage. ........ r83551 | georg.brandl | 2010-08-02 21:35:06 +0200 (Mo, 02 Aug 2010) | 1 line Remove XXX comment that was displayed. ........ r83552 | georg.brandl | 2010-08-02 21:36:36 +0200 (Mo, 02 Aug 2010) | 1 line #9438: clarify that constant names also cannot be assigned as attributes. ........ r83553 | georg.brandl | 2010-08-02 21:39:17 +0200 (Mo, 02 Aug 2010) | 1 line Remove redundant information. ........ r83554 | georg.brandl | 2010-08-02 21:43:05 +0200 (Mo, 02 Aug 2010) | 1 line #7280: note about nasmw.exe. ........ r83555 | georg.brandl | 2010-08-02 21:44:48 +0200 (Mo, 02 Aug 2010) | 1 line #8861: remove unused variable. ........ r83558 | georg.brandl | 2010-08-02 22:05:19 +0200 (Mo, 02 Aug 2010) | 1 line #8648: document UTF-7 codec functions. ........ r83560 | georg.brandl | 2010-08-02 22:16:18 +0200 (Mo, 02 Aug 2010) | 1 line #9087: update json docstrings -- unicode and long do not exist anymore. ........
1 parent 914a218 commit 4009c9e

File tree

22 files changed

+268
-221
lines changed

22 files changed

+268
-221
lines changed

Doc/c-api/unicode.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,38 @@ These are the UTF-16 codec APIs:
641641
Return *NULL* if an exception was raised by the codec.
642642

643643

644+
UTF-7 Codecs
645+
""""""""""""
646+
647+
These are the UTF-7 codec APIs:
648+
649+
650+
.. cfunction:: PyObject* PyUnicode_DecodeUTF7(const char *s, Py_ssize_t size, const char *errors)
651+
652+
Create a Unicode object by decoding *size* bytes of the UTF-7 encoded string
653+
*s*. Return *NULL* if an exception was raised by the codec.
654+
655+
656+
.. cfunction:: PyObject* PyUnicode_DecodeUTF8Stateful(const char *s, Py_ssize_t size, const char *errors, Py_ssize_t *consumed)
657+
658+
If *consumed* is *NULL*, behave like :cfunc:`PyUnicode_DecodeUTF7`. If
659+
*consumed* is not *NULL*, trailing incomplete UTF-7 base-64 sections will not
660+
be treated as an error. Those bytes will not be decoded and the number of
661+
bytes that have been decoded will be stored in *consumed*.
662+
663+
664+
.. cfunction:: PyObject* PyUnicode_EncodeUTF7(const Py_UNICODE *s, Py_ssize_t size, int base64SetO, int base64WhiteSpace, const char *errors)
665+
666+
Encode the :ctype:`Py_UNICODE` buffer of the given size using UTF-7 and
667+
return a Python bytes object. Return *NULL* if an exception was raised by
668+
the codec.
669+
670+
If *base64SetO* is nonzero, "Set O" (punctuation that has no otherwise
671+
special meaning) will be encoded in base-64. If *base64WhiteSpace* is
672+
nonzero, whitespace will be encoded in base-64. Both are set to zero for the
673+
Python "utf-7" codec.
674+
675+
644676
Unicode-Escape Codecs
645677
"""""""""""""""""""""
646678

Doc/c-api/weakref.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,14 @@ as much as it can.
5353
.. cfunction:: PyObject* PyWeakref_GetObject(PyObject *ref)
5454

5555
Return the referenced object from a weak reference, *ref*. If the referent is
56-
no longer live, returns ``None``.
56+
no longer live, returns :const:`Py_None`.
57+
58+
.. warning::
59+
60+
This function returns a **borrowed reference** to the referenced object.
61+
This means that you should always call :cfunc:`Py_INCREF` on the object
62+
except if you know that it cannot be destroyed while you are still
63+
using it.
5764

5865

5966
.. cfunction:: PyObject* PyWeakref_GET_OBJECT(PyObject *ref)

Doc/distutils/apiref.rst

Lines changed: 80 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ setup script). Indirectly provides the :class:`distutils.dist.Distribution` and
147147
In addition, the :mod:`distutils.core` module exposed a number of classes that
148148
live elsewhere.
149149

150-
* :class:`Extension` from :mod:`distutils.extension`
150+
* :class:`~distutils.extension.Extension` from :mod:`distutils.extension`
151151

152-
* :class:`Command` from :mod:`distutils.cmd`
152+
* :class:`~distutils.cmd.Command` from :mod:`distutils.cmd`
153153

154-
* :class:`Distribution` from :mod:`distutils.dist`
154+
* :class:`~distutils.dist.Distribution` from :mod:`distutils.dist`
155155

156156
A short description of each of these follows, but see the relevant module for
157157
the full reference.
@@ -1679,8 +1679,8 @@ lines, and joining lines with backslashes.
16791679
===================================================================
16801680

16811681
.. module:: distutils.cmd
1682-
:synopsis: This module provides the abstract base class Command. This class is subclassed
1683-
by the modules in the distutils.command subpackage.
1682+
:synopsis: This module provides the abstract base class Command. This class
1683+
is subclassed by the modules in the distutils.command subpackage.
16841684

16851685

16861686
This module supplies the abstract base class :class:`Command`.
@@ -1690,20 +1690,84 @@ This module supplies the abstract base class :class:`Command`.
16901690

16911691
Abstract base class for defining command classes, the "worker bees" of the
16921692
Distutils. A useful analogy for command classes is to think of them as
1693-
subroutines with local variables called *options*. The options are declared in
1694-
:meth:`initialize_options` and defined (given their final values) in
1695-
:meth:`finalize_options`, both of which must be defined by every command class.
1696-
The distinction between the two is necessary because option values might come
1697-
from the outside world (command line, config file, ...), and any options
1698-
dependent on other options must be computed after these outside influences have
1699-
been processed --- hence :meth:`finalize_options`. The body of the subroutine,
1700-
where it does all its work based on the values of its options, is the
1701-
:meth:`run` method, which must also be implemented by every command class.
1702-
1703-
The class constructor takes a single argument *dist*, a :class:`Distribution`
1693+
subroutines with local variables called *options*. The options are declared
1694+
in :meth:`initialize_options` and defined (given their final values) in
1695+
:meth:`finalize_options`, both of which must be defined by every command
1696+
class. The distinction between the two is necessary because option values
1697+
might come from the outside world (command line, config file, ...), and any
1698+
options dependent on other options must be computed after these outside
1699+
influences have been processed --- hence :meth:`finalize_options`. The body
1700+
of the subroutine, where it does all its work based on the values of its
1701+
options, is the :meth:`run` method, which must also be implemented by every
1702+
command class.
1703+
1704+
The class constructor takes a single argument *dist*, a :class:`Distribution`
17041705
instance.
17051706

17061707

1708+
Creating a new Distutils command
1709+
================================
1710+
1711+
This section outlines the steps to create a new Distutils command.
1712+
1713+
A new command lives in a module in the :mod:`distutils.command` package. There
1714+
is a sample template in that directory called :file:`command_template`. Copy
1715+
this file to a new module with the same name as the new command you're
1716+
implementing. This module should implement a class with the same name as the
1717+
module (and the command). So, for instance, to create the command
1718+
``peel_banana`` (so that users can run ``setup.py peel_banana``), you'd copy
1719+
:file:`command_template` to :file:`distutils/command/peel_banana.py`, then edit
1720+
it so that it's implementing the class :class:`peel_banana`, a subclass of
1721+
:class:`distutils.cmd.Command`.
1722+
1723+
Subclasses of :class:`Command` must define the following methods.
1724+
1725+
.. method:: Command.initialize_options()
1726+
1727+
Set default values for all the options that this command supports. Note that
1728+
these defaults may be overridden by other commands, by the setup script, by
1729+
config files, or by the command-line. Thus, this is not the place to code
1730+
dependencies between options; generally, :meth:`initialize_options`
1731+
implementations are just a bunch of ``self.foo = None`` assignments.
1732+
1733+
1734+
.. method:: Command.finalize_options()
1735+
1736+
Set final values for all the options that this command supports. This is
1737+
always called as late as possible, ie. after any option assignments from the
1738+
command-line or from other commands have been done. Thus, this is the place
1739+
to to code option dependencies: if *foo* depends on *bar*, then it is safe to
1740+
set *foo* from *bar* as long as *foo* still has the same value it was
1741+
assigned in :meth:`initialize_options`.
1742+
1743+
1744+
.. method:: Command.run()
1745+
1746+
A command's raison d'etre: carry out the action it exists to perform, controlled
1747+
by the options initialized in :meth:`initialize_options`, customized by other
1748+
commands, the setup script, the command-line, and config files, and finalized in
1749+
:meth:`finalize_options`. All terminal output and filesystem interaction should
1750+
be done by :meth:`run`.
1751+
1752+
1753+
.. attribute:: Command.sub_commands
1754+
1755+
*sub_commands* formalizes the notion of a "family" of commands,
1756+
e.g. ``install`` as the parent with sub-commands ``install_lib``,
1757+
``install_headers``, etc. The parent of a family of commands defines
1758+
*sub_commands* as a class attribute; it's a list of 2-tuples ``(command_name,
1759+
predicate)``, with *command_name* a string and *predicate* a function, a
1760+
string or ``None``. *predicate* is a method of the parent command that
1761+
determines whether the corresponding command is applicable in the current
1762+
situation. (E.g. we ``install_headers`` is only applicable if we have any C
1763+
header files to install.) If *predicate* is ``None``, that command is always
1764+
applicable.
1765+
1766+
*sub_commands* is usually defined at the *end* of a class, because
1767+
predicates can be methods of the class, so they must already have been
1768+
defined. The canonical example is the :command:`install` command.
1769+
1770+
17071771
:mod:`distutils.command` --- Individual Distutils commands
17081772
==========================================================
17091773

@@ -1942,76 +2006,3 @@ The ``register`` command registers the package with the Python Package Index.
19422006
This is described in more detail in :pep:`301`.
19432007

19442008
.. % todo
1945-
1946-
:mod:`distutils.command.check` --- Check the meta-data of a package
1947-
===================================================================
1948-
1949-
.. module:: distutils.command.check
1950-
:synopsis: Check the metadata of a package
1951-
1952-
1953-
The ``check`` command performs some tests on the meta-data of a package.
1954-
For example, it verifies that all required meta-data are provided as
1955-
the arguments passed to the :func:`setup` function.
1956-
1957-
.. % todo
1958-
1959-
1960-
Creating a new Distutils command
1961-
================================
1962-
1963-
This section outlines the steps to create a new Distutils command.
1964-
1965-
A new command lives in a module in the :mod:`distutils.command` package. There
1966-
is a sample template in that directory called :file:`command_template`. Copy
1967-
this file to a new module with the same name as the new command you're
1968-
implementing. This module should implement a class with the same name as the
1969-
module (and the command). So, for instance, to create the command
1970-
``peel_banana`` (so that users can run ``setup.py peel_banana``), you'd copy
1971-
:file:`command_template` to :file:`distutils/command/peel_banana.py`, then edit
1972-
it so that it's implementing the class :class:`peel_banana`, a subclass of
1973-
:class:`distutils.cmd.Command`.
1974-
1975-
Subclasses of :class:`Command` must define the following methods.
1976-
1977-
1978-
.. method:: Command.initialize_options()
1979-
1980-
Set default values for all the options that this command supports. Note that
1981-
these defaults may be overridden by other commands, by the setup script, by
1982-
config files, or by the command-line. Thus, this is not the place to code
1983-
dependencies between options; generally, :meth:`initialize_options`
1984-
implementations are just a bunch of ``self.foo = None`` assignments.
1985-
1986-
1987-
.. method:: Command.finalize_options()
1988-
1989-
Set final values for all the options that this command supports. This is
1990-
always called as late as possible, ie. after any option assignments from the
1991-
command-line or from other commands have been done. Thus, this is the place
1992-
to to code option dependencies: if *foo* depends on *bar*, then it is safe to
1993-
set *foo* from *bar* as long as *foo* still has the same value it was
1994-
assigned in :meth:`initialize_options`.
1995-
1996-
1997-
.. method:: Command.run()
1998-
1999-
A command's raison d'etre: carry out the action it exists to perform, controlled
2000-
by the options initialized in :meth:`initialize_options`, customized by other
2001-
commands, the setup script, the command-line, and config files, and finalized in
2002-
:meth:`finalize_options`. All terminal output and filesystem interaction should
2003-
be done by :meth:`run`.
2004-
2005-
*sub_commands* formalizes the notion of a "family" of commands, eg. ``install``
2006-
as the parent with sub-commands ``install_lib``, ``install_headers``, etc. The
2007-
parent of a family of commands defines *sub_commands* as a class attribute; it's
2008-
a list of 2-tuples ``(command_name, predicate)``, with *command_name* a string
2009-
and *predicate* a function, a string or None. *predicate* is a method of
2010-
the parent command that determines whether the corresponding command is
2011-
applicable in the current situation. (Eg. we ``install_headers`` is only
2012-
applicable if we have any C header files to install.) If *predicate* is None,
2013-
that command is always applicable.
2014-
2015-
*sub_commands* is usually defined at the \*end\* of a class, because predicates
2016-
can be methods of the class, so they must already have been defined. The
2017-
canonical example is the :command:`install` command.

Doc/distutils/builtdist.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ easily specify multiple formats in one run. If you need to do both, you can
176176
explicitly specify multiple :command:`bdist_\*` commands and their options::
177177

178178
python setup.py bdist_rpm --packager="John Doe <jdoe@example.org>" \
179-
bdist_wininst --target_version="2.0"
179+
bdist_wininst --target-version="2.0"
180180

181181
Creating RPM packages is driven by a :file:`.spec` file, much as using the
182182
Distutils is driven by the setup script. To make your life easier, the

Doc/distutils/extending.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ want to modify existing commands; many simply add a few file extensions that
1515
should be copied into packages in addition to :file:`.py` files as a
1616
convenience.
1717

18-
Most distutils command implementations are subclasses of the :class:`Command`
19-
class from :mod:`distutils.cmd`. New commands may directly inherit from
18+
Most distutils command implementations are subclasses of the
19+
:class:`distutils.cmd.Command` class. New commands may directly inherit from
2020
:class:`Command`, while replacements often derive from :class:`Command`
2121
indirectly, directly subclassing the command they are replacing. Commands are
2222
required to derive from :class:`Command`.

Doc/library/constants.rst

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@ Built-in Constants
33

44
A small number of constants live in the built-in namespace. They are:
55

6-
7-
.. note::
8-
9-
:data:`None`, :data:`False`, :data:`True` and :data:`__debug__` cannot be
10-
reassigned (assignments to them raise :exc:`SyntaxError`), so they can be
11-
considered "true" constants.
12-
13-
.. XXX False, True, None are keywords too
14-
156
.. data:: False
167

178
The false value of the :class:`bool` type. Assignments to ``False``
@@ -40,19 +31,23 @@ A small number of constants live in the built-in namespace. They are:
4031

4132
.. data:: Ellipsis
4233

43-
The same as ``...``. Special value used mostly in conjunction with extended
44-
slicing syntax for user-defined container data types, as in ::
45-
46-
.. XXX Someone who understands extended slicing should fill in here.
34+
The same as ``...``. Special value used mostly in conjunction with extended
35+
slicing syntax for user-defined container data types.
4736

4837

4938
.. data:: __debug__
5039

5140
This constant is true if Python was not started with an :option:`-O` option.
52-
Assignments to :const:`__debug__` are illegal and raise a :exc:`SyntaxError`.
5341
See also the :keyword:`assert` statement.
5442

5543

44+
.. note::
45+
46+
The names :data:`None`, :data:`False`, :data:`True` and :data:`__debug__`
47+
cannot be reassigned (assignments to them, even as an attribute name, raise
48+
:exc:`SyntaxError`), so they can be considered "true" constants.
49+
50+
5651
Constants added by the :mod:`site` module
5752
-----------------------------------------
5853

Doc/library/functions.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ are always available. They are listed here in alphabetical order.
331331
returns the current global and local dictionary, respectively, which may be
332332
useful to pass around for use by :func:`eval` or :func:`exec`.
333333

334+
See :func:`ast.literal_eval` for a function that can safely evaluate strings
335+
with expressions containing only literals.
336+
334337

335338
.. function:: exec(object[, globals[, locals]])
336339

@@ -855,7 +858,7 @@ are always available. They are listed here in alphabetical order.
855858

856859
*fget* is a function for getting an attribute value, likewise *fset* is a
857860
function for setting, and *fdel* a function for del'ing, an attribute. Typical
858-
use is to define a managed attribute x::
861+
use is to define a managed attribute ``x``::
859862

860863
class C(object):
861864
def __init__(self):
@@ -869,6 +872,9 @@ are always available. They are listed here in alphabetical order.
869872
del self._x
870873
x = property(getx, setx, delx, "I'm the 'x' property.")
871874

875+
If then *c* is an instance of *C*, ``c.x`` will invoke the getter,
876+
``c.x = value`` will invoke the setter and ``del c.x`` the deleter.
877+
872878
If given, *doc* will be the docstring of the property attribute. Otherwise, the
873879
property will copy *fget*'s docstring (if it exists). This makes it possible to
874880
create read-only properties easily using :func:`property` as a :term:`decorator`::

Doc/library/os.path.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ applications should use string objects to access all files.
206206
.. function:: normpath(path)
207207

208208
Normalize a pathname. This collapses redundant separators and up-level
209-
references so that ``A//B``, ``A/./B`` and ``A/foo/../B`` all become ``A/B``.
209+
references so that ``A//B``, ``A/B/``, ``A/./B`` and ``A/foo/../B`` all become
210+
``A/B``.
211+
210212
It does not normalize the case (use :func:`normcase` for that). On Windows, it
211213
converts forward slashes to backward slashes. It should be understood that this
212214
may change the meaning of the path if it contains symbolic links!

0 commit comments

Comments
 (0)