Merged revisions 68582,68718,68720-68721,68724-68727,68859,68973,69288-69289,69293,69295,69297-69301,69409,69414,69570,69573,69576,69728-69730,69769,69776,69803-69805,69840,69896 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r68582 | georg.brandl | 2009-01-13 23:14:01 +0100 (Di, 13 Jan 2009) | 2 lines

  Use assertRaises.
........
  r68718 | georg.brandl | 2009-01-18 11:42:35 +0100 (So, 18 Jan 2009) | 1 line

  #4976: union() and intersection() take multiple args, but talk about "the other".
........
  r68720 | georg.brandl | 2009-01-18 11:45:22 +0100 (So, 18 Jan 2009) | 1 line

  #4974: fix redundant mention of lists and tuples.
........
  r68721 | georg.brandl | 2009-01-18 11:48:16 +0100 (So, 18 Jan 2009) | 1 line

  #4914: trunc is in math.
........
  r68724 | georg.brandl | 2009-01-18 14:24:10 +0100 (So, 18 Jan 2009) | 1 line

  #4979: correct result range for some random functions.
........
  r68725 | georg.brandl | 2009-01-18 14:47:26 +0100 (So, 18 Jan 2009) | 1 line

  #4857: fix augmented assignment target spec.
........
  r68726 | georg.brandl | 2009-01-18 15:41:52 +0100 (So, 18 Jan 2009) | 1 line

  #4923: clarify what was added.
........
  r68727 | georg.brandl | 2009-01-18 19:25:30 +0100 (So, 18 Jan 2009) | 1 line

  #4986: augassigns are not expressions.
........
  r68859 | georg.brandl | 2009-01-22 19:29:28 +0100 (Do, 22 Jan 2009) | 2 lines

  Clarify wording.
........
  r68973 | georg.brandl | 2009-01-26 22:29:38 +0100 (Mo, 26 Jan 2009) | 2 lines

  Copy over docs on advanced role features from Sphinx docs.
........
  r69288 | georg.brandl | 2009-02-05 11:30:57 +0100 (Do, 05 Feb 2009) | 1 line

  #5153: fix typo in example.
........
  r69289 | georg.brandl | 2009-02-05 11:37:07 +0100 (Do, 05 Feb 2009) | 1 line

  #5144: document that PySys_SetArgv prepends the script directory (or the empty string) to sys.path.
........
  r69293 | georg.brandl | 2009-02-05 11:59:28 +0100 (Do, 05 Feb 2009) | 1 line

  #5059: fix example.
........
  r69295 | georg.brandl | 2009-02-05 12:23:47 +0100 (Do, 05 Feb 2009) | 1 line

  PyErr_PrintEx is also in 2.x...
........
  r69297 | georg.brandl | 2009-02-05 12:32:18 +0100 (Do, 05 Feb 2009) | 1 line

  #5015: document PythonHome API functions.
........
  r69298 | georg.brandl | 2009-02-05 12:33:21 +0100 (Do, 05 Feb 2009) | 1 line

  #4827: fix callback example.
........
  r69299 | georg.brandl | 2009-02-05 12:35:28 +0100 (Do, 05 Feb 2009) | 1 line

  #4820: use correct module for ctypes.util.
........
  r69300 | georg.brandl | 2009-02-05 12:38:23 +0100 (Do, 05 Feb 2009) | 1 line

  #4563: disable alpha and roman lists, fixes wrong formatting of contributor list.
........
  r69301 | georg.brandl | 2009-02-05 12:40:35 +0100 (Do, 05 Feb 2009) | 1 line

  #5031: fix Thread.daemon property docs.
........
  r69409 | georg.brandl | 2009-02-07 13:21:17 +0100 (Sa, 07 Feb 2009) | 1 line

  #5174: fix wrong file closing in example.
........
  r69414 | georg.brandl | 2009-02-07 19:49:54 +0100 (Sa, 07 Feb 2009) | 1 line

  make "super only for new-style classes" a note.
........
  r69570 | georg.brandl | 2009-02-13 11:40:14 +0100 (Fr, 13 Feb 2009) | 1 line

  #4894: document "newurl" parameter to redirect_request().
........
  r69573 | georg.brandl | 2009-02-13 11:44:17 +0100 (Fr, 13 Feb 2009) | 1 line

  #3734: document complex coercing behavior better.
