Commit 16215c73 authored by Georg Brandl's avatar Georg Brandl

Merged revisions 78959,79170,79175,79177,79180,79183,79186,79193,79581 via svnmerge from

svn+ssh://svn.python.org/python/branches/py3k

................
  r78959 | georg.brandl | 2010-03-14 11:56:14 +0100 (So, 14 Mär 2010) | 33 lines

  Merged revisions 78760,78771-78773,78802,78922,78952 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r78760 | georg.brandl | 2010-03-07 16:23:59 +0100 (So, 07 Mär 2010) | 1 line

    #5341: more built-in vs builtin fixes.
  ........
    r78771 | georg.brandl | 2010-03-07 21:58:31 +0100 (So, 07 Mär 2010) | 1 line

    #8085: The function is called PyObject_NewVar, not PyObject_VarNew.
  ........
    r78772 | georg.brandl | 2010-03-07 22:12:28 +0100 (So, 07 Mär 2010) | 1 line

    #8039: document conditional expressions better, giving them their own section.
  ........
    r78773 | georg.brandl | 2010-03-07 22:32:06 +0100 (So, 07 Mär 2010) | 1 line

    #8044: document Py_{Enter,Leave}RecursiveCall functions.
  ........
    r78802 | georg.brandl | 2010-03-08 17:28:40 +0100 (Mo, 08 Mär 2010) | 1 line

    Fix typo.
  ........
    r78922 | georg.brandl | 2010-03-13 14:41:58 +0100 (Sa, 13 Mär 2010) | 1 line

    Update for new download location.
  ........
    r78952 | georg.brandl | 2010-03-14 10:55:08 +0100 (So, 14 Mär 2010) | 1 line

    #8137: add iso-8859-16 to the standard encodings table.
  ........
................
  r79170 | georg.brandl | 2010-03-21 10:02:59 +0100 (So, 21 Mär 2010) | 1 line

  Fix some issues found by Jacques Ducasse on the docs list.
................
  r79175 | georg.brandl | 2010-03-21 10:10:32 +0100 (So, 21 Mär 2010) | 9 lines

  Merged revisions 79172 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r79172 | georg.brandl | 2010-03-21 10:08:00 +0100 (So, 21 Mär 2010) | 1 line

    Add a paragraph about set displays.
  ........
................
  r79177 | georg.brandl | 2010-03-21 10:25:54 +0100 (So, 21 Mär 2010) | 1 line

  Need to use list(range()) to get a list.
................
  r79180 | georg.brandl | 2010-03-21 10:50:49 +0100 (So, 21 Mär 2010) | 9 lines

  Merged revisions 79178 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r79178 | georg.brandl | 2010-03-21 10:28:16 +0100 (So, 21 Mär 2010) | 1 line

    Clarify that for shell=True, the shell PID will be the child PID.
  ........
................
  r79183 | georg.brandl | 2010-03-21 10:52:24 +0100 (So, 21 Mär 2010) | 9 lines

  Merged revisions 79181 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r79181 | georg.brandl | 2010-03-21 10:51:16 +0100 (So, 21 Mär 2010) | 1 line

    Update os.kill() emulation example for Windows to use ctypes.
  ........
................
  r79186 | georg.brandl | 2010-03-21 11:03:36 +0100 (So, 21 Mär 2010) | 13 lines

  Merged revisions 79184-79185 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r79184 | georg.brandl | 2010-03-21 10:58:36 +0100 (So, 21 Mär 2010) | 1 line

    Update text for newest US DST regulation.  The sample file already has the calculation right.
  ........
    r79185 | georg.brandl | 2010-03-21 11:02:47 +0100 (So, 21 Mär 2010) | 1 line

    Include structmember.h correctly.
  ........
................
  r79193 | georg.brandl | 2010-03-21 12:53:50 +0100 (So, 21 Mär 2010) | 9 lines

  Merged revisions 79192 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r79192 | georg.brandl | 2010-03-21 12:50:58 +0100 (So, 21 Mär 2010) | 1 line

    Remove leftover word.
  ........
................
  r79581 | georg.brandl | 2010-04-02 10:47:07 +0200 (Fr, 02 Apr 2010) | 1 line

  #8213: document behavior of -u on py3k better.
