Index: Doc/distutils/builtdist.rst =================================================================== --- Doc/distutils/builtdist.rst (revision 58748) +++ Doc/distutils/builtdist.rst (working copy) @@ -311,7 +311,7 @@ have to create a separate installer for every Python version you want to support. -The installer will try to compile pure modules into bytecode after installation +The installer will try to compile pure modules into :term:`bytecode` after installation on the target system in normal and optimizing mode. If you don't want this to happen for some reason, you can run the :command:`bdist_wininst` command with the :option:`--no-target-compile` and/or the :option:`--no-target-optimize` Index: Doc/distutils/apiref.rst =================================================================== --- Doc/distutils/apiref.rst (revision 58748) +++ Doc/distutils/apiref.rst (working copy) @@ -1199,7 +1199,7 @@ If *force* is true, all files are recompiled regardless of timestamps. - The source filename encoded in each bytecode file defaults to the filenames + The source filename encoded in each :term:`bytecode` file defaults to the filenames listed in *py_files*; you can modify these with *prefix* and *basedir*. *prefix* is a string that will be stripped off of each source filename, and *base_dir* is a directory name that will be prepended (after *prefix* is Index: Doc/extending/newtypes.rst =================================================================== --- Doc/extending/newtypes.rst (revision 58748) +++ Doc/extending/newtypes.rst (working copy) @@ -1110,7 +1110,7 @@ attributes, when the values are computed, or how relevant data is stored. When :cfunc:`PyType_Ready` is called, it uses three tables referenced by the -type object to create *descriptors* which are placed in the dictionary of the +type object to create :term:`descriptor`\s which are placed in the dictionary of the type object. Each descriptor controls access to one attribute of the instance object. Each of the tables is optional; if all three are *NULL*, instances of the type will only have attributes that are inherited from their base type, and @@ -1154,7 +1154,7 @@ char *doc; } PyMemberDef; -For each entry in the table, a descriptor will be constructed and added to the +For each entry in the table, a :term:`descriptor` will be constructed and added to the type which will be able to extract a value from the instance structure. The :attr:`type` field should contain one of the type codes defined in the :file:`structmember.h` header; the value will be used to determine how to Index: Doc/c-api/newtypes.rst =================================================================== --- Doc/c-api/newtypes.rst (revision 58748) +++ Doc/c-api/newtypes.rst (working copy) @@ -611,6 +611,7 @@ The :attr:`tp_as_sequence` field is not inherited, but the contained fields are inherited individually. +<<<<<<< .working .. cmember:: PyMappingMethods* tp_as_mapping @@ -622,6 +623,19 @@ inherited individually. +======= + +.. cmember:: PyMappingMethods* tp_as_mapping + + Pointer to an additional structure that contains fields relevant only to + objects which implement the mapping protocol. These fields are documented in + :ref:`mapping-structs`. + + The :attr:`tp_as_mapping` field is not inherited, but the contained fields + are inherited individually. + + +>>>>>>> .merge-right.r58739 .. cmember:: hashfunc PyTypeObject.tp_hash .. index:: builtin: hash @@ -1418,6 +1432,7 @@ of the library. +<<<<<<< .working .. _number-structs: Number Object Structures @@ -1488,6 +1503,99 @@ and set an exception. +======= +.. _number-structs: + +Number Object Structures +======================== + +.. sectionauthor:: Amaury Forgeot d'Arc + + +.. ctype:: PyNumberMethods + + This structure holds pointers to the functions which an object uses to + implement the number protocol. Almost every function below is used by the + function of similar name documented in the :ref:`number` section. + + Here is the structure definition:: + + typedef struct { + binaryfunc nb_add; + binaryfunc nb_subtract; + binaryfunc nb_multiply; + binaryfunc nb_remainder; + binaryfunc nb_divmod; + ternaryfunc nb_power; + unaryfunc nb_negative; + unaryfunc nb_positive; + unaryfunc nb_absolute; + inquiry nb_nonzero; /* Used by PyObject_IsTrue */ + unaryfunc nb_invert; + binaryfunc nb_lshift; + binaryfunc nb_rshift; + binaryfunc nb_and; + binaryfunc nb_xor; + binaryfunc nb_or; + coercion nb_coerce; /* Used by the coerce() funtion */ + unaryfunc nb_int; + unaryfunc nb_long; + unaryfunc nb_float; + unaryfunc nb_oct; + unaryfunc nb_hex; + + /* Added in release 2.0 */ + binaryfunc nb_inplace_add; + binaryfunc nb_inplace_subtract; + binaryfunc nb_inplace_multiply; + binaryfunc nb_inplace_remainder; + ternaryfunc nb_inplace_power; + binaryfunc nb_inplace_lshift; + binaryfunc nb_inplace_rshift; + binaryfunc nb_inplace_and; + binaryfunc nb_inplace_xor; + binaryfunc nb_inplace_or; + + /* Added in release 2.2 */ + binaryfunc nb_floor_divide; + binaryfunc nb_true_divide; + binaryfunc nb_inplace_floor_divide; + binaryfunc nb_inplace_true_divide; + + /* Added in release 2.5 */ + unaryfunc nb_index; + } PyNumberMethods; + + +Binary and ternary functions may receive different kinds of arguments, depending +on the flag bit :const:`Py_TPFLAGS_CHECKTYPES`: + +- If :const:`Py_TPFLAGS_CHECKTYPES` is not set, the function arguments are + guaranteed to be of the object's type; the caller is responsible for calling + the coercion method specified by the :attr:`nb_coerce` member to convert the + arguments: + + .. cmember:: coercion PyNumberMethods.nb_coerce + + This function is used by :cfunc:`PyNumber_CoerceEx` and has the same + signature. The first argument is always a pointer to an object of the + defined type. If the conversion to a common "larger" type is possible, the + function replaces the pointers with new references to the converted objects + and returns ``0``. If the conversion is not possible, the function returns + ``1``. If an error condition is set, it will return ``-1``. + +- If the :const:`Py_TPFLAGS_CHECKTYPES` flag is set, binary and ternary + functions must check the type of all their operands, and implement the + necessary conversions (at least one of the operands is an instance of the + defined type). This is the recommended way; with Python 3.0 coercion will + disappear completely. + +If the operation is not defined for the given operands, binary and ternary +functions must return ``Py_NotImplemented``, if another error occurred they must +return ``NULL`` and set an exception. + + +>>>>>>> .merge-right.r58739 .. _mapping-structs: Mapping Object Structures Index: Doc/c-api/abstract.rst =================================================================== --- Doc/c-api/abstract.rst (revision 58748) +++ Doc/c-api/abstract.rst (working copy) @@ -31,22 +31,15 @@ instead of the :func:`repr`. -.. cfunction:: int PyObject_HasAttrString(PyObject *o, const char *attr_name) +.. cfunction:: int PyObject_HasAttr(PyObject *o, PyObject *attr_name) Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This is equivalent to the Python expression ``hasattr(o, attr_name)``. This function always succeeds. -.. cfunction:: PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name) +.. cfunction:: int PyObject_HasAttrString(PyObject *o, const char *attr_name) - Retrieve an attribute named *attr_name* from object *o*. Returns the attribute - value on success, or *NULL* on failure. This is the equivalent of the Python - expression ``o.attr_name``. - - -.. cfunction:: int PyObject_HasAttr(PyObject *o, PyObject *attr_name) - Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This is equivalent to the Python expression ``hasattr(o, attr_name)``. This function always succeeds. @@ -59,27 +52,34 @@ expression ``o.attr_name``. -.. cfunction:: int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v) +.. cfunction:: PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name) + Retrieve an attribute named *attr_name* from object *o*. Returns the attribute + value on success, or *NULL* on failure. This is the equivalent of the Python + expression ``o.attr_name``. + + +.. 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 *v*. Returns ``-1`` on failure. This is the equivalent of the Python statement ``o.attr_name = v``. -.. cfunction:: int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v) +.. cfunction:: int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v) Set the value of the attribute named *attr_name*, for object *o*, to the value *v*. Returns ``-1`` on failure. This is the equivalent of the Python statement ``o.attr_name = v``. -.. cfunction:: int PyObject_DelAttrString(PyObject *o, const char *attr_name) +.. cfunction:: int PyObject_DelAttr(PyObject *o, PyObject *attr_name) Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure. - This is the equivalent of the Python statement: ``del o.attr_name``. + This is the equivalent of the Python statement ``del o.attr_name``. -.. cfunction:: int PyObject_DelAttr(PyObject *o, PyObject *attr_name) +.. cfunction:: int PyObject_DelAttrString(PyObject *o, const char *attr_name) Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure. This is the equivalent of the Python statement ``del o.attr_name``. @@ -327,7 +327,14 @@ .. cfunction:: int PyObject_AsFileDescriptor(PyObject *o) +<<<<<<< .working Derives a file-descriptor from a Python object. +======= + Derives a file descriptor from a Python object. If the object is an integer or + long integer, its value is returned. If not, the object's :meth:`fileno` method + is called if it exists; the method must return an integer or long integer, which + is returned as the file descriptor value. Returns ``-1`` on failure. +>>>>>>> .merge-right.r58739 .. cfunction:: PyObject* PyObject_Dir(PyObject *o) @@ -575,6 +582,13 @@ the Python statement ``o1 |= o2``. +.. cfunction:: int PyNumber_CoerceEx(PyObject **p1, PyObject **p2) + + This function is similar to :cfunc:`PyNumber_Coerce`, except that it returns + ``1`` when the conversion is not possible and when no error is raised. + Reference counts are still not increased in this case. + + .. cfunction:: PyObject* PyNumber_Int(PyObject *o) .. index:: builtin: int Index: Doc/c-api/index.rst =================================================================== --- Doc/c-api/index.rst (revision 58748) +++ Doc/c-api/index.rst (working copy) @@ -12,12 +12,6 @@ which describes the general principles of extension writing but does not document the API functions in detail. -.. warning:: - - The current version of this document is somewhat incomplete. However, most of - the important functions, types and structures are described. - - .. toctree:: :maxdepth: 2 Index: Doc/reference/datamodel.rst =================================================================== --- Doc/reference/datamodel.rst (revision 58748) +++ Doc/reference/datamodel.rst (working copy) @@ -852,7 +852,7 @@ single: bytecode object: code - Code objects represent *byte-compiled* executable Python code, or *bytecode*. + Code objects represent *byte-compiled* executable Python code, or :term:`bytecode`. The difference between a code object and a function object is that the function object contains an explicit reference to the function's globals (the module in which it was defined), while a code object contains no context; also the default @@ -873,7 +873,7 @@ used by the bytecode; :attr:`co_names` is a tuple containing the names used by the bytecode; :attr:`co_filename` is the filename from which the code was compiled; :attr:`co_firstlineno` is the first line number of the function; - :attr:`co_lnotab` is a string encoding the mapping from byte code offsets to + :attr:`co_lnotab` is a string encoding the mapping from bytecode offsets to line numbers (for details see the source code of the interpreter); :attr:`co_stacksize` is the required stack size (including local variables); :attr:`co_flags` is an integer encoding a number of flags for the interpreter. @@ -1039,6 +1039,7 @@ .. % ========================================================================= +.. _newstyle: .. _specialnames: Index: Doc/reference/compound_stmts.rst =================================================================== --- Doc/reference/compound_stmts.rst (revision 58748) +++ Doc/reference/compound_stmts.rst (working copy) @@ -553,8 +553,14 @@ class and instance variables are accessible through the notation "``self.name``", and an instance variable hides a class variable with the same name when accessed in this way. Class variables with immutable values can be +<<<<<<< .working used as defaults for instance variables. Descriptors can be used to create instance variables with different implementation details. +======= +used as defaults for instance variables. For :term:`new-style class`\es, +descriptors can be used to create instance variables with different +implementation details. +>>>>>>> .merge-right.r58739 .. XXX add link to descriptor docs above Index: Doc/reference/expressions.rst =================================================================== --- Doc/reference/expressions.rst (revision 58748) +++ Doc/reference/expressions.rst (working copy) @@ -1270,10 +1270,19 @@ cases, Python returns the latter result, in order to preserve that ``divmod(x,y)[0] * y + x % y`` be very close to ``x``. +<<<<<<< .working .. [#] While comparisons between strings make sense at the byte level, they may be counter-intuitive to users. For example, the strings ``"\u00C7"`` and ``"\u0327\u0043"`` compare differently, even though they both represent the same unicode character (LATIN CAPTITAL LETTER C WITH CEDILLA). +======= +.. [#] While comparisons between unicode strings make sense at the byte + level, they may be counter-intuitive to users. For example, the + strings ``u"\u00C7"`` and ``u"\u0043\u0327"`` compare differently, + even though they both represent the same unicode character (LATIN + CAPTITAL LETTER C WITH CEDILLA). To compare strings in a human + recognizable way, compare using :func:`unicodedata.normalize`. +>>>>>>> .merge-right.r58739 .. [#] The implementation computes this efficiently, without constructing lists or sorting. Index: Doc/ACKS.txt =================================================================== --- Doc/ACKS.txt (revision 58748) +++ Doc/ACKS.txt (working copy) @@ -104,6 +104,7 @@ * Detlef Lannert * Piers Lauder * Glyph Lefkowitz +* Robert Lehmann * Marc-André Lemburg * Ulf A. Lindgren * Everett Lipman Index: Doc/howto/regex.rst =================================================================== --- Doc/howto/regex.rst (revision 58748) +++ Doc/howto/regex.rst (working copy) @@ -354,7 +354,7 @@ | | returns them as a list. | +------------------+-----------------------------------------------+ | ``finditer()`` | Find all substrings where the RE matches, and | -| | returns them as an iterator. | +| | returns them as an :term:`iterator`. | +------------------+-----------------------------------------------+ :meth:`match` and :meth:`search` return ``None`` if no match can be found. If @@ -460,7 +460,7 @@ :meth:`findall` has to create the entire list before it can be returned as the result. The :meth:`finditer` method returns a sequence of :class:`MatchObject` -instances as an iterator. [#]_ :: +instances as an :term:`iterator`. [#]_ :: >>> iterator = p.finditer('12 drummers drumming, 11 ... 10 ...') >>> iterator Index: Doc/howto/functional.rst =================================================================== --- Doc/howto/functional.rst (revision 58748) +++ Doc/howto/functional.rst (working copy) @@ -13,8 +13,8 @@ In this document, we'll take a tour of Python's features suitable for implementing programs in a functional style. After an introduction to the concepts of functional programming, we'll look at language features such as -iterators and generators and relevant library modules such as :mod:`itertools` -and :mod:`functools`. +:term:`iterator`\s and :term:`generator`\s and relevant library modules such as +:mod:`itertools` and :mod:`functools`. Introduction @@ -448,8 +448,8 @@ yield i Any function containing a ``yield`` keyword is a generator function; this is -detected by Python's bytecode compiler which compiles the function specially as -a result. +detected by Python's :term:`bytecode` compiler which compiles the function +specially as a result. When you call a generator function, it doesn't return a single value; instead it returns a generator object that supports the iterator protocol. On executing Index: Doc/howto/pythonmac.rst =================================================================== --- Doc/howto/pythonmac.rst (revision 58749) +++ Doc/howto/pythonmac.rst (working copy) @@ -1,202 +0,0 @@ - -.. _using-on-mac: - -*************************** -Using Python on a Macintosh -*************************** - -:Author: Bob Savage - - -Python on a Macintosh running Mac OS X is in principle very similar to Python on -any other Unix platform, but there are a number of additional features such as -the IDE and the Package Manager that are worth pointing out. - -The Mac-specific modules are documented in :ref:`mac-specific-services`. - -Python on Mac OS 9 or earlier can be quite different from Python on Unix or -Windows, but is beyond the scope of this manual, as that platform is no longer -supported, starting with Python 2.4. See http://www.cwi.nl/~jack/macpython for -installers for the latest 2.3 release for Mac OS 9 and related documentation. - - -.. _getting-osx: - -Getting and Installing MacPython -================================ - -Mac OS X 10.4 comes with Python 2.3 pre-installed by Apple. However, you are -encouraged to install the most recent version of Python from the Python website -(http://www.python.org). A "universal binary" build of Python 2.5, which runs -natively on the Mac's new Intel and legacy PPC CPU's, is available there. - -What you get after installing is a number of things: - -* A :file:`MacPython 2.5` folder in your :file:`Applications` folder. In here - you find IDLE, the development environment that is a standard part of official - Python distributions; PythonLauncher, which handles double-clicking Python - scripts from the Finder; and the "Build Applet" tool, which allows you to - package Python scripts as standalone applications on your system. - -* A framework :file:`/Library/Frameworks/Python.framework`, which includes the - Python executable and libraries. The installer adds this location to your shell - path. To uninstall MacPython, you can simply remove these three things. A - symlink to the Python executable is placed in /usr/local/bin/. - -The Apple-provided build of Python is installed in -:file:`/System/Library/Frameworks/Python.framework` and :file:`/usr/bin/python`, -respectively. You should never modify or delete these, as they are -Apple-controlled and are used by Apple- or third-party software. - -IDLE includes a help menu that allows you to access Python documentation. If you -are completely new to Python you should start reading the tutorial introduction -in that document. - -If you are familiar with Python on other Unix platforms you should read the -section on running Python scripts from the Unix shell. - - -How to run a Python script --------------------------- - -Your best way to get started with Python on Mac OS X is through the IDLE -integrated development environment, see section :ref:`ide` and use the Help menu -when the IDE is running. - -If you want to run Python scripts from the Terminal window command line or from -the Finder you first need an editor to create your script. Mac OS X comes with a -number of standard Unix command line editors, :program:`vim` and -:program:`emacs` among them. If you want a more Mac-like editor, -:program:`BBEdit` or :program:`TextWrangler` from Bare Bones Software (see -http://www.barebones.com/products/bbedit/index.shtml) are good choices, as is -:program:`TextMate` (see http://macromates.com/). Other editors include -:program:`Gvim` (http://macvim.org) and :program:`Aquamacs` -(http://aquamacs.org). - -To run your script from the Terminal window you must make sure that -:file:`/usr/local/bin` is in your shell search path. - -To run your script from the Finder you have two options: - -* Drag it to :program:`PythonLauncher` - -* Select :program:`PythonLauncher` as the default application to open your - script (or any .py script) through the finder Info window and double-click it. - :program:`PythonLauncher` has various preferences to control how your script is - launched. Option-dragging allows you to change these for one invocation, or use - its Preferences menu to change things globally. - - -.. _osx-gui-scripts: - -Running scripts with a GUI --------------------------- - -With older versions of Python, there is one Mac OS X quirk that you need to be -aware of: programs that talk to the Aqua window manager (in other words, -anything that has a GUI) need to be run in a special way. Use :program:`pythonw` -instead of :program:`python` to start such scripts. - -With Python 2.5, you can use either :program:`python` or :program:`pythonw`. - - -Configuration -------------- - -Python on OS X honors all standard Unix environment variables such as -:envvar:`PYTHONPATH`, but setting these variables for programs started from the -Finder is non-standard as the Finder does not read your :file:`.profile` or -:file:`.cshrc` at startup. You need to create a file :file:`~ -/.MacOSX/environment.plist`. See Apple's Technical Document QA1067 for details. - -For more information on installation Python packages in MacPython, see section -:ref:`mac-package-manager`. - - -.. _ide: - -The IDE -======= - -MacPython ships with the standard IDLE development environment. A good -introduction to using IDLE can be found at http://hkn.eecs.berkeley.edu/ -dyoo/python/idle_intro/index.html. - - -.. _mac-package-manager: - -Installing Additional Python Packages -===================================== - -There are several methods to install additional Python packages: - -* http://pythonmac.org/packages/ contains selected compiled packages for Python - 2.5, 2.4, and 2.3. - -* Packages can be installed via the standard Python distutils mode (``python - setup.py install``). - -* Many packages can also be installed via the :program:`setuptools` extension. - - -GUI Programming on the Mac -========================== - -There are several options for building GUI applications on the Mac with Python. - -*PyObjC* is a Python binding to Apple's Objective-C/Cocoa framework, which is -the foundation of most modern Mac development. Information on PyObjC is -available from http://pyobjc.sourceforge.net. - -The standard Python GUI toolkit is :mod:`Tkinter`, based on the cross-platform -Tk toolkit (http://www.tcl.tk). An Aqua-native version of Tk is bundled with OS -X by Apple, and the latest version can be downloaded and installed from -http://www.activestate.com; it can also be built from source. - -*wxPython* is another popular cross-platform GUI toolkit that runs natively on -Mac OS X. Packages and documentation are available from http://www.wxpython.org. - -*PyQt* is another popular cross-platform GUI toolkit that runs natively on Mac -OS X. More information can be found at -http://www.riverbankcomputing.co.uk/pyqt/. - - -Distributing Python Applications on the Mac -=========================================== - -The "Build Applet" tool that is placed in the MacPython 2.5 folder is fine for -packaging small Python scripts on your own machine to run as a standard Mac -application. This tool, however, is not robust enough to distribute Python -applications to other users. - -The standard tool for deploying standalone Python applications on the Mac is -:program:`py2app`. More information on installing and using py2app can be found -at http://undefined.org/python/#py2app. - - -Application Scripting -===================== - -Python can also be used to script other Mac applications via Apple's Open -Scripting Architecture (OSA); see http://appscript.sourceforge.net. Appscript is -a high-level, user-friendly Apple event bridge that allows you to control -scriptable Mac OS X applications using ordinary Python scripts. Appscript makes -Python a serious alternative to Apple's own *AppleScript* language for -automating your Mac. A related package, *PyOSA*, is an OSA language component -for the Python scripting language, allowing Python code to be executed by any -OSA-enabled application (Script Editor, Mail, iTunes, etc.). PyOSA makes Python -a full peer to AppleScript. - - -Other Resources -=============== - -The MacPython mailing list is an excellent support resource for Python users and -developers on the Mac: - -http://www.python.org/community/sigs/current/pythonmac-sig/ - -Another useful resource is the MacPython wiki: - -http://wiki.python.org/moin/MacPython - Index: Doc/howto/index.rst =================================================================== --- Doc/howto/index.rst (revision 58748) +++ Doc/howto/index.rst (working copy) @@ -14,7 +14,6 @@ :maxdepth: 1 advocacy.rst - pythonmac.rst curses.rst doanddont.rst functional.rst Index: Doc/whatsnew/2.6.rst =================================================================== --- Doc/whatsnew/2.6.rst (revision 58748) +++ Doc/whatsnew/2.6.rst (working copy) @@ -67,7 +67,6 @@ .. % Large, PEP-level features and changes should be described here. .. % Should there be a new section here for 3k migration? .. % Or perhaps a more general section describing module changes/deprecation? -.. % sets module deprecated .. % ====================================================================== Python 3.0 @@ -75,8 +74,24 @@ .. % XXX add general comment about Python 3.0 features in 2.6 -.. % XXX mention -3 switch +The development cycle for Python 2.6 also saw the release of the first +alphas of Python 3.0, and the development of 3.0 has influenced +a number of features in 2.6. +Python 3.0 is a far-ranging redesign of Python that breaks +compatibility with the 2.x series. This means that existing Python +code will need a certain amount of conversion in order to run on +Python 3.0. However, not all the changes in 3.0 necessarily break +compatibility. In cases where new features won't cause existing code +to break, they've been backported to 2.6 and are described in this +document in the appropriate place. Some of the 3.0-derived features +are: + +* A :meth:`__complex__` method for converting objects to a complex number. +* Alternate syntax for catching exceptions: ``except TypeError as exc``. +* The addition of :func:`functools.reduce` as a synonym for the built-in + :func:`reduce` function. + A new command-line switch, :option:`-3`, enables warnings about features that will be removed in Python 3.0. You can run code with this switch to see how much work will be necessary to port @@ -406,11 +421,6 @@ Here are all of the changes that Python 2.6 makes to the core Python language. -* Changes to the :class:`Exception` interface - as dictated by :pep:`352` continue to be made. For 2.6, - the :attr:`message` attribute is being deprecated in favor of the - :attr:`args` attribute. - * When calling a function using the ``**`` syntax to provide keyword arguments, you are no longer required to use a Python dictionary; any mapping will now work:: @@ -426,8 +436,29 @@ .. % Patch 1686487 +* The built-in types now have improved support for extended slicing syntax, + where various combinations of ``(start, stop, step)`` are supplied. + Previously, the support was partial and certain corner cases wouldn't work. + (Implemented by Thomas Wouters.) + + .. % Revision 57619 + +* C functions and methods that use + :cfunc:`PyComplex_AsCComplex` will now accept arguments that + have a :meth:`__complex__` method. In particular, the functions in the + :mod:`cmath` module will now accept objects with this method. + This is a backport of a Python 3.0 change. + (Contributed by Mark Dickinson.) + + .. % Patch #1675423 + +* Changes to the :class:`Exception` interface + as dictated by :pep:`352` continue to be made. For 2.6, + the :attr:`message` attribute is being deprecated in favor of the + :attr:`args` attribute. + * The :func:`compile` built-in function now accepts keyword arguments - as well as positional parameters. (Contributed by XXX.) + as well as positional parameters. (Contributed by Thomas Wouters.) .. % Patch 1444529 @@ -483,21 +514,73 @@ by module name. Consult the :file:`Misc/NEWS` file in the source tree for a more complete list of changes, or look through the CVS logs for all the details. -* A new data type in the :mod:`collections` module: :class:`NamedTuple(typename, +* The :mod:`bsddb.dbshelve` module now uses the highest pickling protocol + available, instead of restricting itself to protocol 1. + (Contributed by W. Barnes.) + + .. % Patch 1551443 + +* A new data type in the :mod:`collections` module: :class:`namedtuple(typename, fieldnames)` is a factory function that creates subclasses of the standard tuple whose fields are accessible by name as well as index. For example:: - var_type = collections.NamedTuple('variable', - 'id name type size') - var = var_type(1, 'frequency', 'int', 4) + >>> var_type = collections.namedtuple('variable', + ... 'id name type size') + # Names are separated by spaces or commas. + # 'id, name, type, size' would also work. + >>> var_type.__fields__ + ('id', 'name', 'type', 'size') - print var[0], var.id # Equivalent - print var[2], var.type # Equivalent + >>> var = var_type(1, 'frequency', 'int', 4) + >>> print var[0], var.id # Equivalent + 1 1 + >>> print var[2], var.type # Equivalent + int int + >>> var.__asdict__() + {'size': 4, 'type': 'int', 'id': 1, 'name': 'frequency'} + >>> v2 = var.__replace__('name', 'amplitude') + >>> v2 + variable(id=1, name='amplitude', type='int', size=4) (Contributed by Raymond Hettinger.) +* Another change to the :mod:`collections` module is that the + :class:`deque` type now supports an optional `maxlen` parameter; + if supplied, the deque's size will be restricted to no more + than ``maxlen`` items. Adding more items to a full deque causes + old items to be discarded. + + :: + + >>> from collections import deque + >>> dq=deque(maxlen=3) + >>> dq + deque([], maxlen=3) + >>> dq.append(1) ; dq.append(2) ; dq.append(3) + >>> dq + deque([1, 2, 3], maxlen=3) + >>> dq.append(4) + >>> dq + deque([2, 3, 4], maxlen=3) + + (Contributed by Raymond Hettinger.) + +* The :mod:`ctypes` module now supports a :class:`c_bool` datatype + that represents the C99 ``bool`` type. (Contributed by David Remahl.) + + .. % Patch 1649190 + + The :mod:`ctypes` string, buffer and array types also have improved + support for extended slicing syntax, + where various combinations of ``(start, stop, step)`` are supplied. + (Implemented by Thomas Wouters.) + + .. % Revision 57769 + + * A new method in the :mod:`curses` module: for a window, :meth:`chgat` changes - the display characters for a certain number of characters on a single line. :: + the display characters for a certain number of characters on a single line. + :: # Boldface text starting at y=0,x=21 # and affecting the rest of the line. @@ -505,11 +588,33 @@ (Contributed by Fabian Kreutz.) +* The :mod:`decimal` module was updated to version 1.66 of + `the General Decimal Specification `__. New features + include some methods for some basic mathematical functions such as + :meth:`exp` and :meth:`log10`:: + + >>> Decimal(1).exp() + Decimal("2.718281828459045235360287471") + >>> Decimal("2.7182818").ln() + Decimal("0.9999999895305022877376682436") + >>> Decimal(1000).log10() + Decimal("3") + + (Implemented by Facundo Batista and Mark Dickinson.) + * An optional ``timeout`` parameter was added to the :class:`ftplib.FTP` class constructor as well as the :meth:`connect` method, specifying a timeout measured in seconds. (Added by Facundo Batista.) +* The :func:`reduce` built-in function is also available in the + :mod:`functools` module. In Python 3.0, the built-in is dropped and it's + only available from :mod:`functools`; currently there are no plans + to drop the built-in in the 2.x series. (Patched by + Christian Heimes.) + + .. % Patch 1739906 + * The :func:`glob.glob` function can now return Unicode filenames if a Unicode path was used and Unicode filenames are matched within the directory. @@ -548,7 +653,7 @@ .. % Patch #1490190 -* The :func:`os.walk` function now has a "followlinks" parameter. If +* The :func:`os.walk` function now has a ``followlinks`` parameter. If set to True, it will follow symlinks pointing to directories and visit the directory's contents. For backward compatibility, the parameter's default value is false. Note that the function can fall @@ -557,6 +662,12 @@ .. % Patch 1273829 +* The ``os.environ`` object's :meth:`clear` method will now unset the + environment variables using :func:`os.unsetenv` in addition to clearing + the object's keys. (Contributed by Martin Horcicka.) + + .. % Patch #1181 + * In the :mod:`os.path` module, the :func:`splitext` function has been changed to not split on leading period characters. This produces better results when operating on Unix's dot-files. @@ -574,10 +685,17 @@ On Windows, :func:`os.path.expandvars` will now expand environment variables in the form "%var%", and "~user" will be expanded into the - user's home directory path. (Contributed by XXX.) + user's home directory path. (Contributed by Josiah Carlson.) .. % Patch 957650 +* The Python debugger provided by the :mod:`pdb` module + gained a new command: "run" restarts the Python program being debugged, + and can optionally take new command-line arguments for the program. + (Contributed by Rocky Bernstein.) + + .. % Patch #1393667 + * New functions in the :mod:`posix` module: :func:`chflags` and :func:`lchflags` are wrappers for the corresponding system calls (where they're available). Constants for the flag values are defined in the :mod:`stat` module; some @@ -587,6 +705,9 @@ * The :mod:`rgbimg` module has been removed. +* The :mod:`sets` module has been deprecated; it's better to + use the built-in :class:`set` and :class:`frozenset` types. + * The :mod:`smtplib` module now supports SMTP over SSL thanks to the addition of the :class:`SMTP_SSL` class. This class supports an interface identical to the existing :class:`SMTP` class. Both @@ -701,9 +822,48 @@ (Added by Facundo Batista.) +* The XML-RPC classes :class:`SimpleXMLRPCServer` and :class:`DocXMLRPCServer` + classes can now be prevented from immediately opening and binding to + their socket by passing True as the ``bind_and_activate`` + constructor parameter. This can be used to modify the instance's + :attr:`allow_reuse_address` attribute before calling the + :meth:`server_bind` and :meth:`server_activate` methods to + open the socket and begin listening for connections. + (Contributed by Peter Parente.) + + .. % Patch 1599845 + + :class:`SimpleXMLRPCServer` also has a :attr:`_send_traceback_header` + attribute; if true, the exception and formatted traceback are returned + as HTTP headers "X-Exception" and "X-Traceback". This feature is + for debugging purposes only and should not be used on production servers + because the tracebacks could possibly reveal passwords or other sensitive + information. (Contributed by Alan McIntyre as part of his + project for Google's Summer of Code 2007.) + .. % ====================================================================== -.. % whole new modules get described in \subsections here +.. % whole new modules get described in subsections here +Improved SSL Support +-------------------------------------------------- + +Bill Janssen made extensive improvements to Python 2.6's support for +SSL. + +XXX use ssl.sslsocket - subclass of socket.socket. + +XXX Can specify if certificate is required, and obtain certificate info +by calling getpeercert method. + +XXX sslwrap() behaves like socket.ssl + +XXX Certain features require the OpenSSL package to be installed, notably + the 'openssl' binary. + +.. seealso:: + + SSL module documentation. + .. % ====================================================================== @@ -712,8 +872,14 @@ Changes to Python's build process and to the C API include: -* Detailed changes are listed here. +* The BerkeleyDB module now has a C API object, available as + ``bsddb.db.api``. This object can be used by other C extensions + that wish to use the :mod:`bsddb` module for their own purposes. + (Contributed by Duncan Grisby.) + .. % Patch 1551895 + + .. % ====================================================================== @@ -737,7 +903,7 @@ Some of the more notable changes are: -* Details go here. +* Details will go here. .. % ====================================================================== @@ -748,9 +914,13 @@ This section lists previously described changes that may require changes to your code: -* The :mod:`socket` module exception :exc:`socket.error` now inherits from - :exc:`IOError`. +* The :mod:`socket` module exception :exc:`socket.error` now inherits + from :exc:`IOError`. Previously it wasn't a subclass of + :exc:`StandardError` but now it is, through :exc:`IOError`. + (Implemented by Gregory P. Smith.) + .. % http://bugs.python.org/issue1706815 + .. % ====================================================================== Index: Doc/tutorial/modules.rst =================================================================== --- Doc/tutorial/modules.rst (revision 58748) +++ Doc/tutorial/modules.rst (working copy) @@ -191,8 +191,8 @@ * When the Python interpreter is invoked with the :option:`-O` flag, optimized code is generated and stored in :file:`.pyo` files. The optimizer currently doesn't help much; it only removes :keyword:`assert` statements. When - :option:`-O` is used, *all* bytecode is optimized; ``.pyc`` files are ignored - and ``.py`` files are compiled to optimized bytecode. + :option:`-O` is used, *all* :term:`bytecode` is optimized; ``.pyc`` files are + ignored and ``.py`` files are compiled to optimized bytecode. * Passing two :option:`-O` flags to the Python interpreter (:option:`-OO`) will cause the bytecode compiler to perform optimizations that could in some rare Index: Doc/tutorial/controlflow.rst =================================================================== --- Doc/tutorial/controlflow.rst (revision 58748) +++ Doc/tutorial/controlflow.rst (working copy) @@ -266,9 +266,14 @@ technically speaking, procedures do return a value, albeit a rather boring one. This value is called ``None`` (it's a built-in name). Writing the value ``None`` is normally suppressed by the interpreter if it would be the only value -written. You can see it if you really want to:: +written. You can see it if you really want to using :keyword:`print`:: +<<<<<<< .working >>> print(fib(0)) +======= + >>> fib(0) + >>> print fib(0) +>>>>>>> .merge-right.r58739 None It is simple to write a function that returns a list of the numbers of the Index: Doc/tutorial/interactive.rst =================================================================== --- Doc/tutorial/interactive.rst (revision 58748) +++ Doc/tutorial/interactive.rst (working copy) @@ -123,7 +123,7 @@ # bound to the Esc key by default (you can change it - see readline docs). # # Store the file in ~/.pystartup, and set an environment variable to point - # to it: "export PYTHONSTARTUP=/max/home/itamar/.pystartup" in bash. + # to it: "export PYTHONSTARTUP=/home/user/.pystartup" in bash. # # Note that PYTHONSTARTUP does *not* expand "~", so you have to put in the # full path to your home directory. Index: Doc/tutorial/classes.rst =================================================================== --- Doc/tutorial/classes.rst (revision 58748) +++ Doc/tutorial/classes.rst (working copy) @@ -496,6 +496,7 @@ call-next-method and is more powerful than the super call found in single-inheritance languages. +<<<<<<< .working Dynamic ordering is necessary because all cases of multiple inheritance exhibit one or more diamond relationships (where one at least one of the parent classes can be accessed through multiple paths from the bottommost class). For example, @@ -507,6 +508,25 @@ class can be subclassed without affecting the precedence order of its parents). Taken together, these properties make it possible to design reliable and extensible classes with multiple inheritance. For more detail, see +======= +For :term:`new-style class`\es, the method resolution order changes dynamically +to support cooperative calls to :func:`super`. This approach is known in some +other multiple-inheritance languages as call-next-method and is more powerful +than the super call found in single-inheritance languages. + +With new-style classes, dynamic ordering is necessary because all cases of +multiple inheritance exhibit one or more diamond relationships (where one at +least one of the parent classes can be accessed through multiple paths from the +bottommost class). For example, all new-style classes inherit from +:class:`object`, so any case of multiple inheritance provides more than one path +to reach :class:`object`. To keep the base classes from being accessed more +than once, the dynamic algorithm linearizes the search order in a way that +preserves the left-to-right ordering specified in each class, that calls each +parent only once, and that is monotonic (meaning that a class can be subclassed +without affecting the precedence order of its parents). Taken together, these +properties make it possible to design reliable and extensible classes with +multiple inheritance. For more detail, see +>>>>>>> .merge-right.r58739 http://www.python.org/download/releases/2.3/mro/. @@ -707,12 +727,21 @@ Generators ========== +<<<<<<< .working Generators are a simple and powerful tool for creating iterators. They are written like regular functions but use the :keyword:`yield` statement whenever they want to return data. Each time :func:`next` is called on it, the generator resumes where it left-off (it remembers all the data values and which statement was last executed). An example shows that generators can be trivially easy to create:: +======= +:term:`Generator`\s are a simple and powerful tool for creating iterators. They +are written like regular functions but use the :keyword:`yield` statement +whenever they want to return data. Each time :meth:`next` is called, the +generator resumes where it left-off (it remembers all the data values and which +statement was last executed). An example shows that generators can be trivially +easy to create:: +>>>>>>> .merge-right.r58739 def reverse(data): for index in range(len(data)-1, -1, -1): Index: Doc/library/pty.rst =================================================================== --- Doc/library/pty.rst (revision 58748) +++ Doc/library/pty.rst (working copy) @@ -43,6 +43,6 @@ reading from the controlling terminal. The functions *master_read* and *stdin_read* should be functions which read from - a file-descriptor. The defaults try to read 1024 bytes each time they are + a file descriptor. The defaults try to read 1024 bytes each time they are called. Index: Doc/library/csv.rst =================================================================== --- Doc/library/csv.rst (revision 58748) +++ Doc/library/csv.rst (working copy) @@ -60,7 +60,7 @@ .. function:: reader(csvfile[, dialect='excel'][, fmtparam]) Return a reader object which will iterate over lines in the given *csvfile*. - *csvfile* can be any object which supports the iterator protocol and returns a + *csvfile* can be any object which supports the :term:`iterator` protocol and returns a string each time its :meth:`next` method is called --- file objects and list objects are both suitable. If *csvfile* is a file object, it must be opened with the 'b' flag on platforms where that makes a difference. An optional @@ -138,7 +138,7 @@ The :mod:`csv` module defines the following classes: -.. class:: DictReader(csvfile[, fieldnames=:const:None,[, restkey=:const:None[, restval=None[, dialect='excel'[, *args, **kwds]]]]]) +.. class:: DictReader(csvfile[, fieldnames=None[, restkey=None[, restval=None[, dialect='excel'[, *args, **kwds]]]]]) Create an object which operates like a regular reader but maps the information read into a dict whose keys are given by the optional *fieldnames* parameter. @@ -436,9 +436,9 @@ write functions or classes that handle the encoding and decoding for you as long as you avoid encodings like UTF-16 that use NULs. UTF-8 is recommended. -:func:`unicode_csv_reader` below is a generator that wraps :class:`csv.reader` +:func:`unicode_csv_reader` below is a :term:`generator` that wraps :class:`csv.reader` to handle Unicode CSV data (a list of Unicode strings). :func:`utf_8_encoder` -is a generator that encodes the Unicode strings as UTF-8, one string (or row) at +is a :term:`generator` that encodes the Unicode strings as UTF-8, one string (or row) at a time. The encoded strings are parsed by the CSV reader, and :func:`unicode_csv_reader` decodes the UTF-8-encoded cells back into Unicode:: Index: Doc/library/ctypes.rst =================================================================== --- Doc/library/ctypes.rst (revision 58748) +++ Doc/library/ctypes.rst (working copy) @@ -584,8 +584,8 @@ >>> r = RECT(POINT(1, 2), POINT(3, 4)) >>> r = RECT((1, 2), (3, 4)) -Fields descriptors can be retrieved from the *class*, they are useful for -debugging because they can provide useful information:: +Field :term:`descriptor`\s can be retrieved from the *class*, they are useful +for debugging because they can provide useful information:: >>> print(POINT.x) @@ -1195,10 +1195,10 @@ >>> Why is it printing ``False``? ctypes instances are objects containing a memory -block plus some descriptors accessing the contents of the memory. Storing a -Python object in the memory block does not store the object itself, instead the -``contents`` of the object is stored. Accessing the contents again constructs a -new Python each time! +block plus some :term:`descriptor`\s accessing the contents of the memory. +Storing a Python object in the memory block does not store the object itself, +instead the ``contents`` of the object is stored. Accessing the contents again +constructs a new Python object each time! .. _ctypes-variable-sized-data-types: @@ -1366,8 +1366,8 @@ :class:`WinDLL` and :class:`OleDLL` use the standard calling convention on this platform. -The Python GIL is released before calling any function exported by these -libraries, and reacquired afterwards. +The Python :term:`global interpreter lock` is released before calling any +function exported by these libraries, and reacquired afterwards. .. class:: PyDLL(name, mode=DEFAULT_MODE, handle=None) @@ -1948,7 +1948,7 @@ in case the memory block contains pointers. Common methods of ctypes data types, these are all class methods (to be exact, -they are methods of the metaclass): +they are methods of the :term:`metaclass`): .. method:: _CData.from_address(address) @@ -2263,7 +2263,7 @@ Concrete structure and union types must be created by subclassing one of these types, and at least define a :attr:`_fields_` class variable. ``ctypes`` will -create descriptors which allow reading and writing the fields by direct +create :term:`descriptor`\s which allow reading and writing the fields by direct attribute accesses. These are the Index: Doc/library/inspect.rst =================================================================== --- Doc/library/inspect.rst (revision 58748) +++ Doc/library/inspect.rst (working copy) @@ -31,6 +31,7 @@ They also help you determine when you can expect to find the following special attributes: +<<<<<<< .working +-----------+-----------------+---------------------------+ | Type | Attribute | Description | +===========+=================+===========================+ @@ -175,6 +176,156 @@ | | | method is bound, or | | | | ``None`` | +-----------+-----------------+---------------------------+ +======= ++-----------+-----------------+---------------------------+-------+ +| Type | Attribute | Description | Notes | ++===========+=================+===========================+=======+ +| module | __doc__ | documentation string | | ++-----------+-----------------+---------------------------+-------+ +| | __file__ | filename (missing for | | +| | | built-in modules) | | ++-----------+-----------------+---------------------------+-------+ +| class | __doc__ | documentation string | | ++-----------+-----------------+---------------------------+-------+ +| | __module__ | name of module in which | | +| | | this class was defined | | ++-----------+-----------------+---------------------------+-------+ +| method | __doc__ | documentation string | | ++-----------+-----------------+---------------------------+-------+ +| | __name__ | name with which this | | +| | | method was defined | | ++-----------+-----------------+---------------------------+-------+ +| | im_class | class object that asked | \(1) | +| | | for this method | | ++-----------+-----------------+---------------------------+-------+ +| | im_func | function object | | +| | | containing implementation | | +| | | of method | | ++-----------+-----------------+---------------------------+-------+ +| | im_self | instance to which this | | +| | | method is bound, or | | +| | | ``None`` | | ++-----------+-----------------+---------------------------+-------+ +| function | __doc__ | documentation string | | ++-----------+-----------------+---------------------------+-------+ +| | __name__ | name with which this | | +| | | function was defined | | ++-----------+-----------------+---------------------------+-------+ +| | func_code | code object containing | | +| | | compiled function | | +| | | :term:`bytecode` | | ++-----------+-----------------+---------------------------+-------+ +| | func_defaults | tuple of any default | | +| | | values for arguments | | ++-----------+-----------------+---------------------------+-------+ +| | func_doc | (same as __doc__) | | ++-----------+-----------------+---------------------------+-------+ +| | func_globals | global namespace in which | | +| | | this function was defined | | ++-----------+-----------------+---------------------------+-------+ +| | func_name | (same as __name__) | | ++-----------+-----------------+---------------------------+-------+ +| traceback | tb_frame | frame object at this | | +| | | level | | ++-----------+-----------------+---------------------------+-------+ +| | tb_lasti | index of last attempted | | +| | | instruction in bytecode | | ++-----------+-----------------+---------------------------+-------+ +| | tb_lineno | current line number in | | +| | | Python source code | | ++-----------+-----------------+---------------------------+-------+ +| | tb_next | next inner traceback | | +| | | object (called by this | | +| | | level) | | ++-----------+-----------------+---------------------------+-------+ +| frame | f_back | next outer frame object | | +| | | (this frame's caller) | | ++-----------+-----------------+---------------------------+-------+ +| | f_builtins | built-in namespace seen | | +| | | by this frame | | ++-----------+-----------------+---------------------------+-------+ +| | f_code | code object being | | +| | | executed in this frame | | ++-----------+-----------------+---------------------------+-------+ +| | f_exc_traceback | traceback if raised in | | +| | | this frame, or ``None`` | | ++-----------+-----------------+---------------------------+-------+ +| | f_exc_type | exception type if raised | | +| | | in this frame, or | | +| | | ``None`` | | ++-----------+-----------------+---------------------------+-------+ +| | f_exc_value | exception value if raised | | +| | | in this frame, or | | +| | | ``None`` | | ++-----------+-----------------+---------------------------+-------+ +| | f_globals | global namespace seen by | | +| | | this frame | | ++-----------+-----------------+---------------------------+-------+ +| | f_lasti | index of last attempted | | +| | | instruction in bytecode | | ++-----------+-----------------+---------------------------+-------+ +| | f_lineno | current line number in | | +| | | Python source code | | ++-----------+-----------------+---------------------------+-------+ +| | f_locals | local namespace seen by | | +| | | this frame | | ++-----------+-----------------+---------------------------+-------+ +| | f_restricted | 0 or 1 if frame is in | | +| | | restricted execution mode | | ++-----------+-----------------+---------------------------+-------+ +| | f_trace | tracing function for this | | +| | | frame, or ``None`` | | ++-----------+-----------------+---------------------------+-------+ +| code | co_argcount | number of arguments (not | | +| | | including \* or \*\* | | +| | | args) | | ++-----------+-----------------+---------------------------+-------+ +| | co_code | string of raw compiled | | +| | | bytecode | | ++-----------+-----------------+---------------------------+-------+ +| | co_consts | tuple of constants used | | +| | | in the bytecode | | ++-----------+-----------------+---------------------------+-------+ +| | co_filename | name of file in which | | +| | | this code object was | | +| | | created | | ++-----------+-----------------+---------------------------+-------+ +| | co_firstlineno | number of first line in | | +| | | Python source code | | ++-----------+-----------------+---------------------------+-------+ +| | co_flags | bitmap: 1=optimized ``|`` | | +| | | 2=newlocals ``|`` 4=\*arg | | +| | | ``|`` 8=\*\*arg | | ++-----------+-----------------+---------------------------+-------+ +| | co_lnotab | encoded mapping of line | | +| | | numbers to bytecode | | +| | | indices | | ++-----------+-----------------+---------------------------+-------+ +| | co_name | name with which this code | | +| | | object was defined | | ++-----------+-----------------+---------------------------+-------+ +| | co_names | tuple of names of local | | +| | | variables | | ++-----------+-----------------+---------------------------+-------+ +| | co_nlocals | number of local variables | | ++-----------+-----------------+---------------------------+-------+ +| | co_stacksize | virtual machine stack | | +| | | space required | | ++-----------+-----------------+---------------------------+-------+ +| | co_varnames | tuple of names of | | +| | | arguments and local | | +| | | variables | | ++-----------+-----------------+---------------------------+-------+ +| builtin | __doc__ | documentation string | | ++-----------+-----------------+---------------------------+-------+ +| | __name__ | original name of this | | +| | | function or method | | ++-----------+-----------------+---------------------------+-------+ +| | __self__ | instance to which a | | +| | | method is bound, or | | +| | | ``None`` | | ++-----------+-----------------+---------------------------+-------+ +>>>>>>> .merge-right.r58739 .. function:: getmembers(object[, predicate]) @@ -253,30 +404,31 @@ .. function:: ismethoddescriptor(object) - Return true if the object is a method descriptor, but not if ismethod() or - isclass() or isfunction() are true. + Return true if the object is a method descriptor, but not if :func:`ismethod` + or :func:`isclass` or :func:`isfunction` are true. - This is new as of Python 2.2, and, for example, is true of int.__add__. An - object passing this test has a __get__ attribute but not a __set__ attribute, - but beyond that the set of attributes varies. __name__ is usually sensible, and - __doc__ often is. + This is new as of Python 2.2, and, for example, is true of + ``int.__add__``. An object passing this test has a :attr:`__get__` attribute + but not a :attr:`__set__` attribute, but beyond that the set of attributes + varies. :attr:`__name__` is usually sensible, and :attr:`__doc__` often is. - Methods implemented via descriptors that also pass one of the other tests return - false from the ismethoddescriptor() test, simply because the other tests promise - more -- you can, e.g., count on having the im_func attribute (etc) when an - object passes ismethod(). + Methods implemented via descriptors that also pass one of the other tests + return false from the :func:`ismethoddescriptor` test, simply because the + other tests promise more -- you can, e.g., count on having the + :attr:`im_func` attribute (etc) when an object passes :func:`ismethod`. .. function:: isdatadescriptor(object) Return true if the object is a data descriptor. - Data descriptors have both a __get__ and a __set__ attribute. Examples are - properties (defined in Python), getsets, and members. The latter two are - defined in C and there are more specific tests available for those types, which - is robust across Python implementations. Typically, data descriptors will also - have __name__ and __doc__ attributes (properties, getsets, and members have both - of these attributes), but this is not guaranteed. + Data descriptors have both a :attr:`__get__` and a :attr:`__set__` attribute. + Examples are properties (defined in Python), getsets, and members. The + latter two are defined in C and there are more specific tests available for + those types, which is robust across Python implementations. Typically, data + descriptors will also have :attr:`__name__` and :attr:`__doc__` attributes + (properties, getsets, and members have both of these attributes), but this is + not guaranteed. .. function:: isgetsetdescriptor(object) @@ -293,8 +445,8 @@ Return true if the object is a member descriptor. Member descriptors are attributes defined in extension modules via - ``PyMemberDef`` structures. For Python implementations without such types, this - method will always return ``False``. + ``PyMemberDef`` structures. For Python implementations without such types, + this method will always return ``False``. .. _inspect-source: Index: Doc/library/re.rst =================================================================== --- Doc/library/re.rst (revision 58748) +++ Doc/library/re.rst (working copy) @@ -28,14 +28,14 @@ patterns; backslashes are not handled in any special way in a string literal prefixed with ``'r'``. So ``r"\n"`` is a two-character string containing ``'\'`` and ``'n'``, while ``"\n"`` is a one-character string containing a -newline. Usually patterns will be expressed in Python code using this raw string -notation. +newline. Usually patterns will be expressed in Python code using this raw +string notation. .. seealso:: Mastering Regular Expressions Book on regular expressions by Jeffrey Friedl, published by O'Reilly. The - second edition of the book no longer covers Python at all, but the first + second edition of the book no longer covers Python at all, but the first edition covered writing good regular expression patterns in great detail. @@ -427,8 +427,8 @@ .. function:: compile(pattern[, flags]) - Compile a regular expression pattern into a regular expression object, which can - be used for matching using its :func:`match` and :func:`search` methods, + Compile a regular expression pattern into a regular expression object, which + can be used for matching using its :func:`match` and :func:`search` methods, described below. The expression's behaviour can be modified by specifying a *flags* value. @@ -444,8 +444,8 @@ result = re.match(pat, str) - but the version using :func:`compile` is more efficient when the expression will - be used several times in a single program. + but the version using :func:`compile` is more efficient when the expression + will be used several times in a single program. .. % (The compiled version of the last pattern passed to .. % \function{re.match()} or \function{re.search()} is cached, so @@ -463,8 +463,8 @@ .. data:: L LOCALE - Make ``\w``, ``\W``, ``\b``, ``\B``, ``\s`` and ``\S`` dependent on the current - locale. + Make ``\w``, ``\W``, ``\b``, ``\B``, ``\s`` and ``\S`` dependent on the + current locale. .. data:: M @@ -556,17 +556,18 @@ .. function:: findall(pattern, string[, flags]) - Return a list of all non-overlapping matches of *pattern* in *string*. If one - or more groups are present in the pattern, return a list of groups; this will be - a list of tuples if the pattern has more than one group. Empty matches are - included in the result unless they touch the beginning of another match. + Return all non-overlapping matches of *pattern* in *string*, as a list of + strings. If one or more groups are present in the pattern, return a list of + groups; this will be a list of tuples if the pattern has more than one group. + Empty matches are included in the result unless they touch the beginning of + another match. .. function:: finditer(pattern, string[, flags]) - Return an iterator over all non-overlapping matches for the RE *pattern* in - *string*. For each match, the iterator returns a match object. Empty matches - are included in the result unless they touch the beginning of another match. + Return an :term:`iterator` yielding :class:`MatchObject` instances over all + non-overlapping matches for the RE *pattern* in *string*. Empty matches are + included in the result unless they touch the beginning of another match. .. function:: sub(pattern, repl, string[, count]) @@ -729,7 +730,9 @@ Match Objects ------------- -:class:`MatchObject` instances support the following methods and attributes: +Match objects always have a boolean value of :const:`True`, so that you can test +whether e.g. :func:`match` resulted in a match with a simple if statement. They +support the following methods and attributes: .. method:: MatchObject.expand(template) Index: Doc/library/contextlib.rst =================================================================== --- Doc/library/contextlib.rst (revision 58748) +++ Doc/library/contextlib.rst (working copy) @@ -37,9 +37,9 @@ foo - The function being decorated must return a generator-iterator when called. This - iterator must yield exactly one value, which will be bound to the targets in the - :keyword:`with` statement's :keyword:`as` clause, if any. + The function being decorated must return a :term:`generator`-iterator when + called. This iterator must yield exactly one value, which will be bound to + the targets in the :keyword:`with` statement's :keyword:`as` clause, if any. At the point where the generator yields, the block nested in the :keyword:`with` statement is executed. The generator is then resumed after the block is exited. Index: Doc/library/mailbox.rst =================================================================== --- Doc/library/mailbox.rst (revision 58748) +++ Doc/library/mailbox.rst (working copy) @@ -805,7 +805,7 @@ A message is typically moved from :file:`new` to :file:`cur` after its mailbox has been accessed, whether or not the message is has been read. A message - ``msg`` has been read if ``"S" not in msg.get_flags()`` is ``True``. + ``msg`` has been read if ``"S" in msg.get_flags()`` is ``True``. .. method:: MaildirMessage.set_subdir(subdir) Index: Doc/library/decimal.rst =================================================================== --- Doc/library/decimal.rst (revision 58748) +++ Doc/library/decimal.rst (working copy) @@ -174,7 +174,7 @@ >>> c % a Decimal("0.77") -And some mathematic functions are also available to Decimal:: +And some mathematical functions are also available to Decimal:: >>> Decimal(2).sqrt() Decimal("1.414213562373095048801688724") Index: Doc/library/types.rst =================================================================== --- Doc/library/types.rst (revision 58748) +++ Doc/library/types.rst (working copy) @@ -113,8 +113,8 @@ .. data:: GeneratorType - The type of generator-iterator objects, produced by calling a generator - function. + The type of :term:`generator`-iterator objects, produced by calling a + generator function. .. data:: CodeType Index: Doc/library/pdb.rst =================================================================== --- Doc/library/pdb.rst (revision 58748) +++ Doc/library/pdb.rst (working copy) @@ -239,7 +239,7 @@ Specifying any command resuming execution (currently continue, step, next, return, jump, quit and their abbreviations) terminates the command list (as if that command was immediately followed by end). This is because any time you - resume execution (even with a simple next or step), you may encounter· another + resume execution (even with a simple next or step), you may encounter another breakpoint--which could have its own command list, leading to ambiguities about which list to execute. @@ -323,7 +323,7 @@ (Pdb) run [*args* ...] - Restart the debugged python program. If an argument is supplied, it is splitted + Restart the debugged python program. If an argument is supplied, it is split with "shlex" and the result is used as the new sys.argv. History, breakpoints, actions and debugger options are preserved. "restart" is an alias for "run". Index: Doc/library/itertools.rst =================================================================== --- Doc/library/itertools.rst (revision 58748) +++ Doc/library/itertools.rst (working copy) @@ -8,7 +8,7 @@ .. sectionauthor:: Raymond Hettinger -This module implements a number of iterator building blocks inspired by +This module implements a number of :term:`iterator` building blocks inspired by constructs from the Haskell and SML programming languages. Each has been recast in a form suitable for Python. @@ -77,20 +77,16 @@ .. function:: count([n]) Make an iterator that returns consecutive integers starting with *n*. If not - specified *n* defaults to zero. Does not currently support python long - integers. Often used as an argument to :func:`imap` to generate consecutive - data points. Also, used with :func:`izip` to add sequence numbers. Equivalent - to:: + specified *n* defaults to zero. Often used as an argument to :func:`imap` to + generate consecutive data points. Also, used with :func:`izip` to add sequence + numbers. Equivalent to:: def count(n=0): while True: yield n n += 1 - Note, :func:`count` does not check for overflow and will return negative numbers - after exceeding ``sys.maxint``. This behavior may change in the future. - .. function:: cycle(iterable) Make an iterator returning elements from the iterable and saving a copy of each. @@ -451,8 +447,8 @@ rather than bringing the whole iterable into memory all at once. Code volume is kept small by linking the tools together in a functional style which helps eliminate temporary variables. High speed is retained by preferring -"vectorized" building blocks over the use of for-loops and generators which -incur interpreter overhead. :: +"vectorized" building blocks over the use of for-loops and :term:`generator`\s +which incur interpreter overhead. :: def take(n, seq): return list(islice(seq, n)) Index: Doc/library/tokenize.rst =================================================================== --- Doc/library/tokenize.rst (revision 58748) +++ Doc/library/tokenize.rst (working copy) @@ -13,7 +13,7 @@ well, making it useful for implementing "pretty-printers," including colorizers for on-screen displays. -The primary entry point is a generator: +The primary entry point is a :term:`generator`: .. function:: generate_tokens(readline) Index: Doc/library/difflib.rst =================================================================== --- Doc/library/difflib.rst (revision 58748) +++ Doc/library/difflib.rst (working copy) @@ -10,6 +10,16 @@ .. % LaTeXification by Fred L. Drake, Jr. . +<<<<<<< .working +======= +.. versionadded:: 2.1 + +This module provides classes and functions for comparing sequences. It +can be used for example, for comparing files, and can produce difference +information in various formats, including HTML and context and unified +diffs. For comparing directories and files, see also, the :mod:`filecmp` module. + +>>>>>>> .merge-right.r58739 .. class:: SequenceMatcher This is a flexible class for comparing pairs of sequences of any type, so long @@ -117,8 +127,8 @@ .. function:: context_diff(a, b[, fromfile][, tofile][, fromfiledate][, tofiledate][, n][, lineterm]) - Compare *a* and *b* (lists of strings); return a delta (a generator generating - the delta lines) in context diff format. + Compare *a* and *b* (lists of strings); return a delta (a :term:`generator` + generating the delta lines) in context diff format. Context diffs are a compact way of showing just the lines that have changed plus a few lines of context. The changes are shown in a before/after style. The @@ -170,8 +180,8 @@ .. function:: ndiff(a, b[, linejunk][, charjunk]) - Compare *a* and *b* (lists of strings); return a :class:`Differ`\ -style delta - (a generator generating the delta lines). + Compare *a* and *b* (lists of strings); return a :class:`Differ`\ -style + delta (a :term:`generator` generating the delta lines). Optional keyword parameters *linejunk* and *charjunk* are for filter functions (or ``None``): @@ -231,8 +241,8 @@ .. function:: unified_diff(a, b[, fromfile][, tofile][, fromfiledate][, tofiledate][, n][, lineterm]) - Compare *a* and *b* (lists of strings); return a delta (a generator generating - the delta lines) in unified diff format. + Compare *a* and *b* (lists of strings); return a delta (a :term:`generator` + generating the delta lines) in unified diff format. Unified diffs are a compact way of showing just the lines that have changed plus a few lines of context. The changes are shown in a inline style (instead of @@ -423,7 +433,7 @@ .. method:: SequenceMatcher.get_grouped_opcodes([n]) - Return a generator of groups with up to *n* lines of context. + Return a :term:`generator` of groups with up to *n* lines of context. Starting with the groups returned by :meth:`get_opcodes`, this method splits out smaller change clusters and eliminates intervening ranges which have no changes. Index: Doc/library/logging.rst =================================================================== --- Doc/library/logging.rst (revision 58748) +++ Doc/library/logging.rst (working copy) @@ -20,7 +20,7 @@ Logging is performed by calling methods on instances of the :class:`Logger` class (hereafter called :dfn:`loggers`). Each instance has a name, and they are -conceptually arranged in a name space hierarchy using dots (periods) as +conceptually arranged in a namespace hierarchy using dots (periods) as separators. For example, a logger named "scan" is the parent of loggers "scan.text", "scan.html" and "scan.pdf". Logger names can be anything you want, and indicate the area of an application in which a logged message originates. @@ -430,7 +430,7 @@ FORMAT = "%(asctime)-15s %(clientip)s %(user)-8s %(message)s" logging.basicConfig(format=FORMAT) - dict = { 'clientip' : '192.168.0.1', 'user' : 'fbloggs' } + d = { 'clientip' : '192.168.0.1', 'user' : 'fbloggs' } logger = logging.getLogger("tcpserver") logger.warning("Protocol problem: %s", "connection reset", extra=d) Index: Doc/library/pickletools.rst =================================================================== --- Doc/library/pickletools.rst (revision 58748) +++ Doc/library/pickletools.rst (working copy) @@ -27,9 +27,9 @@ .. function:: genops(pickle) - Provides an iterator over all of the opcodes in a pickle, returning a sequence - of ``(opcode, arg, pos)`` triples. *opcode* is an instance of an - :class:`OpcodeInfo` class; *arg* is the decoded value, as a Python object, of - the opcode's argument; *pos* is the position at which this opcode is located. + Provides an :term:`iterator` over all of the opcodes in a pickle, returning a + sequence of ``(opcode, arg, pos)`` triples. *opcode* is an instance of an + :class:`OpcodeInfo` class; *arg* is the decoded value, as a Python object, of + the opcode's argument; *pos* is the position at which this opcode is located. *pickle* can be a string or a file-like object. Index: Doc/library/cookielib.rst =================================================================== --- Doc/library/cookielib.rst (revision 58748) +++ Doc/library/cookielib.rst (working copy) @@ -140,7 +140,7 @@ CookieJar and FileCookieJar Objects ----------------------------------- -:class:`CookieJar` objects support the iterator protocol for iterating over +:class:`CookieJar` objects support the :term:`iterator` protocol for iterating over contained :class:`Cookie` objects. :class:`CookieJar` has the following methods: Index: Doc/library/xml.etree.elementtree.rst =================================================================== --- Doc/library/xml.etree.elementtree.rst (revision 58748) +++ Doc/library/xml.etree.elementtree.rst (working copy) @@ -87,7 +87,7 @@ Parses an XML section into an element tree incrementally, and reports what's going on to the user. *source* is a filename or file object containing XML data. *events* is a list of events to report back. If omitted, only "end" events are - reported. Returns an iterator providing ``(event, elem)`` pairs. + reported. Returns an :term:`iterator` providing ``(event, elem)`` pairs. .. function:: parse(source[, parser]) @@ -316,7 +316,7 @@ .. method:: ElementTree.findall(path) Finds all toplevel elements with the given tag. Same as getroot().findall(path). - *path* is the element to look for. Returns a list or iterator containing all + *path* is the element to look for. Returns a list or :term:`iterator` containing all matching elements, in document order. Index: Doc/library/glob.rst =================================================================== --- Doc/library/glob.rst (revision 58748) +++ Doc/library/glob.rst (working copy) @@ -28,8 +28,8 @@ .. function:: iglob(pathname) - Return an iterator which yields the same values as :func:`glob` without actually - storing them all simultaneously. + Return an :term:`iterator` which yields the same values as :func:`glob` + without actually storing them all simultaneously. For example, consider a directory containing only the following files: Index: Doc/library/sqlite3.rst =================================================================== --- Doc/library/sqlite3.rst (revision 58748) +++ Doc/library/sqlite3.rst (working copy) @@ -69,10 +69,10 @@ ): c.execute('insert into stocks values (?,?,?,?,?)', t) -To retrieve data after executing a SELECT statement, you can either treat the -cursor as an iterator, call the cursor's :meth:`fetchone` method to retrieve a -single matching row, or call :meth:`fetchall` to get a list of the matching -rows. +To retrieve data after executing a SELECT statement, you can either treat the +cursor as an :term:`iterator`, call the cursor's :meth:`fetchone` method to +retrieve a single matching row, or call :meth:`fetchall` to get a list of the +matching rows. This example uses the iterator form:: @@ -408,13 +408,13 @@ .. method:: Cursor.executemany(sql, seq_of_parameters) - Executes a SQL command against all parameter sequences or mappings found in the - sequence *sql*. The :mod:`sqlite3` module also allows using an iterator yielding - parameters instead of a sequence. + Executes a SQL command against all parameter sequences or mappings found in + the sequence *sql*. The :mod:`sqlite3` module also allows using an + :term:`iterator` yielding parameters instead of a sequence. .. literalinclude:: ../includes/sqlite3/executemany_1.py - Here's a shorter example using a generator: + Here's a shorter example using a :term:`generator`: .. literalinclude:: ../includes/sqlite3/executemany_2.py @@ -545,6 +545,14 @@ The other possibility is to create a function that converts the type to the string representation and register the function with :meth:`register_adapter`. +<<<<<<< .working +======= +.. note:: + + The type/class to adapt must be a :term:`new-style class`, i. e. it must have + :class:`object` as one of its bases. + +>>>>>>> .merge-right.r58739 .. literalinclude:: ../includes/sqlite3/adapter_point_2.py The :mod:`sqlite3` module has two default adapters for Python's built-in Index: Doc/library/xmlrpclib.rst =================================================================== --- Doc/library/xmlrpclib.rst (revision 58748) +++ Doc/library/xmlrpclib.rst (working copy) @@ -108,6 +108,15 @@ compatibility. New code should use :class:`ServerProxy`. +<<<<<<< .working +======= + .. versionchanged:: 2.6 + Instances of :term:`new-style class`\es can be passed in if they have an + *__dict__* attribute and don't have a base class that is marshalled in a + special way. + + +>>>>>>> .merge-right.r58739 .. seealso:: `XML-RPC HOWTO `_ @@ -314,7 +323,8 @@ return ``None``, and only store the call name and parameters in the :class:`MultiCall` object. Calling the object itself causes all stored calls to be transmitted as a single ``system.multicall`` request. The result of this call - is a generator; iterating over this generator yields the individual results. + is a :term:`generator`; iterating over this generator yields the individual + results. A usage example of this class is :: Index: Doc/library/filecmp.rst =================================================================== --- Doc/library/filecmp.rst (revision 58748) +++ Doc/library/filecmp.rst (working copy) @@ -8,7 +8,8 @@ The :mod:`filecmp` module defines functions to compare files and directories, -with various optional time/correctness trade-offs. +with various optional time/correctness trade-offs. For comparing files, +see also the :mod:`difflib` module. The :mod:`filecmp` module defines the following functions: Index: Doc/library/optparse.rst =================================================================== --- Doc/library/optparse.rst (revision 58748) +++ Doc/library/optparse.rst (working copy) @@ -950,7 +950,7 @@ * ``append_const`` [required: ``const``; relevant: :attr:`dest`] Like ``store_const``, but the value ``const`` is appended to :attr:`dest`; as - with ``append``, :attr:`dest` defaults to ``None``, and an an empty list is + with ``append``, :attr:`dest` defaults to ``None``, and an empty list is automatically created the first time the option is encountered. * ``count`` [relevant: :attr:`dest`] @@ -1116,7 +1116,7 @@ * if the number starts with ``0``, it is parsed as an octal number -* if the number starts with ``0b``, is is parsed as a binary number +* if the number starts with ``0b``, it is parsed as a binary number * otherwise, the number is parsed as a decimal number Index: Doc/library/dis.rst =================================================================== --- Doc/library/dis.rst (revision 58748) +++ Doc/library/dis.rst (working copy) @@ -1,14 +1,14 @@ -:mod:`dis` --- Disassembler for Python byte code -================================================ +:mod:`dis` --- Disassembler for Python bytecode +=============================================== .. module:: dis - :synopsis: Disassembler for Python byte code. + :synopsis: Disassembler for Python bytecode. -The :mod:`dis` module supports the analysis of Python byte code by disassembling +The :mod:`dis` module supports the analysis of Python :term:`bytecode` by disassembling it. Since there is no Python assembler, this module defines the Python assembly -language. The Python byte code which this module takes as an input is defined +language. The Python bytecode which this module takes as an input is defined in the file :file:`Include/opcode.h` and used by the compiler and the interpreter. @@ -35,7 +35,7 @@ Disassemble the *bytesource* object. *bytesource* can denote either a module, a class, a method, a function, or a code object. For a module, it disassembles all functions. For a class, it disassembles all methods. For a single code - sequence, it prints one line per byte code instruction. If no object is + sequence, it prints one line per bytecode instruction. If no object is provided, it disassembles the last traceback. @@ -70,12 +70,12 @@ .. data:: opname - Sequence of operation names, indexable using the byte code. + Sequence of operation names, indexable using the bytecode. .. data:: opmap - Dictionary mapping byte codes to operation names. + Dictionary mapping bytecodes to operation names. .. data:: cmp_op @@ -85,45 +85,45 @@ .. data:: hasconst - Sequence of byte codes that have a constant parameter. + Sequence of bytecodes that have a constant parameter. .. data:: hasfree - Sequence of byte codes that access a free variable. + Sequence of bytecodes that access a free variable. .. data:: hasname - Sequence of byte codes that access an attribute by name. + Sequence of bytecodes that access an attribute by name. .. data:: hasjrel - Sequence of byte codes that have a relative jump target. + Sequence of bytecodes that have a relative jump target. .. data:: hasjabs - Sequence of byte codes that have an absolute jump target. + Sequence of bytecodes that have an absolute jump target. .. data:: haslocal - Sequence of byte codes that access a local variable. + Sequence of bytecodes that access a local variable. .. data:: hascompare - Sequence of byte codes of Boolean operations. + Sequence of bytecodes of Boolean operations. .. _bytecodes: -Python Byte Code Instructions ------------------------------ +Python Bytecode Instructions +---------------------------- -The Python compiler currently generates the following byte code instructions. +The Python compiler currently generates the following bytecode instructions. .. opcode:: STOP_CODE () @@ -381,7 +381,7 @@ .. opcode:: YIELD_VALUE () - Pops ``TOS`` and yields it from a generator. + Pops ``TOS`` and yields it from a :term:`generator`. .. opcode:: IMPORT_STAR () @@ -416,9 +416,9 @@ context manager's :meth:`__exit__` bound method. Below that are 1--3 values indicating how/why the finally clause was entered: - * SECOND = None - * (SECOND, THIRD) = (WHY_{RETURN,CONTINUE}), retval - * SECOND = WHY_\*; no retval below it + * SECOND = ``None`` + * (SECOND, THIRD) = (``WHY_{RETURN,CONTINUE}``), retval + * SECOND = ``WHY_*``; no retval below it * (SECOND, THIRD, FOURTH) = exc_info() In the last case, ``TOS(SECOND, THIRD, FOURTH)`` is called, otherwise @@ -428,7 +428,9 @@ returns a 'true' value, this information is "zapped", to prevent ``END_FINALLY`` from re-raising the exception. (But non-local gotos should still be resumed.) + .. XXX explain the WHY stuff! + All of the following opcodes expect arguments. An argument is two bytes, with the more significant byte last. @@ -548,32 +550,39 @@ .. opcode:: JUMP_FORWARD (delta) - Increments byte code counter by *delta*. + Increments bytecode counter by *delta*. .. opcode:: JUMP_IF_TRUE (delta) - If TOS is true, increment the byte code counter by *delta*. TOS is left on the + If TOS is true, increment the bytecode counter by *delta*. TOS is left on the stack. .. opcode:: JUMP_IF_FALSE (delta) - If TOS is false, increment the byte code counter by *delta*. TOS is not + If TOS is false, increment the bytecode counter by *delta*. TOS is not changed. .. opcode:: JUMP_ABSOLUTE (target) - Set byte code counter to *target*. + Set bytecode counter to *target*. .. opcode:: FOR_ITER (delta) +<<<<<<< .working ``TOS`` is an iterator. Call its :meth:`__next__` method. If this yields a new value, push it on the stack (leaving the iterator below it). If the iterator indicates it is exhausted ``TOS`` is popped, and the byte code counter is incremented by *delta*. +======= + ``TOS`` is an :term:`iterator`. Call its :meth:`next` method. If this + yields a new value, push it on the stack (leaving the iterator below it). If + the iterator indicates it is exhausted ``TOS`` is popped, and the bytecode + counter is incremented by *delta*. +>>>>>>> .merge-right.r58739 .. % \begin{opcodedesc}{FOR_LOOP}{delta} .. % This opcode is obsolete. Index: Doc/library/_ast.rst =================================================================== --- Doc/library/_ast.rst (revision 58748) +++ Doc/library/_ast.rst (working copy) @@ -12,7 +12,7 @@ The ``_ast`` module helps Python applications to process trees of the Python abstract syntax grammar. The Python compiler currently provides read-only access to such trees, meaning that applications can only create a tree for a given -piece of Python source code; generating byte code from a (potentially modified) +piece of Python source code; generating :term:`bytecode` from a (potentially modified) tree is not supported. The abstract syntax itself might change with each Python release; this module helps to find out programmatically what the current grammar looks like. Index: Doc/library/mmap.rst =================================================================== --- Doc/library/mmap.rst (revision 58748) +++ Doc/library/mmap.rst (working copy) @@ -38,7 +38,7 @@ To map anonymous memory, -1 should be passed as the fileno along with the length. -.. function:: mmap(fileno, length[, tagname[, access]]) +.. function:: mmap(fileno, length[, tagname[, access[, offset]]]) **(Windows version)** Maps *length* bytes from the file specified by the file handle *fileno*, and returns a mmap object. If *length* is larger than the @@ -54,8 +54,12 @@ the mapping is created without a name. Avoiding the use of the tag parameter will assist in keeping your code portable between Unix and Windows. + *offset* may be specified as a non-negative integer offset. mmap references will + be relative to the offset from the beginning of the file. *offset* defaults to 0. + *offset* must be a multiple of the ALLOCATIONGRANULARITY. -.. function:: mmap(fileno, length[, flags[, prot[, access]]]) + +.. function:: mmap(fileno, length[, flags[, prot[, access[, offset]]]]) :noindex: **(Unix version)** Maps *length* bytes from the file specified by the file @@ -77,6 +81,10 @@ parameter. It is an error to specify both *flags*, *prot* and *access*. See the description of *access* above for information on how to use this parameter. + *offset* may be specified as a non-negative integer offset. mmap references will + be relative to the offset from the beginning of the file. *offset* defaults to 0. + *offset* must be a multiple of the PAGESIZE or ALLOCATIONGRANULARITY. + Memory-mapped file objects support the following methods: @@ -169,3 +177,4 @@ created with :const:`ACCESS_READ`, then writing to it will throw a :exc:`TypeError` exception. + Index: Doc/library/pyclbr.rst =================================================================== --- Doc/library/pyclbr.rst (revision 58748) +++ Doc/library/pyclbr.rst (working copy) @@ -19,10 +19,10 @@ .. function:: readmodule(module[, path]) Read a module and return a dictionary mapping class names to class descriptor - objects. The parameter *module* should be the name of a module as a string; it - may be the name of a module within a package. The *path* parameter should be a - sequence, and is used to augment the value of ``sys.path``, which is used to - locate module source code. + objects. The parameter *module* should be the name of a module as a string; + it may be the name of a module within a package. The *path* parameter should + be a sequence, and is used to augment the value of ``sys.path``, which is + used to locate module source code. .. % The 'inpackage' parameter appears to be for internal use only.... Index: Doc/library/codecs.rst =================================================================== --- Doc/library/codecs.rst (revision 58748) +++ Doc/library/codecs.rst (working copy) @@ -238,15 +238,15 @@ .. function:: iterencode(iterable, encoding[, errors]) Uses an incremental encoder to iteratively encode the input provided by - *iterable*. This function is a generator. *errors* (as well as any other keyword - argument) is passed through to the incremental encoder. + *iterable*. This function is a :term:`generator`. *errors* (as well as any + other keyword argument) is passed through to the incremental encoder. .. function:: iterdecode(iterable, encoding[, errors]) Uses an incremental decoder to iteratively decode the input provided by - *iterable*. This function is a generator. *errors* (as well as any other keyword - argument) is passed through to the incremental decoder. + *iterable*. This function is a :term:`generator`. *errors* (as well as any + other keyword argument) is passed through to the incremental decoder. The module also provides the following constants which are useful for reading and writing to platform dependent files: Index: Doc/library/ssl.rst =================================================================== --- Doc/library/ssl.rst (revision 58748) +++ Doc/library/ssl.rst (working copy) @@ -223,7 +223,7 @@ .. data:: PROTOCOL_TLSv1 - Selects SSL version 2 as the channel encryption protocol. This is + Selects TLS version 1 as the channel encryption protocol. This is the most modern version, and probably the best choice for maximum protection, if both sides can speak it. Index: Doc/library/weakref.rst =================================================================== --- Doc/library/weakref.rst (revision 58748) +++ Doc/library/weakref.rst (working copy) @@ -51,9 +51,9 @@ Not all objects can be weakly referenced; those objects which can include class instances, functions written in Python (but not in C), methods (both bound and -unbound), sets, frozensets, file objects, generators, type objects, DBcursor -objects from the :mod:`bsddb` module, sockets, arrays, deques, and regular -expression pattern objects. +unbound), sets, frozensets, file objects, :term:`generator`\s, type objects, +:class:`DBcursor` objects from the :mod:`bsddb` module, sockets, arrays, deques, +and regular expression pattern objects. Several builtin types such as :class:`list` and :class:`dict` do not directly support weak references but can add support through subclassing:: @@ -146,7 +146,7 @@ .. method:: WeakKeyDictionary.iterkeyrefs() - Return an iterator that yields the weak references to the keys. + Return an :term:`iterator` that yields the weak references to the keys. .. method:: WeakKeyDictionary.keyrefs() @@ -174,7 +174,7 @@ .. method:: WeakValueDictionary.itervaluerefs() - Return an iterator that yields the weak references to the values. + Return an :term:`iterator` that yields the weak references to the values. .. method:: WeakValueDictionary.valuerefs() Index: Doc/library/marshal.rst =================================================================== --- Doc/library/marshal.rst (revision 58748) +++ Doc/library/marshal.rst (working copy) @@ -25,7 +25,9 @@ writing the "pseudo-compiled" code for Python modules of :file:`.pyc` files. Therefore, the Python maintainers reserve the right to modify the marshal format in backward incompatible ways should the need arise. If you're serializing and -de-serializing Python objects, use the :mod:`pickle` module instead. +de-serializing Python objects, use the :mod:`pickle` module instead -- the +performance is comparable, version independence is guaranteed, and pickle +supports a substantially wider range of objects than marshal. .. warning:: @@ -36,13 +38,19 @@ Not all Python object types are supported; in general, only objects whose value is independent from a particular invocation of Python can be written and read by this module. The following types are supported: ``None``, integers, long -integers, floating point numbers, strings, Unicode objects, tuples, lists, +integers, floating point numbers, strings, Unicode objects, tuples, lists, sets, dictionaries, and code objects, where it should be understood that tuples, lists and dictionaries are only supported as long as the values contained therein are themselves supported; and recursive lists and dictionaries should not be written (they will cause infinite loops). .. warning:: + + Some unsupported types such as subclasses of builtins will appear to marshal + and unmarshal correctly, but in fact, their type will change and the + additional subclass functionality and instance attributes will be lost. + +.. warning:: On machines where C's ``long int`` type has more than 32 bits (such as the DEC Alpha), it is possible to create plain Python integers that are longer Index: Doc/library/wsgiref.rst =================================================================== --- Doc/library/wsgiref.rst (revision 58748) +++ Doc/library/wsgiref.rst (working copy) @@ -124,7 +124,7 @@ .. class:: FileWrapper(filelike [, blksize=8192]) - A wrapper to convert a file-like object to an iterator. The resulting objects + A wrapper to convert a file-like object to an :term:`iterator`. The resulting objects support both :meth:`__getitem__` and :meth:`__iter__` iteration styles, for compatibility with Python 2.1 and Jython. As the object is iterated over, the optional *blksize* parameter will be repeatedly passed to the *filelike* Index: Doc/library/stdtypes.rst =================================================================== --- Doc/library/stdtypes.rst (revision 58748) +++ Doc/library/stdtypes.rst (working copy) @@ -449,10 +449,17 @@ continue to do so on subsequent calls. Implementations that do not obey this property are deemed broken. +<<<<<<< .working Python's generators provide a convenient way to implement the iterator protocol. If a container object's :meth:`__iter__` method is implemented as a generator, it will automatically return an iterator object (technically, a generator object) supplying the :meth:`__iter__` and :meth:`__next__` methods. +======= +Python's :term:`generator`\s provide a convenient way to implement the iterator +protocol. If a container object's :meth:`__iter__` method is implemented as a +generator, it will automatically return an iterator object (technically, a +generator object) supplying the :meth:`__iter__` and :meth:`next` methods. +>>>>>>> .merge-right.r58739 .. _typesseq: @@ -655,9 +662,9 @@ .. method:: str.count(sub[, start[, end]]) - Return the number of occurrences of substring *sub* in string S\ - ``[start:end]``. Optional arguments *start* and *end* are interpreted as in - slice notation. + Return the number of occurrences of substring *sub* in the range [*start*, + *end*]. Optional arguments *start* and *end* are interpreted as in slice + notation. .. method:: str.encode([encoding[, errors]]) @@ -682,8 +689,11 @@ .. method:: str.expandtabs([tabsize]) - Return a copy of the string where all tab characters are expanded using spaces. - If *tabsize* is not given, a tab size of ``8`` characters is assumed. + Return a copy of the string where all tab characters are replaced by one or + more spaces, depending on the current column and the given tab size. The + column number is reset to zero after each newline occurring in the string. + If *tabsize* is not given, a tab size of ``8`` characters is assumed. This + doesn't understand other non-printing characters or escape sequences. .. method:: str.find(sub[, start[, end]]) @@ -865,6 +875,7 @@ .. method:: str.split([sep[, maxsplit]]) +<<<<<<< .working Return a list of the words in the string, using *sep* as the delimiter string. If *maxsplit* is given, at most *maxsplit* splits are done (thus, the list will have at most ``maxsplit+1`` elements). If *maxsplit* is not @@ -874,16 +885,36 @@ ``['1', '', '2']``). The *sep* argument may consist of multiple characters (for example, ``'1, 2, 3'.split(', ')`` returns ``['1', '2', '3']``). Splitting an empty string with a specified separator returns ``['']``. +======= +.. method:: str.split([sep[, maxsplit]]) +>>>>>>> .merge-right.r58739 +<<<<<<< .working +======= + Return a list of the words in the string, using *sep* as the delimiter + string. If *maxsplit* is given, at most *maxsplit* splits are done (thus, + the list will have at most ``maxsplit+1`` elements). If *maxsplit* is not + specified, then there is no limit on the number of splits (all possible + splits are made). + +>>>>>>> .merge-right.r58739 + If *sep is given, consecutive delimiters are not grouped together and are + deemed to delimit empty strings (for example, ``'1,,2'.split(',')`` returns + ``['1', '', '2']``). The *sep* argument may consist of multiple characters + (for example, ``'1<>2<>3'.split('<>')`` returns ``['1', '2', '3']``). + Splitting an empty string with a specified separator returns ``['']``. + If *sep* is not specified or is ``None``, a different splitting algorithm is - applied. First, whitespace characters (spaces, tabs, newlines, returns, and - formfeeds) are stripped from both ends. Then, words are separated by arbitrary - length strings of whitespace characters. Consecutive whitespace delimiters are - treated as a single delimiter (``'1 2 3'.split()`` returns ``['1', '2', - '3']``). Splitting an empty string or a string consisting of just whitespace - returns an empty list. + applied: runs of consecutive whitespace are regarded as a single separator, + and the result will contain no empty strings at the start or end if the + string has leading or trailing whitespace. Consequently, splitting an empty + string or a string consisting of just whitespace with a ``None`` separator + returns ``[]``. + For example, ``' 1 2 3 '.split()`` returns ``['1', '2', '3']``, and + ``' 1 2 3 '.split(None, 1)`` returns ``['1', '2 3 ']``. + .. method:: str.splitlines([keepends]) Return a list of the lines in the string, breaking at line boundaries. Line @@ -947,8 +978,10 @@ .. method:: str.zfill(width) - Return the numeric string left filled with zeros in a string of length *width*. - The original string is returned if *width* is less than ``len(s)``. + Return the numeric string left filled with zeros in a string of length + *width*. A sign prefix is handled correctly. The original string is + returned if *width* is less than ``len(s)``. + .. _old-string-formatting: @@ -1865,8 +1898,7 @@ .. method:: file.fileno() .. index:: - single: file descriptor - single: descriptor, file + pair: file; descriptor module: fcntl Return the integer "file descriptor" that is used by the underlying @@ -2091,7 +2123,7 @@ .. method:: contextmanager.__exit__(exc_type, exc_val, exc_tb) - Exit the runtime context and return a Boolean flag indicating if any expection + Exit the runtime context and return a Boolean flag indicating if any exception that occurred should be suppressed. If an exception occurred while executing the body of the :keyword:`with` statement, the arguments contain the exception type, value and traceback information. Otherwise, all three arguments are ``None``. @@ -2115,7 +2147,7 @@ their implementation of the context management protocol. See the :mod:`contextlib` module for some examples. -Python's generators and the ``contextlib.contextfactory`` decorator provide a +Python's :term:`generator`\s and the ``contextlib.contextfactory`` decorator provide a convenient way to implement these protocols. If a generator function is decorated with the ``contextlib.contextfactory`` decorator, it will return a context manager implementing the necessary :meth:`__enter__` and Index: Doc/library/parser.rst =================================================================== --- Doc/library/parser.rst (revision 58748) +++ Doc/library/parser.rst (working copy) @@ -321,7 +321,7 @@ .. index:: builtin: compile The parser modules allows operations to be performed on the parse tree of Python -source code before the bytecode is generated, and provides for inspection of the +source code before the :term:`bytecode` is generated, and provides for inspection of the parse tree for information gathering purposes. Two examples are presented. The simple example demonstrates emulation of the :func:`compile` built-in function and the complex example shows the use of a parse tree for information discovery. Index: Doc/library/heapq.rst =================================================================== --- Doc/library/heapq.rst (revision 58748) +++ Doc/library/heapq.rst (working copy) @@ -90,8 +90,8 @@ .. function:: merge(*iterables) Merge multiple sorted inputs into a single sorted output (for example, merge - timestamped entries from multiple log files). Returns an iterator over over the - sorted values. + timestamped entries from multiple log files). Returns an :term:`iterator` + over over the sorted values. Similar to ``sorted(itertools.chain(*iterables))`` but returns an iterable, does not pull the data into memory all at once, and assumes that each of the input Index: Doc/library/collections.rst =================================================================== --- Doc/library/collections.rst (revision 58748) +++ Doc/library/collections.rst (working copy) @@ -10,7 +10,7 @@ This module implements high-performance container datatypes. Currently, there are two datatypes, :class:`deque` and :class:`defaultdict`, and -one datatype factory function, :func:`NamedTuple`. Python already +one datatype factory function, :func:`named_tuple`. Python already includes built-in containers, :class:`dict`, :class:`list`, :class:`set`, and :class:`tuple`. In addition, the optional :mod:`bsddb` module has a :meth:`bsddb.btopen` method that can be used to create in-memory @@ -24,6 +24,7 @@ a class provides a particular interface, for example, is it hashable or a mapping. The ABCs provided include those in the following table: +<<<<<<< .working ===================================== ======================================== ABC Notes ===================================== ======================================== @@ -52,6 +53,10 @@ :class:`collections.Set` Derived from :class:`Container`, :class:`Iterable`, and :class:`Sized` :class:`collections.Sized` Defines ``__len__()`` ===================================== ======================================== +======= +.. versionchanged:: 2.6 + Added :func:`named_tuple`. +>>>>>>> .merge-right.r58739 .. XXX Have not included them all and the notes are imcomplete .. Deliberately did one row wide to get a neater output @@ -75,7 +80,7 @@ ---------------------- -.. class:: deque([iterable]) +.. class:: deque([iterable[, maxlen]]) Returns a new deque object initialized left-to-right (using :meth:`append`) with data from *iterable*. If *iterable* is not specified, the new deque is empty. @@ -91,6 +96,17 @@ position of the underlying data representation. + If *maxlen* is not specified or is *None*, deques may grow to an + arbitrary length. Otherwise, the deque is bounded to the specified maximum + length. Once a bounded length deque is full, when new items are added, a + corresponding number of items are discarded from the opposite end. Bounded + length deques provide functionality similar to the ``tail`` filter in + Unix. They are also useful for tracking transactions and other pools of data + where only the most recent activity is of interest. + + .. versionchanged:: 2.6 + Added *maxlen* + Deque objects support the following methods: .. method:: deque.append(x) @@ -205,8 +221,8 @@ .. _deque-recipes: -Recipes -^^^^^^^ +:class:`deque` Recipes +^^^^^^^^^^^^^^^^^^^^^^ This section shows various approaches to working with deques. @@ -223,11 +239,11 @@ :meth:`rotate` to bring a target element to the left side of the deque. Remove old entries with :meth:`popleft`, add new entries with :meth:`extend`, and then reverse the rotation. - With minor variations on that approach, it is easy to implement Forth style stack manipulations such as ``dup``, ``drop``, ``swap``, ``over``, ``pick``, ``rot``, and ``roll``. +<<<<<<< .working A roundrobin task server can be built from a :class:`deque` using :meth:`popleft` to select the current task and :meth:`append` to add it back to the tasklist if the input stream is not exhausted:: @@ -255,10 +271,12 @@ h +======= +>>>>>>> .merge-right.r58739 Multi-pass data reduction algorithms can be succinctly expressed and efficiently coded by extracting elements with multiple calls to :meth:`popleft`, applying -the reduction function, and calling :meth:`append` to add the result back to the -queue. +a reduction function, and calling :meth:`append` to add the result back to the +deque. For example, building a balanced binary tree of nested lists entails reducing two adjacent nodes into one by grouping them in a list:: @@ -273,7 +291,12 @@ >>> print(maketree('abcdefgh')) [[[['a', 'b'], ['c', 'd']], [['e', 'f'], ['g', 'h']]]] +Bounded length deques provide functionality similar to the ``tail`` filter +in Unix:: + def tail(filename, n=10): + 'Return the last n lines of a file' + return deque(open(filename), n) .. _defaultdict-objects: @@ -395,14 +418,14 @@ .. _named-tuple-factory: -:func:`NamedTuple` Factory Function for Tuples with Named Fields ----------------------------------------------------------------- +:func:`named_tuple` Factory Function for Tuples with Named Fields +----------------------------------------------------------------- Named tuples assign meaning to each position in a tuple and allow for more readable, self-documenting code. They can be used wherever regular tuples are used, and they add the ability to access fields by name instead of position index. -.. function:: NamedTuple(typename, fieldnames, [verbose]) +.. function:: named_tuple(typename, fieldnames, [verbose]) Returns a new tuple subclass named *typename*. The new subclass is used to create tuple-like objects that have fields accessable by attribute lookup as @@ -410,17 +433,24 @@ helpful docstring (with typename and fieldnames) and a helpful :meth:`__repr__` method which lists the tuple contents in a ``name=value`` format. - The *fieldnames* are specified in a single string with each fieldname separated by - a space and/or comma. Any valid Python identifier may be used for a fieldname. + The *fieldnames* are a single string with each fieldname separated by whitespace + and/or commas (for example 'x y' or 'x, y'). Alternatively, the *fieldnames* + can be specified as a list of strings (such as ['x', 'y']). + Any valid Python identifier may be used for a fieldname except for names + starting and ending with double underscores. Valid identifiers consist of + letters, digits, and underscores but do not start with a digit and cannot be + a :mod:`keyword` such as *class*, *for*, *return*, *global*, *pass*, *print*, + or *raise*. + If *verbose* is true, will print the class definition. - *NamedTuple* instances do not have per-instance dictionaries, so they are + Named tuple instances do not have per-instance dictionaries, so they are lightweight and require no more memory than regular tuples. Example:: - >>> Point = NamedTuple('Point', 'x y', True) + >>> Point = named_tuple('Point', 'x y', verbose=True) class Point(tuple): 'Point(x, y)' __slots__ = () @@ -429,6 +459,9 @@ return tuple.__new__(cls, (x, y)) def __repr__(self): return 'Point(x=%r, y=%r)' % self + def __asdict__(self): + 'Return a new dict mapping field names to their values' + return dict(zip(('x', 'y'), self)) def __replace__(self, field, value): 'Return a new Point object replacing one field with a new value' return Point(**dict(zip(('x', 'y'), self) + [(field, value)])) @@ -449,24 +482,47 @@ Named tuples are especially useful for assigning field names to result tuples returned by the :mod:`csv` or :mod:`sqlite3` modules:: + EmployeeRecord = named_tuple('EmployeeRecord', 'name, age, title, department, paygrade') + from itertools import starmap import csv - EmployeeRecord = NamedTuple('EmployeeRecord', 'name age title department paygrade') for record in starmap(EmployeeRecord, csv.reader(open("employees.csv", "rb"))): print(emp.name, emp.title) -When casting a single record to a *NamedTuple*, use the star-operator [#]_ to unpack + import sqlite3 + conn = sqlite3.connect('/companydata') + cursor = conn.cursor() + cursor.execute('SELECT name, age, title, department, paygrade FROM employees') + for emp in starmap(EmployeeRecord, cursor.fetchall()): + print emp.name, emp.title + +When casting a single record to a named tuple, use the star-operator [#]_ to unpack the values:: >>> t = [11, 22] >>> Point(*t) # the star-operator unpacks any iterable object Point(x=11, y=22) +When casting a dictionary to a named tuple, use the double-star-operator:: + + >>> d = {'x': 11, 'y': 22} + >>> Point(**d) + Point(x=11, y=22) + In addition to the methods inherited from tuples, named tuples support -an additonal method and an informational read-only attribute. +two additonal methods and a read-only attribute. -.. method:: somenamedtuple.replace(field, value) +.. method:: somenamedtuple.__asdict__() + Return a new dict which maps field names to their corresponding values: + +:: + + >>> p.__asdict__() + {'x': 11, 'y': 22} + +.. method:: somenamedtuple.__replace__(field, value) + Return a new instance of the named tuple replacing the named *field* with a new *value*: :: @@ -480,20 +536,16 @@ .. attribute:: somenamedtuple.__fields__ - Return a tuple of strings listing the field names. This is useful for introspection, - for converting a named tuple instance to a dictionary, and for combining named tuple - types to create new named tuple types: + Return a tuple of strings listing the field names. This is useful for introspection + and for creating new named tuple types from existing named tuples. :: - >>> p.__fields__ # view the field names + >>> p.__fields__ # view the field names ('x', 'y') - >>> dict(zip(p.__fields__, p)) # convert to a dictionary - {'y': 22, 'x': 11} - >>> Color = NamedTuple('Color', 'red green blue') - >>> pixel_fields = ' '.join(Point.__fields__ + Color.__fields__) # combine fields - >>> Pixel = NamedTuple('Pixel', pixel_fields) + >>> Color = named_tuple('Color', 'red green blue') + >>> Pixel = named_tuple('Pixel', Point.__fields__ + Color.__fields__) >>> Pixel(11, 22, 128, 255, 0) Pixel(x=11, y=22, red=128, green=255, blue=0)' Index: Doc/library/os.rst =================================================================== --- Doc/library/os.rst (revision 58748) +++ Doc/library/os.rst (working copy) @@ -107,11 +107,16 @@ passed to the appropriate process-creation functions to cause child processes to use a modified environment. - If the platform supports the :func:`unsetenv` function, you can delete items in + If the platform supports the :func:`unsetenv` function, you can delete items in this mapping to unset environment variables. :func:`unsetenv` will be called - automatically when an item is deleted from ``os.environ``. + automatically when an item is deleted from ``os.environ``, and when + one of the :meth:`pop` or :meth:`clear` methods is called. + .. versionchanged:: 2.6 + Also unset environment variables when calling :meth:`os.environ.clear` + and :meth:`os.environ.pop`. + .. function:: chdir(path) fchdir(fd) getcwd() @@ -541,7 +546,7 @@ .. function:: ttyname(fd) Return a string which specifies the terminal device associated with - file-descriptor *fd*. If *fd* is not associated with a terminal device, an + file descriptor *fd*. If *fd* is not associated with a terminal device, an exception is raised. Availability:Macintosh, Unix. Index: Doc/library/autogil.rst =================================================================== --- Doc/library/autogil.rst (revision 58748) +++ Doc/library/autogil.rst (working copy) @@ -9,8 +9,8 @@ The :mod:`autoGIL` module provides a function :func:`installAutoGIL` that -automatically locks and unlocks Python's Global Interpreter Lock when running an -event loop. +automatically locks and unlocks Python's :term:`Global Interpreter Lock` when +running an event loop. .. exception:: AutoGILError Index: Doc/library/asynchat.rst =================================================================== --- Doc/library/asynchat.rst (revision 58748) +++ Doc/library/asynchat.rst (working copy) @@ -9,72 +9,90 @@ This module builds on the :mod:`asyncore` infrastructure, simplifying -asynchronous clients and servers and making it easier to handle protocols whose -elements are terminated by arbitrary strings, or are of variable length. +asynchronous clients and servers and making it easier to handle protocols +whose elements are terminated by arbitrary strings, or are of variable length. :mod:`asynchat` defines the abstract class :class:`async_chat` that you subclass, providing implementations of the :meth:`collect_incoming_data` and :meth:`found_terminator` methods. It uses the same asynchronous loop as -:mod:`asyncore`, and the two types of channel, :class:`asyncore.dispatcher` and -:class:`asynchat.async_chat`, can freely be mixed in the channel map. Typically -an :class:`asyncore.dispatcher` server channel generates new -:class:`asynchat.async_chat` channel objects as it receives incoming connection -requests. +:mod:`asyncore`, and the two types of channel, :class:`asyncore.dispatcher` +and :class:`asynchat.async_chat`, can freely be mixed in the channel map. +Typically an :class:`asyncore.dispatcher` server channel generates new +:class:`asynchat.async_chat` channel objects as it receives incoming +connection requests. .. class:: async_chat() This class is an abstract subclass of :class:`asyncore.dispatcher`. To make practical use of the code you must subclass :class:`async_chat`, providing - meaningful :meth:`collect_incoming_data` and :meth:`found_terminator` methods. + meaningful :meth:`collect_incoming_data` and :meth:`found_terminator` + methods. The :class:`asyncore.dispatcher` methods can be used, although not all make sense in a message/response context. - Like :class:`asyncore.dispatcher`, :class:`async_chat` defines a set of events - that are generated by an analysis of socket conditions after a :cfunc:`select` - call. Once the polling loop has been started the :class:`async_chat` object's - methods are called by the event-processing framework with no action on the part - of the programmer. + Like :class:`asyncore.dispatcher`, :class:`async_chat` defines a set of + events that are generated by an analysis of socket conditions after a + :cfunc:`select` call. Once the polling loop has been started the + :class:`async_chat` object's methods are called by the event-processing + framework with no action on the part of the programmer. - Unlike :class:`asyncore.dispatcher`, :class:`async_chat` allows you to define a - first-in-first-out queue (fifo) of *producers*. A producer need have only one - method, :meth:`more`, which should return data to be transmitted on the channel. + Two class attributes can be modified, to improve performance, or possibly + even to conserve memory. + + + .. data:: ac_in_buffer_size + + The asynchronous input buffer size (default ``4096``). + + + .. data:: ac_out_buffer_size + + The asynchronous output buffer size (default ``4096``). + + Unlike :class:`asyncore.dispatcher`, :class:`async_chat` allows you to + define a first-in-first-out queue (fifo) of *producers*. A producer need + have only one method, :meth:`more`, which should return data to be + transmitted on the channel. The producer indicates exhaustion (*i.e.* that it contains no more data) by having its :meth:`more` method return the empty string. At this point the - :class:`async_chat` object removes the producer from the fifo and starts using - the next producer, if any. When the producer fifo is empty the + :class:`async_chat` object removes the producer from the fifo and starts + using the next producer, if any. When the producer fifo is empty the :meth:`handle_write` method does nothing. You use the channel object's - :meth:`set_terminator` method to describe how to recognize the end of, or an - important breakpoint in, an incoming transmission from the remote endpoint. + :meth:`set_terminator` method to describe how to recognize the end of, or + an important breakpoint in, an incoming transmission from the remote + endpoint. To build a functioning :class:`async_chat` subclass your input methods - :meth:`collect_incoming_data` and :meth:`found_terminator` must handle the data - that the channel receives asynchronously. The methods are described below. + :meth:`collect_incoming_data` and :meth:`found_terminator` must handle the + data that the channel receives asynchronously. The methods are described + below. .. method:: async_chat.close_when_done() - Pushes a ``None`` on to the producer fifo. When this producer is popped off the - fifo it causes the channel to be closed. + Pushes a ``None`` on to the producer fifo. When this producer is popped off + the fifo it causes the channel to be closed. .. method:: async_chat.collect_incoming_data(data) - Called with *data* holding an arbitrary amount of received data. The default - method, which must be overridden, raises a :exc:`NotImplementedError` exception. + Called with *data* holding an arbitrary amount of received data. The + default method, which must be overridden, raises a + :exc:`NotImplementedError` exception. .. method:: async_chat.discard_buffers() - In emergencies this method will discard any data held in the input and/or output - buffers and the producer fifo. + In emergencies this method will discard any data held in the input and/or + output buffers and the producer fifo. .. method:: async_chat.found_terminator() - Called when the incoming data stream matches the termination condition set by - :meth:`set_terminator`. The default method, which must be overridden, raises a - :exc:`NotImplementedError` exception. The buffered input data should be - available via an instance attribute. + Called when the incoming data stream matches the termination condition set + by :meth:`set_terminator`. The default method, which must be overridden, + raises a :exc:`NotImplementedError` exception. The buffered input data + should be available via an instance attribute. .. method:: async_chat.get_terminator() @@ -90,59 +108,59 @@ .. method:: async_chat.handle_read() - Called when a read event fires on the channel's socket in the asynchronous loop. - The default method checks for the termination condition established by - :meth:`set_terminator`, which can be either the appearance of a particular - string in the input stream or the receipt of a particular number of characters. - When the terminator is found, :meth:`handle_read` calls the - :meth:`found_terminator` method after calling :meth:`collect_incoming_data` with - any data preceding the terminating condition. + Called when a read event fires on the channel's socket in the asynchronous + loop. The default method checks for the termination condition established + by :meth:`set_terminator`, which can be either the appearance of a + particular string in the input stream or the receipt of a particular number + of characters. When the terminator is found, :meth:`handle_read` calls the + :meth:`found_terminator` method after calling :meth:`collect_incoming_data` + with any data preceding the terminating condition. .. method:: async_chat.handle_write() - Called when the application may write data to the channel. The default method - calls the :meth:`initiate_send` method, which in turn will call - :meth:`refill_buffer` to collect data from the producer fifo associated with the - channel. + Called when the application may write data to the channel. The default + method calls the :meth:`initiate_send` method, which in turn will call + :meth:`refill_buffer` to collect data from the producer fifo associated + with the channel. .. method:: async_chat.push(data) - Creates a :class:`simple_producer` object (*see below*) containing the data and - pushes it on to the channel's ``producer_fifo`` to ensure its transmission. This - is all you need to do to have the channel write the data out to the network, - although it is possible to use your own producers in more complex schemes to - implement encryption and chunking, for example. + Creates a :class:`simple_producer` object (*see below*) containing the data + and pushes it on to the channel's ``producer_fifo`` to ensure its + transmission. This is all you need to do to have the channel write the + data out to the network, although it is possible to use your own producers + in more complex schemes to implement encryption and chunking, for example. .. method:: async_chat.push_with_producer(producer) - Takes a producer object and adds it to the producer fifo associated with the - channel. When all currently-pushed producers have been exhausted the channel - will consume this producer's data by calling its :meth:`more` method and send - the data to the remote endpoint. + Takes a producer object and adds it to the producer fifo associated with + the channel. When all currently-pushed producers have been exhausted the + channel will consume this producer's data by calling its :meth:`more` + method and send the data to the remote endpoint. .. method:: async_chat.readable() - Should return ``True`` for the channel to be included in the set of channels - tested by the :cfunc:`select` loop for readability. + Should return ``True`` for the channel to be included in the set of + channels tested by the :cfunc:`select` loop for readability. .. method:: async_chat.refill_buffer() - Refills the output buffer by calling the :meth:`more` method of the producer at - the head of the fifo. If it is exhausted then the producer is popped off the - fifo and the next producer is activated. If the current producer is, or becomes, - ``None`` then the channel is closed. + Refills the output buffer by calling the :meth:`more` method of the + producer at the head of the fifo. If it is exhausted then the producer is + popped off the fifo and the next producer is activated. If the current + producer is, or becomes, ``None`` then the channel is closed. .. method:: async_chat.set_terminator(term) - Sets the terminating condition to be recognised on the channel. ``term`` may be - any of three types of value, corresponding to three different ways to handle - incoming protocol data. + Sets the terminating condition to be recognized on the channel. ``term`` + may be any of three types of value, corresponding to three different ways + to handle incoming protocol data. +-----------+---------------------------------------------+ | term | Description | @@ -158,8 +176,8 @@ | | forever | +-----------+---------------------------------------------+ - Note that any data following the terminator will be available for reading by the - channel after :meth:`found_terminator` is called. + Note that any data following the terminator will be available for reading + by the channel after :meth:`found_terminator` is called. .. method:: async_chat.writable() @@ -174,29 +192,29 @@ .. class:: simple_producer(data[, buffer_size=512]) - A :class:`simple_producer` takes a chunk of data and an optional buffer size. - Repeated calls to its :meth:`more` method yield successive chunks of the data no - larger than *buffer_size*. + A :class:`simple_producer` takes a chunk of data and an optional buffer + size. Repeated calls to its :meth:`more` method yield successive chunks of + the data no larger than *buffer_size*. .. method:: simple_producer.more() - Produces the next chunk of information from the producer, or returns the empty - string. + Produces the next chunk of information from the producer, or returns the + empty string. .. class:: fifo([list=None]) - Each channel maintains a :class:`fifo` holding data which has been pushed by the - application but not yet popped for writing to the channel. A :class:`fifo` is a - list used to hold data and/or producers until they are required. If the *list* - argument is provided then it should contain producers or data items to be - written to the channel. + Each channel maintains a :class:`fifo` holding data which has been pushed + by the application but not yet popped for writing to the channel. A + :class:`fifo` is a list used to hold data and/or producers until they are + required. If the *list* argument is provided then it should contain + producers or data items to be written to the channel. .. method:: fifo.is_empty() - Returns ``True`` iff the fifo is empty. + Returns ``True`` if and only if the fifo is empty. .. method:: fifo.first() @@ -206,14 +224,14 @@ .. method:: fifo.push(data) - Adds the given data (which may be a string or a producer object) to the producer - fifo. + Adds the given data (which may be a string or a producer object) to the + producer fifo. .. method:: fifo.pop() - If the fifo is not empty, returns ``True, first()``, deleting the popped item. - Returns ``False, None`` for an empty fifo. + If the fifo is not empty, returns ``True, first()``, deleting the popped + item. Returns ``False, None`` for an empty fifo. The :mod:`asynchat` module also defines one utility function, which may be of use in network and textual analysis operations. @@ -221,8 +239,8 @@ .. function:: find_prefix_at_end(haystack, needle) - Returns ``True`` if string *haystack* ends with any non-empty prefix of string - *needle*. + Returns ``True`` if string *haystack* ends with any non-empty prefix of + string *needle*. .. _asynchat-example: @@ -231,19 +249,20 @@ ---------------- The following partial example shows how HTTP requests can be read with -:class:`async_chat`. A web server might create an :class:`http_request_handler` -object for each incoming client connection. Notice that initially the channel -terminator is set to match the blank line at the end of the HTTP headers, and a -flag indicates that the headers are being read. +:class:`async_chat`. A web server might create an +:class:`http_request_handler` object for each incoming client connection. +Notice that initially the channel terminator is set to match the blank line at +the end of the HTTP headers, and a flag indicates that the headers are being +read. -Once the headers have been read, if the request is of type POST (indicating that -further data are present in the input stream) then the ``Content-Length:`` -header is used to set a numeric terminator to read the right amount of data from -the channel. +Once the headers have been read, if the request is of type POST (indicating +that further data are present in the input stream) then the +``Content-Length:`` header is used to set a numeric terminator to read the +right amount of data from the channel. The :meth:`handle_request` method is called once all relevant input has been -marshalled, after setting the channel terminator to ``None`` to ensure that any -extraneous data sent by the web client are ignored. :: +marshalled, after setting the channel terminator to ``None`` to ensure that +any extraneous data sent by the web client are ignored. :: class http_request_handler(asynchat.async_chat): @@ -281,4 +300,3 @@ self.handling = True self.ibuffer = [] self.handle_request() - Index: Doc/library/functions.rst =================================================================== --- Doc/library/functions.rst (revision 58748) +++ Doc/library/functions.rst (working copy) @@ -41,7 +41,7 @@ top-level package (the name up till the first dot) is returned, *not* the module named by *name*. However, when a non-empty *fromlist* argument is given, the module named by *name* is returned. This is done for - compatibility with the bytecode generated for the different kinds of import + compatibility with the :term:`bytecode` generated for the different kinds of import statement; when using ``import spam.ham.eggs``, the top-level package :mod:`spam` must be placed in the importing namespace, but when using ``from spam.ham import eggs``, the ``spam.ham`` subpackage must be used to find the @@ -317,7 +317,7 @@ .. function:: enumerate(iterable) - Return an enumerate object. *iterable* must be a sequence, an iterator, or some + Return an enumerate object. *iterable* must be a sequence, an :term:`iterator`, or some other object which supports iteration. The :meth:`__next__` method of the iterator returned by :func:`enumerate` returns a tuple containing a count (from zero) and the corresponding value obtained from iterating over *iterable*. @@ -340,7 +340,7 @@ The *expression* argument is parsed and evaluated as a Python expression (technically speaking, a condition list) using the *globals* and *locals* - dictionaries as global and local name space. If the *globals* dictionary is + dictionaries as global and local namespace. If the *globals* dictionary is present and lacks '__builtins__', the current globals are copied into *globals* before *expression* is parsed. This means that *expression* normally has full access to the standard :mod:`__builtin__` module and restricted environments are @@ -406,12 +406,21 @@ .. function:: filter(function, iterable) +<<<<<<< .working Construct an iterator from those elements of *iterable* for which *function* returns true. *iterable* may be either a sequence, a container which supports iteration, or an iterator, If *iterable* is a string or a tuple, the result also has that type; otherwise it is always a list. If *function* is ``None``, the identity function is assumed, that is, all elements of *iterable* that are false are removed. +======= + Construct a list from those elements of *iterable* for which *function* returns + true. *iterable* may be either a sequence, a container which supports + iteration, or an iterator. If *iterable* is a string or a tuple, the result + also has that type; otherwise it is always a list. If *function* is ``None``, + the identity function is assumed, that is, all elements of *iterable* that are + false are removed. +>>>>>>> .merge-right.r58739 Note that ``filter(function, iterable)`` is equivalent to the generator expression ``(item for item in iterable if function(item))`` if function is @@ -542,6 +551,7 @@ .. function:: int([x[, radix]]) +<<<<<<< .working Convert a string or number to an integer. If the argument is a string, it must contain a possibly signed number of arbitrary size, possibly embedded in whitespace. The *radix* parameter gives the base for the @@ -552,6 +562,20 @@ that has an :meth:`__int__` method. Conversion of floating point numbers to integers truncates (towards zero). If no arguments are given, returns ``0``. +======= + Convert a string or number to a plain integer. If the argument is a string, + it must contain a possibly signed decimal number representable as a Python + integer, possibly embedded in whitespace. The *radix* parameter gives the + base for the conversion (which is 10 by default) and may be any integer in + the range [2, 36], or zero. If *radix* is zero, the proper radix is guessed + based on the contents of string; the interpretation is the same as for + integer literals. If *radix* is specified and *x* is not a string, + :exc:`TypeError` is raised. Otherwise, the argument may be a plain or long + integer or a floating point number. Conversion of floating point numbers to + integers truncates (towards zero). If the argument is outside the integer + range a long object will be returned instead. If no arguments are given, + returns ``0``. +>>>>>>> .merge-right.r58739 The integer type is described in :ref:`typesnumeric`. @@ -577,7 +601,7 @@ .. function:: iter(o[, sentinel]) - Return an iterator object. The first argument is interpreted very differently + Return an :term:`iterator` object. The first argument is interpreted very differently depending on the presence of the second argument. Without a second argument, *o* must be a collection object which supports the iteration protocol (the :meth:`__iter__` method), or it must support the sequence protocol (the @@ -787,7 +811,12 @@ .. function:: property([fget[, fset[, fdel[, doc]]]]) +<<<<<<< .working Return a property attribute. +======= + Return a property attribute for :term:`new-style class`\es (classes that + derive from :class:`object`). +>>>>>>> .merge-right.r58739 *fget* is a function for getting an attribute value, likewise *fset* is a function for setting, and *fdel* a function for del'ing, an attribute. Typical @@ -857,9 +886,9 @@ .. function:: reversed(seq) - Return a reverse iterator. *seq* must be an object which supports the sequence - protocol (the :meth:`__len__` method and the :meth:`__getitem__` method with - integer arguments starting at ``0``). + Return a reverse :term:`iterator`. *seq* must be an object which supports + the sequence protocol (the :meth:`__len__` method and the :meth:`__getitem__` + method with integer arguments starting at ``0``). .. function:: round(x[, n]) @@ -1000,7 +1029,12 @@ Return the superclass of *type*. 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, +<<<<<<< .working ``issubclass(type2, type)`` must be true. +======= + ``issubclass(type2, type)`` must be true. :func:`super` only works for + :term:`new-style class`\es. +>>>>>>> .merge-right.r58739 A typical use for calling a cooperative superclass method is:: @@ -1079,6 +1113,77 @@ returns an empty iterator. +<<<<<<< .working +======= + .. versionchanged:: 2.4 + Formerly, :func:`zip` required at least one argument and ``zip()`` raised a + :exc:`TypeError` instead of returning an empty list. + +.. % --------------------------------------------------------------------------- + + +.. _non-essential-built-in-funcs: + +Non-essential Built-in Functions +================================ + +There are several built-in functions that are no longer essential to learn, know +or use in modern Python programming. They have been kept here to maintain +backwards compatibility with programs written for older versions of Python. + +Python programmers, trainers, students and bookwriters should feel free to +bypass these functions without concerns about missing something important. + + +.. function:: apply(function, args[, keywords]) + + The *function* argument must be a callable object (a user-defined or built-in + function or method, or a class object) and the *args* argument must be a + sequence. The *function* is called with *args* as the argument list; the number + of arguments is the length of the tuple. If the optional *keywords* argument is + present, it must be a dictionary whose keys are strings. It specifies keyword + arguments to be added to the end of the argument list. Calling :func:`apply` is + different from just calling ``function(args)``, since in that case there is + always exactly one argument. The use of :func:`apply` is exactly equivalent to + ``function(*args, **keywords)``. + + .. deprecated:: 2.3 + Use the extended call syntax with ``*args`` and ``**keywords`` instead. + + +.. function:: buffer(object[, offset[, size]]) + + The *object* argument must be an object that supports the buffer call interface + (such as strings, arrays, and buffers). A new buffer object will be created + which references the *object* argument. The buffer object will be a slice from + the beginning of *object* (or from the specified *offset*). The slice will + extend to the end of *object* (or will have a length given by the *size* + argument). + + +.. function:: coerce(x, y) + + Return a tuple consisting of the two numeric arguments converted to a common + type, using the same rules as used by arithmetic operations. If coercion is not + possible, raise :exc:`TypeError`. + + +.. function:: intern(string) + + Enter *string* in the table of "interned" strings and return the interned string + -- which is *string* itself or a copy. Interning strings is useful to gain a + little performance on dictionary lookup -- if the keys in a dictionary are + interned, and the lookup key is interned, the key comparisons (after hashing) + can be done by a pointer compare instead of a string compare. Normally, the + names used in Python programs are automatically interned, and the dictionaries + used to hold module, class or instance attributes have interned keys. + + .. versionchanged:: 2.3 + Interned strings are not immortal (like they used to be in Python 2.2 and + before); you must keep a reference to the return value of :func:`intern` around + to benefit from it. + +>>>>>>> .merge-right.r58739 .. rubric:: Footnotes .. [#] Specifying a buffer size currently has no effect on systems that don't have Index: Doc/library/os.path.rst =================================================================== --- Doc/library/os.path.rst (revision 58748) +++ Doc/library/os.path.rst (working copy) @@ -279,8 +279,8 @@ .. note:: - The newer :func:`os.walk` generator supplies similar functionality and can be - easier to use. + The newer :func:`os.walk` :term:`generator` supplies similar functionality + and can be easier to use. .. data:: supports_unicode_filenames Index: Doc/library/exceptions.rst =================================================================== --- Doc/library/exceptions.rst (revision 58748) +++ Doc/library/exceptions.rst (working copy) @@ -135,7 +135,13 @@ .. exception:: GeneratorExit +<<<<<<< .working Raise when a generator's :meth:`close` method is called. +======= + Raise when a :term:`generator`\'s :meth:`close` method is called. It + directly inherits from :exc:`Exception` instead of :exc:`StandardError` since + it is technically not an error. +>>>>>>> .merge-right.r58739 .. exception:: IOError @@ -241,8 +247,15 @@ .. exception:: StopIteration +<<<<<<< .working Raised by builtin :func:`next` and an iterator's :meth:`__next__` method to signal that there are no further values. +======= + Raised by an :term:`iterator`\'s :meth:`next` method to signal that there are + no further values. This is derived from :exc:`Exception` rather than + :exc:`StandardError`, since this is not considered an error in its normal + application. +>>>>>>> .merge-right.r58739 .. exception:: SyntaxError Index: Doc/library/asyncore.rst =================================================================== --- Doc/library/asyncore.rst (revision 58748) +++ Doc/library/asyncore.rst (working copy) @@ -3,7 +3,8 @@ =============================================== .. module:: asyncore - :synopsis: A base class for developing asynchronous socket handling services. + :synopsis: A base class for developing asynchronous socket handling + services. .. moduleauthor:: Sam Rushing .. sectionauthor:: Christopher Petrilli .. sectionauthor:: Steve Holden @@ -16,77 +17,68 @@ There are only two ways to have a program on a single processor do "more than one thing at a time." Multi-threaded programming is the simplest and most -popular way to do it, but there is another very different technique, that lets +popular way to do it, but there is another very different technique, that lets you have nearly all the advantages of multi-threading, without actually using multiple threads. It's really only practical if your program is largely I/O -bound. If your program is processor bound, then pre-emptive scheduled threads -are probably what you really need. Network servers are rarely processor bound, -however. +bound. If your program is processor bound, then pre-emptive scheduled threads +are probably what you really need. Network servers are rarely processor +bound, however. If your operating system supports the :cfunc:`select` system call in its I/O library (and nearly all do), then you can use it to juggle multiple -communication channels at once; doing other work while your I/O is taking place -in the "background." Although this strategy can seem strange and complex, -especially at first, it is in many ways easier to understand and control than -multi-threaded programming. The :mod:`asyncore` module solves many of the -difficult problems for you, making the task of building sophisticated -high-performance network servers and clients a snap. For "conversational" -applications and protocols the companion :mod:`asynchat` module is invaluable. +communication channels at once; doing other work while your I/O is taking +place in the "background." Although this strategy can seem strange and +complex, especially at first, it is in many ways easier to understand and +control than multi-threaded programming. The :mod:`asyncore` module solves +many of the difficult problems for you, making the task of building +sophisticated high-performance network servers and clients a snap. For +"conversational" applications and protocols the companion :mod:`asynchat` +module is invaluable. -The basic idea behind both modules is to create one or more network *channels*, -instances of class :class:`asyncore.dispatcher` and -:class:`asynchat.async_chat`. Creating the channels adds them to a global map, -used by the :func:`loop` function if you do not provide it with your own *map*. +The basic idea behind both modules is to create one or more network +*channels*, instances of class :class:`asyncore.dispatcher` and +:class:`asynchat.async_chat`. Creating the channels adds them to a global +map, used by the :func:`loop` function if you do not provide it with your own +*map*. Once the initial channel(s) is(are) created, calling the :func:`loop` function -activates channel service, which continues until the last channel (including any -that have been added to the map during asynchronous service) is closed. +activates channel service, which continues until the last channel (including +any that have been added to the map during asynchronous service) is closed. .. function:: loop([timeout[, use_poll[, map[,count]]]]) - Enter a polling loop that terminates after count passes or all open channels - have been closed. All arguments are optional. The *count* parameter defaults - to None, resulting in the loop terminating only when all channels have been - closed. The *timeout* argument sets the timeout parameter for the appropriate - :func:`select` or :func:`poll` call, measured in seconds; the default is 30 - seconds. The *use_poll* parameter, if true, indicates that :func:`poll` should - be used in preference to :func:`select` (the default is ``False``). + Enter a polling loop that terminates after count passes or all open + channels have been closed. All arguments are optional. The *count* + parameter defaults to None, resulting in the loop terminating only when all + channels have been closed. The *timeout* argument sets the timeout + parameter for the appropriate :func:`select` or :func:`poll` call, measured + in seconds; the default is 30 seconds. The *use_poll* parameter, if true, + indicates that :func:`poll` should be used in preference to :func:`select` + (the default is ``False``). - The *map* parameter is a dictionary whose items are the channels to watch. As - channels are closed they are deleted from their map. If *map* is omitted, a - global map is used. Channels (instances of :class:`asyncore.dispatcher`, - :class:`asynchat.async_chat` and subclasses thereof) can freely be mixed in the - map. + The *map* parameter is a dictionary whose items are the channels to watch. + As channels are closed they are deleted from their map. If *map* is + omitted, a global map is used. Channels (instances of + :class:`asyncore.dispatcher`, :class:`asynchat.async_chat` and subclasses + thereof) can freely be mixed in the map. .. class:: dispatcher() The :class:`dispatcher` class is a thin wrapper around a low-level socket - object. To make it more useful, it has a few methods for event-handling which - are called from the asynchronous loop. Otherwise, it can be treated as a - normal non-blocking socket object. + object. To make it more useful, it has a few methods for event-handling + which are called from the asynchronous loop. Otherwise, it can be treated + as a normal non-blocking socket object. - Two class attributes can be modified, to improve performance, or possibly even - to conserve memory. + The firing of low-level events at certain times or in certain connection + states tells the asynchronous loop that certain higher-level events have + taken place. For example, if we have asked for a socket to connect to + another host, we know that the connection has been made when the socket + becomes writable for the first time (at this point you know that you may + write to it with the expectation of success). The implied higher-level + events are: - - .. data:: ac_in_buffer_size - - The asynchronous input buffer size (default ``4096``). - - - .. data:: ac_out_buffer_size - - The asynchronous output buffer size (default ``4096``). - - The firing of low-level events at certain times or in certain connection states - tells the asynchronous loop that certain higher-level events have taken place. - For example, if we have asked for a socket to connect to another host, we know - that the connection has been made when the socket becomes writable for the first - time (at this point you know that you may write to it with the expectation of - success). The implied higher-level events are: - +----------------------+----------------------------------------+ | Event | Description | +======================+========================================+ @@ -101,11 +93,11 @@ During asynchronous processing, each mapped channel's :meth:`readable` and :meth:`writable` methods are used to determine whether the channel's socket - should be added to the list of channels :cfunc:`select`\ ed or :cfunc:`poll`\ ed - for read and write events. + should be added to the list of channels :cfunc:`select`\ ed or + :cfunc:`poll`\ ed for read and write events. -Thus, the set of channel events is larger than the basic socket events. The full -set of methods that can be overridden in your subclass follows: +Thus, the set of channel events is larger than the basic socket events. The +full set of methods that can be overridden in your subclass follows: .. method:: dispatcher.handle_read() @@ -116,9 +108,9 @@ .. method:: dispatcher.handle_write() - Called when the asynchronous loop detects that a writable socket can be written. - Often this method will implement the necessary buffering for performance. For - example:: + Called when the asynchronous loop detects that a writable socket can be + written. Often this method will implement the necessary buffering for + performance. For example:: def handle_write(self): sent = self.send(self.buffer) @@ -127,15 +119,15 @@ .. method:: dispatcher.handle_expt() - Called when there is out of band (OOB) data for a socket connection. This will - almost never happen, as OOB is tenuously supported and rarely used. + Called when there is out of band (OOB) data for a socket connection. This + will almost never happen, as OOB is tenuously supported and rarely used. .. method:: dispatcher.handle_connect() - Called when the active opener's socket actually makes a connection. Might send a - "welcome" banner, or initiate a protocol negotiation with the remote endpoint, - for example. + Called when the active opener's socket actually makes a connection. Might + send a "welcome" banner, or initiate a protocol negotiation with the remote + endpoint, for example. .. method:: dispatcher.handle_close() @@ -152,40 +144,40 @@ .. method:: dispatcher.handle_accept() Called on listening channels (passive openers) when a connection can be - established with a new remote endpoint that has issued a :meth:`connect` call - for the local endpoint. + established with a new remote endpoint that has issued a :meth:`connect` + call for the local endpoint. .. method:: dispatcher.readable() - Called each time around the asynchronous loop to determine whether a channel's - socket should be added to the list on which read events can occur. The default - method simply returns ``True``, indicating that by default, all channels will - be interested in read events. + Called each time around the asynchronous loop to determine whether a + channel's socket should be added to the list on which read events can + occur. The default method simply returns ``True``, indicating that by + default, all channels will be interested in read events. .. method:: dispatcher.writable() - Called each time around the asynchronous loop to determine whether a channel's - socket should be added to the list on which write events can occur. The default - method simply returns ``True``, indicating that by default, all channels will - be interested in write events. + Called each time around the asynchronous loop to determine whether a + channel's socket should be added to the list on which write events can + occur. The default method simply returns ``True``, indicating that by + default, all channels will be interested in write events. -In addition, each channel delegates or extends many of the socket methods. Most -of these are nearly identical to their socket partners. +In addition, each channel delegates or extends many of the socket methods. +Most of these are nearly identical to their socket partners. .. method:: dispatcher.create_socket(family, type) - This is identical to the creation of a normal socket, and will use the same - options for creation. Refer to the :mod:`socket` documentation for information - on creating sockets. + This is identical to the creation of a normal socket, and will use the same + options for creation. Refer to the :mod:`socket` documentation for + information on creating sockets. .. method:: dispatcher.connect(address) - As with the normal socket object, *address* is a tuple with the first element - the host to connect to, and the second the port number. + As with the normal socket object, *address* is a tuple with the first + element the host to connect to, and the second the port number. .. method:: dispatcher.send(data) @@ -195,38 +187,41 @@ .. method:: dispatcher.recv(buffer_size) - Read at most *buffer_size* bytes from the socket's remote end-point. An empty - string implies that the channel has been closed from the other end. + Read at most *buffer_size* bytes from the socket's remote end-point. + An empty string implies that the channel has been closed from the other + end. .. method:: dispatcher.listen(backlog) - Listen for connections made to the socket. The *backlog* argument specifies the - maximum number of queued connections and should be at least 1; the maximum value - is system-dependent (usually 5). + Listen for connections made to the socket. The *backlog* argument + specifies the maximum number of queued connections and should be at least + 1; the maximum value is system-dependent (usually 5). .. method:: dispatcher.bind(address) Bind the socket to *address*. The socket must not already be bound. (The - format of *address* depends on the address family --- see above.) To mark the - socket as re-usable (setting the :const:`SO_REUSEADDR` option), call the - :class:`dispatcher` object's :meth:`set_reuse_addr` method. + format of *address* depends on the address family --- see above.) To mark + the socket as re-usable (setting the :const:`SO_REUSEADDR` option), call + the :class:`dispatcher` object's :meth:`set_reuse_addr` method. .. method:: dispatcher.accept() - Accept a connection. The socket must be bound to an address and listening for - connections. The return value is a pair ``(conn, address)`` where *conn* is a - *new* socket object usable to send and receive data on the connection, and - *address* is the address bound to the socket on the other end of the connection. + Accept a connection. The socket must be bound to an address and listening + for connections. The return value is a pair ``(conn, address)`` where + *conn* is a *new* socket object usable to send and receive data on the + connection, and *address* is the address bound to the socket on the other + end of the connection. .. method:: dispatcher.close() - Close the socket. All future operations on the socket object will fail. The - remote end-point will receive no more data (after queued data is flushed). - Sockets are automatically closed when they are garbage-collected. + Close the socket. All future operations on the socket object will fail. + The remote end-point will receive no more data (after queued data is + flushed). Sockets are automatically closed when they are + garbage-collected. .. _asyncore-example: @@ -266,4 +261,3 @@ c = http_client('www.python.org', '/') asyncore.loop() - Index: Doc/library/urllib.rst =================================================================== --- Doc/library/urllib.rst (revision 58748) +++ Doc/library/urllib.rst (working copy) @@ -29,7 +29,7 @@ :exc:`IOError` exception is raised. If all went well, a file-like object is returned. This supports the following methods: :meth:`read`, :meth:`readline`, :meth:`readlines`, :meth:`fileno`, :meth:`close`, :meth:`info` and - :meth:`geturl`. It also has proper support for the iterator protocol. One + :meth:`geturl`. It also has proper support for the :term:`iterator` protocol. One caveat: the :meth:`read` method, if the size argument is omitted or negative, may not read until the end of the data stream; there is no good way to determine that the entire stream from a socket has been read in the general case. Index: Doc/library/pickle.rst =================================================================== --- Doc/library/pickle.rst (revision 58748) +++ Doc/library/pickle.rst (working copy) @@ -122,7 +122,7 @@ earlier versions of Python. * Protocol version 2 was introduced in Python 2.3. It provides much more - efficient pickling of new-style classes. + efficient pickling of :term:`new-style class`\es. Refer to :pep:`307` for more information. @@ -418,8 +418,8 @@ protocol 2. Implementing this method is needed if the type establishes some internal invariants when the instance is created, or if the memory allocation is affected by the values passed to the :meth:`__new__` method for the type (as it -is for tuples and strings). Instances of a new-style type :class:`C` are -created using :: +is for tuples and strings). Instances of a :term:`new-style class` :class:`C` +are created using :: obj = C.__new__(C, *args) @@ -447,8 +447,8 @@ .. warning:: - For new-style classes, if :meth:`__getstate__` returns a false value, the - :meth:`__setstate__` method will not be called. + For :term:`new-style class`\es, if :meth:`__getstate__` returns a false + value, the :meth:`__setstate__` method will not be called. Pickling and unpickling extension types Index: Doc/contents.rst =================================================================== --- Doc/contents.rst (revision 58748) +++ Doc/contents.rst (working copy) @@ -6,6 +6,7 @@ whatsnew/3.0.rst tutorial/index.rst + using/index.rst reference/index.rst library/index.rst extending/index.rst Index: Doc/includes/email-unpack.py =================================================================== --- Doc/includes/email-unpack.py (revision 58748) +++ Doc/includes/email-unpack.py (working copy) @@ -53,7 +53,7 @@ # email message can't be used to overwrite important files filename = part.get_filename() if not filename: - ext = mimetypes.guess_extension(part.get_type()) + ext = mimetypes.guess_extension(part.get_content_type()) if not ext: # Use a generic bag-of-bits extension ext = '.bin' Index: Doc/glossary.rst =================================================================== --- Doc/glossary.rst (revision 58748) +++ Doc/glossary.rst (working copy) @@ -20,13 +20,13 @@ Benevolent Dictator For Life, a.k.a. `Guido van Rossum `_, Python's creator. - byte code - The internal representation of a Python program in the interpreter. The - byte code is also cached in ``.pyc`` and ``.pyo`` files so that executing - the same file is faster the second time (recompilation from source to byte - code can be avoided). This "intermediate language" is said to run on a - "virtual machine" that calls the subroutines corresponding to each - bytecode. + bytecode + Python source code is compiled into bytecode, the internal representation + of a Python program in the interpreter. The bytecode is also cached in + ``.pyc`` and ``.pyo`` files so that executing the same file is faster the + second time (recompilation from source to bytecode can be avoided). This + "intermediate language" is said to run on a "virtual machine" that calls + the subroutines corresponding to each bytecode. classic class One of the two flavors of classes in earlier Python versions. Since @@ -45,6 +45,7 @@ it's almost certain you can safely ignore them. descriptor +<<<<<<< .working An object that defines the methods :meth:`__get__`, :meth:`__set__`, or :meth:`__delete__`. When a class attribute is a descriptor, its special binding behavior is triggered upon attribute lookup. Normally, writing @@ -53,6 +54,19 @@ descriptors is a key to a deep understanding of Python because they are the basis for many features including functions, methods, properties, class methods, static methods, and reference to super classes. +======= + Any *new-style* object that defines the methods :meth:`__get__`, + :meth:`__set__`, or :meth:`__delete__`. When a class attribute is a + descriptor, its special binding behavior is triggered upon attribute + lookup. Normally, using *a.b* to get, set or delete an attribute looks up + the object named *b* in the class dictionary for *a*, but if *b* is a + descriptor, the respective descriptor method gets called. Understanding + descriptors is a key to a deep understanding of Python because they are + the basis for many features including functions, methods, properties, + class methods, static methods, and reference to super classes. + + For more information about descriptors' methods, see :ref:`descriptors`. +>>>>>>> .merge-right.r58739 dictionary An associative array, where arbitrary keys are mapped to values. The use @@ -209,6 +223,8 @@ with an iterator will just return the same exhausted iterator object used in the previous iteration pass, making it appear like an empty container. + More information can be found in :ref:`typeiter`. + LBYL Look before you leap. This coding style explicitly tests for pre-conditions before making calls or lookups. This style contrasts with @@ -237,6 +253,8 @@ powerful, elegant solutions. They have been used for logging attribute access, adding thread-safety, tracking object creation, implementing singletons, and many other tasks. + + More information can be found in :ref:`metaclasses`. mutable Mutable objects can change their value but keep their :func:`id`. See @@ -267,6 +285,8 @@ earlier Python versions, only new-style classes could use Python's newer, versatile features like :attr:`__slots__`, descriptors, properties, :meth:`__getattribute__`, class methods, and static methods. + + More information can be found in :ref:`newstyle`. Python 3000 Nickname for the next major Python version, 3.0 (coined long ago when the Index: Doc/README.txt =================================================================== --- Doc/README.txt (revision 58748) +++ Doc/README.txt (working copy) @@ -72,7 +72,7 @@ You can optionally also install Pygments, either as a checkout via :: - svn co http://svn.python.org/projects/external/Pygments-0.8.1/pygments tools/pygments + svn co http://svn.python.org/projects/external/Pygments-0.9/pygments tools/pygments or from PyPI at http://pypi.python.org/pypi/Pygments. Index: Doc/documenting/markup.rst =================================================================== --- Doc/documenting/markup.rst (revision 58748) +++ Doc/documenting/markup.rst (working copy) @@ -210,9 +210,22 @@ .. describe:: opcode - Describes a Python bytecode instruction. + Describes a Python :term:`bytecode` instruction. +.. describe:: cmdoption + Describes a command line option or switch. Option argument names should be + enclosed in angle brackets. Example:: + + .. cmdoption:: -m + + Run a module as a script. + +.. describe:: envvar + + Describes an environment variable that Python uses or defines. + + There is also a generic version of these directives: .. describe:: describe