]> granicus.if.org Git - python/commitdiff
Merged revisions 85572-85573,85606,85609-85622,85624,85626-85627,85629,85631,85633...
authorGeorg Brandl <georg@python.org>
Fri, 26 Nov 2010 08:49:15 +0000 (08:49 +0000)
committerGeorg Brandl <georg@python.org>
Fri, 26 Nov 2010 08:49:15 +0000 (08:49 +0000)
svn+ssh://svn.python.org/python/branches/py3k

........
  r85572 | georg.brandl | 2010-10-16 20:51:05 +0200 (Sa, 16 Okt 2010) | 1 line

  #10122: typo fix.
........
  r85573 | georg.brandl | 2010-10-16 20:53:08 +0200 (Sa, 16 Okt 2010) | 1 line

  #10124: typo fix.
........
  r85606 | georg.brandl | 2010-10-17 08:32:59 +0200 (So, 17 Okt 2010) | 1 line

  #10058: tweak wording about exception returns.
........
  r85609 | georg.brandl | 2010-10-17 11:19:03 +0200 (So, 17 Okt 2010) | 1 line

  #8556: use less confusing mapping key in example.
........
  r85610 | georg.brandl | 2010-10-17 11:23:05 +0200 (So, 17 Okt 2010) | 1 line

  #8686: remove potentially confusing wording that does not add any value.
........
  r85611 | georg.brandl | 2010-10-17 11:33:24 +0200 (So, 17 Okt 2010) | 1 line

  #8811: small fixes to sqlite3 docs.
........
  r85612 | georg.brandl | 2010-10-17 11:37:54 +0200 (So, 17 Okt 2010) | 1 line

  #8855: add shelve security warning.
........
  r85613 | georg.brandl | 2010-10-17 11:43:35 +0200 (So, 17 Okt 2010) | 1 line

  Fix hmac docs: it takes and returns bytes, except for hexdigest().
........
  r85614 | georg.brandl | 2010-10-17 11:46:11 +0200 (So, 17 Okt 2010) | 1 line

  #8968: add actual name of token constants.
........
  r85615 | georg.brandl | 2010-10-17 12:05:13 +0200 (So, 17 Okt 2010) | 1 line

  #459007: merge info from PC/getpathp.c and using/windows.rst to document the forming of sys.path under Windows.
........
  r85616 | georg.brandl | 2010-10-17 12:07:29 +0200 (So, 17 Okt 2010) | 1 line

  Fix copy-paste error in example.
........
  r85617 | georg.brandl | 2010-10-17 12:09:06 +0200 (So, 17 Okt 2010) | 1 line

  #5212: md5 weaknesses do not affect hmac, so remove the note about that.
........
  r85618 | georg.brandl | 2010-10-17 12:14:38 +0200 (So, 17 Okt 2010) | 1 line

  #9086: correct wrong terminology about linking with pythonXY.dll.
........
  r85619 | georg.brandl | 2010-10-17 12:15:50 +0200 (So, 17 Okt 2010) | 1 line

  Make file names consistent.
........
  r85620 | georg.brandl | 2010-10-17 12:22:28 +0200 (So, 17 Okt 2010) | 1 line

  Remove second parser module example; it referred to non-readily-available example files, and this kind of discovery is much better done with the AST nowadays anyway.
........
  r85621 | georg.brandl | 2010-10-17 12:24:54 +0200 (So, 17 Okt 2010) | 1 line

  #9105: move pickle warning to a bit more prominent location.
........
  r85622 | georg.brandl | 2010-10-17 12:28:04 +0200 (So, 17 Okt 2010) | 1 line

  #9112: document error() and exit() methods of ArgumentParser.
........
  r85624 | georg.brandl | 2010-10-17 12:34:28 +0200 (So, 17 Okt 2010) | 1 line

  Some markup and style fixes in argparse docs.
........
  r85626 | georg.brandl | 2010-10-17 12:38:20 +0200 (So, 17 Okt 2010) | 1 line

  #9117: fix syntax for class definition.
........
  r85627 | georg.brandl | 2010-10-17 12:44:11 +0200 (So, 17 Okt 2010) | 1 line

  #9138: reword introduction to classes in Python.
........
  r85629 | georg.brandl | 2010-10-17 12:51:45 +0200 (So, 17 Okt 2010) | 1 line

  #5962: clarify sys.exit() vs. threads.
........
  r85631 | georg.brandl | 2010-10-17 12:53:54 +0200 (So, 17 Okt 2010) | 1 line

  Fix capitalization.
........
  r85633 | georg.brandl | 2010-10-17 12:59:41 +0200 (So, 17 Okt 2010) | 1 line

  #9204: remove mentions of removed types in the types module.
........
  r85635 | georg.brandl | 2010-10-17 13:03:22 +0200 (So, 17 Okt 2010) | 1 line

  #5121: fix claims about default values leading to segfaults.
........
  r85636 | georg.brandl | 2010-10-17 13:06:14 +0200 (So, 17 Okt 2010) | 1 line

  #9237: document sys.call_tracing().
........
  r85638 | georg.brandl | 2010-10-17 13:13:37 +0200 (So, 17 Okt 2010) | 1 line

  Port changes to pickle docs apparently lost in py3k.
........
  r85639 | georg.brandl | 2010-10-17 13:23:56 +0200 (So, 17 Okt 2010) | 1 line

  Make twisted example a bit more logical.
........
  r85641 | georg.brandl | 2010-10-17 13:29:07 +0200 (So, 17 Okt 2010) | 1 line

  Fix documentation of dis.opmap direction.
........
  r85642 | georg.brandl | 2010-10-17 13:36:28 +0200 (So, 17 Okt 2010) | 1 line

  #9730: fix example.
........

32 files changed:
Doc/c-api/bytearray.rst
Doc/c-api/bytes.rst
Doc/c-api/complex.rst
Doc/c-api/dict.rst
Doc/c-api/float.rst
Doc/c-api/intro.rst
Doc/c-api/list.rst
Doc/c-api/long.rst
Doc/c-api/slice.rst
Doc/c-api/tuple.rst
Doc/c-api/type.rst
Doc/c-api/unicode.rst
Doc/c-api/veryhigh.rst
Doc/faq/windows.rst
Doc/howto/cporting.rst
Doc/library/audioop.rst
Doc/library/base64.rst
Doc/library/difflib.rst
Doc/library/dis.rst
Doc/library/functions.rst
Doc/library/hmac.rst
Doc/library/os.rst
Doc/library/parser.rst
Doc/library/pickle.rst
Doc/library/shelve.rst
Doc/library/sqlite3.rst
Doc/library/stdtypes.rst
Doc/library/sys.rst
Doc/library/token.rst
Doc/reference/compound_stmts.rst
Doc/tutorial/classes.rst
Doc/using/windows.rst

index 4bc545961b904d65d7fc8a397d4eff6e21cda9ca..5e11d8a57174df69cf29283604daddb1140611c3 100644 (file)
@@ -16,7 +16,8 @@ Byte Array Objects
 .. cvar:: PyTypeObject PyByteArray_Type
 
    This instance of :ctype:`PyTypeObject` represents the Python bytearray type;
-   it is the same object as ``bytearray`` in the Python layer.
+   it is the same object as :class:`bytearray` in the Python layer.
+
 
 Type check macros
 ^^^^^^^^^^^^^^^^^
index b66047b021a9a566ea8ed04c5385c8808ebc9356..abd8744108f522b408c42f583e6e3d61abd2bcba 100644 (file)
@@ -18,10 +18,8 @@ called with a non-bytes parameter.
 
 .. cvar:: PyTypeObject PyBytes_Type
 
-   .. index:: single: BytesType (in module types)
-
    This instance of :ctype:`PyTypeObject` represents the Python bytes type; it
-   is the same object as ``bytes`` in the Python layer. .
+   is the same object as :class:`bytes` in the Python layer.
 
 
 .. cfunction:: int PyBytes_Check(PyObject *o)
index 3508a03213fdc00cd49523266f4d2c6343332362..0bcdf4d41a05f7d53cb66f73bdc0f4b1e8327c3c 100644 (file)
@@ -82,7 +82,7 @@ Complex Numbers as Python Objects
 .. cvar:: PyTypeObject PyComplex_Type
 
    This instance of :ctype:`PyTypeObject` represents the Python complex number
-   type. It is the same object as ``complex`` and ``types.ComplexType``.
+   type. It is the same object as :class:`complex` in the Python layer.
 
 
 .. cfunction:: int PyComplex_Check(PyObject *p)