........
  r69576 | georg.brandl | 2009-02-13 11:56:50 +0100 (Fr, 13 Feb 2009) | 1 line

  #1661108: note that urlsafe encoded string can contain "=".
........
  r69728 | georg.brandl | 2009-02-18 01:22:55 +0100 (Mi, 18 Feb 2009) | 2 lines

  #5297: fix example.
........
  r69729 | georg.brandl | 2009-02-18 01:25:13 +0100 (Mi, 18 Feb 2009) | 2 lines

  #5296: sequence -> iterable.
........
  r69730 | georg.brandl | 2009-02-18 01:31:36 +0100 (Mi, 18 Feb 2009) | 2 lines

  #5268: mention VMSError.
........
  r69769 | georg.brandl | 2009-02-19 09:30:06 +0100 (Do, 19 Feb 2009) | 1 line

  #5310, #3558: fix operator precedence table.
........
  r69776 | georg.brandl | 2009-02-19 17:34:51 +0100 (Do, 19 Feb 2009) | 2 lines

  #5317: update IronPython URL.
........
  r69803 | georg.brandl | 2009-02-20 08:48:21 +0100 (Fr, 20 Feb 2009) | 1 line

  #5327: fix a broken link by joining it.
........
  r69804 | georg.brandl | 2009-02-20 09:22:21 +0100 (Fr, 20 Feb 2009) | 1 line

  At least separate imports from other statements.
........
  r69805 | georg.brandl | 2009-02-20 09:45:47 +0100 (Fr, 20 Feb 2009) | 2 lines

  Fix punctuation.
........
  r69840 | georg.brandl | 2009-02-21 20:09:40 +0100 (Sa, 21 Feb 2009) | 1 line

  #5338, #5339: two types in the API manual.
........
  r69896 | georg.brandl | 2009-02-23 11:24:23 +0100 (Mo, 23 Feb 2009) | 1 line

  #5348: format() converts all kinds of values.
........
This commit is contained in:
Georg Brandl 2009-02-23 10:41:11 +00:00
parent 9ac164c71c
commit ec7d3909ba
30 changed files with 188 additions and 111 deletions

View File

@ -41,12 +41,21 @@ is a separate error indicator for each thread.
Either alphabetical or some kind of structure.
.. cfunction:: void PyErr_Print()
.. cfunction:: void PyErr_PrintEx(int set_sys_last_vars)
Print a standard traceback to ``sys.stderr`` and clear the error indicator.
Call this function only when the error indicator is set. (Otherwise it will
cause a fatal error!)
If *set_sys_last_vars* is nonzero, the variables :data:`sys.last_type`,
:data:`sys.last_value` and :data:`sys.last_traceback` will be set to the
type, value and traceback of the printed exception, respectively.
.. cfunction:: void PyErr_Print()
Alias for ``PyErr_PrintEx(1)``.
.. cfunction:: PyObject* PyErr_Occurred()

View File

@ -353,18 +353,36 @@ Initialization, Finalization, and Threads
single: Py_FatalError()
single: argv (in module sys)
Set ``sys.argv`` based on *argc* and *argv*. These parameters are similar to
those passed to the program's :cfunc:`main` function with the difference that
the first entry should refer to the script file to be executed rather than the
executable hosting the Python interpreter. If there isn't a script that will be
run, the first entry in *argv* can be an empty string. If this function fails
to initialize ``sys.argv``, a fatal condition is signalled using
:cfunc:`Py_FatalError`.
Set :data:`sys.argv` based on *argc* and *argv*. These parameters are
similar to those passed to the program's :cfunc:`main` function with the
difference that the first entry should refer to the script file to be
executed rather than the executable hosting the Python interpreter. If there
isn't a script that will be run, the first entry in *argv* can be an empty
string. If this function fails to initialize :data:`sys.argv`, a fatal
condition is signalled using :cfunc:`Py_FatalError`.
This function also prepends the executed script's path to :data:`sys.path`.
If no script is executed (in the case of calling ``python -c`` or just the
interactive interpreter), the empty string is used instead.
.. XXX impl. doesn't seem consistent in allowing 0/NULL for the params;
check w/ Guido.
.. cfunction:: void Py_SetPythonHome(char *home)
Set the default "home" directory, that is, the location of the standard
Python libraries. The libraries are searched in
:file:`{home}/lib/python{version}` and :file:`{home}/lib/python{version}`.
.. cfunction:: char* Py_GetPythonHome()
Return the default "home", that is, the value set by a previous call to
:cfunc:`Py_SetPythonHome`, or the value of the :envvar:`PYTHONHOME`
environment variable if it is set.
.. _threads:
Thread State and the Global Interpreter Lock

