Port rev. 56782.

This commit is contained in:
Georg Brandl
2007-08-07 06:30:02 +00:00
parent 3a946215af
commit 3ffecea9fc
4 changed files with 31 additions and 17 deletions

View File

@@ -52,9 +52,11 @@ The :mod:`runpy` module provides a single function:
If the argument *alter_sys* is supplied and evaluates to ``True``, then
``sys.argv[0]`` is updated with the value of ``__file__`` and
``sys.modules[__name__]`` is updated with a temporary module object for the
module being executed. Both ``sys.argv[0]`` and ``sys.modules[__name__]`` are
restored to their original values before the function returns.
``sys.modules[__name__]`` is updated with a new module object for the module
being executed. Note that neither ``sys.argv[0]`` nor ``sys.modules[__name__]``
are restored to their original values before the function returns -- if client
code needs these values preserved, it must either save them explicitly or
else avoid enabling the automatic alterations to :mod:`sys`.
Note that this manipulation of :mod:`sys` is not thread-safe. Other threads may
see the partially initialised module, as well as the altered list of arguments.

View File

@@ -101,10 +101,10 @@ between conformable Python objects and XML on the wire.
When passing strings, characters special to XML such as ``<``, ``>``, and ``&``
will be automatically escaped. However, it's the caller's responsibility to
ensure that the string is free of characters that aren't allowed in XML, such as
the control characters with ASCII values between 0 and 31; failing to do this
will result in an XML-RPC request that isn't well-formed XML. If you have to
pass arbitrary strings via XML-RPC, use the :class:`Binary` wrapper class
described below.
the control characters with ASCII values between 0 and 31 (except, of course,
tab, newline and carriage return); failing to do this will result in an XML-RPC
request that isn't well-formed XML. If you have to pass arbitrary strings via
XML-RPC, use the :class:`Binary` wrapper class described below.
:class:`Server` is retained as an alias for :class:`ServerProxy` for backwards
compatibility. New code should use :class:`ServerProxy`.

View File

@@ -352,7 +352,8 @@ occurred in the :keyword:`try` clause and has not been handled by an
been executed. The :keyword:`finally` clause is also executed "on the way out"
when any other clause of the :keyword:`try` statement is left via a
:keyword:`break`, :keyword:`continue` or :keyword:`return` statement. A more
complicated example::
complicated example (having :keyword:`except` and :keyword:`finally` clauses in
the same :keyword:`try` statement works as of Python 2.5)::
>>> def divide(x, y):
... try:

View File

@@ -6,7 +6,7 @@
.. |release| replace:: 1.01
.. % $Id: whatsnew25.tex 55005 2007-04-27 19:54:29Z guido.van.rossum $
.. % $Id: whatsnew25.tex 56611 2007-07-29 08:26:10Z georg.brandl $
.. % Fix XXX comments
This article explains the new features in Python 2.5. The final release of
@@ -574,13 +574,19 @@ structure is::
with-block
The expression is evaluated, and it should result in an object that supports the
context management protocol. This object may return a value that can optionally
be bound to the name *variable*. (Note carefully that *variable* is *not*
assigned the result of *expression*.) The object can then run set-up code
before *with-block* is executed and some clean-up code is executed after the
block is done, even if the block raised an exception.
context management protocol (that is, has :meth:`__enter__` and :meth:`__exit__`
methods.
To enable the statement in Python 2.5, you need to add the following directive
The object's :meth:`__enter__` is called before *with-block* is executed and
therefore can run set-up code. It also may return a value that is bound to the
name *variable*, if given. (Note carefully that *variable* is *not* assigned
the result of *expression*.)
After execution of the *with-block* is finished, the object's :meth:`__exit__`
method is called, even if the block raised an exception, and can therefore run
clean-up code.
To enable the statement in Python 2.5, you need to add the following directive
to your module::
from __future__ import with_statement
@@ -596,8 +602,13 @@ be used with the ':keyword:`with`' statement. File objects are one example::
... more processing code ...
After this statement has executed, the file object in *f* will have been
automatically closed, even if the 'for' loop raised an exception part-way
through the block.
automatically closed, even if the :keyword:`for` loop raised an exception part-
way through the block.
.. note::
In this case, *f* is the same object created by :func:`open`, because
:meth:`file.__enter__` returns *self*.
The :mod:`threading` module's locks and condition variables also support the
':keyword:`with`' statement::