index 5943887b2446b053a9ee0c522afe8b41572a6b54..5d355d1e61376b094966b15f3d10fa52faf1be3b 100644 (file)
@@ -15,13 +15,8 @@ Dictionary Objects
 
 .. cvar:: PyTypeObject PyDict_Type
 
-   .. index::
-      single: DictType (in module types)
-      single: DictionaryType (in module types)
-
    This instance of :ctype:`PyTypeObject` represents the Python dictionary
-   type.  This is exposed to Python programs as ``dict`` and
-   ``types.DictType``.
+   type.  This is the same object as :class:`dict` in the Python layer.
 
 
 .. cfunction:: int PyDict_Check(PyObject *p)
index e2e4b735eb187f909821c65a50fce813740bd8e8..93769aa1f4c464c73edc86be830b0945dfe1936b 100644 (file)
@@ -15,10 +15,8 @@ Floating Point Objects
 
 .. cvar:: PyTypeObject PyFloat_Type
 
-   .. index:: single: FloatType (in modules types)
-
    This instance of :ctype:`PyTypeObject` represents the Python floating point
-   type.  This is the same object as ``float`` and ``types.FloatType``.
+   type.  This is the same object as :class:`float` in the Python layer.
 
 
 .. cfunction:: int PyFloat_Check(PyObject *p)
index 4b67912cf406ba394e741f71128ff63a43b565f5..1708a856afc95a012714121f920535d7e3ac4d82 100644 (file)
@@ -361,15 +361,16 @@ traceback.
 
 .. index:: single: PyErr_Occurred()
 
-For C programmers, however, error checking always has to be explicit.   All
-functions in the Python/C API can raise exceptions, unless an  explicit claim is
-made otherwise in a function's documentation.  In  general, when a function
-encounters an error, it sets an exception,  discards any object references that
-it owns, and returns an  error indicator --- usually *NULL* or ``-1``.  A few
-functions  return a Boolean true/false result, with false indicating an error.
-Very few functions return no explicit error indicator or have an  ambiguous
-return value, and require explicit testing for errors with
-:cfunc:`PyErr_Occurred`.
+For C programmers, however, error checking always has to be explicit.  All
+functions in the Python/C API can raise exceptions, unless an explicit claim is
+made otherwise in a function's documentation.  In general, when a function
+encounters an error, it sets an exception, discards any object references that
+it owns, and returns an error indicator.  If not documented otherwise, this
+indicator is either *NULL* or ``-1``, depending on the function's return type.
+A few functions return a Boolean true/false result, with false indicating an
+error.  Very few functions return no explicit error indicator or have an
+ambiguous return value, and require explicit testing for errors with
+:cfunc:`PyErr_Occurred`.  These exceptions are always explicitly documented.
 
 .. index::
    single: PyErr_SetString()
index 89f0f9d3965d23d76f031996b755d04796fe0b0a..dba0f81faded39a2de345a78a55bbaf159f812d2 100644 (file)
@@ -15,8 +15,8 @@ List Objects
 
 .. cvar:: PyTypeObject PyList_Type
 
-   This instance of :ctype:`PyTypeObject` represents the Python list type.  This
-   is the same object as ``list`` in the Python layer.
+   This instance of :ctype:`PyTypeObject` represents the Python list type.
+   This is the same object as :class:`list` in the Python layer.
 
 
 .. cfunction:: int PyList_Check(PyObject *p)
index 9a3d1f1061431af1936f5169c4b01bc0bf13b766..9f8e3c5f645d081ffd70da3bf32158693d24bfb6 100644 (file)
@@ -18,7 +18,7 @@ All integers are implemented as "long" integer objects of arbitrary size.
 .. cvar:: PyTypeObject PyLong_Type
 
    This instance of :ctype:`PyTypeObject` represents the Python integer type.
-   This is the same object as ``int``.
+   This is the same object as :class:`int` in the Python layer.
 
 
 .. cfunction:: int PyLong_Check(PyObject *p)
index f8f2a4475029cc0d19273dc010aa56c4ab82791f..f17915f554e2608c755f164eb4562a1ce20d94dc 100644 (file)
@@ -8,10 +8,8 @@ Slice Objects
 
 .. cvar:: PyTypeObject PySlice_Type
 
-   .. index:: single: SliceType (in module types)
-
-   The type object for slice objects.  This is the same as ``slice`` and
-   ``types.SliceType``.
+   The type object for slice objects.  This is the same as :class:`slice` in the
+   Python layer.
 
 
 .. cfunction:: int PySlice_Check(PyObject *ob)
index c1f8e12ffc8efc659878e0973b63668f54aa3965..612acc754e30288c2900f60ab263470f9cc7ac01 100644 (file)
@@ -15,10 +15,8 @@ Tuple Objects
 
 .. cvar:: PyTypeObject PyTuple_Type
 
-   .. index:: single: TupleType (in module types)
-
-   This instance of :ctype:`PyTypeObject` represents the Python tuple type; it is
-   the same object as ``tuple`` and ``types.TupleType`` in the Python layer..
+   This instance of :ctype:`PyTypeObject` represents the Python tuple type; it
+   is the same object as :class:`tuple` in the Python layer.
 
 
 .. cfunction:: int PyTuple_Check(PyObject *p)
index d0edd5568c5a8c09fa08f55fdd65b6361cb3c8d8..d2a567656e37d18ee8a01a1de9a42d636b6b7c89 100644 (file)
@@ -15,10 +15,8 @@ Type Objects
 
 .. cvar:: PyObject* PyType_Type
 
-   .. index:: single: TypeType (in module types)
-
-   This is the type object for type objects; it is the same object as ``type`` and
-   ``types.TypeType`` in the Python layer.
+   This is the type object for type objects; it is the same object as
+   :class:`type` in the Python layer.
 
 
 .. cfunction:: int PyType_Check(PyObject *o)
index 14d1c27088ae9c5bd5d2607381e216f639509720..de493de6e5fb034824f3fd279b82a2fa3b239611 100644 (file)
@@ -204,7 +204,7 @@ APIs:
 
 .. cfunction:: PyObject* PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size)
 
-   Create a Unicode Object from the Py_UNICODE buffer *u* of the given size. *u*
+   Create a Unicode object from the Py_UNICODE buffer *u* of the given size. *u*
    may be *NULL* which causes the contents to be undefined. It is the user's
    responsibility to fill in the needed data.  The buffer is copied into the new
    object. If the buffer is not *NULL*, the return value might be a shared object.
@@ -214,7 +214,7 @@ APIs:
 
 .. cfunction:: PyObject* PyUnicode_FromStringAndSize(const char *u, Py_ssize_t size)
 
-   Create a Unicode Object from the char buffer *u*.  The bytes will be interpreted
+   Create a Unicode object from the char buffer *u*.  The bytes will be interpreted
    as being UTF-8 encoded.  *u* may also be *NULL* which
    causes the contents to be undefined. It is the user's responsibility to fill in
    the needed data.  The buffer is copied into the new object. If the buffer is not
index d716a46f9db6426c292b50d6f0233aa8efacf240..66789a963da69a270fc69ff750bad6556b7e77da 100644 (file)
@@ -123,13 +123,13 @@ the same library that the Python runtime is using.
 
 .. cfunction:: int PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)
 
-   Read and execute a single statement from a file associated with an interactive
-   device according to the *flags* argument.  If *filename* is *NULL*, ``"???"`` is
-   used instead.  The user will be prompted using ``sys.ps1`` and ``sys.ps2``.
-   Returns ``0`` when the input was executed successfully, ``-1`` if there was an
-   exception, or an error code from the :file:`errcode.h` include file distributed
-   as part of Python if there was a parse error.  (Note that :file:`errcode.h` is
-   not included by :file:`Python.h`, so must be included specifically if needed.)
+   Read and execute a single statement from a file associated with an
+   interactive device according to the *flags* argument.  The user will be
+   prompted using ``sys.ps1`` and ``sys.ps2``.  Returns ``0`` when the input was
+   executed successfully, ``-1`` if there was an exception, or an error code
+   from the :file:`errcode.h` include file distributed as part of Python if
+   there was a parse error.  (Note that :file:`errcode.h` is not included by
+   :file:`Python.h`, so must be included specifically if needed.)
 
 
 .. cfunction:: int PyRun_InteractiveLoop(FILE *fp, const char *filename)
@@ -138,11 +138,11 @@ the same library that the Python runtime is using.
    leaving *flags* set to *NULL*.
 
 
-.. cfunction:: int PyRun_InteractiveLoopFlags(FILE *fp,  const char *filename, PyCompilerFlags *flags)
+.. cfunction:: int PyRun_InteractiveLoopFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)
 
    Read and execute statements from a file associated with an interactive device