View File

@ -187,7 +187,7 @@ caller is said to receive a *new* reference. When no ownership is transferred,
the caller is said to *borrow* the reference. Nothing needs to be done for a
borrowed reference.
Conversely, when a calling function passes it a reference to an object, there
Conversely, when a calling function passes in a reference to an object, there
are two possibilities: the function *steals* a reference to the object, or it
does not. *Stealing a reference* means that when you pass a reference to a
function, that function assumes that it now owns that reference, and you are not

View File

@ -16,7 +16,7 @@ parameter. The available start symbols are :const:`Py_eval_input`,
:const:`Py_file_input`, and :const:`Py_single_input`. These are described
following the functions which accept them as parameters.
Note also that several of these functions take :ctype:`FILE\*` parameters. On
Note also that several of these functions take :ctype:`FILE\*` parameters. One
particular issue which needs to be handled carefully is that the :ctype:`FILE`
structure for different C libraries can be different and incompatible. Under
Windows (at least), it is possible for dynamically linked extensions to actually

View File

@ -285,14 +285,27 @@ Inline markup
As said before, Sphinx uses interpreted text roles to insert semantic markup in
documents.
Variable names are an exception, they should be marked simply with ``*var*``.
Names of local variables, such as function/method arguments, are an exception,
they should be marked simply with ``*var*``.
For all other roles, you have to write ``:rolename:`content```.
.. note::
There are some additional facilities that make cross-referencing roles more
versatile:
For all cross-referencing roles, if you prefix the content with ``!``, no
reference/hyperlink will be created.
* You may supply an explicit title and reference target, like in reST direct
hyperlinks: ``:role:`title <target>``` will refer to *target*, but the link
text will be *title*.
* If you prefix the content with ``!``, no reference/hyperlink will be created.
* For the Python object roles, if you prefix the content with ``~``, the link
text will only be the last component of the target. For example,
``:meth:`~Queue.Queue.get``` will refer to ``Queue.Queue.get`` but only
display ``get`` as the link text.
In HTML output, the link's ``title`` attribute (that is e.g. shown as a
tool-tip on mouse-hover) will always be the full target name.
The following roles refer to objects in modules and are possibly hyperlinked if
a matching identifier is found:
@ -310,7 +323,7 @@ a matching identifier is found:
.. describe:: data
The name of a module-level variable.
The name of a module-level variable or constant.
.. describe:: const

View File

@ -99,7 +99,8 @@ simple CGI program::
# -*- coding: UTF-8 -*-
# enable debugging
import cgitb; cgitb.enable()
import cgitb
cgitb.enable()
print "Content-Type: text/plain;charset=utf-8"
print

View File

@ -63,7 +63,8 @@ The modern interface, which was introduced in Python 2.4, provides:
.. function:: urlsafe_b64encode(s)
Encode string *s* using a URL-safe alphabet, which substitutes ``-`` instead of
``+`` and ``_`` instead of ``/`` in the standard Base64 alphabet.
``+`` and ``_`` instead of ``/`` in the standard Base64 alphabet. The result
can still contain ``=``.
.. function:: urlsafe_b64decode(s)

View File

@ -67,16 +67,18 @@ Begin by writing ``import cgi``. Do not use ``from cgi import *`` --- the
module defines all sorts of names for its own use or for backward compatibility
that you don't want in your namespace.
When you write a new script, consider adding the line::
When you write a new script, consider adding these lines::
import cgitb; cgitb.enable()
import cgitb
cgitb.enable()
This activates a special exception handler that will display detailed reports in
the Web browser if any errors occur. If you'd rather not show the guts of your
program to users of your script, you can have the reports saved to files
instead, with a line like this::
instead, with code like this::
import cgitb; cgitb.enable(display=0, logdir="/tmp")
import cgitb
cgitb.enable(display=0, logdir="/tmp")
It's very helpful to use this feature during script development. The reports
produced by :mod:`cgitb` provide information that can save you a lot of time in
@ -470,9 +472,10 @@ discarded altogether.
Fortunately, once you have managed to get your script to execute *some* code,
you can easily send tracebacks to the Web browser using the :mod:`cgitb` module.
If you haven't done so already, just add the line::
If you haven't done so already, just add the lines::
import cgitb; cgitb.enable()
import cgitb
cgitb.enable()
to the top of your script. Then try running it again; when a problem occurs,
you should see a detailed report that will likely make apparent the cause of the