................
parent d6abb72a
......@@ -446,6 +446,36 @@ Exception Objects
This steals a reference to *ctx*.
Recursion Control
=================
These two functions provide a way to perform safe recursive calls at the C
level, both in the core and in extension modules. They are needed if the
recursive code does not necessarily invoke Python code (which tracks its
recursion depth automatically).
.. cfunction:: int Py_EnterRecursiveCall(char *where)
Marks a point where a recursive C-level call is about to be performed.
If :const:`USE_STACKCHECK` is defined, this function checks if the the OS
stack overflowed using :cfunc:`PyOS_CheckStack`. In this is the case, it
sets a :exc:`MemoryError` and returns a nonzero value.
The function then checks if the recursion limit is reached. If this is the
case, a :exc:`RuntimeError` is set and a nonzero value is returned.
Otherwise, zero is returned.
*where* should be a string such as ``" in instance check"`` to be
concatenated to the :exc:`RuntimeError` message caused by the recursion depth
limit.
.. cfunction:: void Py_LeaveRecursiveCall()
Ends a :cfunc:`Py_EnterRecursiveCall`. Must be called once for each
*successful* invocation of :cfunc:`Py_EnterRecursiveCall`.
.. _standardexceptions:
Standard Exceptions
......
......@@ -28,7 +28,7 @@ include the :const:`Py_TPFLAGS_HAVE_GC` and provide an implementation of the
Constructors for container types must conform to two rules:
#. The memory for the object must be allocated using :cfunc:`PyObject_GC_New`
or :cfunc:`PyObject_GC_VarNew`.
or :cfunc:`PyObject_GC_NewVar`.
#. Once all the fields which may contain references to other containers are
initialized, it must call :cfunc:`PyObject_GC_Track`.
......
......@@ -182,7 +182,7 @@ type objects) *must* have the :attr:`ob_size` field.
instance; this is normally :cfunc:`PyObject_Del` if the instance was allocated
using :cfunc:`PyObject_New` or :cfunc:`PyObject_VarNew`, or
:cfunc:`PyObject_GC_Del` if the instance was allocated using
:cfunc:`PyObject_GC_New` or :cfunc:`PyObject_GC_VarNew`.
:cfunc:`PyObject_GC_New` or :cfunc:`PyObject_GC_NewVar`.
This field is inherited by subtypes.
......
......@@ -236,7 +236,7 @@ This version of the module has a number of changes.
We've added an extra include::
#include "structmember.h"
#include <structmember.h>
This include provides declarations that we use to handle attributes, as
described a bit later.
......
......@@ -445,13 +445,15 @@ present, and ``getch()`` which gets one character without echoing it.
How do I emulate os.kill() in Windows?
--------------------------------------
Use win32api::
To terminate a process, you can use ctypes::
import ctypes
def kill(pid):
"""kill function for Win32"""
import win32api
handle = win32api.OpenProcess(1, 0, pid)
return (0 != win32api.TerminateProcess(handle, 0))
kernel32 = ctypes.windll.kernel32
handle = kernel32.OpenProcess(1, 0, pid)
return (0 != kernel32.TerminateProcess(handle, 0))
Why does os.path.isdir() fail on NT shared directories?
......
......@@ -1063,11 +1063,13 @@ particular, the following variants typically exist:
+-----------------+--------------------------------+--------------------------------+
| iso8859_10 | iso-8859-10, latin6, L6 | Nordic languages |
+-----------------+--------------------------------+--------------------------------+
| iso8859_13 | iso-8859-13 | Baltic languages |
| iso8859_13 | iso-8859-13, latin7, L7 | Baltic languages |
+-----------------+--------------------------------+--------------------------------+
| iso8859_14 | iso-8859-14, latin8, L8 | Celtic languages |
+-----------------+--------------------------------+--------------------------------+
| iso8859_15 | iso-8859-15 | Western Europe |
| iso8859_15 | iso-8859-15, latin9, L9 | Western Europe |
+-----------------+--------------------------------+--------------------------------+
| iso8859_16 | iso-8859-16, latin10, L10 | South-Eastern Europe |
+-----------------+--------------------------------+--------------------------------+
| johab | cp1361, ms1361 | Korean |
+-----------------+--------------------------------+--------------------------------+
......
......@@ -1460,8 +1460,8 @@ Example :class:`tzinfo` classes:
Note that there are unavoidable subtleties twice per year in a :class:`tzinfo`
subclass accounting for both standard and daylight time, at the DST transition
points. For concreteness, consider US Eastern (UTC -0500), where EDT begins the
minute after 1:59 (EST) on the first Sunday in April, and ends the minute after
1:59 (EDT) on the last Sunday in October::
minute after 1:59 (EST) on the second Sunday in March, and ends the minute after
1:59 (EDT) on the first Sunday in November::
UTC 3:MM 4:MM 5:MM 6:MM 7:MM 8:MM
EST 22:MM 23:MM 0:MM 1:MM 2:MM 3:MM
......
......@@ -633,7 +633,7 @@ example. Use ``+`` to enable the named behavior, or ``-`` to disable it.
For example, this test passes::
>>> print(range(20)) #doctest: +NORMALIZE_WHITESPACE
>>> print(list(range(20))) #doctest: +NORMALIZE_WHITESPACE
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
......@@ -642,28 +642,28 @@ two blanks before the single-digit list elements, and because the actual output
is on a single line. This test also passes, and also requires a directive to do
so::
>>> print(range(20)) # doctest: +ELLIPSIS
>>> print(list(range(20))) # doctest: +ELLIPSIS
[0, 1, ..., 18, 19]
Multiple directives can be used on a single physical line, separated by commas::
>>> print(range(20)) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
>>> print(list(range(20))) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
[0, 1, ..., 18, 19]
If multiple directive comments are used for a single example, then they are
combined::
>>> print(range(20)) # doctest: +ELLIPSIS
... # doctest: +NORMALIZE_WHITESPACE
>>> print(list(range(20))) # doctest: +ELLIPSIS
... # doctest: +NORMALIZE_WHITESPACE
[0, 1, ..., 18, 19]
As the previous example shows, you can add ``...`` lines to your example
containing only directives. This can be useful when an example is too long for
a directive to comfortably fit on the same line::
>>> print(range(5) + range(10,20) + range(30,40) + range(50,60))
>>> print(list(range(5)) + list(range(10, 20)) + list(range(30, 40)))
... # doctest: +ELLIPSIS
[0, ..., 4, 10, ..., 19, 30, ..., 39, 50, ..., 59]
[0, ..., 4, 10, ..., 19, 30, ..., 39]
Note that since all options are disabled by default, and directives apply only
to the example they appear in, enabling options (via ``+`` in a directive) is
......
......@@ -1639,6 +1639,10 @@ The :class:`frozenset` type is immutable and :term:`hashable` --- its contents c
altered after it is created; it can therefore be used as a dictionary key or as
an element of another set.
Non-empty sets (not frozensets) can be created by placing a comma-separated list
of elements within braces, for example: ``{'jack', 'sjoerd'}``, in addition to the
:class:`set` constructor.
The constructors for both classes work the same:
.. class:: set([iterable])
......
......@@ -396,6 +396,9 @@ The following attributes are also available:
The process ID of the child process.
Note that if you set the *shell* argument to ``True``, this is the process ID
of the spawned shell.
.. attribute:: Popen.returncode
......
......@@ -127,13 +127,12 @@ always available.
.. index:: object: traceback
If no exception is being handled anywhere on the stack, a tuple containing three
``None`` values is returned. Otherwise, the values returned are ``(type, value,
traceback)``. Their meaning is: *type* gets the exception type of the exception
being handled (a class object); *value* gets the exception parameter (its
:dfn:`associated value` or the second argument to :keyword:`raise`, which is
always a class instance if the exception type is a class object); *traceback*
gets a traceback object (see the Reference Manual) which encapsulates the call
If no exception is being handled anywhere on the stack, a tuple containing
three ``None`` values is returned. Otherwise, the values returned are
``(type, value, traceback)``. Their meaning is: *type* gets the type of the
exception being handled (a subclass of :exc:`BaseException`); *value* gets
the exception instance (an instance of the exception type); *traceback* gets
a traceback object (see the Reference Manual) which encapsulates the call
stack at the point where the exception originally occurred.
.. warning::
......@@ -495,9 +494,7 @@ always available.
more information.)
The meaning of the variables is the same as that of the return values from
:func:`exc_info` above. (Since there is only one interactive thread,
thread-safety is not a concern for these variables, unlike for ``exc_type``
etc.)
:func:`exc_info` above.
.. data:: maxsize
......
......@@ -120,7 +120,7 @@ namespace is searched. The global statement must precede all uses of the name.
.. index:: pair: restricted; execution
The built-in namespace associated with the execution of a code block is actually
The builtins namespace associated with the execution of a code block is actually
found by looking up the name ``__builtins__`` in its global namespace; this
should be a dictionary or a module (in the latter case the module's dictionary
is used). By default, when in the :mod:`__main__` module, ``__builtins__`` is
......@@ -132,7 +132,7 @@ weak form of restricted execution.
.. impl-detail::
Users should not touch ``__builtins__``; it is strictly an implementation
detail. Users wanting to override values in the built-in namespace should
detail. Users wanting to override values in the builtins namespace should
:keyword:`import` the :mod:`builtins` module and modify its
attributes appropriately.
......
......@@ -1120,12 +1120,7 @@ Boolean operations
pair: Conditional; expression
pair: Boolean; operation
Boolean operations have the lowest priority of all Python operations:
.. productionlist::
expression: `conditional_expression` | `lambda_form`
expression_nocond: `or_test` | `lambda_form_nocond`
conditional_expression: `or_test` ["if" `or_test` "else" `expression`]
or_test: `and_test` | `or_test` "or" `and_test`
and_test: `not_test` | `and_test` "and" `not_test`
not_test: `comparison` | "not" `not_test`
......@@ -1142,10 +1137,6 @@ truth value by providing a :meth:`__bool__` method.
The operator :keyword:`not` yields ``True`` if its argument is false, ``False``
otherwise.
The expression ``x if C else y`` first evaluates *C* (*not* *x*); if *C* is
true, *x* is evaluated and its value is returned; otherwise, *y* is evaluated
and its value is returned.
.. index:: operator: and
The expression ``x and y`` first evaluates *x*; if *x* is false, its value is
......@@ -1165,6 +1156,30 @@ not bother to return a value of the same type as its argument, so e.g., ``not
'foo'`` yields ``False``, not ``''``.)
Conditional Expressions
=======================
.. versionadded:: 2.5
.. index::
pair: conditional; expression
pair: ternary; operator
.. productionlist::
conditional_expression: `or_test` ["if" `or_test` "else" `expression`]
expression: `conditional_expression` | `lambda_form`
expression_nocond: `or_test` | `lambda_form_nocond`
Conditional expressions (sometimes called a "ternary operator") have the lowest
priority of all Python operations.
The expression ``x if C else y`` first evaluates the condition, *C* (*not* *x*);
if *C* is true, *x* is evaluated and its value is returned; otherwise, *y* is
evaluated and its value is returned.
See :pep:`308` for more details about conditional expressions.
.. _lambdas:
.. _lambda:
......@@ -1259,6 +1274,8 @@ groups from right to left).
+===============================================+=====================================+
| :keyword:`lambda` | Lambda expression |
+-----------------------------------------------+-------------------------------------+
| :keyword:`if` -- :keyword:`else` | Conditional expression |
+-----------------------------------------------+-------------------------------------+
| :keyword:`or` | Boolean OR |
+-----------------------------------------------+-------------------------------------+
| :keyword:`and` | Boolean AND |
......
......@@ -148,9 +148,9 @@ Assignment of an object to a single target is recursively defined as follows.
.. index:: single: destructor
The name is rebound if it was already bound. This may cause the reference count
for the object previously bound to the name to reach zero, causing the object to
be deallocated and its destructor (if it has one) to be called.
The name is rebound if it was already bound. This may cause the reference
count for the object previously bound to the name to reach zero, causing the
object to 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 an iterable with the same number of items as there are
......
......@@ -232,8 +232,9 @@ Miscellaneous options
.. cmdoption:: -u
Force stdin, stdout and stderr to be totally unbuffered. On systems where it
matters, also put stdin, stdout and stderr in binary mode.
Force the binary layer of the stdin, stdout and stderr streams (which is
available as their ``buffer`` attribute) to be unbuffered. The text I/O
layer will still be line-buffered.
See also :envvar:`PYTHONUNBUFFERED`.
......
......@@ -111,9 +111,9 @@ are:
:func:`reduce` function.
Python 3.0 adds several new built-in functions and changes the
semantics of some existing built-ins. Functions that are new in 3.0
semantics of some existing builtins. Functions that are new in 3.0
such as :func:`bin` have simply been added to Python 2.6, but existing
built-ins haven't been changed; instead, the :mod:`future_builtins`
builtins haven't been changed; instead, the :mod:`future_builtins`
module has versions with the new 3.0 semantics. Code written to be
compatible with 3.0 can do ``from future_builtins import hex, map`` as
necessary.
......@@ -837,7 +837,7 @@ formatted. It receives a single argument, the format specifier::
else:
return str(self)
There's also a :func:`format` built-in that will format a single
There's also a :func:`format` builtin that will format a single
value. It calls the type's :meth:`__format__` method with the
provided specifier::
......@@ -1168,7 +1168,7 @@ access protocol. Abstract Base Classes (or ABCs) are an equivalent
feature for Python. The ABC support consists of an :mod:`abc` module
containing a metaclass called :class:`ABCMeta`, special handling of
this metaclass by the :func:`isinstance` and :func:`issubclass`
built-ins, and a collection of basic ABCs that the Python developers
builtins, and a collection of basic ABCs that the Python developers
think will be widely useful. Future versions of Python will probably
add more ABCs.
......@@ -1322,9 +1322,9 @@ an octal number, but it does add support for "0o" and "0b"::
>>> 0b101111
47
The :func:`oct` built-in still returns numbers
The :func:`oct` builtin still returns numbers
prefixed with a leading zero, and a new :func:`bin`
built-in returns the binary representation for a number::
builtin returns the binary representation for a number::
>>> oct(42)
'052'
......@@ -1333,7 +1333,7 @@ built-in returns the binary representation for a number::
>>> bin(173)
'0b10101101'
The :func:`int` and :func:`long` built-ins will now accept the "0o"
The :func:`int` and :func:`long` builtins will now accept the "0o"
and "0b" prefixes when base-8 or base-2 are requested, or when the
*base* argument is zero (signalling that the base used should be
determined from the string)::
......@@ -1419,7 +1419,7 @@ can be shifted left and right with ``<<`` and ``>>``,
combined using bitwise operations such as ``&`` and ``|``,
and can be used as array indexes and slice boundaries.
In Python 3.0, the PEP slightly redefines the existing built-ins
In Python 3.0, the PEP slightly redefines the existing builtins
:func:`round`, :func:`math.floor`, :func:`math.ceil`, and adds a new
one, :func:`math.trunc`, that's been backported to Python 2.6.
:func:`math.trunc` rounds toward zero, returning the closest
......@@ -1520,7 +1520,7 @@ Some smaller changes made to the core Python language are:
Previously this would have been a syntax error.
(Contributed by Amaury Forgeot d'Arc; :issue:`3473`.)
* A new built-in, ``next(iterator, [default])`` returns the next item
* A new builtin, ``next(iterator, [default])`` returns the next item
from the specified iterator. If the *default* argument is supplied,
it will be returned if *iterator* has been exhausted; otherwise,
the :exc:`StopIteration` exception will be raised. (Backported
......@@ -1949,9 +1949,9 @@ changes, or look through the Subversion logs for all the details.
(Contributed by Phil Schwartz; :issue:`1221598`.)
* The :func:`reduce` built-in function is also available in the
:mod:`functools` module. In Python 3.0, the built-in has been
:mod:`functools` module. In Python 3.0, the builtin has been
dropped and :func:`reduce` is only available from :mod:`functools`;
currently there are no plans to drop the built-in in the 2.x series.
currently there are no plans to drop the builtin in the 2.x series.
(Patched by Christian Heimes; :issue:`1739906`.)
* When possible, the :mod:`getpass` module will now use
......@@ -2753,7 +2753,7 @@ The functions in this module currently include:
* ``filter(predicate, iterable)``,
``map(func, iterable1, ...)``: the 3.0 versions
return iterators, unlike the 2.x built-ins which return lists.
return iterators, unlike the 2.x builtins which return lists.
* ``hex(value)``, ``oct(value)``: instead of calling the
:meth:`__hex__` or :meth:`__oct__` methods, these versions will
......
This diff is collapsed.
......@@ -37,7 +37,7 @@ Py_TRACE_REFS introduced in 1.4
Turn on heavy reference debugging. This is major surgery. Every PyObject
grows two more pointers, to maintain a doubly-linked list of all live
heap-allocated objects. Most builtin type objects are not in this list,
heap-allocated objects. Most built-in type objects are not in this list,
as they're statically allocated. Starting in Python 2.3, if COUNT_ALLOCS
(see below) is also defined, a static type object T does appear in this
list if at least one object of type T has been created.
......
......@@ -165,12 +165,12 @@ and the site-dependent manipulations of
that it entails.
.TP
.B \-u
Force stdin, stdout and stderr to be totally unbuffered. On systems
where it matters, also put stdin, stdout and stderr in binary mode.
Note that there is internal buffering in readlines() and
file-object iterators ("for line in sys.stdin") which is not
influenced by this option. To work around this, you will want to use
"sys.stdin.readline()" inside a "while 1:" loop.
Force the binary I/O layers of stdin, stdout and stderr to be unbuffered.
The text I/O layer will still be line-buffered.
.\" Note that there is internal buffering in readlines() and
.\" file-object iterators ("for line in sys.stdin") which is not
.\" influenced by this option. To work around this, you will want to use
.\" "sys.stdin.readline()" inside a "while 1:" loop.
.TP
.B \-v
Print a message each time a module is initialized, showing the place
......
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