-   until EOF is reached.  If *filename* is *NULL*, ``"???"`` is used instead.  The
-   user will be prompted using ``sys.ps1`` and ``sys.ps2``.  Returns ``0`` at EOF.
+   until EOF is reached.  The user will be prompted using ``sys.ps1`` and
+   ``sys.ps2``.  Returns ``0`` at EOF.
 
 
 .. cfunction:: struct _node* PyParser_SimpleParseString(const char *str, int start)
index 8342657ced5ea6e8546a018f6d08c5317a3a3d2f..7cd16b0f115852597f78705d40705f9ab5061b40 100644 (file)
@@ -290,20 +290,18 @@ Embedding the Python interpreter in a Windows app can be summarized as follows:
 
 1. Do _not_ build Python into your .exe file directly.  On Windows, Python must
    be a DLL to handle importing modules that are themselves DLL's.  (This is the
-   first key undocumented fact.) Instead, link to :file:`python{NN}.dll`; it is
-   typically installed in ``C:\Windows\System``.  NN is the Python version, a
+   first key undocumented fact.)  Instead, link to :file:`python{NN}.dll`; it is
+   typically installed in ``C:\Windows\System``.  *NN* is the Python version, a
    number such as "23" for Python 2.3.
 
-   You can link to Python statically or dynamically.  Linking statically means
-   linking against :file:`python{NN}.lib`, while dynamically linking means
-   linking against :file:`python{NN}.dll`.  The drawback to dynamic linking is
-   that your app won't run if :file:`python{NN}.dll` does not exist on your
-   system.  (General note: :file:`python{NN}.lib` is the so-called "import lib"
-   corresponding to :file:`python.dll`.  It merely defines symbols for the
-   linker.)
+   You can link to Python in two different ways.  Load-time linking means
+   linking against :file:`python{NN}.lib`, while run-time linking means linking
+   against :file:`python{NN}.dll`.  (General note: :file:`python{NN}.lib` is the
+   so-called "import lib" corresponding to :file:`python{NN}.dll`.  It merely
+   defines symbols for the linker.)
 
-   Linking dynamically greatly simplifies link options; everything happens at
-   run time.  Your code must load :file:`python{NN}.dll` using the Windows
+   Run-time linking greatly simplifies link options; everything happens at run
+   time.  Your code must load :file:`python{NN}.dll` using the Windows
    ``LoadLibraryEx()`` routine.  The code must also use access routines and data
    in :file:`python{NN}.dll` (that is, Python's C API's) using pointers obtained
    by the Windows ``GetProcAddress()`` routine.  Macros can make using these
@@ -312,6 +310,8 @@ Embedding the Python interpreter in a Windows app can be summarized as follows:
    Borland note: convert :file:`python{NN}.lib` to OMF format using Coff2Omf.exe
    first.
 
+   .. XXX what about static linking?
+
 2. If you use SWIG, it is easy to create a Python "extension module" that will
    make the app's data and methods available to Python.  SWIG will handle just
    about all the grungy details for you.  The result is C code that you link
index 7c7ea04a4708820fe0dd82400f3b2b03014f59d7..d20e4a6a94cef8a2ac39cd62e0d7099f2118d1b4 100644 (file)
@@ -50,9 +50,9 @@ Python 3.0's :func:`str` (``PyString_*`` functions in C) type is equivalent to
 compatibility with 3.0, :ctype:`PyUnicode` should be used for textual data and
 :ctype:`PyBytes` for binary data.  It's also important to remember that
 :ctype:`PyBytes` and :ctype:`PyUnicode` in 3.0 are not interchangeable like
-:ctype:`PyString` and :ctype:`PyString` are in 2.x.  The following example shows
-best practices with regards to :ctype:`PyUnicode`, :ctype:`PyString`, and
-:ctype:`PyBytes`. ::
+:ctype:`PyString` and :ctype:`PyUnicode` are in 2.x.  The following example
+shows best practices with regards to :ctype:`PyUnicode`, :ctype:`PyString`,
+and :ctype:`PyBytes`. ::
 
    #include "stdlib.h"
    #include "Python.h"
index d50a9704a75adc24dbf29c536a27dd46b1716ffd..198c11a7d2e4917f9bec34e8f6b273d1a2c78bce 100644 (file)
@@ -230,8 +230,8 @@ and recombined later.  Here is an example of how to do that::
    def mul_stereo(sample, width, lfactor, rfactor):
        lsample = audioop.tomono(sample, width, 1, 0)
        rsample = audioop.tomono(sample, width, 0, 1)
-       lsample = audioop.mul(sample, width, lfactor)
-       rsample = audioop.mul(sample, width, rfactor)
+       lsample = audioop.mul(lsample, width, lfactor)
+       rsample = audioop.mul(rsample, width, rfactor)
        lsample = audioop.tostereo(lsample, width, 1, 0)
        rsample = audioop.tostereo(rsample, width, 0, 1)
        return audioop.add(lsample, rsample, width)
index e282ea0ef55e8eb1ed72154a628839b7ec731ba7..0802e6c53c6c715d38b3abc6874e2f628c2381d5 100644 (file)
@@ -157,12 +157,12 @@ The legacy interface:
 An example usage of the module:
 
    >>> import base64
-   >>> encoded = base64.b64encode('data to be encoded')
+   >>> encoded = base64.b64encode(b'data to be encoded')
    >>> encoded
    b'ZGF0YSB0byBiZSBlbmNvZGVk'
    >>> data = base64.b64decode(encoded)
    >>> data
-   'data to be encoded'
+   b'data to be encoded'
 
 
 .. seealso::
index c9d1eee880235797a1112e7e5bb78d3de8fc0ebb..3fd44a6422348cccd7f92940ebdd2d694e4521cc 100644 (file)
@@ -500,16 +500,11 @@ The :class:`SequenceMatcher` class has this constructor:
 
       Return an upper bound on :meth:`ratio` relatively quickly.
 
-      This isn't defined beyond that it is an upper bound on :meth:`ratio`, and
-      is faster to compute.
-
 
    .. method:: real_quick_ratio()
 
       Return an upper bound on :meth:`ratio` very quickly.
 
-      This isn't defined beyond that it is an upper bound on :meth:`ratio`, and
-      is faster to compute than either :meth:`ratio` or :meth:`quick_ratio`.
 
 The three methods that return the ratio of matching to total characters can give
 different results due to differing levels of approximation, although
index 39c11f3f47bc1a7e5cb4ed9aa834761322451f7a..8a1b935f02914077f79bc989d8b996e580a8d291 100644 (file)
@@ -93,7 +93,7 @@ The :mod:`dis` module defines the following functions and constants:
 
 .. data:: opmap
 
-   Dictionary mapping bytecodes to operation names.
+   Dictionary mapping operation names to bytecodes.
 
 
 .. data:: cmp_op
index 4a19de0a4bb8e42cb755ca4a51df57f32c82004e..1547f6d9c80f6852c2b57da5d67de855aab4e72c 100644 (file)
@@ -466,7 +466,7 @@ are always available.  They are listed here in alphabetical order.
 
 .. function:: getattr(object, name[, default])
 
-   Return the value of the named attributed of *object*.  *name* must be a string.
+   Return the value of the named attribute of *object*.  *name* must be a string.
    If the string is the name of one of the object's attributes, the result is the
    value of that attribute.  For example, ``getattr(x, 'foobar')`` is equivalent to
    ``x.foobar``.  If the named attribute does not exist, *default* is returned if
index 6ffd00aa04f47938cc7f1c9d54acd5d4ce560242..b2bd98dfc7cd7e4c8d0d4d405f011154853d73e3 100644 (file)
@@ -2,7 +2,8 @@
 ========================================================
 
 .. module:: hmac
-   :synopsis: Keyed-Hashing for Message Authentication (HMAC) implementation for Python.
+   :synopsis: Keyed-Hashing for Message Authentication (HMAC) implementation
+              for Python.
 .. moduleauthor:: Gerhard Häring <ghaering@users.sourceforge.net>
 .. sectionauthor:: Gerhard Häring <ghaering@users.sourceforge.net>
 
@@ -12,37 +13,34 @@ This module implements the HMAC algorithm as described by :rfc:`2104`.
 
 .. function:: new(key, msg=None, digestmod=None)
 
-   Return a new hmac object.  If *msg* is present, the method call ``update(msg)``
-   is made. *digestmod* is the digest constructor or module for the HMAC object to
-   use. It defaults to  the :func:`hashlib.md5` constructor.
+   Return a new hmac object.  *key* is a bytes object giving the secret key.  If
+   *msg* is present, the method call ``update(msg)`` is made.  *digestmod* is
+   the digest constructor or module for the HMAC object to use. It defaults to
+   the :func:`hashlib.md5` constructor.
 