View File

@ -26,9 +26,10 @@ as well as the values of the arguments and local variables to currently running
functions, to help you debug the problem. Optionally, you can save this
information to a file instead of sending it to the browser.
To enable this feature, simply add one line to the top of your CGI script::
To enable this feature, simply add this to the top of your CGI script::
import cgitb; cgitb.enable()
import cgitb
cgitb.enable()
The options to the :func:`enable` function control whether the report is
displayed in the browser and whether the report is logged to a file for later

View File

@ -769,7 +769,7 @@ returned::
import urllib2
from cookielib import CookieJar, DefaultCookiePolicy
policy = DefaultCookiePolicy(
rfc2965=True, strict_ns_domain=Policy.DomainStrict,
rfc2965=True, strict_ns_domain=DefaultCookiePolicy.DomainStrict,
blocked_domains=["ads.net", ".ads.net"])
cj = CookieJar(policy)
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

View File

@ -1274,6 +1274,7 @@ library to load.
.. data:: find_library(name)
:module: ctypes.util
:noindex:
Try to find a library and return a pathname. *name* is the library name without

View File

@ -1497,11 +1497,10 @@ For :class:`date` objects, the format codes for hours, minutes, seconds, and
microseconds should not be used, as :class:`date` objects have no such
values. If they're used anyway, ``0`` is substituted for them.
:class:`time` and :class:`datetime` objects support a ``%f`` format code
which expands to the number of microseconds in the object, zero-padded on
the left to six places.
.. versionadded:: 2.6
:class:`time` and :class:`datetime` objects support a ``%f`` format code
which expands to the number of microseconds in the object, zero-padded on
the left to six places.
For a naive object, the ``%z`` and ``%Z`` format codes are replaced by empty
strings.
@ -1621,7 +1620,9 @@ Notes:
(1)
When used with the :func:`strptime` function, the ``%f`` directive
accepts from one to six digits and zero pads on the right. ``%f`` is
an extension to the set of format characters in the C standard.
an extension to the set of format characters in the C standard (but
implemented separately in datetime objects, and therefore always
available).
(2)
When used with the :func:`strptime` function, the ``%p`` directive only affects

View File

@ -398,6 +398,11 @@ The following exceptions are the exceptions that are actually raised.
more precise exception such as :exc:`IndexError`.
.. exception:: VMSError
Only available on VMS. Raised when a VMS-specific error occurs.
.. exception:: WindowsError
Raised when a Windows-specific error occurs or when the error number does not

View File

@ -425,6 +425,26 @@ available. They are listed here in alphabetical order.
The float type is described in :ref:`typesnumeric`.
.. function:: format(value[, format_spec])
.. index::
pair: str; format
single: __format__
Convert a *value* to a "formatted" representation, as controlled by
*format_spec*. The interpretation of *format_spec* will depend on the type
of the *value* argument, however there is a standard formatting syntax that
is used by most built-in types: :ref:`formatspec`.
.. note::
``format(value, format_spec)`` merely calls
``value.__format__(format_spec)``.
.. versionadded:: 2.6
.. function:: frozenset([iterable])
:noindex:
@ -1178,8 +1198,10 @@ available. They are listed here in alphabetical order.
If the second argument is omitted the super
object returned is unbound. If the second argument is an object,
``isinstance(obj, type)`` must be true. If the second argument is a type,
``issubclass(type2, type)`` must be true. :func:`super` only works for
:term:`new-style class`\es.
``issubclass(type2, type)`` must be true.
.. note::
:func:`super` only works for :term:`new-style class`\es.
There are two typical use cases for "super". In a class hierarchy with
single inheritance, "super" can be used to refer to parent classes without

View File

@ -1511,7 +1511,7 @@ Here's an example of a callback option that takes no arguments, and simply
records that the option was seen::
def record_foo_seen(option, opt_str, value, parser):
parser.saw_foo = True
parser.values.saw_foo = True
parser.add_option("--foo", action="callback", callback=record_foo_seen)
@ -1651,7 +1651,7 @@ arguments::
value.append(arg)
del parser.rargs[:len(value)]
setattr(parser.values, option.dest, value))
setattr(parser.values, option.dest, value)
[...]
parser.add_option("-c", "--callback", dest="vararg_attr",

View File

@ -188,13 +188,13 @@ be found in any statistics text.
.. function:: uniform(a, b)
Return a random floating point number *N* such that ``a <= N < b`` for
``a <= b`` and ``b <= N < a`` for ``b < a``.
Return a random floating point number *N* such that ``a <= N <= b`` for
``a <= b`` and ``b <= N <= a`` for ``b < a``.
.. function:: triangular(low, high, mode)
Return a random floating point number *N* such that ``low <= N < high`` and
Return a random floating point number *N* such that ``low <= N <= high`` and
with the specified *mode* between those bounds. The *low* and *high* bounds
default to zero and one. The *mode* argument defaults to the midpoint
between the bounds, giving a symmetric distribution.
@ -204,8 +204,8 @@ be found in any statistics text.
.. function:: betavariate(alpha, beta)
Beta distribution. Conditions on the parameters are ``alpha > 0`` and ``beta >
0``. Returned values range between 0 and 1.
Beta distribution. Conditions on the parameters are ``alpha > 0`` and
``beta > 0``. Returned values range between 0 and 1.
.. function:: expovariate(lambd)
@ -219,14 +219,15 @@ be found in any statistics text.
.. function:: gammavariate(alpha, beta)
Gamma distribution. (*Not* the gamma function!) Conditions on the parameters
are ``alpha > 0`` and ``beta > 0``.
Gamma distribution. (*Not* the gamma function!) Conditions on the
parameters are ``alpha > 0`` and ``beta > 0``.
.. function:: gauss(mu, sigma)
Gaussian distribution. *mu* is the mean, and *sigma* is the standard deviation.
This is slightly faster than the :func:`normalvariate` function defined below.
Gaussian distribution. *mu* is the mean, and *sigma* is the standard
deviation. This is slightly faster than the :func:`normalvariate` function
defined below.
.. function:: lognormvariate(mu, sigma)

View File

@ -517,7 +517,7 @@ An example for the :class:`ThreadingMixIn` class::
# Exit the server thread when the main thread terminates
server_thread.setDaemon(True)
server_thread.start()
print "Server loop running in thread:", t.getName()
print "Server loop running in thread:", server_thread.getName()
client(ip, port, "Hello World 1")
client(ip, port, "Hello World 2")

View File

@ -375,7 +375,7 @@ All :class:`numbers.Real` types (:class:`int`, :class:`long`, and
+--------------------+------------------------------------+--------+
| Operation | Result | Notes |
+====================+====================================+========+
| ``trunc(x)`` | *x* truncated to Integral | |
| ``math.trunc(x)`` | *x* truncated to Integral | |
+--------------------+------------------------------------+--------+
| ``round(x[, n])`` | *x* rounded to n digits, | |
| | rounding half to even. If n is | |
@ -601,9 +601,9 @@ Sequence Types --- :class:`str`, :class:`unicode`, :class:`list`, :class:`tuple`
There are six sequence types: strings, Unicode strings, lists, tuples, buffers,
and xrange objects.
(For other containers see the built in :class:`dict`, :class:`list`,
:class:`set`, and :class:`tuple` classes, and the :mod:`collections`
module.)
For other containers see the built in :class:`dict` and :class:`set` classes,
and the :mod:`collections` module.
.. index::
@ -1648,7 +1648,7 @@ The constructors for both classes work the same:
.. method:: union(other, ...)
set | other | ...
Return a new set with elements from both sets.
Return a new set with elements from the set and all others.
.. versionchanged:: 2.6
Accepts multiple input iterables.
@ -1656,7 +1656,7 @@ The constructors for both classes work the same:
.. method:: intersection(other, ...)
set & other & ...
Return a new set with elements common to both sets.
Return a new set with elements common to the set and all others.
.. versionchanged:: 2.6
Accepts multiple input iterables.

View File

@ -210,7 +210,7 @@ changed through the :attr:`name` attribute.
A thread can be flagged as a "daemon thread". The significance of this flag is
that the entire Python program exits when only daemon threads are left. The
initial value is inherited from the creating thread. The flag can be set
through the :attr:`daemon` attribute.
through the :attr:`daemon` property.
There is a "main thread" object; this corresponds to the initial thread of
control in the Python program. It is not a daemon thread.
@ -332,10 +332,11 @@ impossible to detect the termination of alien threads.
.. attribute:: Thread.daemon
The thread's daemon flag. This must be set before :meth:`start` is called,
otherwise :exc:`RuntimeError` is raised.
The initial value is inherited from the creating thread.
A boolean value indicating whether this thread is a daemon thread (True) or
not (False). This must be set before :meth:`start` is called, otherwise
:exc:`RuntimeError` is raised. Its initial value is inherited from the
creating thread; the main thread is not a daemon thread and therefore all
threads created in the main thread default to :attr:`daemon` = ``False``.
The entire Python program exits when no alive non-daemon threads are left.

View File

@ -602,14 +602,15 @@ HTTPRedirectHandler Objects
precise meanings of the various redirection codes.
.. method:: HTTPRedirectHandler.redirect_request(req, fp, code, msg, hdrs)
.. method:: HTTPRedirectHandler.redirect_request(req, fp, code, msg, hdrs, newurl)
Return a :class:`Request` or ``None`` in response to a redirect. This is called
by the default implementations of the :meth:`http_error_30\*` methods when a
redirection is received from the server. If a redirection should take place,
return a new :class:`Request` to allow :meth:`http_error_30\*` to perform the
redirect. Otherwise, raise :exc:`HTTPError` if no other handler should try to
handle this URL, or return ``None`` if you can't but another handler might.
redirect to *newurl*. Otherwise, raise :exc:`HTTPError` if no other handler
should try to handle this URL, or return ``None`` if you can't but another
handler might.
.. note::
@ -622,8 +623,8 @@ HTTPRedirectHandler Objects
.. method:: HTTPRedirectHandler.http_error_301(req, fp, code, msg, hdrs)
Redirect to the ``Location:`` URL. This method is called by the parent
:class:`OpenerDirector` when getting an HTTP 'moved permanently' response.
Redirect to the ``Location:`` or ``URI:`` URL. This method is called by the
parent :class:`OpenerDirector` when getting an HTTP 'moved permanently' response.
.. method:: HTTPRedirectHandler.http_error_302(req, fp, code, msg, hdrs)

View File

@ -529,5 +529,5 @@ This is an example of counting the maximum depth of an XML file::
.. [#] The encoding string included in XML output should conform to the
appropriate standards. For example, "UTF-8" is valid, but "UTF8" is
not. See http://www.w3.org/TR/2006/REC-xml11-20060816/#NT-EncodingDecl
and http://www.iana.org/assignments/character-sets .
and http://www.iana.org/assignments/character-sets.

View File

@ -318,9 +318,8 @@ XMLRPC::
import xmlrpclib
def python_logo():
handle = open("python_logo.jpg")
return xmlrpclib.Binary(handle.read())
handle.close()
with open("python_logo.jpg") as handle:
return xmlrpclib.Binary(handle.read())
server = SimpleXMLRPCServer(("localhost", 8000))
print "Listening on port 8000..."
@ -333,9 +332,8 @@ The client gets the image and saves it to a file::
import xmlrpclib
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
handle = open("fetched_python_logo.jpg", "w")
handle.write(proxy.python_logo().data)
handle.close()
with open("fetched_python_logo.jpg", "w") as handle:
handle.write(proxy.python_logo().data)
.. _fault-objects:

View File

@ -2078,13 +2078,13 @@ left undefined.
object.__ixor__(self, other)
object.__ior__(self, other)
These methods are called to implement the augmented arithmetic operations
These methods are called to implement the augmented arithmetic assignments
(``+=``, ``-=``, ``*=``, ``/=``, ``//=``, ``%=``, ``**=``, ``<<=``, ``>>=``,
``&=``, ``^=``, ``|=``). These methods should attempt to do the operation
in-place (modifying *self*) and return the result (which could be, but does
not have to be, *self*). If a specific method is not defined, the augmented
operation falls back to the normal methods. For instance, to evaluate the
expression ``x += y``, where *x* is an instance of a class that has an
assignment falls back to the normal methods. For instance, to execute the
statement ``x += y``, where *x* is an instance of a class that has an
:meth:`__iadd__` method, ``x.__iadd__(y)`` is called. If *x* is an instance
of a class that does not define a :meth:`__iadd__` method, ``x.__add__(y)``
and ``y.__radd__(x)`` are considered, as with the evaluation of ``x + y``.
@ -2244,7 +2244,8 @@ will not be supported.
In the current implementation, the built-in numeric types :class:`int`,
:class:`long` and :class:`float` do not use coercion; the type :class:`complex`
however does use it. The difference can become apparent when subclassing these
however does use coercion for binary operators and rich comparisons, despite
the above rules. The difference can become apparent when subclassing these
types. Over time, the type :class:`complex` may be fixed to avoid coercion.
All these types implement a :meth:`__coerce__` method, for use by the built-in
:func:`coerce` function.

View File

@ -816,14 +816,14 @@ Raising a negative number to a fractional power results in a :exc:`ValueError`.
.. _unary:
Unary arithmetic operations
===========================
Unary arithmetic and bitwise operations
=======================================
.. index::
triple: unary; arithmetic; operation
triple: unary; bitwise; operation
All unary arithmetic (and bitwise) operations have the same priority:
All unary arithmetic and bitwise operations have the same priority:
.. productionlist::
u_expr: `power` | "-" `u_expr` | "+" `u_expr` | "~" `u_expr`
@ -1276,12 +1276,9 @@ groups from right to left).
+-----------------------------------------------+-------------------------------------+
| :keyword:`not` *x* | Boolean NOT |
+-----------------------------------------------+-------------------------------------+
| :keyword:`in`, :keyword:`not` :keyword:`in` | Membership tests |
+-----------------------------------------------+-------------------------------------+
| :keyword:`is`, :keyword:`is not` | Identity tests |
+-----------------------------------------------+-------------------------------------+
| ``<``, ``<=``, ``>``, ``>=``, ``<>``, ``!=``, | Comparisons |
| ``==`` | |
| :keyword:`in`, :keyword:`not` :keyword:`in`, | Comparisons, including membership |
| :keyword:`is`, :keyword:`is not`, ``<``, | tests and identity tests, |
| ``<=``, ``>``, ``>=``, ``<>``, ``!=``, ``==`` | |
+-----------------------------------------------+-------------------------------------+
| ``|`` | Bitwise OR |
+-----------------------------------------------+-------------------------------------+
@ -1293,29 +1290,19 @@ groups from right to left).
+-----------------------------------------------+-------------------------------------+
| ``+``, ``-`` | Addition and subtraction |
+-----------------------------------------------+-------------------------------------+
| ``*``, ``/``, ``%`` | Multiplication, division, remainder |
| ``*``, ``/``, ``//``, ``%`` | Multiplication, division, remainder |
+-----------------------------------------------+-------------------------------------+
| ``+x``, ``-x`` | Positive, negative |
| ``+x``, ``-x``, ``~x`` | Positive, negative, bitwise NOT |
+-----------------------------------------------+-------------------------------------+
| ``~x`` | Bitwise not |
| ``**`` | Exponentiation [#]_ |
+-----------------------------------------------+-------------------------------------+
| ``**`` | Exponentiation |
| ``x[index]``, ``x[index:index]``, | Subscription, slicing, |
| ``x(arguments...)``, ``x.attribute`` | call, attribute reference |
+-----------------------------------------------+-------------------------------------+
| ``x[index]`` | Subscription |
+-----------------------------------------------+-------------------------------------+
| ``x[index:index]`` | Slicing |
+-----------------------------------------------+-------------------------------------+
| ``x(arguments...)`` | Call |
+-----------------------------------------------+-------------------------------------+
| ``x.attribute`` | Attribute reference |
+-----------------------------------------------+-------------------------------------+
| ``(expressions...)`` | Binding or tuple display |
+-----------------------------------------------+-------------------------------------+
| ``[expressions...]`` | List display |
+-----------------------------------------------+-------------------------------------+
| ``{key:datum...}`` | Dictionary display |
+-----------------------------------------------+-------------------------------------+
| ```expressions...``` | String conversion |
| ``(expressions...)``, | Binding or tuple display, |
| ``[expressions...]``, | list display, |
| ``{key:datum...}``, | dictionary display, |
| ```expressions...``` | string conversion |
+-----------------------------------------------+-------------------------------------+
.. rubric:: Footnotes
@ -1358,3 +1345,6 @@ groups from right to left).
descriptors, you may notice seemingly unusual behaviour in certain uses of
the :keyword:`is` operator, like those involving comparisons between instance
methods, or constants. Check their documentation for more info.
.. [#] The power operator ``**`` binds less tightly than an arithmetic or
bitwise unary operator on its right, that is, ``2**-1`` is ``0.5``.

View File

@ -65,8 +65,7 @@ IronPython
An alternate Python for .NET. Unlike Python.NET, this is a complete Python
implementation that generates IL, and compiles Python code directly to .NET
assemblies. It was created by Jim Hugunin, the original creator of Jython. For
more information, see `the IronPython website
<http://workspaces.gotdotnet.com/ironpython>`_.
more information, see `the IronPython website <http://www.ironpython.com/>`_.
PyPy
An implementation of Python written in Python; even the bytecode interpreter is

View File

@ -118,8 +118,8 @@ Assignment of an object to a target list is recursively defined as follows.
* If the target list is a single target: The object is assigned to that target.
* If the target list is a comma-separated list of targets: The object must be a
sequence with the same number of items as there are targets in the target list,
* If the target list is a comma-separated list of targets: The object must be an
iterable with the same number of items as there are targets in the target list,
and the items are assigned, from left to right, to the corresponding targets.
(This rule is relaxed as of Python 1.5; in earlier versions, the object had to
be a tuple. Since strings are sequences, an assignment like ``a, b = "xy"`` is
@ -143,9 +143,9 @@ Assignment of an object to a single target is recursively defined as follows.
be deallocated and its destructor (if it has one) to be called.
* If the target is a target list enclosed in parentheses or in square brackets:
The object must be a sequence with the same number of items as there are targets
in the target list, and its items are assigned, from left to right, to the
corresponding targets.
The object must be an iterable with the same number of items as there are
targets in the target list, and its items are assigned, from left to right,
to the corresponding targets.
.. index:: pair: attribute; assignment
@ -228,7 +228,8 @@ Augmented assignment is the combination, in a single statement, of a binary
operation and an assignment statement:
.. productionlist::
augmented_assignment_stmt: `target` `augop` (`expression_list` | `yield_expression`)
augmented_assignment_stmt: `augtarget` `augop` (`expression_list` | `yield_expression`)
augtarget: `identifier` | `attributeref` | `subscription` | `slicing`
augop: "+=" | "-=" | "*=" | "/=" | "//=" | "%=" | "**="
: | ">>=" | "<<=" | "&=" | "^=" | "|="

View File

@ -6,6 +6,9 @@
#
# 01/2009, Georg Brandl
# TODO: - wrong versions in versionadded/changed
# - wrong markup after versionchanged directive
from __future__ import with_statement
import os

View File

@ -13,6 +13,14 @@ ISSUE_URI = 'http://bugs.python.org/issue%s'
from docutils import nodes, utils
# monkey-patch reST parser to disable alphabetic and roman enumerated lists
from docutils.parsers.rst.states import Body
Body.enum.converters['loweralpha'] = \
Body.enum.converters['upperalpha'] = \
Body.enum.converters['lowerroman'] = \
Body.enum.converters['upperroman'] = lambda x: None
def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
issue = utils.unescape(text)
text = 'issue ' + issue

View File

@ -1761,8 +1761,8 @@ ElementTree 1.2.6. The :mod:`cElementTree` accelerator module is also
included.
The rest of this section will provide a brief overview of using ElementTree.
Full documentation for ElementTree is available at http://effbot.org/zone
/element-index.htm.
Full documentation for ElementTree is available at
http://effbot.org/zone/element-index.htm.
ElementTree represents an XML document as a tree of element nodes. The text
content of the document is stored as the :attr:`.text` and :attr:`.tail`

View File

@ -271,7 +271,6 @@ class ASTHelpers_Test(unittest.TestCase):
self.assertEqual(ast.literal_eval('(True, False, None)'), (True, False, None))
self.assertRaises(ValueError, ast.literal_eval, 'foo()')
def test_main():
test_support.run_unittest(AST_Tests, ASTHelpers_Test)