-   .. note::
-
-      The md5 hash has known weaknesses but remains the default for backwards
-      compatibility. Choose a better one for your application.
 
 An HMAC object has the following methods:
 
-
 .. method:: hmac.update(msg)
 
-   Update the hmac object with the string *msg*.  Repeated calls are equivalent to
-   a single call with the concatenation of all the arguments: ``m.update(a);
-   m.update(b)`` is equivalent to ``m.update(a + b)``.
+   Update the hmac object with the bytes object *msg*.  Repeated calls are
+   equivalent to a single call with the concatenation of all the arguments:
+   ``m.update(a); m.update(b)`` is equivalent to ``m.update(a + b)``.
 
 
 .. method:: hmac.digest()
 
-   Return the digest of the strings passed to the :meth:`update` method so far.
-   This string will be the same length as the *digest_size* of the digest given to
-   the constructor.  It may contain non-ASCII characters, including NUL bytes.
+   Return the digest of the bytes passed to the :meth:`update` method so far.
+   This bytes object will be the same length as the *digest_size* of the digest
+   given to the constructor.  It may contain non-ASCII bytes, including NUL
+   bytes.
 
 
 .. method:: hmac.hexdigest()
 
-   Like :meth:`digest` except the digest is returned as a string twice the length
-   containing only hexadecimal digits.  This may be used to exchange the value
-   safely in email or other non-binary environments.
+   Like :meth:`digest` except the digest is returned as a string twice the
+   length containing only hexadecimal digits.  This may be used to exchange the
+   value safely in email or other non-binary environments.
 
 
 .. method:: hmac.copy()
@@ -55,4 +53,3 @@ An HMAC object has the following methods:
 
    Module :mod:`hashlib`
       The Python module providing secure hash functions.
-
index 371a902fdc565bdf09e9ec7ddbb1bf111e131c4d..910291ff8f72cf4e8366c151a71096d51cb95c94 100644 (file)
@@ -1421,15 +1421,15 @@ to be ignored.
 
 .. function:: _exit(n)
 
-   Exit to the system with status *n*, without calling cleanup handlers, flushing
+   Exit the process with status *n*, without calling cleanup handlers, flushing
    stdio buffers, etc.
 
    Availability: Unix, Windows.
 
    .. note::
 
-      The standard way to exit is ``sys.exit(n)``. :func:`_exit` should normally only
-      be used in the child process after a :func:`fork`.
+      The standard way to exit is ``sys.exit(n)``.  :func:`_exit` should
+      normally only be used in the child process after a :func:`fork`.
 
 The following exit codes are defined and can be used with :func:`_exit`,
 although they are not required.  These are typically used for system programs
index b79e8d319a7693f5dd2262b04d3927f293cc6d85..b69d1b90dea269d71e5f5617b2e9bcf432d64f89 100644 (file)
@@ -318,22 +318,8 @@ ST objects have the following methods:
    Same as ``st2tuple(st, line_info)``.
 
 
-.. _st-examples:
-
-Examples
---------
-
-.. index:: builtin: compile
-
-The parser modules allows operations to be performed on the parse tree of Python
-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.
-
-
-Emulation of :func:`compile`
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+Example: Emulation of :func:`compile`
+-------------------------------------
 
 While many useful operations may take place between parsing and bytecode
 generation, the simplest operation is to do nothing.  For this purpose, using
@@ -367,320 +353,3 @@ readily available functions::
    def load_expression(source_string):
        st = parser.expr(source_string)
        return st, st.compile()
-
-
-Information Discovery
-^^^^^^^^^^^^^^^^^^^^^
-
-.. index::
-   single: string; documentation
-   single: docstrings
-
-Some applications benefit from direct access to the parse tree.  The remainder
-of this section demonstrates how the parse tree provides access to module
-documentation defined in docstrings without requiring that the code being
-examined be loaded into a running interpreter via :keyword:`import`.  This can
-be very useful for performing analyses of untrusted code.
-
-Generally, the example will demonstrate how the parse tree may be traversed to
-distill interesting information.  Two functions and a set of classes are
-developed which provide programmatic access to high level function and class
-definitions provided by a module.  The classes extract information from the
-parse tree and provide access to the information at a useful semantic level, one
-function provides a simple low-level pattern matching capability, and the other
-function defines a high-level interface to the classes by handling file
-operations on behalf of the caller.  All source files mentioned here which are
-not part of the Python installation are located in the :file:`Demo/parser/`
-directory of the distribution.
-
-The dynamic nature of Python allows the programmer a great deal of flexibility,
-but most modules need only a limited measure of this when defining classes,
-functions, and methods.  In this example, the only definitions that will be
-considered are those which are defined in the top level of their context, e.g.,
-a function defined by a :keyword:`def` statement at column zero of a module, but
-not a function defined within a branch of an :keyword:`if` ... :keyword:`else`
-construct, though there are some good reasons for doing so in some situations.
-Nesting of definitions will be handled by the code developed in the example.
-
-To construct the upper-level extraction methods, we need to know what the parse
-tree structure looks like and how much of it we actually need to be concerned
-about.  Python uses a moderately deep parse tree so there are a large number of
-intermediate nodes.  It is important to read and understand the formal grammar
-used by Python.  This is specified in the file :file:`Grammar/Grammar` in the
-distribution. Consider the simplest case of interest when searching for
-docstrings: a module consisting of a docstring and nothing else.  (See file
-:file:`docstring.py`.) ::
-
-   """Some documentation.
-   """
-
-Using the interpreter to take a look at the parse tree, we find a bewildering
-mass of numbers and parentheses, with the documentation buried deep in nested
-tuples. ::
-
-   >>> import parser
-   >>> import pprint
-   >>> st = parser.suite(open('docstring.py').read())
-   >>> tup = st.totuple()
-   >>> pprint.pprint(tup)
-   (257,
-    (264,
-     (265,
-      (266,
-       (267,
-        (307,
-         (287,
-          (288,
-           (289,
-            (290,
-             (292,
-              (293,
-               (294,
-                (295,
-                 (296,
-                  (297,
-                   (298,
-                    (299,
-                     (300, (3, '"""Some documentation.\n"""'))))))))))))))))),
-      (4, ''))),
-    (4, ''),
-    (0, ''))
-
-The numbers at the first element of each node in the tree are the node types;
-they map directly to terminal and non-terminal symbols in the grammar.
-Unfortunately, they are represented as integers in the internal representation,
-and the Python structures generated do not change that.  However, the
-:mod:`symbol` and :mod:`token` modules provide symbolic names for the node types
-and dictionaries which map from the integers to the symbolic names for the node
-types.
-
-In the output presented above, the outermost tuple contains four elements: the
-integer ``257`` and three additional tuples.  Node type ``257`` has the symbolic
-name :const:`file_input`.  Each of these inner tuples contains an integer as the
-first element; these integers, ``264``, ``4``, and ``0``, represent the node
-types :const:`stmt`, :const:`NEWLINE`, and :const:`ENDMARKER`, respectively.
-Note that these values may change depending on the version of Python you are
-using; consult :file:`symbol.py` and :file:`token.py` for details of the
-mapping.  It should be fairly clear that the outermost node is related primarily
-to the input source rather than the contents of the file, and may be disregarded
-for the moment.  The :const:`stmt` node is much more interesting.  In
-particular, all docstrings are found in subtrees which are formed exactly as
-this node is formed, with the only difference being the string itself.  The
-association between the docstring in a similar tree and the defined entity
-(class, function, or module) which it describes is given by the position of the
-docstring subtree within the tree defining the described structure.
-
-By replacing the actual docstring with something to signify a variable component
-of the tree, we allow a simple pattern matching approach to check any given
-subtree for equivalence to the general pattern for docstrings.  Since the
-example demonstrates information extraction, we can safely require that the tree
-be in tuple form rather than list form, allowing a simple variable
-representation to be ``['variable_name']``.  A simple recursive function can
-implement the pattern matching, returning a Boolean and a dictionary of variable
-name to value mappings.  (See file :file:`example.py`.) ::
-
-   def match(pattern, data, vars=None):
-       if vars is None:
-           vars = {}
-       if isinstance(pattern, list):
-           vars[pattern[0]] = data
-           return True, vars
-       if not instance(pattern, tuple):
-           return (pattern == data), vars
-       if len(data) != len(pattern):
-           return False, vars
-       for pattern, data in zip(pattern, data):
-           same, vars = match(pattern, data, vars)
-           if not same:
-               break
-       return same, vars
-
-Using this simple representation for syntactic variables and the symbolic node
-types, the pattern for the candidate docstring subtrees becomes fairly readable.
-(See file :file:`example.py`.) ::
-
-   import symbol
-   import token
-
-   DOCSTRING_STMT_PATTERN = (
-       symbol.stmt,
-       (symbol.simple_stmt,
-        (symbol.small_stmt,
-         (symbol.expr_stmt,
-          (symbol.testlist,
-           (symbol.test,
-            (symbol.and_test,
-             (symbol.not_test,
-              (symbol.comparison,
-               (symbol.expr,
-                (symbol.xor_expr,
-                 (symbol.and_expr,
-                  (symbol.shift_expr,
-                   (symbol.arith_expr,
-                    (symbol.term,
-                     (symbol.factor,
-                      (symbol.power,
-                       (symbol.atom,
-                        (token.STRING, ['docstring'])
-                        )))))))))))))))),
-        (token.NEWLINE, '')
-        ))
-
-Using the :func:`match` function with this pattern, extracting the module
-docstring from the parse tree created previously is easy::
-
-   >>> found, vars = match(DOCSTRING_STMT_PATTERN, tup[1])
-   >>> found
-   True
-   >>> vars
-   {'docstring': '"""Some documentation.\n"""'}
-
-Once specific data can be extracted from a location where it is expected, the
-question of where information can be expected needs to be answered.  When
-dealing with docstrings, the answer is fairly simple: the docstring is the first
-:const:`stmt` node in a code block (:const:`file_input` or :const:`suite` node
-types).  A module consists of a single :const:`file_input` node, and class and
-function definitions each contain exactly one :const:`suite` node.  Classes and
-functions are readily identified as subtrees of code block nodes which start
-with ``(stmt, (compound_stmt, (classdef, ...`` or ``(stmt, (compound_stmt,
-(funcdef, ...``.  Note that these subtrees cannot be matched by :func:`match`
-since it does not support multiple sibling nodes to match without regard to
-number.  A more elaborate matching function could be used to overcome this
-limitation, but this is sufficient for the example.
-
-Given the ability to determine whether a statement might be a docstring and
-extract the actual string from the statement, some work needs to be performed to
-walk the parse tree for an entire module and extract information about the names
-defined in each context of the module and associate any docstrings with the
-names.  The code to perform this work is not complicated, but bears some
-explanation.
-
-The public interface to the classes is straightforward and should probably be
-somewhat more flexible.  Each "major" block of the module is described by an
-object providing several methods for inquiry and a constructor which accepts at
-least the subtree of the complete parse tree which it represents.  The
-:class:`ModuleInfo` constructor accepts an optional *name* parameter since it
-cannot otherwise determine the name of the module.
-
-The public classes include :class:`ClassInfo`, :class:`FunctionInfo`, and
-:class:`ModuleInfo`.  All objects provide the methods :meth:`get_name`,
-:meth:`get_docstring`, :meth:`get_class_names`, and :meth:`get_class_info`.  The
-:class:`ClassInfo` objects support :meth:`get_method_names` and
-:meth:`get_method_info` while the other classes provide
-:meth:`get_function_names` and :meth:`get_function_info`.
-
-Within each of the forms of code block that the public classes represent, most
-of the required information is in the same form and is accessed in the same way,
-with classes having the distinction that functions defined at the top level are
-referred to as "methods." Since the difference in nomenclature reflects a real
-semantic distinction from functions defined outside of a class, the
-implementation needs to maintain the distinction. Hence, most of the
-functionality of the public classes can be implemented in a common base class,
-:class:`SuiteInfoBase`, with the accessors for function and method information
-provided elsewhere. Note that there is only one class which represents function
-and method information; this parallels the use of the :keyword:`def` statement
-to define both types of elements.
-
-Most of the accessor functions are declared in :class:`SuiteInfoBase` and do not
-need to be overridden by subclasses.  More importantly, the extraction of most
-information from a parse tree is handled through a method called by the
-:class:`SuiteInfoBase` constructor.  The example code for most of the classes is
-clear when read alongside the formal grammar, but the method which recursively
-creates new information objects requires further examination.  Here is the
-relevant part of the :class:`SuiteInfoBase` definition from :file:`example.py`::
-
-   class SuiteInfoBase:
-       _docstring = ''
-       _name = ''
-
-       def __init__(self, tree = None):
-           self._class_info = {}
-           self._function_info = {}
-           if tree:
-               self._extract_info(tree)
-
-       def _extract_info(self, tree):
-           # extract docstring
-           if len(tree) == 2:
-               found, vars = match(DOCSTRING_STMT_PATTERN[1], tree[1])
-           else:
-               found, vars = match(DOCSTRING_STMT_PATTERN, tree[3])
-           if found:
-               self._docstring = eval(vars['docstring'])
-           # discover inner definitions
-           for node in tree[1:]:
-               found, vars = match(COMPOUND_STMT_PATTERN, node)
-               if found:
-                   cstmt = vars['compound']
-                   if cstmt[0] == symbol.funcdef:
-                       name = cstmt[2][1]
-                       self._function_info[name] = FunctionInfo(cstmt)
-                   elif cstmt[0] == symbol.classdef:
-                       name = cstmt[2][1]
-                       self._class_info[name] = ClassInfo(cstmt)
-
-After initializing some internal state, the constructor calls the
-:meth:`_extract_info` method.  This method performs the bulk of the information
-extraction which takes place in the entire example.  The extraction has two
-distinct phases: the location of the docstring for the parse tree passed in, and
-the discovery of additional definitions within the code block represented by the
-parse tree.
-
-The initial :keyword:`if` test determines whether the nested suite is of the
-"short form" or the "long form."  The short form is used when the code block is
-on the same line as the definition of the code block, as in ::
-
-   def square(x): "Square an argument."; return x ** 2
-
-while the long form uses an indented block and allows nested definitions::
-
-   def make_power(exp):
-       "Make a function that raises an argument to the exponent `exp`."
-       def raiser(x, y=exp):
-           return x ** y
-       return raiser
-
-When the short form is used, the code block may contain a docstring as the
-first, and possibly only, :const:`small_stmt` element.  The extraction of such a
-docstring is slightly different and requires only a portion of the complete
-pattern used in the more common case.  As implemented, the docstring will only
-be found if there is only one :const:`small_stmt` node in the
-:const:`simple_stmt` node. Since most functions and methods which use the short
-form do not provide a docstring, this may be considered sufficient.  The
-extraction of the docstring proceeds using the :func:`match` function as
-described above, and the value of the docstring is stored as an attribute of the
-:class:`SuiteInfoBase` object.
-
-After docstring extraction, a simple definition discovery algorithm operates on
-the :const:`stmt` nodes of the :const:`suite` node.  The special case of the
-short form is not tested; since there are no :const:`stmt` nodes in the short
-form, the algorithm will silently skip the single :const:`simple_stmt` node and
-correctly not discover any nested definitions.
-
-Each statement in the code block is categorized as a class definition, function
-or method definition, or something else.  For the definition statements, the
-name of the element defined is extracted and a representation object appropriate
-to the definition is created with the defining subtree passed as an argument to
-the constructor.  The representation objects are stored in instance variables
-and may be retrieved by name using the appropriate accessor methods.
-
-The public classes provide any accessors required which are more specific than
-those provided by the :class:`SuiteInfoBase` class, but the real extraction
-algorithm remains common to all forms of code blocks.  A high-level function can
-be used to extract the complete set of information from a source file.  (See
-file :file:`example.py`.) ::
-
-   def get_docs(fileName):
-       import os
-       import parser
-
-       source = open(fileName).read()
-       basename = os.path.basename(os.path.splitext(fileName)[0])
-       st = parser.suite(source)
-       return ModuleInfo(st.totuple(), basename)
-
-This provides an easy-to-use interface to the documentation of a module.  If
-information is required which is not extracted by the code of this example, the
-code may be extended at clearly defined points to provide additional
-capabilities.
-
index 3358053bd04d4c8e2e8b34e6d36de4ba82d0cb40..8a671a7fbca23d8371c8d26307fda8085fa612db 100644 (file)
@@ -23,6 +23,12 @@ into an object hierarchy.  Pickling (and unpickling) is alternatively known as
 "serialization", "marshalling," [#]_ or "flattening", however, to avoid
 confusion, the terms used here are "pickling" and "unpickling"..
 
+.. warning::
+
+   The :mod:`pickle` module is not intended to be secure against erroneous or
+   maliciously constructed data.  Never unpickle data received from an untrusted
+   or unauthenticated source.
+
 
 Relationship to other Python modules
 ------------------------------------
@@ -63,12 +69,6 @@ The :mod:`pickle` module differs from :mod:`marshal` several significant ways:
   The :mod:`pickle` serialization format is guaranteed to be backwards compatible
   across Python releases.
 
-.. warning::
-
-   The :mod:`pickle` module is not intended to be secure against erroneous or
-   maliciously constructed data.  Never unpickle data received from an untrusted
-   or unauthenticated source.
-
 Note that serialization is a more primitive notion than persistence; although
 :mod:`pickle` reads and writes file objects, it does not handle the issue of
 naming persistent objects, nor the (even more complicated) issue of concurrent
@@ -427,33 +427,38 @@ implementation of this behaviour::
        obj.__dict__.update(attributes)
        return obj
 
-.. index:: single: __getnewargs__() (copy protocol)
-
 Classes can alter the default behaviour by providing one or several special
-methods.  In protocol 2 and newer, classes that implements the
-:meth:`__getnewargs__` method can dictate the values passed to the
-:meth:`__new__` method upon unpickling.  This is often needed for classes
-whose :meth:`__new__` method requires arguments.
+methods:
 
-.. index:: single: __getstate__() (copy protocol)
+.. method:: object.__getnewargs__()
 
-Classes can further influence how their instances are pickled; if the class
-defines the method :meth:`__getstate__`, it is called and the returned object is
-pickled as the contents for the instance, instead of the contents of the
-instance's dictionary.  If the :meth:`__getstate__` method is absent, the
-instance's :attr:`__dict__` is pickled as usual.
+   In protocol 2 and newer, classes that implements the :meth:`__getnewargs__`
+   method can dictate the values passed to the :meth:`__new__` method upon
+   unpickling.  This is often needed for classes whose :meth:`__new__` method
+   requires arguments.
 
-.. index:: single: __setstate__() (copy protocol)
 
-Upon unpickling, if the class defines :meth:`__setstate__`, it is called with
-the unpickled state.  In that case, there is no requirement for the state object
-to be a dictionary. Otherwise, the pickled state must be a dictionary and its
-items are assigned to the new instance's dictionary.
+.. method:: object.__getstate__()
 
-.. note::
+   Classes can further influence how their instances are pickled; if the class
+   defines the method :meth:`__getstate__`, it is called and the returned object
+   is pickled as the contents for the instance, instead of the contents of the
+   instance's dictionary.  If the :meth:`__getstate__` method is absent, the
+   instance's :attr:`__dict__` is pickled as usual.
+
+
+.. method:: object.__setstate__(state)
+
+   Upon unpickling, if the class defines :meth:`__setstate__`, it is called with
+   the unpickled state.  In that case, there is no requirement for the state
+   object to be a dictionary.  Otherwise, the pickled state must be a dictionary
+   and its items are assigned to the new instance's dictionary.
+
+   .. note::
+
+      If :meth:`__getstate__` returns a false value, the :meth:`__setstate__`
+      method will not be called upon unpickling.
 
-   If :meth:`__getstate__` returns a false value, the :meth:`__setstate__`
-   method will not be called.
 
 Refer to the section :ref:`pickle-state` for more information about how to use
 the methods :meth:`__getstate__` and :meth:`__setstate__`.
@@ -462,14 +467,12 @@ the methods :meth:`__getstate__` and :meth:`__setstate__`.
 
    At unpickling time, some methods like :meth:`__getattr__`,
    :meth:`__getattribute__`, or :meth:`__setattr__` may be called upon the
-   instance.  In case those methods rely on some internal invariant being
-   true, the type should implement either :meth:`__getinitargs__` or
-   :meth:`__getnewargs__` to establish such an invariant; otherwise, neither
-   :meth:`__new__` nor :meth:`__init__` will be called.
+   instance.  In case those methods rely on some internal invariant being true,
+   the type should implement :meth:`__getnewargs__` to establish such an
+   invariant; otherwise, neither :meth:`__new__` nor :meth:`__init__` will be
+   called.
 
-.. index::
-   pair: copy; protocol
-   single: __reduce__() (copy protocol)
+.. index:: pair: copy; protocol
 
 As we shall see, pickle does not use directly the methods described above.  In
 fact, these methods are part of the copy protocol which implements the
@@ -480,58 +483,61 @@ objects. [#]_
 Although powerful, implementing :meth:`__reduce__` directly in your classes is
 error prone.  For this reason, class designers should use the high-level
 interface (i.e., :meth:`__getnewargs__`, :meth:`__getstate__` and
-:meth:`__setstate__`) whenever possible.  We will show, however, cases where using
-:meth:`__reduce__` is the only option or leads to more efficient pickling or
-both.
-
-The interface is currently defined as follows. The :meth:`__reduce__` method
-takes no argument and shall return either a string or preferably a tuple (the
-returned object is often referred to as the "reduce value").
-
-If a string is returned, the string should be interpreted as the name of a
-global variable.  It should be the object's local name relative to its module;
-the pickle module searches the module namespace to determine the object's
-module.  This behaviour is typically useful for singletons.
-
-When a tuple is returned, it must be between two and five items long.  Optional
-items can either be omitted, or ``None`` can be provided as their value.  The
-semantics of each item are in order:
-
-.. XXX Mention __newobj__ special-case?
-
-* A callable object that will be called to create the initial version of the
-  object.
-
-* A tuple of arguments for the callable object. An empty tuple must be given if
-  the callable does not accept any argument.
-
-* Optionally, the object's state, which will be passed to the object's
-  :meth:`__setstate__` method as previously described.  If the object has no
-  such method then, the value must be a dictionary and it will be added to the
-  object's :attr:`__dict__` attribute.
-
-* Optionally, an iterator (and not a sequence) yielding successive items.  These
-  items will be appended to the object either using ``obj.append(item)`` or, in
-  batch, using ``obj.extend(list_of_items)``.  This is primarily used for list
-  subclasses, but may be used by other classes as long as they have
-  :meth:`append` and :meth:`extend` methods with the appropriate signature.
-  (Whether :meth:`append` or :meth:`extend` is used depends on which pickle
-  protocol version is used as well as the number of items to append, so both
-  must be supported.)
-
-* Optionally, an iterator (not a sequence) yielding successive key-value pairs.
-  These items will be stored to the object using ``obj[key] = value``.  This is
-  primarily used for dictionary subclasses, but may be used by other classes as
-  long as they implement :meth:`__setitem__`.
-
-.. index:: single: __reduce_ex__() (copy protocol)
-
-Alternatively, a :meth:`__reduce_ex__` method may be defined.  The only
-difference is this method should take a single integer argument, the protocol
-version.  When defined, pickle will prefer it over the :meth:`__reduce__`
-method.  In addition, :meth:`__reduce__` automatically becomes a synonym for the
-extended version.  The main use for this method is to provide
-backwards-compatible reduce values for older Python releases.
+:meth:`__setstate__`) whenever possible.  We will show, however, cases where
+using :meth:`__reduce__` is the only option or leads to more efficient pickling
+or both.
+
+.. method:: object.__reduce__()
+
+   The interface is currently defined as follows.  The :meth:`__reduce__` method
+   takes no argument and shall return either a string or preferably a tuple (the
+   returned object is often referred to as the "reduce value").
+
+   If a string is returned, the string should be interpreted as the name of a
+   global variable.  It should be the object's local name relative to its
+   module; the pickle module searches the module namespace to determine the
+   object's module.  This behaviour is typically useful for singletons.
+
+   When a tuple is returned, it must be between two and five items long.
+   Optional items can either be omitted, or ``None`` can be provided as their
+   value.  The semantics of each item are in order:
+
+   .. XXX Mention __newobj__ special-case?
+
+   * A callable object that will be called to create the initial version of the
+     object.
+
+   * A tuple of arguments for the callable object.  An empty tuple must be given
+     if the callable does not accept any argument.
+
+   * Optionally, the object's state, which will be passed to the object's
+     :meth:`__setstate__` method as previously described.  If the object has no
+     such method then, the value must be a dictionary and it will be added to
+     the object's :attr:`__dict__` attribute.
+
+   * Optionally, an iterator (and not a sequence) yielding successive items.
+     These items will be appended to the object either using
+     ``obj.append(item)`` or, in batch, using ``obj.extend(list_of_items)``.
+     This is primarily used for list subclasses, but may be used by other
+     classes as long as they have :meth:`append` and :meth:`extend` methods with
+     the appropriate signature.  (Whether :meth:`append` or :meth:`extend` is
+     used depends on which pickle protocol version is used as well as the number
+     of items to append, so both must be supported.)
+
+   * Optionally, an iterator (not a sequence) yielding successive key-value
+     pairs.  These items will be stored to the object using ``obj[key] =
+     value``.  This is primarily used for dictionary subclasses, but may be used
+     by other classes as long as they implement :meth:`__setitem__`.
+
+
+.. method:: object.__reduce_ex__(protocol)
+
+   Alternatively, a :meth:`__reduce_ex__` method may be defined.  The only
+   difference is this method should take a single integer argument, the protocol
+   version.  When defined, pickle will prefer it over the :meth:`__reduce__`
+   method.  In addition, :meth:`__reduce__` automatically becomes a synonym for
+   the extended version.  The main use for this method is to provide
+   backwards-compatible reduce values for older Python releases.
 
 .. _pickle-persistent:
 
index 0650b41daf42cdc1405d51f9ca3007320acdbff0..a2f9720d31c7790602df7219ba83111d114c726d 100644 (file)
@@ -43,6 +43,11 @@ lots of shared  sub-objects.  The keys are ordinary strings.
       :meth:`close` explicitly when you don't need it any more, or use a
       :keyword:`with` statement with :func:`contextlib.closing`.
 
+.. warning::
+
+   Because the :mod:`shelve` module is backed by :mod:`pickle`, it is insecure
+   to load a shelf from an untrusted source.  Like with pickle, loading a shelf
+   can execute arbitrary code.
 
 Shelf objects support all methods supported by dictionaries.  This eases the
 transition from dictionary based scripts to those requiring persistent storage.
index b76f6ebd2d68fb25acdb57e5a186e5ef345d5987..0603738c67ada646c44d0a82b3f7bcd4edc5d1d2 100644 (file)
@@ -255,23 +255,22 @@ Connection Objects
 .. method:: Connection.execute(sql, [parameters])
 
    This is a nonstandard shortcut that creates an intermediate cursor object by
-   calling the cursor method, then calls the cursor's
-   :meth:`execute<Cursor.execute>` method with the parameters given.
+   calling the cursor method, then calls the cursor's :meth:`execute
+   <Cursor.execute>` method with the parameters given.
 
 
 .. method:: Connection.executemany(sql, [parameters])
 
    This is a nonstandard shortcut that creates an intermediate cursor object by
-   calling the cursor method, then calls the cursor's
-   :meth:`executemany<Cursor.executemany>` method with the parameters given.
+   calling the cursor method, then calls the cursor's :meth:`executemany
+   <Cursor.executemany>` method with the parameters given.
 
 
 .. method:: Connection.executescript(sql_script)
 
    This is a nonstandard shortcut that creates an intermediate cursor object by
-   calling the cursor method, then calls the cursor's
-   :meth:`executescript<Cursor.executescript>` method with the parameters
-   given.
+   calling the cursor method, then calls the cursor's :meth:`executescript
+   <Cursor.executescript>` method with the parameters given.
 
 
 .. method:: Connection.create_function(name, num_params, func)
@@ -435,7 +434,7 @@ Cursor Objects
 
 .. class:: Cursor
 
-   A SQLite database cursor has the following attributes and methods:
+   A :class:`Cursor` instance has the following attributes and methods.
 
 .. method:: Cursor.execute(sql, [parameters])
 
@@ -853,4 +852,3 @@ threads. If you still try to do so, you will get an exception at runtime.
 
 The only exception is calling the :meth:`~Connection.interrupt` method, which
 only makes sense to call from a different thread.
-
index 5693ed5ef54c4642ffebb32b02395418432ebd92..4b7ae3934fddfeb63155439c22ef7c826d19bf2f 100644 (file)
@@ -1264,9 +1264,8 @@ formats in the string *must* include a parenthesised mapping key into that
 dictionary inserted immediately after the ``'%'`` character. The mapping key
 selects the value to be formatted from the mapping.  For example:
 
-
-   >>> print('%(language)s has %(#)03d quote types.' % \
-   ...       {'language': "Python", "#": 2})
+   >>> print('%(language)s has %(number)03d quote types.' %
+   ...       {'language': "Python", "number": 2})
    Python has 002 quote types.
 
 In this case no ``*`` specifiers may occur in a format (since they require a
@@ -1877,12 +1876,12 @@ pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098:
    values are added as items to the dictionary.  If a key is specified both in
    the positional argument and as a keyword argument, the value associated with
    the keyword is retained in the dictionary.  For example, these all return a
-   dictionary equal to ``{"one": 2, "two": 3}``:
+   dictionary equal to ``{"one": 1, "two": 2}``:
 
-   * ``dict(one=2, two=3)``
-   * ``dict({'one': 2, 'two': 3})``
-   * ``dict(zip(('one', 'two'), (2, 3)))``
-   * ``dict([['two', 3], ['one', 2]])``
+   * ``dict(one=1, two=2)``
+   * ``dict({'one': 1, 'two': 2})``
+   * ``dict(zip(('one', 'two'), (1, 2)))``
+   * ``dict([['two', 2], ['one', 1]])``
 
    The first example only works for keys that are valid Python identifiers; the
    others work with any valid keys.
index 3af5b5f2da3e6e2033e4026689bf1c9e77961e3e..d83f137ca2eafe791e8cac09916cd8841af381b4 100644 (file)
@@ -48,6 +48,13 @@ always available.
    ``modules.keys()`` only lists the imported modules.)
 
 
+.. function:: call_tracing(func, args)
+
+   Call ``func(*args)``, while tracing is enabled.  The tracing state is saved,
+   and restored afterwards.  This is intended to be called from a debugger from
+   a checkpoint, to recursively debug some other code.
+
+
 .. data:: copyright
 
    A string containing the copyright pertaining to the Python interpreter.
@@ -173,19 +180,25 @@ always available.
 
    Exit from Python.  This is implemented by raising the :exc:`SystemExit`
    exception, so cleanup actions specified by finally clauses of :keyword:`try`
-   statements are honored, and it is possible to intercept the exit attempt at an
-   outer level.  The optional argument *arg* can be an integer giving the exit
-   status (defaulting to zero), or another type of object.  If it is an integer,
-   zero is considered "successful termination" and any nonzero value is considered
-   "abnormal termination" by shells and the like.  Most systems require it to be in
-   the range 0-127, and produce undefined results otherwise.  Some systems have a
-   convention for assigning specific meanings to specific exit codes, but these are
-   generally underdeveloped; Unix programs generally use 2 for command line syntax
-   errors and 1 for all other kind of errors.  If another type of object is passed,
-   ``None`` is equivalent to passing zero, and any other object is printed to
-   ``sys.stderr`` and results in an exit code of 1.  In particular,
-   ``sys.exit("some error message")`` is a quick way to exit a program when an
-   error occurs.
+   statements are honored, and it is possible to intercept the exit attempt at
+   an outer level.
+
+   The optional argument *arg* can be an integer giving the exit status
+   (defaulting to zero), or another type of object.  If it is an integer, zero
+   is considered "successful termination" and any nonzero value is considered
+   "abnormal termination" by shells and the like.  Most systems require it to be
+   in the range 0-127, and produce undefined results otherwise.  Some systems
+   have a convention for assigning specific meanings to specific exit codes, but
+   these are generally underdeveloped; Unix programs generally use 2 for command
+   line syntax errors and 1 for all other kind of errors.  If another type of
+   object is passed, ``None`` is equivalent to passing zero, and any other
+   object is printed to :data:`stderr` and results in an exit code of 1.  In
+   particular, ``sys.exit("some error message")`` is a quick way to exit a
+   program when an error occurs.
+
+   Since :func:`exit` ultimately "only" raises an exception, it will only exit
+   the process when called from the main thread, and the exception is not
+   intercepted.
 
 
 .. data:: flags
index bc5c19ef62377d73664e86762fc99b44ffc5eaa1..991762f4e62dd94aef44ffe871b8351840763586 100644 (file)
@@ -12,8 +12,8 @@ in the Python distribution for the definitions of the names in the context of
 the language grammar.  The specific numeric values which the names map to may
 change between Python versions.
 
-This module also provides one data object and some functions.  The functions
-mirror definitions in the Python C header files.
+The module also provides a mapping from numeric codes to names and some
+functions.  The functions mirror definitions in the Python C header files.
 
 
 .. data:: tok_name
@@ -38,6 +38,65 @@ mirror definitions in the Python C header files.
    Return true if *x* is the marker indicating the end of input.
 
 
+The token constants are:
+
+.. data:: ENDMARKER
+          NAME
+          NUMBER
+          STRING
+          NEWLINE
+          INDENT
+          DEDENT
+          LPAR
+          RPAR
+          LSQB
+          RSQB
+          COLON
+          COMMA
+          SEMI
+          PLUS
+          MINUS
+          STAR
+          SLASH
+          VBAR
+          AMPER
+          LESS
+          GREATER
+          EQUAL
+          DOT
+          PERCENT
+          BACKQUOTE
+          LBRACE
+          RBRACE
+          EQEQUAL
+          NOTEQUAL
+          LESSEQUAL
+          GREATEREQUAL
+          TILDE
+          CIRCUMFLEX
+          LEFTSHIFT
+          RIGHTSHIFT
+          DOUBLESTAR
+          PLUSEQUAL
+          MINEQUAL
+          STAREQUAL
+          SLASHEQUAL
+          PERCENTEQUAL
+          AMPEREQUAL
+          VBAREQUAL
+          CIRCUMFLEXEQUAL
+          LEFTSHIFTEQUAL
+          RIGHTSHIFTEQUAL
+          DOUBLESTAREQUAL
+          DOUBLESLASH
+          DOUBLESLASHEQUAL
+          AT
+          OP
+          ERRORTOKEN
+          N_TOKENS
+          NT_OFFSET
+
+
 .. seealso::
 
    Module :mod:`parser`
index f5d919a7cf4c673659adfe88b1543d1b678a9805..d1c4c91e10e9d8a12a372973f6546bf730d8ba0e 100644 (file)
@@ -553,10 +553,9 @@ A class definition defines a class object (see section :ref:`types`):
 
 .. productionlist::
    classdef: [`decorators`] "class" `classname` [`inheritance`] ":" `suite`
-   inheritance: "(" [`argument_list` [","] ] ")"
+   inheritance: "(" [`argument_list` [","] | `comprehension`] ")"
    classname: `identifier`
 
-
 A class definition is an executable statement.  The inheritance list usually
 gives a list of base classes (see :ref:`metaclasses` for more advanced uses), so
 each item in the list should evaluate to a class object which allows
@@ -582,7 +581,7 @@ namespace.
 
 Class creation can be customized heavily using :ref:`metaclasses <metaclasses>`.
 
-Classes can also be decorated; as with functions, ::
+Classes can also be decorated: just like when decorating functions, ::
 
    @f1(arg)
    @f2
@@ -593,6 +592,10 @@ is equivalent to ::
    class Foo: pass
    Foo = f1(arg)(f2(Foo))
 
+The evaluation rules for the decorator expressions are the same as for function
+decorators.  The result must be a class object, which is then bound to the class
+name.
+
 **Programmer's note:** Variables defined in the class definition are class
 attributes; they are shared by instances.  Instance attributes can be set in a
 method with ``self.name = value``.  Both class and instance attributes are
index a7749799eaa1a2ae65df26886ffaefefac5596f2..82735df4cbb463e3626c64aa8d227b5c307a467e 100644 (file)
@@ -4,26 +4,26 @@
 Classes
 *******
 
-Python's class mechanism adds classes to the language with a minimum of new
-syntax and semantics.  It is a mixture of the class mechanisms found in C++ and
-Modula-3.  As is true for modules, classes in Python do not put an absolute
-barrier between definition and user, but rather rely on the politeness of the
-user not to "break into the definition."  The most important features of classes
-are retained with full power, however: the class inheritance mechanism allows
+Compared with other programming languages, Python's class mechanism adds classes
+with a minimum of new syntax and semantics.  It is a mixture of the class
+mechanisms found in C++ and Modula-3.  Python classes provide all the standard
+features of Object Oriented Programming: the class inheritance mechanism allows
 multiple base classes, a derived class can override any methods of its base
 class or classes, and a method can call the method of a base class with the same
-name.  Objects can contain an arbitrary amount of data.
+name.  Objects can contain arbitrary amounts and kinds of data.  As is true for
+modules, classes partake of the dynamic nature of Python: they are created at
+runtime, and can be modified further after creation.
 
 In C++ terminology, normally class members (including the data members) are
-*public* (except see below :ref:`tut-private`),
-and all member functions are *virtual*.  As in Modula-3, there are no shorthands
-for referencing the object's members from its methods: the method function is
-declared with an explicit first argument representing the object, which is
-provided implicitly by the call.  As in Smalltalk, classes themselves are
-objects.  This provides semantics for importing and renaming.  Unlike C++ and
-Modula-3, built-in types can be used as base classes for extension by the user.
-Also, like in C++, most built-in operators with special syntax (arithmetic
-operators, subscripting etc.) can be redefined for class instances.
+*public* (except see below :ref:`tut-private`), and all member functions are
+*virtual*.  As in Modula-3, there are no shorthands for referencing the object's
+members from its methods: the method function is declared with an explicit first
+argument representing the object, which is provided implicitly by the call.  As
+in Smalltalk, classes themselves are objects.  This provides semantics for
+importing and renaming.  Unlike C++ and Modula-3, built-in types can be used as
+base classes for extension by the user.  Also, like in C++, most built-in
+operators with special syntax (arithmetic operators, subscripting etc.) can be
+redefined for class instances.
 
 (Lacking universally accepted terminology to talk about classes, I will make
 occasional use of Smalltalk and C++ terms.  I would use Modula-3 terms, since
index 9571a189651e0bdec12fc824bfb6621698dc42a1..12378b323363dc6b690b405624c9d8ed909d12bd 100644 (file)
@@ -156,23 +156,48 @@ installation directory.  So, if you had installed Python to
 :file:`C:\\Python\\Lib\\` and third-party modules should be stored in
 :file:`C:\\Python\\Lib\\site-packages\\`.
 
-.. `` this fixes syntax highlighting errors in some editors due to the \\ hackery
-
-You can add folders to your search path to make Python's import mechanism search
-in these directories as well.  Use :envvar:`PYTHONPATH`, as described in
-:ref:`using-on-envvars`, to modify :data:`sys.path`.  On Windows, paths are
-separated by semicolons, though, to distinguish them from drive identifiers
-(:file:`C:\\` etc.).
-
-.. ``
-
-Modifying the module search path can also be done through the Windows registry
-under the key :file:`HKLM\\SOFTWARE\\Python\\PythonCore\\{version}\\PythonPath`.
-Subkeys which have semicolon-delimited path strings as their default value will
-cause each path to be searched.  Multiple subkeys can be created and are
-appended to the path in alphabetical order.  A convenient registry editor is
-:program:`regedit` (start it by typing "regedit" into :menuselection:`Start -->
-Run`).
+This is how :data:`sys.path` is populated on Windows:
+
+* An empty entry is added at the start, which corresponds to the current
+  directory.
+
+* If the environment variable :envvar:`PYTHONPATH` exists, as described in
+  :ref:`using-on-envvars`, its entries are added next.  Note that on Windows,
+  paths in this variable must be separated by semicolons, to distinguish them
+  from the colon used in drive identifiers (``C:\`` etc.).
+
+* Additional "application paths" can be added in the registry as subkeys of
+  :samp:`\\SOFTWARE\\Python\\PythonCore\\{version}\\PythonPath` under both the
+  ``HKEY_CURRENT_USER`` and ``HKEY_LOCAL_MACHINE`` hives.  Subkeys which have
+  semicolon-delimited path strings as their default value will cause each path
+  to be added to :data:`sys.path`.  (Note that all known installers only use
+  HKLM, so HKCU is typically empty.)
+
+* If the environment variable :envvar:`PYTHONHOME` is set, it is assumed as
+  "Python Home".  Otherwise, the path of the main Python executable is used to
+  locate a "landmark file" (``Lib\os.py``) to deduce the "Python Home".  If a
+  Python home is found, the relevant sub-directories added to :data:`sys.path`
+  (``Lib``, ``plat-win``, etc) are based on that folder.  Otherwise, the core
+  Python path is constructed from the PythonPath stored in the registry.
+
+* If the Python Home cannot be located, no :envvar:`PYTHONPATH` is specified in
+  the environment, and no registry entries can be found, a default path with
+  relative entries is used (e.g. ``.\Lib;.\plat-win``, etc).
+
+The end result of all this is:
+
+* When running :file:`python.exe`, or any other .exe in the main Python
+  directory (either an installed version, or directly from the PCbuild
+  directory), the core path is deduced, and the core paths in the registry are
+  ignored.  Other "application paths" in the registry are always read.
+
+* When Python is hosted in another .exe (different directory, embedded via COM,
+  etc), the "Python Home" will not be deduced, so the core path from the
+  registry is used.  Other "application paths" in the registry are always read.
+
+* If Python can't find its home and there is no registry (eg, frozen .exe, some
+  very strange installation setup) you get a path with some default, but
+  relative, paths.
 
 
 Executing scripts