----------------
0) To use Tix.py, you need Tcl/Tk (V8.3.3), Tix (V8.1.1) and Python (V2.1.1).
- Tix.py has been written and tested on a Intel Pentium running RH Linux 5.2
+ Tix.py has been written and tested on an Intel Pentium running RH Linux 5.2
and Mandrake Linux 7.0 and Windows with the above mentioned packages.
Older versions, e.g. Tix 4.1 and Tk 8.0, might also work.
#
# $Id$
#
-# Tix Demostration Program
+# Tix Demonstration Program
#
# This sample program is structured in such a way so that it can be
# executed from the Tix demo program "tixwidgets.py": it must have a
#
# $Id$
#
-# Tix Demostration Program
+# Tix Demonstration Program
#
# This sample program is structured in such a way so that it can be
# executed from the Tix demo program "tixwidgets.py": it must have a
#
# $Id$
#
-# Tix Demostration Program
+# Tix Demonstration Program
#
# This sample program is structured in such a way so that it can be
# executed from the Tix demo program "tixwidgets.py": it must have a
#
# $Id$
#
-# Tix Demostration Program
+# Tix Demonstration Program
#
# This sample program is structured in such a way so that it can be
# executed from the Tix demo program "tixwidgets.py": it must have a
#
# $Id$
#
-# Tix Demostration Program
+# Tix Demonstration Program
#
# This sample program is structured in such a way so that it can be
# executed from the Tix demo program "tixwidgets.py": it must have a
#
# $Id$
#
-# Tix Demostration Program
+# Tix Demonstration Program
#
# This sample program is structured in such a way so that it can be
# executed from the Tix demo program "tixwidgets.py": it must have a
#
# $Id$
#
-# Tix Demostration Program
+# Tix Demonstration Program
#
# This sample program is structured in such a way so that it can be
# executed from the Tix demo program "tixwidgets.py": it must have a
#
# $Id$
#
-# Tix Demostration Program
+# Tix Demonstration Program
#
# This sample program is structured in such a way so that it can be
# executed from the Tix demo program "tixwidgets.py": it must have a
#
# $Id$
#
-# Tix Demostration Program
+# Tix Demonstration Program
#
# This sample program is structured in such a way so that it can be
# executed from the Tix demo program "tixwidgets.py": it must have a
#
# $Id$
#
-# Tix Demostration Program
+# Tix Demonstration Program
#
# This sample program is structured in such a way so that it can be
# executed from the Tix demo program "tixwidgets.py": it must have a
#
# $Id$
#
-# Tix Demostration Program
+# Tix Demonstration Program
#
# This sample program is structured in such a way so that it can be
# executed from the Tix demo program "tixwidgets.py": it must have a
#
# $Id$
#
-# Tix Demostration Program
+# Tix Demonstration Program
#
# This sample program is structured in such a way so that it can be
# executed from the Tix demo program "tixwidgets.py": it must have a
#
# $Id$
#
-# Tix Demostration Program
+# Tix Demonstration Program
#
# This sample program is structured in such a way so that it can be
# executed from the Tix demo program "tixwidget": it must have a
#
# $Id$
#
-# Tix Demostration Program
+# Tix Demonstration Program
#
# This sample program is structured in such a way so that it can be
# executed from the Tix demo program "tixwidgets.py": it must have a
tdemo-I_dont_like_tiltdemo.py
-Demostrates
+Demonstrates
(a) use of a tilted ellipse as
turtle shape
(b) stamping that shape
# for development releases: always build
autobuild-dev:
- make dist SPHINXOPTS='-A daily=1 -A versionswitcher=1'
+ make dist SPHINXOPTS='$(SPHINXOPTS) -A daily=1 -A versionswitcher=1'
-make suspicious
# for quick rebuilds (HTML only)
-autobuild-html:
- make html SPHINXOPTS='-A daily=1 -A versionswitcher=1'
+autobuild-dev-html:
+ make html SPHINXOPTS='$(SPHINXOPTS) -A daily=1 -A versionswitcher=1'
# for stable releases: only build if not in pre-release stage (alpha, beta)
# release candidate downloads are okay, since the stable tree can be in that stage
esac
@make autobuild-dev
+autobuild-stable-html:
+ @case $(DISTVERSION) in *[ab]*) \
+ echo "Not building; $(DISTVERSION) is not a release version."; \
+ exit 1;; \
+ esac
+ @make autobuild-dev-html
only if its format string contains two or more format units. If the format
string is empty, it returns ``None``; if it contains exactly one format
unit, it returns whatever object is described by that format unit. To
- force it to return a tuple of size 0 or one, parenthesize the format
+ force it to return a tuple of size ``0`` or one, parenthesize the format
string.
When memory buffers are passed as parameters to supply data to build
.. c:member:: int ndim
The number of dimensions the memory represents as a multi-dimensional
- array. If it is 0, :c:data:`strides` and :c:data:`suboffsets` must be
+ array. If it is ``0``, :c:data:`strides` and :c:data:`suboffsets` must be
*NULL*.
.. c:member:: Py_ssize_t *shape
.. c:function:: int PyObject_CheckBuffer(PyObject *obj)
- Return 1 if *obj* supports the buffer interface otherwise 0.
+ Return ``1`` if *obj* supports the buffer interface otherwise ``0``.
.. c:function:: int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)
:c:data:`Py_buffer` structure is filled in with non-default values and/or
raise an error if the object can't support a simpler view of its memory.
- 0 is returned on success and -1 on error.
+ ``0`` is returned on success and ``-1`` on error.
The following table gives possible values to the *flags* arguments.
.. c:function:: int PyBuffer_IsContiguous(Py_buffer *view, char fortran)
- Return 1 if the memory defined by the *view* is C-style (*fortran* is
+ Return ``1`` if the memory defined by the *view* is C-style (*fortran* is
``'C'``) or Fortran-style (*fortran* is ``'F'``) contiguous or either one
- (*fortran* is ``'A'``). Return 0 otherwise.
+ (*fortran* is ``'A'``). Return ``0`` otherwise.
.. c:function:: void PyBuffer_FillContiguousStrides(int ndim, Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t itemsize, char fortran)
Fill in a buffer-info structure, *view*, correctly for an exporter that can
only share a contiguous chunk of memory of "unsigned bytes" of the given
- length. Return 0 on success and -1 (with raising an error) on error.
+ length. Return ``0`` on success and ``-1`` (with raising an error) on error.
MemoryView objects
guaranteed to succeed.
Return a nonzero value if the object is valid and matches the name passed in.
- Return 0 otherwise. This function will not fail.
+ Return ``0`` otherwise. This function will not fail.
.. c:function:: int PyCapsule_SetContext(PyObject *capsule, void *context)
Set the context pointer inside *capsule* to *context*.
- Return 0 on success. Return nonzero and set an exception on failure.
+ Return ``0`` on success. Return nonzero and set an exception on failure.
.. c:function:: int PyCapsule_SetDestructor(PyObject *capsule, PyCapsule_Destructor destructor)
Set the destructor inside *capsule* to *destructor*.
- Return 0 on success. Return nonzero and set an exception on failure.
+ Return ``0`` on success. Return nonzero and set an exception on failure.
.. c:function:: int PyCapsule_SetName(PyObject *capsule, const char *name)
outlive the capsule. If the previous *name* stored in the capsule was not
*NULL*, no attempt is made to free it.
- Return 0 on success. Return nonzero and set an exception on failure.
+ Return ``0`` on success. Return nonzero and set an exception on failure.
.. c:function:: int PyCapsule_SetPointer(PyObject *capsule, void *pointer)
Set the void pointer inside *capsule* to *pointer*. The pointer may not be
*NULL*.
- Return 0 on success. Return nonzero and set an exception on failure.
+ Return ``0`` on success. Return nonzero and set an exception on failure.
Create a new instance of a specific class without calling its constructor.
*class* is the class of new object. The *dict* parameter will be used as the
- object's :attr:`__dict__`; if *NULL*, a new dictionary will be created for the
+ object's :attr:`~object.__dict__`; if *NULL*, a new dictionary will be created for the
instance.
*format_code* must be one of ``'e'``, ``'E'``, ``'f'``, ``'F'``,
``'g'``, ``'G'`` or ``'r'``. For ``'r'``, the supplied *precision*
- must be 0 and is ignored. The ``'r'`` format code specifies the
+ must be ``0`` and is ignored. The ``'r'`` format code specifies the
standard :func:`repr` format.
*flags* can be zero or more of the values *Py_DTSF_SIGN*,
.. c:function:: int PyFile_SetEncoding(PyFileObject *p, const char *enc)
- Set the file's encoding for Unicode output to *enc*. Return 1 on success and 0
+ Set the file's encoding for Unicode output to *enc*. Return ``1`` on success and ``0``
on failure.
.. versionadded:: 2.3
.. c:function:: int PyFile_SetEncodingAndErrors(PyFileObject *p, const char *enc, *errors)
Set the file's encoding for Unicode output to *enc*, and its error
- mode to *err*. Return 1 on success and 0 on failure.
+ mode to *err*. Return ``1`` on success and ``0`` on failure.
.. versionadded:: 2.6
.. versionchanged:: 2.6
The function is an alias for :c:func:`PyImport_ImportModuleLevel` with
- -1 as level, meaning relative import.
+ ``-1`` as level, meaning relative import.
.. c:function:: PyObject* PyImport_ImportModuleLevel(char *name, PyObject *globals, PyObject *locals, PyObject *fromlist, int level)
.. c:function:: void Py_InitializeEx(int initsigs)
- This function works like :c:func:`Py_Initialize` if *initsigs* is 1. If
- *initsigs* is 0, it skips initialization registration of signal handlers, which
+ This function works like :c:func:`Py_Initialize` if *initsigs* is ``1``. If
+ *initsigs* is ``0``, it skips initialization registration of signal handlers, which
might be useful when Python is embedded.
.. versionadded:: 2.4
.. note::
It is recommended that applications embedding the Python interpreter
- for purposes other than executing a single script pass 0 as *updatepath*,
+ for purposes other than executing a single script pass ``0`` as *updatepath*,
and update :data:`sys.path` themselves if desired.
See `CVE-2008-5983 <https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5983>`_.
.. versionadded:: 2.6.6
- .. XXX impl. doesn't seem consistent in allowing 0/NULL for the params;
+ .. XXX impl. doesn't seem consistent in allowing ``0``/``NULL`` for the params;
check w/ Guido.
.. c:function:: void PySys_SetArgv(int argc, char **argv)
- This function works like :c:func:`PySys_SetArgvEx` with *updatepath* set to 1.
+ This function works like :c:func:`PySys_SetArgvEx` with *updatepath* set to ``1``.
.. c:function:: void Py_SetPythonHome(char *home)
.. index:: single: Py_AddPendingCall()
Schedule a function to be called from the main interpreter thread. On
- success, 0 is returned and *func* is queued for being called in the
- main thread. On failure, -1 is returned without setting any exception.
+ success, ``0`` is returned and *func* is queued for being called in the
+ main thread. On failure, ``-1`` is returned without setting any exception.
When successfully queued, *func* will be *eventually* called from the
main interpreter thread with the argument *arg*. It will be called
* with the main thread holding the :term:`global interpreter lock`
(*func* can therefore use the full C API).
- *func* must return 0 on success, or -1 on failure with an exception
+ *func* must return ``0`` on success, or ``-1`` on failure with an exception
set. *func* won't be interrupted to perform another asynchronous
notification recursively, but it can still be interrupted to switch
threads if the global interpreter lock is released.
Will first attempt to cast the object to a :c:type:`PyIntObject`, if it is not
already one, and then return its value. If there is an error, ``-1`` is
returned, and the caller should check ``PyErr_Occurred()`` to find out whether
- there was an error, or whether the value just happened to be -1.
+ there was an error, or whether the value just happened to be ``-1``.
.. c:function:: long PyInt_AS_LONG(PyObject *io)
Numeric values are stored with the least significant byte first.
-The module supports two versions of the data format: version 0 is the
-historical version, version 1 (new in Python 2.4) shares interned strings in
+The module supports two versions of the data format: version ``0`` is the
+historical version, version ``1`` (new in Python 2.4) shares interned strings in
the file, and upon unmarshalling. Version 2 (new in Python 2.5) uses a binary
format for floating point numbers. *Py_MARSHAL_VERSION* indicates the current
file format (currently 2).
.. index:: single: __dict__ (module attribute)
Return the dictionary object that implements *module*'s namespace; this object
- is the same as the :attr:`__dict__` attribute of the module object. This
+ is the same as the :attr:`~object.__dict__` attribute of the module object. This
function never fails. It is recommended extensions use other
:c:func:`PyModule_\*` and :c:func:`PyObject_\*` functions rather than directly
- manipulate a module's :attr:`__dict__`.
+ manipulate a module's :attr:`~object.__dict__`.
.. c:function:: char* PyModule_GetName(PyObject *module)
.. _noneobject:
-The None Object
----------------
+The ``None`` Object
+-------------------
.. index:: object: None
.. c:function:: int PyIndex_Check(PyObject *o)
- Returns True if *o* is an index integer (has the nb_index slot of the
- tp_as_number structure filled in).
+ Returns ``1`` if *o* is an index integer (has the nb_index slot of the
+ tp_as_number structure filled in), and ``0`` otherwise.
.. versionadded:: 2.5
.. c:function:: 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
+ *v*. Raise an exception and return ``-1`` on failure;
+ return ``0`` on success. This is the equivalent of the Python statement
``o.attr_name = v``.
+ If *v* is *NULL*, the attribute is deleted, however this feature is
+ deprecated in favour of using :c:func:`PyObject_DelAttr`.
+
.. c:function:: 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
+ *v*. Raise an exception and return ``-1`` on failure;
+ return ``0`` on success. This is the equivalent of the Python statement
``o.attr_name = v``.
+ If *v* is *NULL*, the attribute is deleted, however this feature is
+ deprecated in favour of using :c:func:`PyObject_DelAttrString`.
+
.. c:function:: int PyObject_GenericSetAttr(PyObject *o, PyObject *name, PyObject *value)
- Generic attribute setter function that is meant to be put into a type
- object's ``tp_setattro`` slot. It looks for a data descriptor in the
+ Generic attribute setter and deleter function that is meant
+ to be put into a type object's :c:member:`~PyTypeObject.tp_setattro`
+ slot. It looks for a data descriptor in the
dictionary of classes in the object's MRO, and if found it takes preference
- over setting the attribute in the instance dictionary. Otherwise, the
- attribute is set in the object's :attr:`~object.__dict__` (if present).
- Otherwise, an :exc:`AttributeError` is raised and ``-1`` is returned.
+ over setting or deleting the attribute in the instance dictionary. Otherwise, the
+ attribute is set or deleted in the object's :attr:`~object.__dict__` (if present).
+ On success, ``0`` is returned, otherwise an :exc:`AttributeError`
+ is raised and ``-1`` is returned.
.. c:function:: int PyObject_DelAttr(PyObject *o, PyObject *attr_name)
.. c:function:: int PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v)
- Map the object *key* to the value *v*. Returns ``-1`` on failure. This is the
+ Map the object *key* to the value *v*. Raise an exception and
+ return ``-1`` on failure; return ``0`` on success. This is the
equivalent of the Python statement ``o[key] = v``.
.. c:function:: int PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v)
- Assign object *v* to the *i*\ th element of *o*. Returns ``-1`` on failure. This
+ Assign object *v* to the *i*\ th element of *o*. Raise an exception
+ and return ``-1`` on failure; return ``0`` on success. This
is the equivalent of the Python statement ``o[i] = v``. This function *does
not* steal a reference to *v*.
+ If *v* is *NULL*, the element is deleted, however this feature is
+ deprecated in favour of using :c:func:`PySequence_DelItem`.
+
.. versionchanged:: 2.5
This function used an :c:type:`int` type for *i*. This might require
changes in your code for properly supporting 64-bit systems.
.. c:function:: int PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, PyObject *v)
Assign the sequence object *v* to the slice in sequence object *o* from *i1* to
- *i2*. This is the equivalent of the Python statement ``o[i1:i2] = v``.
+ *i2*. Raise an exception and return ``-1`` on failure; return ``0`` on success.
+ This is the equivalent of the Python statement ``o[i1:i2] = v``.
+
+ If *v* is *NULL*, the slice is deleted, however this feature is
+ deprecated in favour of using :c:func:`PySequence_DelSlice`.
.. versionchanged:: 2.5
This function used an :c:type:`int` type for *i1* and *i2*. This might
.. c:function:: int PySet_Contains(PyObject *anyset, PyObject *key)
- Return 1 if found, 0 if not found, and -1 if an error is encountered. Unlike
+ Return ``1`` if found, ``0`` if not found, and ``-1`` if an error is encountered. Unlike
the Python :meth:`__contains__` method, this function does not automatically
convert unhashable sets into temporary frozensets. Raise a :exc:`TypeError` if
the *key* is unhashable. Raise :exc:`PyExc_SystemError` if *anyset* is not a
.. c:function:: int PySet_Add(PyObject *set, PyObject *key)
Add *key* to a :class:`set` instance. Does not apply to :class:`frozenset`
- instances. Return 0 on success or -1 on failure. Raise a :exc:`TypeError` if
+ instances. Return ``0`` on success or ``-1`` on failure. Raise a :exc:`TypeError` if
the *key* is unhashable. Raise a :exc:`MemoryError` if there is no room to grow.
Raise a :exc:`SystemError` if *set* is not an instance of :class:`set` or its
subtype.
.. c:function:: int PySet_Discard(PyObject *set, PyObject *key)
- Return 1 if found and removed, 0 if not found (no action taken), and -1 if an
+ Return ``1`` if found and removed, ``0`` if not found (no action taken), and ``-1`` if an
error is encountered. Does not raise :exc:`KeyError` for missing keys. Raise a
:exc:`TypeError` if the *key* is unhashable. Unlike the Python :meth:`~set.discard`
method, this function does not automatically convert unhashable sets into
assuming a sequence of length *length*. Treats indices greater than
*length* as errors.
- Returns 0 on success and -1 on error with no exception set (unless one of
+ Returns ``0`` on success and ``-1`` on error with no exception set (unless one of
the indices was not :const:`None` and failed to be converted to an integer,
- in which case -1 is returned with an exception set).
+ in which case ``-1`` is returned with an exception set).
You probably do not want to use this function. If you want to use slice
objects in versions of Python prior to 2.3, you would probably do well to
of bounds indices are clipped in a manner consistent with the handling of
normal slices.
- Returns 0 on success and -1 on error with exception set.
+ Returns ``0`` on success and ``-1`` on error with exception set.
.. versionadded:: 2.3
The :attr:`ml_flags` field is a bitfield which can include the following flags.
The individual flags indicate either a calling convention or a binding
convention. Of the calling convention flags, only :const:`METH_VARARGS` and
-:const:`METH_KEYWORDS` can be combined (but note that :const:`METH_KEYWORDS`
-alone is equivalent to ``METH_VARARGS | METH_KEYWORDS``). Any of the calling
-convention flags can be combined with a binding flag.
+:const:`METH_KEYWORDS` can be combined. Any of the calling convention flags
+can be combined with a binding flag.
.. data:: METH_VARARGS
handles use of the :keyword:`del` statement on that attribute more correctly
than :c:macro:`T_OBJECT`.
- :attr:`flags` can be 0 for write and read access or :c:macro:`READONLY` for
+ :attr:`flags` can be ``0`` for write and read access or :c:macro:`READONLY` for
read-only access. Using :c:macro:`T_STRING` for :attr:`type` implies
:c:macro:`READONLY`. Only :c:macro:`T_OBJECT` and :c:macro:`T_OBJECT_EX`
members can be deleted. (They are set to *NULL*).
For statically allocated type objects, the tp_name field should contain a dot.
Everything before the last dot is made accessible as the :attr:`__module__`
attribute, and everything after the last dot is made accessible as the
- :attr:`__name__` attribute.
+ :attr:`~definition.__name__` attribute.
If no dot is present, the entire :c:member:`~PyTypeObject.tp_name` field is made accessible as the
- :attr:`__name__` attribute, and the :attr:`__module__` attribute is undefined
+ :attr:`~definition.__name__` attribute, and the :attr:`__module__` attribute is undefined
(unless explicitly set in the dictionary, as explained above). This means your
- type will be impossible to pickle.
+ type will be impossible to pickle. Additionally, it will not be listed in
+ module documentations created with pydoc.
This field is not inherited by subtypes.
This field is deprecated. When it is defined, it should point to a function
that acts the same as the :c:member:`~PyTypeObject.tp_getattro` function, but taking a C string
- instead of a Python string object to give the attribute name. The signature is
- the same as for :c:func:`PyObject_GetAttrString`.
+ instead of a Python string object to give the attribute name. The signature is ::
+
+ PyObject * tp_getattr(PyObject *o, char *attr_name);
This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_getattro`: a subtype
inherits both :c:member:`~PyTypeObject.tp_getattr` and :c:member:`~PyTypeObject.tp_getattro` from its base type when
.. c:member:: setattrfunc PyTypeObject.tp_setattr
- An optional pointer to the set-attribute-string function.
+ An optional pointer to the function for setting and deleting attributes.
This field is deprecated. When it is defined, it should point to a function
that acts the same as the :c:member:`~PyTypeObject.tp_setattro` function, but taking a C string
- instead of a Python string object to give the attribute name. The signature is
- the same as for :c:func:`PyObject_SetAttrString`.
+ instead of a Python string object to give the attribute name. The signature is ::
+
+ PyObject * tp_setattr(PyObject *o, char *attr_name, PyObject *v);
+ The *v* argument is set to *NULL* to delete the attribute.
This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_setattro`: a subtype
inherits both :c:member:`~PyTypeObject.tp_setattr` and :c:member:`~PyTypeObject.tp_setattro` from its base type when
the subtype's :c:member:`~PyTypeObject.tp_setattr` and :c:member:`~PyTypeObject.tp_setattro` are both *NULL*.
.. c:member:: setattrofunc PyTypeObject.tp_setattro
- An optional pointer to the set-attribute function.
+ An optional pointer to the function for setting and deleting attributes.
- The signature is the same as for :c:func:`PyObject_SetAttr`. It is usually
+ The signature is the same as for :c:func:`PyObject_SetAttr`, but setting
+ *v* to *NULL* to delete an attribute must be supported. It is usually
convenient to set this field to :c:func:`PyObject_GenericSetAttr`, which
implements the normal way of setting object attributes.
typedef struct PyGetSetDef {
char *name; /* attribute name */
getter get; /* C function to get the attribute */
- setter set; /* C function to set the attribute */
+ setter set; /* C function to set or delete the attribute */
char *doc; /* optional doc string */
void *closure; /* optional additional data for getter and setter */
} PyGetSetDef;
.. c:member:: descrsetfunc PyTypeObject.tp_descr_set
- An optional pointer to a "descriptor set" function.
+ An optional pointer to a function for setting and deleting
+ a descriptor's value.
The function signature is ::
int tp_descr_set(PyObject *self, PyObject *obj, PyObject *value);
+ The *value* argument is set to *NULL* to delete the value.
This field is inherited by subtypes.
.. XXX explain.
.. c:member:: objobjargproc PyMappingMethods.mp_ass_subscript
- This function is used by :c:func:`PyObject_SetItem` and has the same
- signature. If this slot is *NULL*, the object does not support item
- assignment.
+ This function is used by :c:func:`PyObject_SetItem` and
+ :c:func:`PyObject_DelItem`. It has the same signature as
+ :c:func:`PyObject_SetItem`, but *v* can also be set to *NULL* to delete
+ an item. If this slot is *NULL*, the object does not support item
+ assignment and deletion.
.. _sequence-structs:
This function is used by :c:func:`PySequence_SetItem` and has the same
signature. This slot may be left to *NULL* if the object does not support
- item assignment.
+ item assignment and deletion.
.. c:member:: objobjproc PySequenceMethods.sq_contains
all segments in ``*lenp``. The function cannot fail.
-.. c:type:: Py_ssize_t (*charbufferproc) (PyObject *self, Py_ssize_t segment, const char **ptrptr)
+.. c:type:: Py_ssize_t (*charbufferproc) (PyObject *self, Py_ssize_t segment, char **ptrptr)
Return the size of the segment *segment* that *ptrptr* is set to. ``*ptrptr``
is set to the memory buffer. Returns ``-1`` on error.
.. c:function:: int Py_UNICODE_ISSPACE(Py_UNICODE ch)
- Return 1 or 0 depending on whether *ch* is a whitespace character.
+ Return ``1`` or ``0`` depending on whether *ch* is a whitespace character.
.. c:function:: int Py_UNICODE_ISLOWER(Py_UNICODE ch)
- Return 1 or 0 depending on whether *ch* is a lowercase character.
+ Return ``1`` or ``0`` depending on whether *ch* is a lowercase character.
.. c:function:: int Py_UNICODE_ISUPPER(Py_UNICODE ch)
- Return 1 or 0 depending on whether *ch* is an uppercase character.
+ Return ``1`` or ``0`` depending on whether *ch* is an uppercase character.
.. c:function:: int Py_UNICODE_ISTITLE(Py_UNICODE ch)
- Return 1 or 0 depending on whether *ch* is a titlecase character.
+ Return ``1`` or ``0`` depending on whether *ch* is a titlecase character.
.. c:function:: int Py_UNICODE_ISLINEBREAK(Py_UNICODE ch)
- Return 1 or 0 depending on whether *ch* is a linebreak character.
+ Return ``1`` or ``0`` depending on whether *ch* is a linebreak character.
.. c:function:: int Py_UNICODE_ISDECIMAL(Py_UNICODE ch)
- Return 1 or 0 depending on whether *ch* is a decimal character.
+ Return ``1`` or ``0`` depending on whether *ch* is a decimal character.
.. c:function:: int Py_UNICODE_ISDIGIT(Py_UNICODE ch)
- Return 1 or 0 depending on whether *ch* is a digit character.
+ Return ``1`` or ``0`` depending on whether *ch* is a digit character.
.. c:function:: int Py_UNICODE_ISNUMERIC(Py_UNICODE ch)
- Return 1 or 0 depending on whether *ch* is a numeric character.
+ Return ``1`` or ``0`` depending on whether *ch* is a numeric character.
.. c:function:: int Py_UNICODE_ISALPHA(Py_UNICODE ch)
- Return 1 or 0 depending on whether *ch* is an alphabetic character.
+ Return ``1`` or ``0`` depending on whether *ch* is an alphabetic character.
.. c:function:: int Py_UNICODE_ISALNUM(Py_UNICODE ch)
- Return 1 or 0 depending on whether *ch* is an alphanumeric character.
+ Return ``1`` or ``0`` depending on whether *ch* is an alphanumeric character.
These APIs can be used for fast direct character conversions:
Copy the Unicode object contents into the :c:type:`wchar_t` buffer *w*. At most
*size* :c:type:`wchar_t` characters are copied (excluding a possibly trailing
0-termination character). Return the number of :c:type:`wchar_t` characters
- copied or -1 in case of an error. Note that the resulting :c:type:`wchar_t`
+ copied or ``-1`` in case of an error. Note that the resulting :c:type:`wchar_t`
string may or may not be 0-terminated. It is the responsibility of the caller
to make sure that the :c:type:`wchar_t` string is 0-terminated in case this is
required by the application. Also, note that the :c:type:`wchar_t*` string
decode characters.
Decoding mappings must map single string characters to single Unicode
-characters, integers (which are then interpreted as Unicode ordinals) or None
+characters, integers (which are then interpreted as Unicode ordinals) or ``None``
(meaning "undefined mapping" and causing an error).
Encoding mappings must map single Unicode characters to single string
-characters, integers (which are then interpreted as Latin-1 ordinals) or None
+characters, integers (which are then interpreted as Latin-1 ordinals) or ``None``
(meaning "undefined mapping" and causing an error).
The mapping objects provided must only support the __getitem__ mapping
*NULL* when an exception was raised by the codec.
The *mapping* table must map Unicode ordinal integers to Unicode ordinal
- integers or None (causing deletion of the character).
+ integers or ``None`` (causing deletion of the character).
Mapping tables need only provide the :meth:`__getitem__` interface; dictionaries
and sequences work well. Unmapped character ordinals (ones which cause a
.. c:function:: PyObject* PyUnicode_Splitlines(PyObject *s, int keepend)
Split a Unicode string at line breaks, returning a list of Unicode strings.
- CRLF is considered to be one line break. If *keepend* is 0, the Line break
+ CRLF is considered to be one line break. If *keepend* is ``0``, the Line break
characters are not included in the resulting strings.
resulting Unicode object.
The mapping table must map Unicode ordinal integers to Unicode ordinal integers
- or None (causing deletion of the character).
+ or ``None`` (causing deletion of the character).
Mapping tables need only provide the :meth:`__getitem__` interface; dictionaries
and sequences work well. Unmapped character ordinals (ones which cause a
.. c:function:: Py_ssize_t PyUnicode_Tailmatch(PyObject *str, PyObject *substr, Py_ssize_t start, Py_ssize_t end, int direction)
- Return 1 if *substr* matches ``str[start:end]`` at the given tail end
- (*direction* == -1 means to do a prefix match, *direction* == 1 a suffix match),
- 0 otherwise. Return ``-1`` if an error occurred.
+ Return ``1`` if *substr* matches ``str[start:end]`` at the given tail end
+ (*direction* == ``-1`` means to do a prefix match, *direction* == ``1`` a suffix match),
+ ``0`` otherwise. Return ``-1`` if an error occurred.
.. versionchanged:: 2.5
This function used an :c:type:`int` type for *start* and *end*. This
.. c:function:: Py_ssize_t PyUnicode_Find(PyObject *str, PyObject *substr, Py_ssize_t start, Py_ssize_t end, int direction)
Return the first position of *substr* in ``str[start:end]`` using the given
- *direction* (*direction* == 1 means to do a forward search, *direction* == -1 a
+ *direction* (*direction* == ``1`` means to do a forward search, *direction* == ``-1`` a
backward search). The return value is the index of the first match; a value of
``-1`` indicates that no match was found, and ``-2`` indicates that an error
occurred and an exception has been set.
.. c:function:: PyObject* PyUnicode_Replace(PyObject *str, PyObject *substr, PyObject *replstr, Py_ssize_t maxcount)
Replace at most *maxcount* occurrences of *substr* in *str* with *replstr* and
- return the resulting Unicode object. *maxcount* == -1 means replace all
+ return the resulting Unicode object. *maxcount* == ``-1`` means replace all
occurrences.
.. versionchanged:: 2.5
.. c:function:: int PyUnicode_Compare(PyObject *left, PyObject *right)
- Compare two strings and return -1, 0, 1 for less than, equal, and greater than,
+ Compare two strings and return ``-1``, ``0``, ``1`` for less than, equal, and greater than,
respectively.
.. class:: Extension
- The Extension class describes a single C or C++extension module in a setup
+ The Extension class describes a single C or C++ extension module in a setup
script. It accepts the following keyword arguments in its constructor
.. tabularcolumns:: |l|L|l|
| | to or ``None`` to define it | |
| | without a particular value | |
| | (equivalent of ``#define FOO`` | |
- | | in source or :option:`-DFOO` | |
+ | | in source or :option:`!-DFOO` | |
| | on Unix C compiler command | |
| | line) | |
+------------------------+--------------------------------+---------------------------+
.. function:: gen_preprocess_options(macros, include_dirs)
- Generate C pre-processor options (:option:`-D`, :option:`!-U`, :option:`!-I`) as
+ Generate C pre-processor options (:option:`!-D`, :option:`!-U`, :option:`!-I`) as
used by at least two types of compilers: the typical Unix compiler and Visual
C++. *macros* is the usual thing, a list of 1- or 2-tuples, where ``(name,)``
means undefine (:option:`!-U`) macro *name*, and ``(name, value)`` means define
- (:option:`-D`) macro *name* to *value*. *include_dirs* is just a list of
+ (:option:`!-D`) macro *name* to *value*. *include_dirs* is just a list of
directory names to be added to the header file search path (:option:`!-I`).
Returns a list of command-line options suitable for either Unix compilers or
Visual C++.
.. function:: show_compilers()
- Print list of available compilers (used by the :option:`--help-compiler` options
+ Print list of available compilers (used by the :option:`!--help-compiler` options
to :command:`build`, :command:`build_ext`, :command:`build_clib`).
This module provides the :class:`UnixCCompiler` class, a subclass of
:class:`CCompiler` that handles the typical Unix-style command-line C compiler:
-* macros defined with :option:`-Dname[=value]`
+* macros defined with :option:`!-Dname[=value]`
-* macros undefined with :option:`-Uname`
+* macros undefined with :option:`!-Uname`
-* include search directories specified with :option:`-Idir`
+* include search directories specified with :option:`!-Idir`
-* libraries specified with :option:`-llib`
+* libraries specified with :option:`!-llib`
-* library search directories specified with :option:`-Ldir`
+* library search directories specified with :option:`!-Ldir`
* compile handled by :program:`cc` (or similar) executable with :option:`!-c`
option: compiles :file:`.c` to :file:`.o`
* link static library handled by :program:`ar` command (possibly with
:program:`ranlib`)
-* link shared library handled by :program:`cc` :option:`-shared`
+* link shared library handled by :program:`cc` :option:`!-shared`
:mod:`distutils.msvccompiler` --- Microsoft Compiler
* options set attributes of a passed-in object
-* boolean options can have "negative aliases" --- eg. if :option:`--quiet` is
- the "negative alias" of :option:`--verbose`, then :option:`--quiet` on the
+* boolean options can have "negative aliases" --- eg. if :option:`!--quiet` is
+ the "negative alias" of :option:`!--verbose`, then :option:`!--quiet` on the
command line sets *verbose* to false.
Windows, is far more convenient for users even if your distribution doesn't
include any extensions.
-The :command:`bdist` command has a :option:`--formats` option, similar to the
+The :command:`bdist` command has a :option:`!--formats` option, similar to the
:command:`sdist` command, which you can use to select the types of built
distribution to generate: for example, ::
requires external :program:`rpm` utility, version 3.0.4 or better (use ``rpm
--version`` to find out which version you have)
-You don't have to use the :command:`bdist` command with the :option:`--formats`
+You don't have to use the :command:`bdist` command with the :option:`!--formats`
option; you can also use the command that directly implements the format you're
interested in. Some of these :command:`bdist` "sub-commands" actually generate
several similar formats; for instance, the :command:`bdist_dumb` command
python setup.py bdist_rpm
-or the :command:`bdist` command with the :option:`--format` option::
+or the :command:`bdist` command with the :option:`!--format` option::
python setup.py bdist --formats=rpm
all three steps are typically bundled together.
If you wish, you can separate these three steps. You can use the
-:option:`--spec-only` option to make :command:`bdist_rpm` just create the
+:option:`!--spec-only` option to make :command:`bdist_rpm` just create the
:file:`.spec` file and exit; in this case, the :file:`.spec` file will be
written to the "distribution directory"---normally :file:`dist/`, but
-customizable with the :option:`--dist-dir` option. (Normally, the :file:`.spec`
+customizable with the :option:`!--dist-dir` option. (Normally, the :file:`.spec`
file winds up deep in the "build tree," in a temporary directory created by
:command:`bdist_rpm`.)
python setup.py bdist_wininst
-or the :command:`bdist` command with the :option:`--formats` option::
+or the :command:`bdist` command with the :option:`!--formats` option::
python setup.py bdist --formats=wininst
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`
+the :option:`!--no-target-compile` and/or the :option:`!--no-target-optimize`
option.
By default the installer will display the cool "Python Powered" logo when it is
run, but you can also supply your own 152x261 bitmap which must be a Windows
-:file:`.bmp` file with the :option:`--bitmap` option.
+:file:`.bmp` file with the :option:`!--bitmap` option.
The installer will also display a large title on the desktop background window
when it is run, which is constructed from the name of your distribution and the
version number. This can be changed to another text by using the
-:option:`--title` option.
+:option:`!--title` option.
The installer file will be written to the "distribution directory" --- normally
-:file:`dist/`, but customizable with the :option:`--dist-dir` option.
+:file:`dist/`, but customizable with the :option:`!--dist-dir` option.
.. _cross-compile-windows:
installed, you can use a 32bit version of Windows to create 64bit extensions
and vice-versa.
-To build for an alternate platform, specify the :option:`--plat-name` option
+To build for an alternate platform, specify the :option:`!--plat-name` option
to the build command. Valid values are currently 'win32', 'win-amd64' and
'win-ia64'. For example, on a 32bit version of Windows, you could execute::
---------------------------
Starting with Python 2.3, a postinstallation script can be specified with the
-:option:`--install-script` option. The basename of the script must be
+:option:`!--install-script` option. The basename of the script must be
specified, and the script filename must also be listed in the scripts argument
to the setup function.
This script will be run at installation time on the target system after all the
-files have been copied, with ``argv[1]`` set to :option:`-install`, and again at
+files have been copied, with ``argv[1]`` set to :option:`!-install`, and again at
uninstallation time before the files are removed with ``argv[1]`` set to
-:option:`-remove`.
+:option:`!-remove`.
The installation script runs embedded in the windows installer, every output
(``sys.stdout``, ``sys.stderr``) is redirected into a buffer and will be
Vista User Access Control (UAC)
===============================
-Starting with Python 2.6, bdist_wininst supports a :option:`--user-access-control`
+Starting with Python 2.6, bdist_wininst supports a :option:`!--user-access-control`
option. The default is 'none' (meaning no UAC handling is done), and other
valid values are 'auto' (meaning prompt for UAC elevation if Python was
installed for all users) and 'force' (meaning always prompt for elevation).
--swig-opts list of SWIG command line options
[...]
-Note that an option spelled :option:`--foo-bar` on the command-line is spelled
+Note that an option spelled :option:`!--foo-bar` on the command-line is spelled
``foo_bar`` in configuration files.
.. _distutils-build-ext-inplace:
have an extension :mod:`pkg.ext`, and you want the compiled extension file
(:file:`ext.so` on Unix, say) to be put in the same source directory as your
pure Python modules :mod:`pkg.mod1` and :mod:`pkg.mod2`. You can always use the
-:option:`--inplace` option on the command-line to ensure this::
+:option:`!--inplace` option on the command-line to ensure this::
python setup.py build_ext --inplace
But this requires that you always specify the :command:`build_ext` command
-explicitly, and remember to provide :option:`--inplace`. An easier way is to
+explicitly, and remember to provide :option:`!--inplace`. An easier way is to
"set and forget" this option, by encoding it in :file:`setup.cfg`, the
configuration file for this distribution::
third-party extensions to provide support for additional packaging systems, but
the commands can be used for anything distutils commands can be used for. A new
configuration option, ``command_packages`` (command-line option
-:option:`--command-packages`), can be used to specify additional packages to be
+:option:`!--command-packages`), can be used to specify additional packages to be
searched for modules implementing commands. Like all distutils options, this
can be specified on the command line or in a configuration file. This option
can only be set in the ``[global]`` section of a configuration file, or before
To prevent registering broken reStructuredText content, you can use the
:program:`rst2html` program that is provided by the :mod:`docutils` package and
-check the ``long_description`` from the command line::
+check the ``long_description`` from the command line:
+
+.. code-block:: shell-session
$ python setup.py --long-description | rst2html.py > output.html
a list of source
files. Since the Distutils currently only support C, C++, and Objective-C
extensions, these are normally C/C++/Objective-C source files. (Be sure to use
-appropriate extensions to distinguish C++\ source files: :file:`.cc` and
+appropriate extensions to distinguish C++ source files: :file:`.cc` and
:file:`.cpp` seem to be recognized by both Unix and Windows compilers.)
However, you can also include SWIG interface (:file:`.i`) files in the list; the
The only clever feature is that if the first line of the script starts with
``#!`` and contains the word "python", the Distutils will adjust the first line
to refer to the current interpreter location. By default, it is replaced with
-the current interpreter location. The :option:`--executable` (or :option:`-e`)
+the current interpreter location. The :option:`!--executable` (or :option:`!-e`)
option will allow the interpreter path to be explicitly overridden.
The ``scripts`` option simply is a list of files to be handled in this
the current platform. The default format is a gzip'ed tar file
(:file:`.tar.gz`) on Unix, and ZIP file on Windows.
-You can specify as many formats as you like using the :option:`--formats`
+You can specify as many formats as you like using the :option:`!--formats`
option, for example::
python setup.py sdist --formats=gztar,zip
in) to create the source distribution archive(s)
There are a couple of options that modify this behaviour. First, use the
-:option:`--no-defaults` and :option:`--no-prune` to disable the standard
+:option:`!--no-defaults` and :option:`!--no-prune` to disable the standard
"include" and "exclude" sets.
Second, you might just want to (re)generate the manifest, but not create a
python setup.py sdist --manifest-only
-:option:`-o` is a shortcut for :option:`--manifest-only`.
+:option:`!-o` is a shortcut for :option:`!--manifest-only`.
.. _manifest_template:
:file:`examples/sample?/build`. All of this is done *after* the standard
include set, so you can exclude files from the standard set with explicit
instructions in the manifest template. (Or, you can use the
-:option:`--no-defaults` option to disable the standard set entirely.)
+:option:`!--no-defaults` option to disable the standard set entirely.)
The order of commands in the manifest template matters: initially, we have the
list of default files as described above, and each command in the template adds
future reference, and then used to build the source distribution archive(s).
You can disable the default set of included files with the
-:option:`--no-defaults` option, and you can disable the standard exclude set
-with :option:`--no-prune`.
+:option:`!--no-defaults` option, and you can disable the standard exclude set
+with :option:`!--no-prune`.
Following the Distutils' own manifest template, let's trace how the
:command:`sdist` command builds the list of files to include in the Distutils
extension.
A distutils package contains a driver script, :file:`setup.py`. This is a plain
-Python file, which, in the most simple case, could look like this::
+Python file, which, in the most simple case, could look like this:
+
+.. code-block:: python
from distutils.core import setup, Extension
In many cases, building an extension is more complex, since additional
preprocessor defines and libraries may be needed. This is demonstrated in the
-example below. ::
+example below.
+
+.. code-block:: python
from distutils.core import setup, Extension
python setup.py bdist_wininst
python setup.py bdist_rpm
python setup.py bdist_dumb
-
c = c + b
return c
-then the result should be::
+then the result should be:
+
+.. code-block:: shell-session
$ call multiply multiply 3 2
Will compute 3 times 2
be directly useful to you:
* ``pythonX.Y-config --cflags`` will give you the recommended flags when
- compiling::
+ compiling:
+
+ .. code-block:: shell-session
- $ /opt/bin/python2.7-config --cflags
- -I/opt/include/python2.7 -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
+ $ /opt/bin/python2.7-config --cflags
+ -I/opt/include/python2.7 -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes
* ``pythonX.Y-config --ldflags`` will give you the recommended flags when
- linking::
+ linking:
+
+ .. code-block:: shell-session
- $ /opt/bin/python2.7-config --ldflags
- -L/opt/lib/python2.7/config -lpthread -ldl -lutil -lm -lpython2.7 -Xlinker -export-dynamic
+ $ /opt/bin/python2.7-config --ldflags
+ -L/opt/lib/python2.7/config -lpthread -ldl -lutil -lm -lpython2.7 -Xlinker -export-dynamic
.. note::
To avoid confusion between several Python installations (and especially
format unit, it returns whatever object is described by that format unit. To
force it to return a tuple of size 0 or one, parenthesize the format string.
-Examples (to the left the call, to the right the resulting Python value)::
+Examples (to the left the call, to the right the resulting Python value):
+
+.. code-block:: none
Py_BuildValue("") None
Py_BuildValue("i", 123) 123
:func:`~gc.collect` function), as well as configuration
interfaces and the ability to disable the detector at runtime. The cycle
detector is considered an optional component; though it is included by default,
-it can be disabled at build time using the :option:`--without-cycle-gc` option
+it can be disabled at build time using the :option:`!--without-cycle-gc` option
to the :program:`configure` script on Unix platforms (including Mac OS X) or by
removing the definition of ``WITH_CYCLE_GC`` in the :file:`pyconfig.h` header on
other platforms. If the cycle detector is disabled in this way, the :mod:`gc`
Note that the name is a dotted name that includes both the module name and the
name of the type within the module. The module in this case is :mod:`noddy` and
-the type is :class:`Noddy`, so we set the type name to :class:`noddy.Noddy`. ::
+the type is :class:`Noddy`, so we set the type name to :class:`noddy.Noddy`.
+One side effect of using an undotted name is that the pydoc documentation tool
+will not list the new type in the module documentation. ::
sizeof(noddy_NoddyObject), /* tp_basicsize */
setup(name="noddy", version="1.0",
ext_modules=[Extension("noddy", ["noddy.c"])])
-in a file called :file:`setup.py`; then typing ::
+in a file called :file:`setup.py`; then typing
+
+.. code-block:: shell-session
$ python setup.py build
structure::
typedef struct PyMethodDef {
- char *ml_name; /* method name */
+ const char *ml_name; /* method name */
PyCFunction ml_meth; /* implementation function */
int ml_flags; /* flags */
- char *ml_doc; /* docstring */
+ const char *ml_doc; /* docstring */
} PyMethodDef;
One entry should be defined for each method provided by the type; no entries are
.. [#] Even in the third version, we aren't guaranteed to avoid cycles. Instances of
string subclasses are allowed and string subclasses could allow cycles even if
normal strings don't.
-
Many coding styles place begin/end brackets on a line by themselves. This makes
programs considerably longer and wastes valuable screen space, making it harder
to get a good overview of a program. Ideally, a function should fit on one
-screen (say, 20-30 lines). 20 lines of Python can do a lot more work than 20
+screen (say, 20--30 lines). 20 lines of Python can do a lot more work than 20
lines of C. This is not solely due to the lack of begin/end brackets -- the
lack of declarations and the high-level data types are also responsible -- but
the indentation-based syntax certainly helps.
Sample code and use for catching stdout:
+.. code-block:: pycon
+
>>> class StdoutCatcher:
... def __init__(self):
... self.data = ''
When using GDB with dynamically loaded extensions, you can't set a breakpoint in
your extension until your extension is loaded.
-In your ``.gdbinit`` file (or interactively), add the command::
+In your ``.gdbinit`` file (or interactively), add the command:
+
+.. code-block:: none
br _PyImport_LoadDynamicModule
-Then, when you run GDB::
+Then, when you run GDB:
+
+.. code-block:: shell-session
$ gdb /local/bin/python
gdb) run myscript.py
You can check the size of the Unicode character a Python interpreter is using by
checking the value of sys.maxunicode:
+.. code-block:: pycon
+
>>> import sys
>>> if sys.maxunicode > 65535:
... print 'UCS4 build'
Guido van Rossum and Jelke de Boer, "Interactively Testing Remote Servers
Using the Python Programming Language", CWI Quarterly, Volume 4, Issue 4
- (December 1991), Amsterdam, pp 283-303.
+ (December 1991), Amsterdam, pp 283--303.
Are there any books on Python?
--------------------
Python 3 has only one integer type, :func:`int`. But it actually
-corresponds to Python 2's :func:`long` type--the :func:`int` type
+corresponds to Python 2's :func:`long` type—the :func:`int` type
used in Python 2 was removed. In the C-API, ``PyInt_*`` functions
are replaced by their ``PyLong_*`` equivalents.
The curses library hides all the details of different terminals, and provides
the programmer with an abstraction of a display, containing multiple
non-overlapping windows. The contents of a window can be changed in various
-ways-- adding text, erasing it, changing its appearance--and the curses library
+ways---adding text, erasing it, changing its appearance---and the curses library
will automagically figure out what control codes need to be sent to the terminal
to produce the right output.
While they could have been implemented that way, the actual C implementation of
:c:type:`PyMethod_Type` in :source:`Objects/classobject.c` is a single object
with two different representations depending on whether the :attr:`im_self`
-field is set or is *NULL* (the C equivalent of *None*).
+field is set or is *NULL* (the C equivalent of ``None``).
Likewise, the effects of calling a method object depend on the :attr:`im_self`
field. If set (meaning bound), the original function (stored in the
logger = logging.getLogger('mylogger')
logger.debug('A debug message')
-To run this, you will probably need to run as ``root``::
+To run this, you will probably need to run as ``root``:
+
+.. code-block:: shell-session
$ sudo python3.3 chowntest.py
$ cat chowntest.log
completion, the status is as it was before so message #6 appears (like message
#1) whereas message #7 doesn't (just like message #2).
-If we run the resulting script, the result is as follows::
+If we run the resulting script, the result is as follows:
+
+.. code-block:: shell-session
$ python logctx.py
1. This should appear just once on stderr.
6. This should appear just once on stderr.
If we run it again, but pipe ``stderr`` to ``/dev/null``, we see the following,
-which is the only message written to ``stdout``::
+which is the only message written to ``stdout``:
+
+.. code-block:: shell-session
$ python logctx.py 2>/dev/null
5. This should appear twice - once on stderr and once on stdout.
-Once again, but piping ``stdout`` to ``/dev/null``, we get::
+Once again, but piping ``stdout`` to ``/dev/null``, we get:
+
+.. code-block:: shell-session
$ python logctx.py >/dev/null
1. This should appear just once on stderr.
logging.warning('Watch out!') # will print a message to the console
logging.info('I told you so') # will not print anything
-If you type these lines into a script and run it, you'll see::
+If you type these lines into a script and run it, you'll see:
+
+.. code-block:: none
WARNING:root:Watch out!
import logging
logging.warning('%s before you %s', 'Look', 'leap!')
-will display::
+will display:
+
+.. code-block:: none
WARNING:root:Look before you leap!
handlers for all the loggers an application uses. It is sufficient to
configure handlers for a top-level logger and create child loggers as needed.
(You can, however, turn off propagation by setting the *propagate*
-attribute of a logger to *False*.)
+attribute of a logger to ``False``.)
.. _handler-basic:
logger.error('error message')
logger.critical('critical message')
-Running this module from the command line produces the following output::
+Running this module from the command line produces the following output:
+
+.. code-block:: shell-session
$ python simple_logging_module.py
2005-03-19 15:10:26,618 - simple_example - DEBUG - debug message
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=
-The output is nearly identical to that of the non-config-file-based example::
+The output is nearly identical to that of the non-config-file-based example:
+
+.. code-block:: shell-session
$ python simple_logging_config.py
2005-03-19 15:38:55,977 - simpleExample - DEBUG - debug message
For Python 2.x, the behaviour is as follows:
-* If *logging.raiseExceptions* is *False* (production mode), the event is
+* If *logging.raiseExceptions* is ``False`` (production mode), the event is
silently dropped.
-* If *logging.raiseExceptions* is *True* (development mode), a message
+* If *logging.raiseExceptions* is ``True`` (development mode), a message
'No handlers could be found for logger X.Y.Z' is printed once.
.. _library-config:
Useful handlers included with the logging module.
:ref:`A logging cookbook <logging-cookbook>`
-
devoted to discussing various metacharacters and what they do.
Here's a complete list of the metacharacters; their meanings will be discussed
-in the rest of this HOWTO. ::
+in the rest of this HOWTO.
+
+.. code-block:: none
. ^ $ * + ? { } [ ] \ | ( )
There's actually 3 general ways in which this loop could work - dispatching a
thread to handle ``clientsocket``, create a new process to handle
``clientsocket``, or restructure this app to use non-blocking sockets, and
-mulitplex between our "server" socket and any active ``clientsocket``\ s using
+multiplex between our "server" socket and any active ``clientsocket``\ s using
``select``. More about that later. The important thing to understand now is
this: this is *all* a "server" socket does. It doesn't send any data. It doesn't
receive any data. It just produces "client" sockets. Each ``clientsocket`` is
[1, 2, 3, 4, 5]
You can also use the :meth:`list.sort` method of a list. It modifies the list
-in-place (and returns *None* to avoid confusion). Usually it's less convenient
+in-place (and returns ``None`` to avoid confusion). Usually it's less convenient
than :func:`sorted` - but if you don't need the original list, it's slightly
more efficient.
as keys. For example:
>>> student_tuples = [
- ('john', 'A', 15),
- ('jane', 'B', 12),
- ('dave', 'B', 10),
- ]
+ ... ('john', 'A', 15),
+ ... ('jane', 'B', 12),
+ ... ('dave', 'B', 10),
+ ... ]
>>> sorted(student_tuples, key=lambda student: student[2]) # sort by age
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
The same technique works for objects with named attributes. For example:
>>> class Student:
- def __init__(self, name, grade, age):
- self.name = name
- self.grade = grade
- self.age = age
- def __repr__(self):
- return repr((self.name, self.grade, self.age))
+ ... def __init__(self, name, grade, age):
+ ... self.name = name
+ ... self.grade = grade
+ ... self.age = age
+ ... def __repr__(self):
+ ... return repr((self.name, self.grade, self.age))
>>> student_objects = [
- Student('john', 'A', 15),
- Student('jane', 'B', 12),
- Student('dave', 'B', 10),
- ]
+ ... Student('john', 'A', 15),
+ ... Student('jane', 'B', 12),
+ ... Student('dave', 'B', 10),
+ ... ]
>>> sorted(student_objects, key=lambda student: student.age) # sort by age
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
The key-function patterns shown above are very common, so Python provides
convenience functions to make accessor functions easier and faster. The operator
module has :func:`operator.itemgetter`, :func:`operator.attrgetter`, and
-starting in Python 2.5 a :func:`operator.methodcaller` function.
+starting in Python 2.5 an :func:`operator.methodcaller` function.
Using those functions, the above examples become simpler and faster:
method could be used to compute message priority by counting the
number of exclamation marks in a message:
+ >>> from operator import methodcaller
>>> messages = ['critical!!!', 'hurry!', 'standby', 'immediate!!']
>>> sorted(messages, key=methodcaller('count', '!'))
['standby', 'hurry!', 'immediate!!', 'critical!!!']
a positive value for greater-than. For example, we can do:
>>> def numeric_compare(x, y):
- return x - y
- >>> sorted([5, 2, 4, 1, 3], cmp=numeric_compare)
+ ... return x - y
+ >>> sorted([5, 2, 4, 1, 3], cmp=numeric_compare) # doctest: +SKIP
[1, 2, 3, 4, 5]
Or you can reverse the order of comparison with:
>>> def reverse_numeric(x, y):
- return y - x
- >>> sorted([5, 2, 4, 1, 3], cmp=reverse_numeric)
+ ... return y - x
+ >>> sorted([5, 2, 4, 1, 3], cmp=reverse_numeric) # doctest: +SKIP
[5, 4, 3, 2, 1]
When porting code from Python 2.x to 3.x, the situation can arise when you have
To convert to a key function, just wrap the old comparison function:
+.. testsetup::
+
+ from functools import cmp_to_key
+
+.. doctest::
+
>>> sorted([5, 2, 4, 1, 3], key=cmp_to_key(reverse_numeric))
[5, 4, 3, 2, 1]
hold values ranging from 0 to 255. ASCII codes only went up to 127, so some
machines assigned values between 128 and 255 to accented characters. Different
machines had different codes, however, which led to problems exchanging files.
-Eventually various commonly used sets of values for the 128-255 range emerged.
+Eventually various commonly used sets of values for the 128--255 range emerged.
Some were true standards, defined by the International Standards Organization,
and some were **de facto** conventions that were invented by one company or
another and managed to catch on.
255 characters aren't very many. For example, you can't fit both the accented
characters used in Western Europe and the Cyrillic alphabet used for Russian
-into the 128-255 range because there are more than 128 such characters.
+into the 128--255 range because there are more than 128 such characters.
You could write files using different codes (all your Russian files in a coding
system called KOI8, all your French files in a different coding system called
to represent many different characters from many different alphabets; an initial
goal was to have Unicode contain the alphabets for every single human language.
It turns out that even 16 bits isn't enough to meet that goal, and the modern
-Unicode specification uses a wider range of codes, 0-1,114,111 (0x10ffff in
+Unicode specification uses a wider range of codes, 0--1,114,111 (0x10ffff in
base-16).
There's a related ISO standard, ISO 10646. Unicode and ISO 10646 were
To summarize the previous section: a Unicode string is a sequence of code
points, which are numbers from 0 to 0x10ffff. This sequence needs to be
-represented as a set of bytes (meaning, values from 0-255) in memory. The rules
+represented as a set of bytes (meaning, values from 0--255) in memory. The rules
for translating a Unicode string into a sequence of bytes are called an
**encoding**.
case.)
Latin-1, also known as ISO-8859-1, is a similar encoding. Unicode code points
-0-255 are identical to the Latin-1 values, so converting to this encoding simply
+0--255 are identical to the Latin-1 values, so converting to this encoding simply
requires converting code points to byte values; if a code point larger than 255
is encountered, the string can't be encoded into Latin-1.
print os.listdir('.')
print os.listdir(u'.')
-will produce the following output::
+will produce the following output:
+
+.. code-block:: shell-session
amk:~$ python t.py
['.svn', 'filename\xe4\x94\x80abc', ...]
~~~~~~~~~~~
Because the default handlers handle redirects (codes in the 300 range), and
-codes in the 100-299 range indicate success, you will usually only see error
-codes in the 400-599 range.
+codes in the 100--299 range indicate success, you will usually only see error
+codes in the 400--599 range.
``BaseHTTPServer.BaseHTTPRequestHandler.responses`` is a useful dictionary of
response codes in that shows all the response codes used by RFC 2616. The
through a proxy. However, this can be enabled by extending urllib2 as
shown in the recipe [#]_.
+.. note::
+
+ ``HTTP_PROXY`` will be ignored if a variable ``REQUEST_METHOD`` is set; see
+ the documentation on :func:`~urllib.getproxies`.
+
Sockets and Layers
==================
.. [#] For an introduction to the CGI protocol see
`Writing Web Applications in Python <http://www.pyzine.com/Issue008/Section_Articles/article_CGIOne.html>`_.
.. [#] Google for example.
-.. [#] Browser sniffing is a very bad practise for website design - building
+.. [#] Browser sniffing is a very bad practice for website design - building
sites using web standards is much more sensible. Unfortunately a lot of
sites still send different versions to different browsers.
.. [#] The user agent for MSIE 6 is
just download middleware which does that, plug it in, and get on with coding
the unique parts of your application. The same thing with compression -- there
is existing middleware which handles compressing your HTML using gzip to save
-on your server's bandwidth. Authentication is another a problem easily solved
-using existing middleware.
+on your server's bandwidth. Authentication is another problem that is easily
+solved using existing middleware.
Although WSGI may seem complex, the initial phase of learning can be very
rewarding because WSGI and the associated middleware already have solutions to
files to install into a *build directory*. By default, this is :file:`build`
under the distribution root; if you're excessively concerned with speed, or want
to keep the source tree pristine, you can change the build directory with the
-:option:`--build-base` option. For example::
+:option:`!--build-base` option. For example::
python setup.py build --build-base=/path/to/pybuild/foo-1.0
python setup.py install --home=<dir>
-where you can supply any directory you like for the :option:`--home` option. On
+where you can supply any directory you like for the :option:`!--home` option. On
Unix, lazy typists can just type a tilde (``~``); the :command:`install` command
will expand this to your home directory::
:mod:`sitecustomize` (see :mod:`site`) to call :func:`site.addsitedir` or edit
:data:`sys.path`.
-The :option:`--home` option defines the installation base directory. Files are
+The :option:`!--home` option defines the installation base directory. Files are
installed to the following directories under the installation base as follows:
=============== ===========================================================
(Mentally replace slashes with backslashes if you're on Windows.)
.. versionchanged:: 2.4
- The :option:`--home` option used to be supported only on Unix.
+ The :option:`!--home` option used to be supported only on Unix.
.. _inst-alt-install-prefix-unix:
/usr/local/bin/python setup.py install --prefix=/mnt/@server/export
-In either case, the :option:`--prefix` option defines the installation base, and
-the :option:`--exec-prefix` option defines the platform-specific installation
+In either case, the :option:`!--prefix` option defines the installation base, and
+the :option:`!--exec-prefix` option defines the platform-specific installation
base, which is used for platform-specific files. (Currently, this just means
non-pure module distributions, but could be expanded to C libraries, binary
-executables, etc.) If :option:`--exec-prefix` is not supplied, it defaults to
-:option:`--prefix`. Files are installed as follows:
+executables, etc.) If :option:`!--exec-prefix` is not supplied, it defaults to
+:option:`!--prefix`. Files are installed as follows:
================= ==========================================================
Type of file Installation directory
C headers :file:`{prefix}/include/python{X.Y}/{distname}`
================= ==========================================================
-There is no requirement that :option:`--prefix` or :option:`--exec-prefix`
+There is no requirement that :option:`!--prefix` or :option:`!--exec-prefix`
actually point to an alternate Python installation; if the directories listed
above do not already exist, they are created at installation time.
Incidentally, the real reason the prefix scheme is important is simply that a
-standard Unix installation uses the prefix scheme, but with :option:`--prefix`
-and :option:`--exec-prefix` supplied by Python itself as ``sys.prefix`` and
+standard Unix installation uses the prefix scheme, but with :option:`!--prefix`
+and :option:`!--exec-prefix` supplied by Python itself as ``sys.prefix`` and
``sys.exec_prefix``. Thus, you might think you'll never use the prefix scheme,
but every time you run ``python setup.py install`` without any other options,
you're using it.
in this way is compatible with the interpreter used to build them. The best way
to do this is to ensure that the two interpreters are the same version of Python
(possibly different builds, or possibly copies of the same build). (Of course,
-if your :option:`--prefix` and :option:`--exec-prefix` don't even point to an
+if your :option:`!--prefix` and :option:`!--exec-prefix` don't even point to an
alternate Python installation, this is immaterial.)
---------------------------------------------------
Windows has no concept of a user's home directory, and since the standard Python
-installation under Windows is simpler than under Unix, the :option:`--prefix`
+installation under Windows is simpler than under Unix, the :option:`!--prefix`
option has traditionally been used to install additional packages in separate
locations on Windows. ::
to install modules to the :file:`\\Temp\\Python` directory on the current drive.
-The installation base is defined by the :option:`--prefix` option; the
-:option:`--exec-prefix` option is not supported under Windows, which means that
+The installation base is defined by the :option:`!--prefix` option; the
+:option:`!--exec-prefix` option is not supported under Windows, which means that
pure Python modules and extension modules are installed into the same location.
Files are installed as follows:
For example, say you're installing a module distribution to your home directory
under Unix---but you want scripts to go in :file:`~/scripts` rather than
:file:`~/bin`. As you might expect, you can override this directory with the
-:option:`--install-scripts` option; in this case, it makes most sense to supply
+:option:`!--install-scripts` option; in this case, it makes most sense to supply
a relative path, which will be interpreted relative to the installation base
directory (your home directory, in this case)::
with a prefix of :file:`/usr/local/python`, so under a standard installation
scripts will wind up in :file:`/usr/local/python/bin`. If you want them in
:file:`/usr/local/bin` instead, you would supply this absolute directory for the
-:option:`--install-scripts` option::
+:option:`!--install-scripts` option::
python setup.py install --install-scripts=/usr/local/bin
to be in Objective C.
* *cpparg* is an argument for the C preprocessor, and is anything starting with
- :option:`!-I`, :option:`-D`, :option:`!-U` or :option:`-C`.
+ :option:`!-I`, :option:`!-D`, :option:`!-U` or :option:`!-C`.
-* *library* is anything ending in :file:`.a` or beginning with :option:`-l` or
- :option:`-L`.
+* *library* is anything ending in :file:`.a` or beginning with :option:`!-l` or
+ :option:`!-L`.
If a particular platform requires a special library on your platform, you can
add it by editing the :file:`Setup` file and running ``python setup.py build``.
foo foomodule.c
must be linked with the math library :file:`libm.a` on your platform, simply add
-:option:`-lm` to the line::
+:option:`!-lm` to the line::
foo foomodule.c -lm
Arbitrary switches intended for the compiler or the linker can be supplied with
-the :option:`-Xcompiler` *arg* and :option:`-Xlinker` *arg* options::
+the :option:`!-Xcompiler` *arg* and :option:`!-Xlinker` *arg* options::
foo foomodule.c -Xcompiler -o32 -Xlinker -shared -lm
-The next option after :option:`-Xcompiler` and :option:`-Xlinker` will be
+The next option after :option:`!-Xcompiler` and :option:`!-Xlinker` will be
appended to the proper command line, so in the above example the compiler will
-be passed the :option:`-o32` option, and the linker will be passed
-:option:`-shared`. If a compiler option requires an argument, you'll have to
-supply multiple :option:`-Xcompiler` options; for example, to pass ``-x c++``
+be passed the :option:`!-o32` option, and the linker will be passed
+:option:`!-shared`. If a compiler option requires an argument, you'll have to
+supply multiple :option:`!-Xcompiler` options; for example, to pass ``-x c++``
the :file:`Setup` file would have to contain ``-Xcompiler -x -Xcompiler c++``.
Compiler flags can also be supplied through setting the :envvar:`CFLAGS`
name = raw_input()
greet(name)
-It can be converted to Python 3.x code via 2to3 on the command line::
+It can be converted to Python 3.x code via 2to3 on the command line:
+
+.. code-block:: shell-session
$ 2to3 example.py
A diff against the original source file is printed. 2to3 can also write the
needed modifications right back to the source file. (A backup of the original
-file is made unless :option:`-n` is also given.) Writing the changes back is
-enabled with the :option:`-w` flag::
+file is made unless :option:`!-n` is also given.) Writing the changes back is
+enabled with the :option:`!-w` flag:
+
+.. code-block:: shell-session
$ 2to3 -w example.py
Comments and exact indentation are preserved throughout the translation process.
By default, 2to3 runs a set of :ref:`predefined fixers <2to3-fixers>`. The
-:option:`-l` flag lists all available fixers. An explicit set of fixers to run
-can be given with :option:`-f`. Likewise the :option:`!-x` explicitly disables a
-fixer. The following example runs only the ``imports`` and ``has_key`` fixers::
+:option:`!-l` flag lists all available fixers. An explicit set of fixers to run
+can be given with :option:`!-f`. Likewise the :option:`!-x` explicitly disables a
+fixer. The following example runs only the ``imports`` and ``has_key`` fixers:
+
+.. code-block:: shell-session
$ 2to3 -f imports -f has_key example.py
-This command runs every fixer except the ``apply`` fixer::
+This command runs every fixer except the ``apply`` fixer:
+
+.. code-block:: shell-session
$ 2to3 -x apply example.py
Some fixers are *explicit*, meaning they aren't run by default and must be
listed on the command line to be run. Here, in addition to the default fixers,
-the ``idioms`` fixer is run::
+the ``idioms`` fixer is run:
+
+.. code-block:: shell-session
$ 2to3 -f all -f idioms example.py
cannot always read files containing the print function. When 2to3 detects the
presence of the ``from __future__ import print_function`` compiler directive, it
modifies its internal grammar to interpret :func:`print` as a function. This
-change can also be enabled manually with the :option:`-p` flag. Use
-:option:`-p` to run fixers on code that already has had its print statements
+change can also be enabled manually with the :option:`!-p` flag. Use
+:option:`!-p` to run fixers on code that already has had its print statements
converted.
-The :option:`-o` or :option:`--output-dir` option allows specification of an
+The :option:`!-o` or :option:`!--output-dir` option allows specification of an
alternate directory for processed output files to be written to. The
-:option:`-n` flag is required when using this as backup files do not make sense
+:option:`!-n` flag is required when using this as backup files do not make sense
when not overwriting the input files.
.. versionadded:: 2.7.3
- The :option:`-o` option was added.
+ The :option:`!-o` option was added.
-The :option:`!-W` or :option:`--write-unchanged-files` flag tells 2to3 to always
+The :option:`!-W` or :option:`!--write-unchanged-files` flag tells 2to3 to always
write output files even if no changes were required to the file. This is most
-useful with :option:`-o` so that an entire Python source tree is copied with
+useful with :option:`!-o` so that an entire Python source tree is copied with
translation from one directory to another.
-This option implies the :option:`-w` flag as it would not make sense otherwise.
+This option implies the :option:`!-w` flag as it would not make sense otherwise.
.. versionadded:: 2.7.3
The :option:`!-W` flag was added.
-The :option:`--add-suffix` option specifies a string to append to all output
-filenames. The :option:`-n` flag is required when specifying this as backups
-are not necessary when writing to different filenames. Example::
+The :option:`!--add-suffix` option specifies a string to append to all output
+filenames. The :option:`!-n` flag is required when specifying this as backups
+are not necessary when writing to different filenames. Example:
+
+.. code-block:: shell-session
$ 2to3 -n -W --add-suffix=3 example.py
Will cause a converted file named ``example.py3`` to be written.
.. versionadded:: 2.7.3
- The :option:`--add-suffix` option was added.
+ The :option:`!--add-suffix` option was added.
+
+To translate an entire project from one directory tree to another use:
-To translate an entire project from one directory tree to another use::
+.. code-block:: shell-session
$ 2to3 --output-dir=python3-version/mycode -W -n python2-version/mycode
Most modules have the name ``__builtins__`` (note the ``'s'``) made available
as part of their globals. The value of ``__builtins__`` is normally either
- this module or the value of this modules's :attr:`__dict__` attribute. Since
+ this module or the value of this modules's :attr:`~object.__dict__` attribute. Since
this is an implementation detail, it may not be used by alternate
implementations of Python.
classes. Packing and unpacking instances of these classes is handled
automatically by :mod:`aepack`.
-An object specifier is essentially an address of an object implemented in a
+An object specifier is essentially an address of an object implemented in an
Apple Event server. An Apple Event specifier is used as the direct object for an
Apple Event or as the argument of an optional parameter. The :mod:`aetypes`
module contains the base classes for OSA classes and properties, which are used
print args.accumulate(args.integers)
Assuming the Python code above is saved into a file called ``prog.py``, it can
-be run at the command line and provides useful help messages::
+be run at the command line and provides useful help messages:
+
+.. code-block:: shell-session
$ python prog.py -h
usage: prog.py [-h] [--sum] N [N ...]
--sum sum the integers (default: find the max)
When run with the appropriate arguments, it prints either the sum or the max of
-the command-line integers::
+the command-line integers:
+
+.. code-block:: shell-session
$ python prog.py 1 2 3 4
4
$ python prog.py 1 2 3 4 --sum
10
-If invalid arguments are passed in, it will issue an error::
+If invalid arguments are passed in, it will issue an error:
+
+.. code-block:: shell-session
$ python prog.py a b c
usage: prog.py [-h] [--sum] N [N ...]
prog
^^^^
-By default, :class:`ArgumentParser` objects uses ``sys.argv[0]`` to determine
+By default, :class:`ArgumentParser` objects use ``sys.argv[0]`` to determine
how to display the name of the program in help messages. This default is almost
always desirable because it will make the help messages match how the program was
invoked on the command line. For example, consider a file named
args = parser.parse_args()
The help for this program will display ``myprogram.py`` as the program name
-(regardless of where the program was invoked from)::
+(regardless of where the program was invoked from):
+
+.. code-block:: shell-session
$ python myprogram.py --help
usage: myprogram.py [-h] [--foo FOO]
^^^^^^^^^^^^^^^^
:class:`ArgumentParser` objects do not allow two actions with the same option
-string. By default, :class:`ArgumentParser` objects raises an exception if an
+string. By default, :class:`ArgumentParser` objects raise an exception if an
attempt is made to create an argument with an option string that is already in
use::
args = parser.parse_args()
If ``-h`` or ``--help`` is supplied at the command line, the ArgumentParser
-help will be printed::
+help will be printed:
+
+.. code-block:: shell-session
$ python myprogram.py --help
usage: myprogram.py [-h] [--foo FOO]
* ``'store_true'`` and ``'store_false'`` - These are special cases of
``'store_const'`` using for storing the values ``True`` and ``False``
- respectively. In addition, they create default values of *False* and *True*
+ respectively. In addition, they create default values of ``False`` and ``True``
respectively. For example::
>>> parser = argparse.ArgumentParser()
positional arguments
* description - description for the sub-parser group in help output, by
- default None
+ default ``None``
* prog - usage information that will be displayed with sub-command help,
by default the name of the program and any positional arguments before the
encountered at the command line
* dest_ - name of the attribute under which sub-command name will be
- stored; by default None and no value is stored
+ stored; by default ``None`` and no value is stored
- * help_ - help for sub-parser group in help output, by default None
+ * help_ - help for sub-parser group in help output, by default ``None``
* metavar_ - string presenting available sub-commands in help; by default it
- is None and presents sub-commands in form {cmd1, cmd2, ..}
+ is ``None`` and presents sub-commands in form {cmd1, cmd2, ..}
Some example usage::
.. data:: ArrayType
- Obsolete alias for :class:`array`.
+ Obsolete alias for :class:`~array.array`.
Array objects support the ordinary sequence operations of indexing, slicing,
concatenation, and multiplication. When using slice assignment, the assigned
empty, otherwise it is a string if the *typecode* is ``'c'``, otherwise it is a
list of numbers. The string is guaranteed to be able to be converted back to an
array with the same type and value using :func:`eval`, so long as the
-:func:`array` function has been imported using ``from array import array``.
+:class:`~array.array` class has been imported using ``from array import array``.
Examples::
array('l')
The abstract grammar is currently defined as follows:
.. literalinclude:: ../../Parser/Python.asdl
+ :language: none
:mod:`ast` Helpers
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
+ 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.select` or :func:`~select.poll`
call, measured in seconds; the default is 30 seconds. The *use_poll*
.. method:: set_continue()
Stop only at breakpoints or when finished. If there are no breakpoints,
- set the system trace function to None.
+ set the system trace function to ``None``.
.. method:: set_quit()
.. method:: itermonthdates(year, month)
- Return an iterator for the month *month* (1-12) in the year *year*. This
+ Return an iterator for the month *month* (1--12) in the year *year*. This
iterator will return all days (as :class:`datetime.date` objects) for the
month and all days before the start of the month or after the end of the
month that are required to get a complete week.
invoked as a script, the file will dump its environment and the contents of the
form in HTML form. Give it the right mode etc, and send it a request. If it's
installed in the standard :file:`cgi-bin` directory, it should be possible to
-send it a request by entering a URL into your browser of the form::
+send it a request by entering a URL into your browser of the form:
+
+.. code-block:: none
http://yourhostname/cgi-bin/cgi.py?name=Joe+Blow&addr=At+Home
field values should be supplied in, but knowing whether a request was
received from a conforming browser, or even from a browser at all, is tedious
and error-prone.
-
the :class:`Chunk` class defined here is to instantiate an instance at the start
of each chunk and read from the instance until it reaches the end, after which a
new instance can be instantiated. At the end of the file, creating a new
-instance will fail with a :exc:`EOFError` exception.
+instance will fail with an :exc:`EOFError` exception.
.. class:: Chunk(file[, align, bigendian, inclheader])
.. function:: isinf(x)
- Return *True* if the real or the imaginary part of x is positive
+ Return ``True`` if the real or the imaginary part of x is positive
or negative infinity.
.. versionadded:: 2.6
.. function:: isnan(x)
- Return *True* if the real or imaginary part of x is not a number (NaN).
+ Return ``True`` if the real or imaginary part of x is not a number (NaN).
.. versionadded:: 2.6
Kahan, W: Branch cuts for complex elementary functions; or, Much ado about
nothing's sign bit. In Iserles, A., and Powell, M. (eds.), The state of the art
- in numerical analysis. Clarendon Press (1987) pp165-211.
+ in numerical analysis. Clarendon Press (1987) pp165--211.
unicode object into a sequence of bytes is called encoding and recreating the
unicode object from the sequence of bytes is known as decoding. There are many
different methods for how this transformation can be done (these methods are
-also called encodings). The simplest method is to map the code points 0-255 to
-the bytes ``0x0``-``0xff``. This means that a unicode object that contains
+also called encodings). The simplest method is to map the code points 0--255 to
+the bytes ``0x0``--``0xff``. This means that a unicode object that contains
code points above ``U+00FF`` can't be encoded with this method (which is called
``'latin-1'`` or ``'iso-8859-1'``). :func:`unicode.encode` will raise a
:exc:`UnicodeEncodeError` that looks like this: ``UnicodeEncodeError: 'latin-1'
There's another group of encodings (the so called charmap encodings) that choose
a different subset of all unicode code points and how these code points are
-mapped to the bytes ``0x0``-``0xff``. To see how this is done simply open
+mapped to the bytes ``0x0``--``0xff``. To see how this is done simply open
e.g. :file:`encodings/cp1252.py` (which is an encoding that is used primarily on
Windows). There's a string constant with 256 characters that shows you which
character is mapped to which byte value.
.. versionadded:: 2.4
- If *maxlen* is not specified or is *None*, deques may grow to an
+ 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
.. attribute:: maxlen
- Maximum size of a deque or *None* if unbounded.
+ Maximum size of a deque or ``None`` if unbounded.
.. versionadded:: 2.7
_fields = ('x', 'y')
<BLANKLINE>
def __new__(_cls, x, y):
- 'Create a new instance of Point(x, y)'
+ 'Create new instance of Point(x, y)'
return _tuple.__new__(_cls, (x, y))
<BLANKLINE>
@classmethod
return result
<BLANKLINE>
def __getnewargs__(self):
- 'Return self as a plain tuple. Used by copy and pickle.'
+ 'Return self as a plain tuple. Used by copy and pickle.'
return tuple(self)
<BLANKLINE>
__dict__ = _property(_asdict)
<BLANKLINE>
y = _property(_itemgetter(1), doc='Alias for field number 1')
<BLANKLINE>
+ <BLANKLINE>
>>> p = Point(11, y=22) # instantiate with positional or keyword arguments
>>> p[0] + p[1] # indexable like the plain tuple (11, 22)
Point(x=33, y=22)
>>> for partnum, record in inventory.items():
- inventory[partnum] = record._replace(price=newprices[partnum], timestamp=time.now())
+ ... inventory[partnum] = record._replace(price=newprices[partnum], timestamp=time.now())
.. attribute:: somenamedtuple._fields
a fixed-width print format:
>>> class Point(namedtuple('Point', 'x y')):
- __slots__ = ()
- @property
- def hypot(self):
- return (self.x ** 2 + self.y ** 2) ** 0.5
- def __str__(self):
- return 'Point: x=%6.3f y=%6.3f hypot=%6.3f' % (self.x, self.y, self.hypot)
-
+ ... __slots__ = ()
+ ... @property
+ ... def hypot(self):
+ ... return (self.x ** 2 + self.y ** 2) ** 0.5
+ ... def __str__(self):
+ ... return 'Point: x=%6.3f y=%6.3f hypot=%6.3f' % (self.x, self.y, self.hypot)
+ ...
>>> for p in Point(3, 4), Point(14, 5/7.):
- print p
+ ... print p
Point: x= 3.000 y= 4.000 hypot= 5.000
Point: x=14.000 y= 0.714 hypot=14.018
>>> Status.open, Status.pending, Status.closed
(0, 1, 2)
>>> class Status:
- open, pending, closed = range(3)
+ ... open, pending, closed = range(3)
.. seealso::
single: ini file
single: Windows ini file
-This module defines the class :class:`ConfigParser`. The :class:`ConfigParser`
+This module defines the class :class:`~ConfigParser.ConfigParser`. The :class:`~ConfigParser.ConfigParser`
class implements a basic configuration file parser language which provides a
structure similar to what you would find on Microsoft Windows INI files. You
can use this to write Python programs which can be customized by end users
would resolve the ``%(dir)s`` to the value of ``dir`` (``frob`` in this case).
All reference expansions are done on demand.
-Default values can be specified by passing them into the :class:`ConfigParser`
+Default values can be specified by passing them into the :class:`~ConfigParser.ConfigParser`
constructor as a dictionary. Additional defaults may be passed into the
:meth:`get` method which will override all others.
Sections are normally stored in a built-in dictionary. An alternative dictionary
-type can be passed to the :class:`ConfigParser` constructor. For example, if a
+type can be passed to the :class:`~ConfigParser.ConfigParser` constructor. For example, if a
dictionary type is passed that sorts its keys, the sections will be sorted on
write-back, as will be the keys within each section.
.. class:: SafeConfigParser([defaults[, dict_type[, allow_no_value]]])
- Derived class of :class:`ConfigParser` that implements a more-sane variant of
+ Derived class of :class:`~ConfigParser.ConfigParser` that implements a more-sane variant of
the magical interpolation feature. This implementation is more predictable as
well. New applications should prefer this version if they don't need to be
compatible with older versions of Python.
.. data:: MAX_INTERPOLATION_DEPTH
The maximum depth for recursive interpolation for :meth:`get` when the *raw*
- parameter is false. This is relevant only for the :class:`ConfigParser` class.
+ parameter is false. This is relevant only for the :class:`~ConfigParser.ConfigParser` class.
.. seealso::
list of potential configuration file locations (for example, the current
directory, the user's home directory, and some system-wide directory), and all
existing configuration files in the list will be read. If none of the named
- files exist, the :class:`ConfigParser` instance will contain an empty dataset.
+ files exist, the :class:`~ConfigParser.ConfigParser` instance will contain an empty dataset.
An application which requires initial values to be loaded from a file should
load the required file or files using :meth:`readfp` before calling :meth:`read`
for any optional files::
If the given section exists, set the given option to the specified value;
otherwise raise :exc:`NoSectionError`. While it is possible to use
- :class:`RawConfigParser` (or :class:`ConfigParser` with *raw* parameters set to
+ :class:`RawConfigParser` (or :class:`~ConfigParser.ConfigParser` with *raw* parameters set to
true) for *internal* storage of non-string values, full functionality (including
interpolation and output to files) can only be achieved using string values.
ConfigParser Objects
--------------------
-The :class:`ConfigParser` class extends some methods of the
+The :class:`~ConfigParser.ConfigParser` class extends some methods of the
:class:`RawConfigParser` interface, adding some optional arguments.
------------------------
The :class:`SafeConfigParser` class implements the same extended interface as
-:class:`ConfigParser`, with the following addition:
+:class:`~ConfigParser.ConfigParser`, with the following addition:
.. method:: SafeConfigParser.set(section, option, value)
if config.getboolean('Section1', 'a_bool'):
print config.get('Section1', 'foo')
-To get interpolation, you will need to use a :class:`ConfigParser` or
+To get interpolation, you will need to use a :class:`~ConfigParser.ConfigParser` or
:class:`SafeConfigParser`::
import ConfigParser
The same security warning from :class:`SerialCookie` applies here.
A further security note is warranted. For backwards compatibility, the
-:mod:`Cookie` module exports a class named :class:`Cookie` which is just an
-alias for :class:`SmartCookie`. This is probably a mistake and will likely be
-removed in a future version. You should not use the :class:`Cookie` class in
-your applications, for the same reason why you should not use the
-:class:`SerialCookie` class.
+:mod:`Cookie` module exports a class named :class:`~Cookie.Cookie` which is
+just an alias for :class:`SmartCookie`. This is probably a mistake and will
+likely be removed in a future version. You should not use the
+:class:`~Cookie.Cookie` class in your applications, for the same reason why
+you should not use the :class:`SerialCookie` class.
.. seealso::
1) are treated according to the RFC 2965 rules. However, if RFC 2965 handling
is turned off or :attr:`rfc2109_as_netscape` is ``True``, RFC 2109 cookies are
'downgraded' by the :class:`CookieJar` instance to Netscape cookies, by
- setting the :attr:`version` attribute of the :class:`Cookie` instance to 0.
+ setting the :attr:`version` attribute of the :class:`~cookielib.Cookie` instance to 0.
:class:`DefaultCookiePolicy` also provides some parameters to allow some
fine-tuning of policy.
.. class:: Cookie()
This class represents Netscape, RFC 2109 and RFC 2965 cookies. It is not
- expected that users of :mod:`cookielib` construct their own :class:`Cookie`
+ expected that users of :mod:`cookielib` construct their own :class:`~cookielib.Cookie`
instances. Instead, if necessary, call :meth:`make_cookies` on a
:class:`CookieJar` instance.
-----------------------------------
:class:`CookieJar` objects support the :term:`iterator` protocol for iterating over
-contained :class:`Cookie` objects.
+contained :class:`~cookielib.Cookie` objects.
:class:`CookieJar` has the following methods:
.. method:: CookieJar.make_cookies(response, request)
- Return sequence of :class:`Cookie` objects extracted from *response* object.
+ Return sequence of :class:`~cookielib.Cookie` objects extracted from *response* object.
See the documentation for :meth:`extract_cookies` for the interfaces required of
the *response* and *request* arguments.
.. method:: CookieJar.set_cookie_if_ok(cookie, request)
- Set a :class:`Cookie` if policy says it's OK to do so.
+ Set a :class:`~cookielib.Cookie` if policy says it's OK to do so.
.. method:: CookieJar.set_cookie(cookie)
- Set a :class:`Cookie`, without checking with policy to see whether or not it
+ Set a :class:`~cookielib.Cookie`, without checking with policy to see whether or not it
should be set.
:meth:`path_return_ok` is called for the cookie path. Otherwise,
:meth:`path_return_ok` and :meth:`return_ok` are never called for that cookie
domain. If :meth:`path_return_ok` returns true, :meth:`return_ok` is called
- with the :class:`Cookie` object itself for a full check. Otherwise,
+ with the :class:`~cookielib.Cookie` object itself for a full check. Otherwise,
:meth:`return_ok` is never called for that cookie path.
Note that :meth:`domain_return_ok` is called for every *cookie* domain, not just
If true, request that the :class:`CookieJar` instance downgrade RFC 2109 cookies
(ie. cookies received in a :mailheader:`Set-Cookie` header with a version
cookie-attribute of 1) to Netscape cookies by setting the version attribute of
- the :class:`Cookie` instance to 0. The default value is :const:`None`, in which
+ the :class:`~cookielib.Cookie` instance to 0. The default value is :const:`None`, in which
case RFC 2109 cookies are downgraded if and only if RFC 2965 handling is turned
off. Therefore, RFC 2109 cookies are downgraded by default.
Cookie Objects
--------------
-:class:`Cookie` instances have Python attributes roughly corresponding to the
+:class:`~cookielib.Cookie` instances have Python attributes roughly corresponding to the
standard cookie-attributes specified in the various cookie standards. The
correspondence is not one-to-one, because there are complicated rules for
assigning default values, because the ``max-age`` and ``expires``
Set the value of the named cookie-attribute.
-The :class:`Cookie` class also defines the following method:
+The :class:`~cookielib.Cookie` class also defines the following method:
.. method:: Cookie.is_expired([now=None])
reference to themselves) may cause a recursive loop.
* Because deep copy copies *everything* it may copy too much, e.g.,
- administrative data structures that should be shared even between copies.
+ even administrative data structures that should be shared even between copies.
The :func:`deepcopy` function avoids these problems by:
Try to find a library and return a pathname. *name* is the library name without
any prefix like *lib*, suffix like ``.so``, ``.dylib`` or version number (this
- is the form used for the posix linker option :option:`-l`). If no library can
+ is the form used for the posix linker option :option:`!-l`). If no library can
be found, returns ``None``.
The exact functionality is system dependent.
it.
The *mode* parameter can be used to specify how the library is loaded. For
-details, consult the :manpage:`dlopen(3)` manpage, on Windows, *mode* is
-ignored.
+details, consult the :manpage:`dlopen(3)` manpage. On Windows, *mode* is
+ignored. On posix systems, RTLD_NOW is always added, and is not
+configurable.
-The *use_errno* parameter, when set to True, enables a ctypes mechanism that
+The *use_errno* parameter, when set to true, enables a ctypes mechanism that
allows accessing the system :data:`errno` error number in a safe way.
:mod:`ctypes` maintains a thread-local copy of the systems :data:`errno`
variable; if you call foreign functions created with ``use_errno=True`` then the
copy, and the function :func:`ctypes.set_errno` changes the ctypes private copy
to a new value and returns the former value.
-The *use_last_error* parameter, when set to True, enables the same mechanism for
+The *use_last_error* parameter, when set to true, enables the same mechanism for
the Windows error code which is managed by the :func:`GetLastError` and
:func:`SetLastError` Windows API functions; :func:`ctypes.get_last_error` and
:func:`ctypes.set_last_error` are used to request and change the ctypes private
The returned function prototype creates functions that use the standard C
calling convention. The function will release the GIL during the call. If
- *use_errno* is set to True, the ctypes private copy of the system
+ *use_errno* is set to true, the ctypes private copy of the system
:data:`errno` variable is exchanged with the real :data:`errno` value before
and after the call; *use_last_error* does the same for the Windows error
code.
Try to find a library and return a pathname. *name* is the library name
without any prefix like ``lib``, suffix like ``.so``, ``.dylib`` or version
- number (this is the form used for the posix linker option :option:`-l`). If
+ number (this is the form used for the posix linker option :option:`!-l`). If
no library can be found, returns ``None``.
The exact functionality is system dependent.
.. function:: isblank(c)
- Checks for an ASCII whitespace character.
+ Checks for an ASCII whitespace character; space or horizontal tab.
.. function:: iscntrl(c)
- Checks for an ASCII control character (in the range 0x00 to 0x1f).
+ Checks for an ASCII control character (in the range 0x00 to 0x1f or 0x7f).
.. function:: isdigit(c)
Return a string representation of the ASCII character *c*. If *c* is printable,
this string is the character itself. If the character is a control character
- (0x00-0x1f) the string consists of a caret (``'^'``) followed by the
+ (0x00--0x1f) the string consists of a caret (``'^'``) followed by the
corresponding uppercase letter. If the character is an ASCII delete (0x7f) the
string is ``'^?'``. If the character has its meta bit (0x80) set, the meta bit
is stripped, the preceding rules applied, and ``'!'`` prepended to the result.
Return the name of the key numbered *k*. The name of a key generating printable
ASCII character is the key's character. The name of a control-key combination
is a two-character string consisting of a caret followed by the corresponding
- printable ASCII character. The name of an alt-key combination (128-255) is a
+ printable ASCII character. The name of an alt-key combination (128--255) is a
string consisting of the prefix 'M-' followed by the name of the corresponding
ASCII character.
.. _datetime-time:
-:class:`time` Objects
----------------------
+:class:`.time` Objects
+----------------------
A time object represents a (local) time of day, independent of any particular
day, and subject to adjustment via a :class:`tzinfo` object.
.. method:: to_eng_string([context])
- Convert to an engineering-type string.
+ Convert to a string, using engineering notation if an exponent is needed.
- Engineering notation has an exponent which is a multiple of 3, so there
- are up to 3 digits left of the decimal place. For example, converts
- ``Decimal('123E+1')`` to ``Decimal('1.23E+3')``.
+ Engineering notation has an exponent which is a multiple of 3. This
+ can leave up to 3 digits to the left of the decimal place and may
+ require the addition of either one or two trailing zeros.
+
+ For example, this converts ``Decimal('123E+1')`` to ``Decimal('1.23E+3')``.
.. method:: to_integral([rounding[, context]])
.. method:: to_eng_string(x)
- Converts a number to a string, using scientific notation.
+ Convert to a string, using engineering notation if an exponent is needed.
+
+ Engineering notation has an exponent which is a multiple of 3. This
+ can leave up to 3 digits to the left of the decimal place and may
+ require the addition of either one or two trailing zeros.
.. method:: to_integral_exact(x)
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
+ a few lines of context. The changes are shown in an inline style (instead of
separate before/after blocks). The number of context lines is set by *n* which
defaults to three.
doctest.testmod()
If you run :file:`example.py` directly from the command line, :mod:`doctest`
-works its magic::
+works its magic:
+
+.. code-block:: shell-session
$ python example.py
$
There's no output! That's normal, and it means all the examples worked. Pass
``-v`` to the script, and :mod:`doctest` prints a detailed log of what
-it's trying, and prints a summary at the end::
+it's trying, and prints a summary at the end:
+
+.. code-block:: shell-session
$ python example.py -v
Trying:
[1, 1, 2, 6, 24, 120]
ok
-And so on, eventually ending with::
+And so on, eventually ending with:
+
+.. code-block:: none
Trying:
factorial(1e100)
That short script executes and verifies any interactive Python examples
contained in the file :file:`example.txt`. The file content is treated as if it
were a single giant docstring; the file doesn't need to contain a Python
-program! For example, perhaps :file:`example.txt` contains this::
+program! For example, perhaps :file:`example.txt` contains this:
+
+.. code-block:: none
The ``example`` module
======================
.. attribute:: docstring
- The string that the test was extracted from, or 'None' if the string is
+ The string that the test was extracted from, or ``None`` if the string is
unavailable, or if the test was not extracted from a string.
not specified, then ``obj.__name__`` is used.
The optional parameter *module* is the module that contains the given object.
- If the module is not specified or is None, then the test finder will attempt
+ If the module is not specified or is ``None``, then the test finder will attempt
to automatically determine the correct module. The object's module is used:
* As a default namespace, if *globs* is not specified.
The :mod:`DocXMLRPCServer` module extends the classes found in
:mod:`SimpleXMLRPCServer` to serve HTML documentation in response to HTTP GET
-requests. Servers can either be free standing, using :class:`DocXMLRPCServer`,
+requests. Servers can either be free standing, using :class:`~DocXMLRPCServer.DocXMLRPCServer`,
or embedded in a CGI environment, using :class:`DocCGIXMLRPCRequestHandler`.
Create a new request handler instance. This request handler supports XML-RPC
POST requests, documentation GET requests, and modifies logging so that the
- *logRequests* parameter to the :class:`DocXMLRPCServer` constructor parameter is
+ *logRequests* parameter to the :class:`~DocXMLRPCServer.DocXMLRPCServer` constructor parameter is
honored.
DocXMLRPCServer Objects
-----------------------
-The :class:`DocXMLRPCServer` class is derived from
+The :class:`~DocXMLRPCServer.DocXMLRPCServer` class is derived from
:class:`SimpleXMLRPCServer.SimpleXMLRPCServer` and provides a means of creating
self-documenting, stand alone XML-RPC servers. HTTP POST requests are handled as
XML-RPC method calls. HTTP GET requests are handled by generating pydoc-style
---------------
In addition to the methods provided by the :class:`UserDict.DictMixin` class,
-:class:`dumbdbm` objects provide the following methods.
+:class:`~dumbdbm.dumbdbm` objects provide the following methods.
.. method:: dumbdbm.sync()
+----------------------+------------------------------------------+
| *optstr* format | Command-line format |
+======================+==========================================+
- | ``x`` | :option:`-x` (short option) |
+ | ``x`` | :option:`!-x` (short option) |
+----------------------+------------------------------------------+
- | ``x:`` or ``x=`` | :option:`-x` (short option with value) |
+ | ``x:`` or ``x=`` | :option:`!-x` (short option with value) |
+----------------------+------------------------------------------+
- | ``xyz`` | :option:`--xyz` (long option) |
+ | ``xyz`` | :option:`!--xyz` (long option) |
+----------------------+------------------------------------------+
- | ``xyz:`` or ``xyz=`` | :option:`--xyz` (long option with value) |
+ | ``xyz:`` or ``xyz=`` | :option:`!--xyz` (long option with value)|
+----------------------+------------------------------------------+
*commandlist* is a list of items of the form *cmdstr* or ``(cmdstr, descr)``,
Bootstraps ``pip`` into the current or designated environment.
*root* specifies an alternative root directory to install relative to.
- If *root* is None, then installation uses the default install location
+ If *root* is ``None``, then installation uses the default install location
for the current environment.
*upgrade* indicates whether or not to upgrade an existing installation
.. function:: translate(pattern)
- Return the shell-style *pattern* converted to a regular expression.
+ Return the shell-style *pattern* converted to a regular expression for
+ using with :func:`re.match`.
Example:
.. index:: single: HTMLParser (class in htmllib)
This module supports two interface definitions, each with multiple
-implementations. The *formatter* interface is used by the :class:`HTMLParser`
+implementations. The *formatter* interface is used by the :class:`~HTMLParser.HTMLParser`
class of the :mod:`htmllib` module, and the *writer* interface is required by
the formatter interface.
.. class:: DumbWriter(file=None, maxcol=72)
Simple writer class which writes output on the file object passed in as *file*
- or, if *file* is None, on standard output. The output is simply word-wrapped
+ or, if *file* is ``None``, on standard output. The output is simply word-wrapped
to the number of columns specified by *maxcol*. This class is suitable for
reflowing a sequence of paragraphs.
.. method:: FTP.transfercmd(cmd[, rest])
- Initiate a transfer over the data connection. If the transfer is active, send a
+ Initiate a transfer over the data connection. If the transfer is active, send an
``EPRT`` or ``PORT`` command and the transfer command specified by *cmd*, and
- accept the connection. If the server is passive, send a ``EPSV`` or ``PASV``
+ accept the connection. If the server is passive, send an ``EPSV`` or ``PASV``
command, connect to it, and start the transfer command. Either way, return the
socket for the connection.
:func:`dir` reports their attributes.
If the object does not provide :meth:`__dir__`, the function tries its best to
- gather information from the object's :attr:`__dict__` attribute, if defined, and
+ gather information from the object's :attr:`~object.__dict__` attribute, if defined, and
from its type object. The resulting list is not necessarily complete, and may
be inaccurate when the object has a custom :func:`__getattr__`.
preceded by ``+`` or ``-`` (with no space in between) and surrounded by
whitespace. A base-n literal consists of the digits 0 to n-1, with ``a``
to ``z`` (or ``A`` to ``Z``) having
- values 10 to 35. The default *base* is 10. The allowed values are 0 and 2-36.
+ values 10 to 35. The default *base* is 10. The allowed values are 0 and 2--36.
Base-2, -8, and -16 literals can be optionally prefixed with ``0b``/``0B``,
``0o``/``0O``/``0``, or ``0x``/``0X``, as with integer literals in code.
Base 0 means to interpret the string exactly as an integer literal, so that
With three arguments, return a new type object. This is essentially a
dynamic form of the :keyword:`class` statement. The *name* string is the
- class name and becomes the :attr:`~class.__name__` attribute; the *bases* tuple
+ class name and becomes the :attr:`~definition.__name__` attribute; the *bases* tuple
itemizes the base classes and becomes the :attr:`~class.__bases__` attribute;
and the *dict* dictionary is the namespace containing definitions for class
body and becomes the :attr:`~object.__dict__` attribute. For example, the
.. function:: vars([object])
Return the :attr:`~object.__dict__` attribute for a module, class, instance,
- or any other object with a :attr:`__dict__` attribute.
+ or any other object with a :attr:`~object.__dict__` attribute.
- Objects such as modules and instances have an updateable :attr:`__dict__`
+ Objects such as modules and instances have an updateable :attr:`~object.__dict__`
attribute; however, other objects may have write restrictions on their
- :attr:`__dict__` attributes (for example, new-style classes use a
+ :attr:`~object.__dict__` attributes (for example, new-style classes use a
dictproxy to prevent direct dictionary updates).
Without an argument, :func:`vars` acts like :func:`locals`. Note, the
:class:`partial` objects are like :class:`function` objects in that they are
callable, weak referencable, and can have attributes. There are some important
-differences. For instance, the :attr:`__name__` and :attr:`__doc__` attributes
+differences. For instance, the :attr:`~definition.__name__` and :attr:`__doc__` attributes
are not created automatically. Also, :class:`partial` objects defined in
classes behave like static methods and do not transform into bound methods
during instance attribute look-up.
*fileobj*, since you might wish to append more material after the compressed
data. This also allows you to pass a :class:`~StringIO.StringIO` object opened for
writing as *fileobj*, and retrieve the resulting memory buffer using the
- :class:`StringIO` object's :meth:`~StringIO.StringIO.getvalue` method.
+ :class:`~StringIO.StringIO` object's :meth:`~StringIO.StringIO.getvalue` method.
:class:`GzipFile` supports iteration and the :keyword:`with` statement.
If *a* and *b* are of different lengths, or if an error occurs,
a timing attack could theoretically reveal information about the
- types and lengths of *a* and *b*--but not their values.
+ types and lengths of *a* and *b*—but not their values.
.. versionadded:: 2.7.7
formatted in the HyperText Mark-up Language (HTML). The class is not directly
concerned with I/O --- it must be provided with input in string form via a
method, and makes calls to methods of a "formatter" object in order to produce
-output. The :class:`HTMLParser` class is designed to be used as a base class
+output. The :class:`~HTMLParser.HTMLParser` class is designed to be used as a base class
for other classes in order to add functionality, and allows most of its methods
to be extended or overridden. In turn, this class is derived from and extends
the :class:`SGMLParser` class defined in module :mod:`sgmllib`. The
-:class:`HTMLParser` implementation supports the HTML 2.0 language as described
+:class:`~HTMLParser.HTMLParser` implementation supports the HTML 2.0 language as described
in :rfc:`1866`. Two implementations of formatter objects are provided in the
:mod:`formatter` module; refer to the documentation for that module for
information on the formatter interface.
.. exception:: HTMLParseError
- Exception raised by the :class:`HTMLParser` class when it encounters an error
+ Exception raised by the :class:`~HTMLParser.HTMLParser` class when it encounters an error
while parsing.
.. versionadded:: 2.4
Definition of replacement text for XHTML 1.0 entities.
Module :mod:`sgmllib`
- Base class for :class:`HTMLParser`.
+ Base class for :class:`~HTMLParser.HTMLParser`.
.. _html-parser-objects:
HTMLParser Objects
------------------
-In addition to tag methods, the :class:`HTMLParser` class provides some
+In addition to tag methods, the :class:`~HTMLParser.HTMLParser` class provides some
additional methods and instance variables for use within tag methods.
This module defines three dictionaries, ``name2codepoint``, ``codepoint2name``,
and ``entitydefs``. ``entitydefs`` is used by the :mod:`htmllib` module to
-provide the :attr:`entitydefs` attribute of the :class:`HTMLParser` class. The
+provide the :attr:`entitydefs` attribute of the :class:`~HTMLParser.HTMLParser` class. The
definition provided here contains all the entities defined by XHTML 1.0 that
can be handled using simple textual substitution in the Latin-1 character set
(ISO-8859-1).
parser.feed('<html><head><title>Test</title></head>'
'<body><h1>Parse me!</h1></body></html>')
-The output will then be::
+The output will then be:
+
+.. code-block:: none
Encountered a start tag: html
Encountered a start tag: head
server. It should be instantiated passing it a host and optional port
number. If no port number is passed, the port is extracted from the host
string if it has the form ``host:port``, else the default HTTP port (80) is
- used. When True, the optional parameter *strict* (which defaults to a false
+ used. When true, the optional parameter *strict* (which defaults to a false
value) causes ``BadStatusLine`` to
be raised if the status line can't be parsed as a valid HTTP/1.0 or 1.1
status line. If the optional *timeout* parameter is given, blocking
Restart Shell
Restart the shell to clean the environment.
+Interrupt Execution
+ Stop a running program.
+
Debug menu (Shell window only)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Command line usage
^^^^^^^^^^^^^^^^^^
-::
+.. code-block:: none
idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
-c command run command in the shell window
-d enable debugger and open shell window
-e open editor window
- -h print help message with legal combinatios and exit
+ -h print help message with legal combinations and exit
-i open shell window
-r file run file in shell window
-s run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window
``print`` will not work correctly.
With IDLE's Shell, one enters, edits, and recalls complete statements.
-Some consoles only work with a single physical line at a time.
+Some consoles only work with a single physical line at a time. IDLE uses
+``exec`` to run each statement. As a result, ``'__builtins__'`` is always
+defined for each statement.
Running without a subprocess
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Parse an IMAP4 ``INTERNALDATE`` string and return corresponding local
time. The return value is a :class:`time.struct_time` instance or
- None if the string has wrong format.
+ ``None`` if the string has wrong format.
.. function:: Int2AP(num)
| | gi_code | code object | |
+-----------+-----------------+---------------------------+-------+
| | gi_frame | frame object or possibly | |
-| | | None once the generator | |
-| | | has been exhausted | |
+| | | ``None`` once the | |
+| | | generator has been | |
+| | | exhausted | |
+-----------+-----------------+---------------------------+-------+
| | gi_running | set to 1 when generator | |
| | | is executing, 0 otherwise | |
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 :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.
+ ``int.__add__``. An object passing this test
+ has a :meth:`~object.__get__` method but not a :meth:`~object.__set__`
+ method, but beyond that the set of attributes varies. A
+ :attr:`~definition.__name__` attribute is usually
+ sensible, and :attr:`__doc__` often is.
Methods implemented via descriptors that also pass one of the other tests
return false from the :func:`ismethoddescriptor` test, simply because the
Return true if the object is a data descriptor.
- Data descriptors have both a :attr:`__get__` and a :attr:`__set__` attribute.
+ Data descriptors have both a :attr:`~object.__get__` and a :attr:`~object.__set__` method.
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
+ descriptors will also have :attr:`~definition.__name__` and :attr:`__doc__` attributes
(properties, getsets, and members have both of these attributes), but this is
not guaranteed.
four things is returned: ``(args, varargs, keywords, defaults)``. *args* is a
list of the argument names (it may contain nested lists). *varargs* and
*keywords* are the names of the ``*`` and ``**`` arguments or
- ``None``. *defaults* is a tuple of default argument values or None if there
+ ``None``. *defaults* is a tuple of default argument values or ``None`` if there
are no default arguments; if this tuple has *n* elements, they correspond to
the last *n* elements listed in *args*.
streams whose bytes represent text, and handles encoding and decoding
from and to :class:`unicode` strings. :class:`TextIOWrapper`, which extends
it, is a buffered text interface to a buffered raw stream
-(:class:`BufferedIOBase`). Finally, :class:`StringIO` is an in-memory
+(:class:`BufferedIOBase`). Finally, :class:`~io.StringIO` is an in-memory
stream for unicode text.
Argument names are not part of the specification, and only the arguments of
the list of supported encodings.
*errors* is an optional string that specifies how encoding and decoding
- errors are to be handled--this cannot be used in binary mode. Pass
+ errors are to be handled—this cannot be used in binary mode. Pass
``'strict'`` to raise a :exc:`ValueError` exception if there is an encoding
error (the default of ``None`` has the same effect), or pass ``'ignore'`` to
ignore errors. (Note that ignoring encoding errors can lead to data loss.)
It is also possible to use an :class:`unicode` or :class:`bytes` string
as a file for both reading and writing. For :class:`unicode` strings
- :class:`StringIO` can be used like a file opened in text mode,
+ :class:`~io.StringIO` can be used like a file opened in text mode,
and for :class:`bytes` a :class:`BytesIO` can be used like a
file opened in a binary mode.
Even though :class:`IOBase` does not declare :meth:`read`, :meth:`readinto`,
or :meth:`write` because their signatures will vary, implementations and
clients should consider those methods part of the interface. Also,
- implementations may raise a :exc:`IOError` when operations they do not
+ implementations may raise an :exc:`IOError` when operations they do not
support are called.
The basic type used for binary data read from or written to a file is
After the underlying buffer has been detached, the :class:`TextIOBase` is
in an unusable state.
- Some :class:`TextIOBase` implementations, like :class:`StringIO`, may not
+ Some :class:`TextIOBase` implementations, like :class:`~io.StringIO`, may not
have the concept of an underlying buffer and calling this method will
raise :exc:`UnsupportedOperation`.
newlines are written as ``\n`` on all platforms, but universal
newline decoding is still performed when reading.
- :class:`StringIO` provides this method in addition to those from
+ :class:`~io.StringIO` provides this method in addition to those from
:class:`TextIOWrapper` and its parents:
.. method:: getvalue()
Return a ``unicode`` containing the entire contents of the buffer at any
- time before the :class:`StringIO` object's :meth:`close` method is
+ time before the :class:`~io.StringIO` object's :meth:`close` method is
called. Newlines are decoded as if by :meth:`~TextIOBase.read`,
although the stream position is not changed.
Also, :meth:`TextIOWrapper.tell` and :meth:`TextIOWrapper.seek` are both
quite slow due to the reconstruction algorithm used.
-:class:`StringIO`, however, is a native in-memory unicode container and will
+:class:`~io.StringIO`, however, is a native in-memory unicode container and will
exhibit similar speed to :class:`BytesIO`.
Multi-threading
.. highlight:: none
-Using json.tool from the shell to validate and pretty-print::
+Using :mod:`json.tool` from the shell to validate and pretty-print::
- $ echo '{"json":"obj"}' | python -mjson.tool
+ $ echo '{"json":"obj"}' | python -m json.tool
{
"json": "obj"
}
:term:`file-like object`) using this :ref:`conversion table
<py-to-json-table>`.
- If *skipkeys* is ``True`` (default: ``False``), then dict keys that are not
+ If *skipkeys* is true (default: ``False``), then dict keys that are not
of a basic type (:class:`str`, :class:`unicode`, :class:`int`, :class:`long`,
:class:`float`, :class:`bool`, ``None``) will be skipped instead of raising a
:exc:`TypeError`.
- If *ensure_ascii* is ``True`` (the default), all non-ASCII characters in the
+ If *ensure_ascii* is true (the default), all non-ASCII characters in the
output are escaped with ``\uXXXX`` sequences, and the result is a
:class:`str` instance consisting of ASCII characters only. If
- *ensure_ascii* is ``False``, some chunks written to *fp* may be
+ *ensure_ascii* is false, some chunks written to *fp* may be
:class:`unicode` instances. This usually happens because the input contains
unicode strings or the *encoding* parameter is used. Unless ``fp.write()``
explicitly understands :class:`unicode` (as in :func:`codecs.getwriter`)
this is likely to cause an error.
- If *check_circular* is ``False`` (default: ``True``), then the circular
+ If *check_circular* is false (default: ``True``), then the circular
reference check for container types will be skipped and a circular reference
will result in an :exc:`OverflowError` (or worse).
- If *allow_nan* is ``False`` (default: ``True``), then it will be a
+ If *allow_nan* is false (default: ``True``), then it will be a
:exc:`ValueError` to serialize out of range :class:`float` values (``nan``,
- ``inf``, ``-inf``) in strict compliance of the JSON specification, instead of
- using the JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
+ ``inf``, ``-inf``) in strict compliance of the JSON specification.
+ If *allow_nan* is true, their JavaScript equivalents (``NaN``,
+ ``Infinity``, ``-Infinity``) will be used.
If *indent* is a non-negative integer, then JSON array elements and object
members will be pretty-printed with that indent level. An indent level of 0,
trailing whitespace when *indent* is specified. You can use
``separators=(',', ': ')`` to avoid this.
- If *separators* is an ``(item_separator, dict_separator)`` tuple, then it
- will be used instead of the default ``(', ', ': ')`` separators. ``(',',
- ':')`` is the most compact JSON representation.
+ If specified, *separators* should be an ``(item_separator, key_separator)``
+ tuple. By default, ``(', ', ': ')`` are used. To get the most compact JSON
+ representation, you should specify ``(',', ':')`` to eliminate whitespace.
*encoding* is the character encoding for str instances, default is UTF-8.
- *default(obj)* is a function that should return a serializable version of
- *obj* or raise :exc:`TypeError`. The default simply raises :exc:`TypeError`.
+ If specified, *default* should be a function that gets called for objects that
+ can't otherwise be serialized. It should return a JSON encodable version of
+ the object or raise a :exc:`TypeError`. If not specified, :exc:`TypeError`
+ is raised.
- If *sort_keys* is ``True`` (default: ``False``), then the output of
+ If *sort_keys* is true (default: ``False``), then the output of
dictionaries will be sorted by key.
To use a custom :class:`JSONEncoder` subclass (e.g. one that overrides the
default=None, sort_keys=False, **kw)
Serialize *obj* to a JSON formatted :class:`str` using this :ref:`conversion
- table <py-to-json-table>`. If *ensure_ascii* is ``False``, the result may
+ table <py-to-json-table>`. If *ensure_ascii* is false, the result may
contain non-ASCII characters and the return value may be a :class:`unicode`
instance.
(e.g. :class:`float`).
*parse_constant*, if specified, will be called with one of the following
- strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``, ``'null'``, ``'true'``,
- ``'false'``. This can be used to raise an exception if invalid JSON numbers
+ strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``.
+ This can be used to raise an exception if invalid JSON numbers
are encountered.
- If *strict* is ``False`` (``True`` is the default), then control characters
+ If *strict* is false (``True`` is the default), then control characters
will be allowed inside strings. Control characters in this context are
- those with character codes in the 0-31 range, including ``'\t'`` (tab),
+ those with character codes in the 0--31 range, including ``'\t'`` (tab),
``'\n'``, ``'\r'`` and ``'\0'``.
If the data being deserialized is not a valid JSON document, a
for ``o`` if possible, otherwise it should call the superclass implementation
(to raise :exc:`TypeError`).
- If *skipkeys* is ``False`` (the default), then it is a :exc:`TypeError` to
- attempt encoding of keys that are not str, int, long, float or None. If
- *skipkeys* is ``True``, such items are simply skipped.
+ If *skipkeys* is false (the default), then it is a :exc:`TypeError` to
+ attempt encoding of keys that are not str, int, long, float or ``None``. If
+ *skipkeys* is true, such items are simply skipped.
- If *ensure_ascii* is ``True`` (the default), all non-ASCII characters in the
+ If *ensure_ascii* is true (the default), all non-ASCII characters in the
output are escaped with ``\uXXXX`` sequences, and the results are
:class:`str` instances consisting of ASCII characters only. If
- *ensure_ascii* is ``False``, a result may be a :class:`unicode`
+ *ensure_ascii* is false, a result may be a :class:`unicode`
instance. This usually happens if the input contains unicode strings or the
*encoding* parameter is used.
- If *check_circular* is ``True`` (the default), then lists, dicts, and custom
+ If *check_circular* is true (the default), then lists, dicts, and custom
encoded objects will be checked for circular references during encoding to
prevent an infinite recursion (which would cause an :exc:`OverflowError`).
Otherwise, no such check takes place.
- If *allow_nan* is ``True`` (the default), then ``NaN``, ``Infinity``, and
+ If *allow_nan* is true (the default), then ``NaN``, ``Infinity``, and
``-Infinity`` will be encoded as such. This behavior is not JSON
specification compliant, but is consistent with most JavaScript based
encoders and decoders. Otherwise, it will be a :exc:`ValueError` to encode
such floats.
- If *sort_keys* is ``True`` (default ``False``), then the output of dictionaries
+ If *sort_keys* is true (default: ``False``), then the output of dictionaries
will be sorted by key; this is useful for regression tests to ensure that
JSON serializations can be compared on a day-to-day basis.
``separators=(',', ': ')`` to avoid this.
If specified, *separators* should be an ``(item_separator, key_separator)``
- tuple. The default is ``(', ', ': ')``. To get the most compact JSON
+ tuple. By default, ``(', ', ': ')`` are used. To get the most compact JSON
representation, you should specify ``(',', ':')`` to eliminate whitespace.
- If specified, *default* is a function that gets called for objects that can't
- otherwise be serialized. It should return a JSON encodable version of the
- object or raise a :exc:`TypeError`.
+ If specified, *default* should be a function that gets called for objects that
+ can't otherwise be serialized. It should return a JSON encodable version of
+ the object or raise a :exc:`TypeError`. If not specified, :exc:`TypeError`
+ is raised.
If *encoding* is not ``None``, then all input strings will be transformed
into unicode using that encoding prior to JSON-encoding. The default is
handler.
All *other* keys are passed through as keyword arguments to the
- handler's constructor. For example, given the snippet::
+ handler's constructor. For example, given the snippet:
+
+ .. code-block:: yaml
handlers:
console:
configuration to indicate that a connection exists between the source
and the destination object with that id.
-So, for example, consider the following YAML snippet::
+So, for example, consider the following YAML snippet:
+
+.. code-block:: yaml
formatters:
brief:
configuration dictionary and which returns the instantiated object.
This is signalled by an absolute import path to the factory being
made available under the special key ``'()'``. Here's a concrete
-example::
+example:
+
+.. code-block:: yaml
formatters:
brief:
:func:`dictConfig`, so it's worth considering transitioning to this newer
API when it's convenient to do so.
-Examples of these sections in the file are given below. ::
+Examples of these sections in the file are given below.
+
+.. code-block:: ini
[loggers]
keys=root,log02,log03,log04,log05,log06,log07
keys=form01,form02,form03,form04,form05,form06,form07,form08,form09
The root logger must specify a level and a list of handlers. An example of a
-root logger section is given below. ::
+root logger section is given below.
+
+.. code-block:: ini
[logger_root]
level=NOTSET
file.
For loggers other than the root logger, some additional information is required.
-This is illustrated by the following example. ::
+This is illustrated by the following example.
+
+.. code-block:: ini
[logger_parser]
level=DEBUG
say the name used by the application to get the logger.
Sections which specify handler configuration are exemplified by the following.
-::
+
+.. code-block:: ini
[handler_hand01]
class=StreamHandler
The ``args`` entry, when :func:`eval`\ uated in the context of the ``logging``
package's namespace, is the list of arguments to the constructor for the handler
class. Refer to the constructors for the relevant handlers, or to the examples
-below, to see how typical entries are constructed. ::
+below, to see how typical entries are constructed.
+
+.. code-block:: ini
[handler_hand02]
class=FileHandler
formatter=form09
args=('localhost:9022', '/log', 'GET')
-Sections which specify formatter configuration are typified by the following. ::
+Sections which specify formatter configuration are typified by the following.
+
+.. code-block:: ini
[formatter_form01]
format=F1 %(asctime)s %(levelname)s %(message)s
Module :mod:`logging.handlers`
Useful handlers included with the logging module.
-
-
Returns a new instance of the :class:`FileHandler` class. The specified file is
opened and used as the stream for logging. If *mode* is not specified,
- :const:`'a'` is used. If *encoding* is not *None*, it is used to open the file
+ :const:`'a'` is used. If *encoding* is not ``None``, it is used to open the file
with that encoding. If *delay* is true, then file opening is deferred until the
first call to :meth:`emit`. By default, the file grows indefinitely.
Returns a new instance of the :class:`WatchedFileHandler` class. The specified
file is opened and used as the stream for logging. If *mode* is not specified,
- :const:`'a'` is used. If *encoding* is not *None*, it is used to open the file
+ :const:`'a'` is used. If *encoding* is not ``None``, it is used to open the file
with that encoding. If *delay* is true, then file opening is deferred until the
first call to :meth:`emit`. By default, the file grows indefinitely.
Returns a new instance of the :class:`RotatingFileHandler` class. The specified
file is opened and used as the stream for logging. If *mode* is not specified,
- ``'a'`` is used. If *encoding* is not *None*, it is used to open the file
+ ``'a'`` is used. If *encoding* is not ``None``, it is used to open the file
with that encoding. If *delay* is true, then file opening is deferred until the
first call to :meth:`emit`. By default, the file grows indefinitely.
:param args: Variable data to merge into the *msg* argument to obtain the
event description.
:param exc_info: An exception tuple with the current exception information,
- or *None* if no exception information is available.
+ or ``None`` if no exception information is available.
:param func: The name of the function or method from which the logging call
was invoked.
| | | (as returned by :func:`time.time`). |
+----------------+-------------------------+-----------------------------------------------+
| exc_info | You shouldn't need to | Exception tuple (Ã la ``sys.exc_info``) or, |
-| | format this yourself. | if no exception has occurred, *None*. |
+| | format this yourself. | if no exception has occurred, ``None``. |
+----------------+-------------------------+-----------------------------------------------+
| filename | ``%(filename)s`` | Filename portion of ``pathname``. |
+----------------+-------------------------+-----------------------------------------------+
The :mod:`email` package should be used in preference to the :mod:`MimeWriter`
module. This module is present only to maintain backward compatibility.
-This module defines the class :class:`MimeWriter`. The :class:`MimeWriter`
+This module defines the class :class:`~MimeWriter.MimeWriter`. The :class:`~MimeWriter.MimeWriter`
class implements a basic formatter for creating MIME multi-part files. It
doesn't seek around the output file nor does it use large amounts of buffer
space. You must write the parts out in the order that they should occur in the
-final file. :class:`MimeWriter` does buffer the headers you add, allowing you
+final file. :class:`~MimeWriter.MimeWriter` does buffer the headers you add, allowing you
to rearrange their order.
.. class:: MimeWriter(fp)
- Return a new instance of the :class:`MimeWriter` class. The only argument
+ Return a new instance of the :class:`~MimeWriter.MimeWriter` class. The only argument
passed, *fp*, is a file object to be used for writing. Note that a
:class:`~StringIO.StringIO` object could also be used.
MimeWriter Objects
------------------
-:class:`MimeWriter` instances have the following methods:
+:class:`~MimeWriter.MimeWriter` instances have the following methods:
.. method:: MimeWriter.addheader(key, value[, prefix])
.. method:: MimeWriter.nextpart()
- Returns a new instance of :class:`MimeWriter` which represents an individual
+ Returns a new instance of :class:`~MimeWriter.MimeWriter` which represents an individual
part in a multipart message. This may be used to write the part as well as
used for creating recursively complex multipart messages. The message must first
be initialized with :meth:`startmultipartbody` before using :meth:`nextpart`.
also read and write data starting at the current file position, and
:meth:`seek` through the file to different positions.
-A memory-mapped file is created by the :class:`mmap` constructor, which is
+A memory-mapped file is created by the :class:`~mmap.mmap` constructor, which is
different on Unix and on Windows. In either case you must provide a file
descriptor for a file opened for update. If you wish to map an existing Python
file object, use its :meth:`fileno` method to obtain the correct value for the
**(Unix version)** Maps *length* bytes from the file specified by the file
descriptor *fileno*, and returns a mmap object. If *length* is ``0``, the
maximum length of the map will be the current size of the file when
- :class:`mmap` is called.
+ :class:`~mmap.mmap` is called.
*flags* specifies the nature of the mapping. :const:`MAP_PRIVATE` creates a
private copy-on-write mapping, so changes to the contents of the mmap
by the descriptor *fileno* is internally automatically synchronized
with physical backing store on Mac OS X and OpenVMS.
- This example shows a simple way of using :class:`mmap`::
+ This example shows a simple way of using :class:`~mmap.mmap`::
import mmap
.. versionadded:: 2.7
*maxtasksperchild* is the number of tasks a worker process can complete
before it will exit and be replaced with a fresh worker process, to enable
- unused resources to be freed. The default *maxtasksperchild* is None, which
+ unused resources to be freed. The default *maxtasksperchild* is ``None``, which
means worker processes will live as long as the pool.
.. note::
``None`` then digest authentication is used.
If *authkey* is a string then it will be used as the authentication key;
- otherwise it must be *None*.
+ otherwise it must be ``None``.
If *authkey* is ``None`` and *authenticate* is ``True`` then
``current_process().authkey`` is used as the authentication key. If
Mutex Objects
-------------
-:class:`mutex` objects have following methods:
+:class:`~mutex.mutex` objects have following methods:
.. method:: mutex.test()
--------------
-The :class:`netrc` class parses and encapsulates the netrc file format used by
+The :class:`~netrc.netrc` class parses and encapsulates the netrc file format used by
the Unix :program:`ftp` program and other FTP clients.
.. class:: netrc([file])
- A :class:`netrc` instance or subclass instance encapsulates data from a netrc
+ A :class:`~netrc.netrc` instance or subclass instance encapsulates data from a netrc
file. The initialization argument, if present, specifies the file to parse. If
no argument is given, the file :file:`.netrc` in the user's home directory will
be read. Parse errors will raise :exc:`NetrcParseError` with diagnostic
.. exception:: NetrcParseError
- Exception raised by the :class:`netrc` class when syntactical errors are
+ Exception raised by the :class:`~netrc.netrc` class when syntactical errors are
encountered in source text. Instances of this exception provide three
interesting attributes: :attr:`msg` is a textual explanation of the error,
:attr:`filename` is the name of the source file, and :attr:`lineno` gives the
netrc Objects
-------------
-A :class:`netrc` instance has the following methods:
+A :class:`~netrc.netrc` instance has the following methods:
.. method:: netrc.authenticators(host)
Dump the class data as a string in the format of a netrc file. (This discards
comments and may reorder the entries.)
-Instances of :class:`netrc` have public instance variables:
+Instances of :class:`~netrc.netrc` have public instance variables:
.. attribute:: netrc.hosts
this option on the command line, it expands your ``version`` string (by
replacing ``%prog``), prints it to stdout, and exits.
-For example, if your script is called ``/usr/bin/foo``::
+For example, if your script is called ``/usr/bin/foo``:
+
+.. code-block:: shell-session
$ /usr/bin/foo --version
foo 1.0
error status 2.
Consider the first example above, where the user passes ``4x`` to an option
-that takes an integer::
+that takes an integer:
+
+.. code-block:: shell-session
$ /usr/bin/foo -n 4x
Usage: foo [options]
foo: error: option -n: invalid integer value: '4x'
-Or, where the user fails to pass a value at all::
+Or, where the user fails to pass a value at all:
+
+.. code-block:: shell-session
$ /usr/bin/foo -n
Usage: foo [options]
the list of arguments to process (default: ``sys.argv[1:]``)
``values``
- a :class:`optparse.Values` object to store option arguments in (default: a
+ an :class:`optparse.Values` object to store option arguments in (default: a
new instance of :class:`Values`) -- if you give an existing object, the
option defaults will not be initialized on it
values.ensure_value(attr, value)
- If the ``attr`` attribute of ``values`` doesn't exist or is None, then
+ If the ``attr`` attribute of ``values`` doesn't exist or is ``None``, then
ensure_value() first sets it to ``value``, and then returns 'value. This is
very handy for actions like ``"extend"``, ``"append"``, and ``"count"``, all
of which accumulate data in a variable and expect that variable to be of a
certain type (a list for the first two, an integer for the latter). Using
:meth:`ensure_value` means that scripts using your action don't have to worry
about setting a default value for the option destinations in question; they
- can just leave the default as None and :meth:`ensure_value` will take care of
+ can just leave the default as ``None`` and :meth:`ensure_value` will take care of
getting it right when it's needed.
.. function:: samefile(path1, path2)
Return ``True`` if both pathname arguments refer to the same file or directory
- (as indicated by device number and i-node number). Raise an exception if a
+ (as indicated by device number and i-node number). Raise an exception if an
:func:`os.stat` call on either pathname fails.
Availability: Unix.
O_EXCL
O_TRUNC
- These constants are available on Unix and Windows.
+ The above constants are available on Unix and Windows.
.. data:: O_DSYNC
O_NDELAY
O_NONBLOCK
O_NOCTTY
- O_SHLOCK
- O_EXLOCK
- These constants are only available on Unix.
+ The above constants are only available on Unix.
.. data:: O_BINARY
O_SEQUENTIAL
O_TEXT
- These constants are only available on Windows.
+ The above constants are only available on Windows.
.. data:: O_ASYNC
O_DIRECTORY
O_NOFOLLOW
O_NOATIME
+ O_SHLOCK
+ O_EXLOCK
- These constants are GNU extensions and not present if they are not defined by
- the C library.
+ The above constants are extensions and not present if they are not
+ defined by the C library.
.. _os-file-dir:
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
- breakpoint--which could have its own command list, leading to ambiguities about
+ breakpoint—which could have its own command list, leading to ambiguities about
which list to execute.
If you use the 'silent' command in the command list, the usual message about
.. function:: compile(file[, cfile[, dfile[, doraise]]])
Compile a source file to byte-code and write out the byte-code cache file. The
- source code is loaded from the file name *file*. The byte-code is written to
+ source code is loaded from the file named *file*. The byte-code is written to
*cfile*, which defaults to *file* ``+`` ``'c'`` (``'o'`` if optimization is
enabled in the current interpreter). If *dfile* is specified, it is used as the
name of the source file in error messages instead of *file*. If *doraise* is
separator.
For example, if *namespace_separator* is set to a space character (``' '``) and
- the following document is parsed::
+ the following document is parsed:
+
+ .. code-block:: xml
<?xml version="1.0"?>
<root xmlns = "http://default-namespace.org/"
The following attributes contain values relating to the most recent error
encountered by an :class:`xmlparser` object, and will only have correct values
-once a call to :meth:`Parse` or :meth:`ParseFile` has raised a
+once a call to :meth:`Parse` or :meth:`ParseFile` has raised an
:exc:`xml.parsers.expat.ExpatError` exception.
The :mod:`Queue` module implements multi-producer, multi-consumer queues.
It is especially useful in threaded programming when information must be
-exchanged safely between multiple threads. The :class:`Queue` class in this
+exchanged safely between multiple threads. The :class:`~Queue.Queue` class in this
module implements all the required locking semantics. It depends on the
availability of thread support in Python; see the :mod:`threading`
module.
Exception raised when non-blocking :meth:`~Queue.get` (or
:meth:`~Queue.get_nowait`) is called
- on a :class:`Queue` object which is empty.
+ on a :class:`~Queue.Queue` object which is empty.
.. exception:: Full
Exception raised when non-blocking :meth:`~Queue.put` (or
:meth:`~Queue.put_nowait`) is called
- on a :class:`Queue` object which is full.
+ on a :class:`~Queue.Queue` object which is full.
.. seealso::
Queue Objects
-------------
-Queue objects (:class:`Queue`, :class:`LifoQueue`, or :class:`PriorityQueue`)
+Queue objects (:class:`~Queue.Queue`, :class:`LifoQueue`, or :class:`PriorityQueue`)
provide the public methods described below.
.. method:: Queue.put(item[, block[, timeout]])
Put *item* into the queue. If optional args *block* is true and *timeout* is
- None (the default), block if necessary until a free slot is available. If
+ ``None`` (the default), block if necessary until a free slot is available. If
*timeout* is a positive number, it blocks at most *timeout* seconds and raises
the :exc:`Full` exception if no free slot was available within that time.
Otherwise (*block* is false), put an item on the queue if a free slot is
.. method:: Queue.get([block[, timeout]])
Remove and return an item from the queue. If optional args *block* is true and
- *timeout* is None (the default), block if necessary until an item is available.
+ *timeout* is ``None`` (the default), block if necessary until an item is available.
If *timeout* is a positive number, it blocks at most *timeout* seconds and
raises the :exc:`Empty` exception if no item was available within that time.
Otherwise (*block* is false), return an item if one is immediately available,
they are used instead of the system time (see the :func:`os.urandom` function
for details on availability).
+ If a :term:`hashable` object is given, deterministic results are only assured
+ when :envvar:`PYTHONHASHSEED` is disabled.
+
.. versionchanged:: 2.4
formerly, operating system resources were not used.
M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-dimensionally
equidistributed uniform pseudorandom number generator", ACM Transactions on
- Modeling and Computer Simulation Vol. 8, No. 1, January pp.3-30 1998.
+ Modeling and Computer Simulation Vol. 8, No. 1, January pp.3--30 1998.
Wichmann, B. A. & Hill, I. D., "Algorithm AS 183: An efficient and portable
pseudo-random number generator", Applied Statistics 31 (1982) 188-190.
expression pattern strings may not contain null bytes, but can specify
the null byte using the ``\number`` notation, e.g., ``'\x00'``.
+Repetition qualifiers (``*``, ``+``, ``?``, ``{m,n}``, etc) cannot be
+directly nested. This avoids ambiguity with the non-greedy modifier suffix
+``?``, and with other modifiers in other implementations. To apply a second
+repetition to an inner repetition, parentheses may be used. For example,
+the expression ``(?:a{6})*`` matches any multiple of six ``'a'`` characters.
+
The special characters are:
be used as the new hook function; if omitted or ``None``, any
function already installed is removed. The hook is called
with no arguments after the first prompt has been printed and just before
- readline starts reading input characters.
+ readline starts reading input characters. This function only exists
+ if Python was compiled for a version of the library that supports it.
Completion
.. data:: RLIMIT_FSIZE
- The maximum size of a file which the process may create. This only affects the
- stack of the main thread in a multi-threaded process.
+ The maximum size of a file which the process may create.
.. data:: RLIMIT_DATA
.. data:: RLIMIT_STACK
- The maximum size (in bytes) of the call stack for the current process.
+ The maximum size (in bytes) of the call stack for the current process. This only
+ affects the stack of the main thread in a multi-threaded process.
.. data:: RLIMIT_RSS
Python code executing in restricted mode faces a number of limitations that are
designed to prevent it from escaping from the padded cell. For instance, the
function object attribute :attr:`func_globals` and the class and instance object
-attribute :attr:`__dict__` are unavailable.
+attribute :attr:`~object.__dict__` are unavailable.
Two modules provide the framework for setting up restricted execution
environments:
The :mod:`ScrolledText` module provides a class of the same name which
implements a basic text widget which has a vertical scroll bar configured to do
-the "right thing." Using the :class:`ScrolledText` class is a lot easier than
+the "right thing." Using the :class:`~ScrolledText.ScrolledText` class is a lot easier than
setting up a text widget and scroll bar directly. The constructor is the same
as that of the :class:`Tkinter.Text` class.
The text widget and scrollbar are packed together in a :class:`Frame`, and the
methods of the :class:`Grid` and :class:`Pack` geometry managers are acquired
-from the :class:`Frame` object. This allows the :class:`ScrolledText` widget to
+from the :class:`Frame` object. This allows the :class:`~ScrolledText.ScrolledText` widget to
be used directly to achieve most normal geometry management behavior.
Should more specific control be necessary, the following attributes are
Low level interface to kevent
- - changelist must be an iterable of kevent object or None
+ - changelist must be an iterable of kevent object or ``None``
- max_events must be 0 or a positive integer
- timeout in seconds (floats possible)
Convert a character reference to a string, or ``None``. *ref* is the reference
passed in as a string. In the base implementation, *ref* must be a decimal
- number in the range 0-255. It converts the code point found using the
+ number in the range 0--255. It converts the code point found using the
:meth:`convert_codepoint` method. If *ref* is invalid or out of range, this
method returns ``None``. This method is called by the default
:meth:`handle_charref` implementation and by the attribute value parser.
Because of Python semantics, a shelf cannot know when a mutable
persistent-dictionary entry is modified. By default modified objects are
written *only* when assigned to the shelf (see :ref:`shelve-example`). If the
- optional *writeback* parameter is set to *True*, all entries accessed are also
+ optional *writeback* parameter is set to ``True``, all entries accessed are also
cached in memory, and written back on :meth:`~Shelf.sync` and
:meth:`~Shelf.close`; this can make it handier to mutate mutable entries in
the persistent dictionary, but, if many entries are accessed, it can consume
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.
+Shelf objects support most of the methods supported by dictionaries. This
+eases the transition from dictionary based scripts to those requiring
+persistent storage.
+
+Note, the Python 3 transition methods (:meth:`~dict.viewkeys`,
+:meth:`~dict.viewvalues`, and :meth:`~dict.viewitems`) are not supported.
Two additional methods are supported:
>>> make_archive(archive_name, 'gztar', root_dir)
'/Users/tarek/myarchive.tar.gz'
-The resulting archive contains::
+The resulting archive contains:
+
+.. code-block:: shell-session
$ tar -tzvf /Users/tarek/myarchive.tar.gz
drwx------ tarek/staff 0 2010-02-01 16:23:40 ./
The :mod:`SimpleXMLRPCServer` module provides a basic server framework for
XML-RPC servers written in Python. Servers can either be free standing, using
-:class:`SimpleXMLRPCServer`, or embedded in a CGI environment, using
+:class:`~SimpleXMLRPCServer.SimpleXMLRPCServer`, or embedded in a CGI environment, using
:class:`CGIXMLRPCRequestHandler`.
Create a new request handler instance. This request handler supports ``POST``
requests and modifies logging so that the *logRequests* parameter to the
- :class:`SimpleXMLRPCServer` constructor parameter is honored.
+ :class:`~SimpleXMLRPCServer.SimpleXMLRPCServer` constructor parameter is honored.
.. _simple-xmlrpc-servers:
SimpleXMLRPCServer Objects
--------------------------
-The :class:`SimpleXMLRPCServer` class is based on
+The :class:`~SimpleXMLRPCServer.SimpleXMLRPCServer` class is based on
:class:`SocketServer.TCPServer` and provides a means of creating simple, stand
alone XML-RPC servers.
# Print list of available methods
print s.system.listMethods()
-The following :class:`SimpleXMLRPCServer` example is included in the module
+The following :class:`~SimpleXMLRPCServer.SimpleXMLRPCServer` example is included in the module
`Lib/SimpleXMLRPCServer.py`::
server = SimpleXMLRPCServer(("localhost", 8000))
.. method:: CGIXMLRPCRequestHandler.handle_request([request_text = None])
- Handle a XML-RPC request. If *request_text* is given, it should be the POST
+ Handle an XML-RPC request. If *request_text* is given, it should be the POST
data provided by the HTTP server, otherwise the contents of stdin will be used.
Example::
.. class:: SMTPServer(localaddr, remoteaddr)
Create a new :class:`SMTPServer` object, which binds to local address
- *localaddr*. It will treat *remoteaddr* as an upstream SMTP relayer. It
- inherits from :class:`asyncore.dispatcher`, and so will insert itself into
- :mod:`asyncore`'s event loop on instantiation.
+ *localaddr*. It will treat *remoteaddr* as an upstream SMTP relayer. Both
+ *localaddr* and *remoteaddr* should be a :ref:`(host, port) <host_port>`
+ tuple. The object inherits from :class:`asyncore.dispatcher`, and so will
+ insert itself into :mod:`asyncore`'s event loop on instantiation.
.. method:: process_message(peer, mailfrom, rcpttos, data)
.. class:: SMTP([host[, port[, local_hostname[, timeout]]]])
- A :class:`SMTP` instance encapsulates an SMTP connection. It has methods
+ An :class:`SMTP` instance encapsulates an SMTP connection. It has methods
that support a full repertoire of SMTP and ESMTP operations. If the optional
host and port parameters are given, the SMTP :meth:`connect` method is
called with those parameters during initialization. If specified,
.. class:: SMTP_SSL([host[, port[, local_hostname[, keyfile[, certfile[, timeout]]]]]])
- A :class:`SMTP_SSL` instance behaves exactly the same as instances of
+ An :class:`SMTP_SSL` instance behaves exactly the same as instances of
:class:`SMTP`. :class:`SMTP_SSL` should be used for situations where SSL is
required from the beginning of the connection and using :meth:`starttls` is
not appropriate. If *host* is not specified, the local host is used. If
files, buffer allocation on receive operations is automatic, and buffer length
is implicit on send operations.
+.. _host_port:
+
Socket addresses are represented as follows: A single string is used for the
:const:`AF_UNIX` address family. A pair ``(host, port)`` is used for the
:const:`AF_INET` address family, where *host* is a string representing either a
Set blocking or non-blocking mode of the socket: if *flag* is 0, the socket is
set to non-blocking, else to blocking mode. Initially all sockets are in
blocking mode. In non-blocking mode, if a :meth:`recv` call doesn't find any
- data, or if a :meth:`send` call can't immediately dispose of the data, a
+ data, or if a :meth:`send` call can't immediately dispose of the data, an
:exc:`error` exception is raised; in blocking mode, the calls block until they
can proceed. ``s.setblocking(0)`` is equivalent to ``s.settimeout(0.0)``;
``s.setblocking(1)`` is equivalent to ``s.settimeout(None)``.
:meth:`~socket.recv` and :meth:`~socket.send` without *flags* argument instead.
Socket objects also have these (read-only) attributes that correspond to the
-values given to the :class:`socket` constructor.
+values given to the :class:`~socket.socket` constructor.
.. attribute:: socket.family
The output of the example should look something like this:
-Server::
+Server:
+
+.. code-block:: shell-session
$ python TCPServer.py
127.0.0.1 wrote:
127.0.0.1 wrote:
python is nice
-Client::
+Client:
+
+.. code-block:: shell-session
$ python TCPClient.py hello world with TCP
Sent: hello world with TCP
server.server_close()
-The output of the example should look something like this::
+The output of the example should look something like this:
+
+.. code-block:: shell-session
$ python ThreadedTCPServer.py
Server loop running in thread: Thread-1
:ref:`sqlite3-controlling-transactions` for a more detailed explanation.
- .. method:: cursor([cursorClass])
+ .. method:: cursor(factory=Cursor)
- The cursor method accepts a single optional parameter *cursorClass*. If
- supplied, this must be a custom cursor class that extends
- :class:`sqlite3.Cursor`.
+ The cursor method accepts a single optional parameter *factory*. If
+ supplied, this must be a callable returning an instance of :class:`Cursor`
+ or its subclasses.
.. method:: commit()
as the SQL function.
The function can return any of the types supported by SQLite: unicode, str, int,
- long, float, buffer and None.
+ long, float, buffer and ``None``.
Example:
final result of the aggregate.
The ``finalize`` method can return any of the types supported by SQLite:
- unicode, str, int, long, float, buffer and None.
+ unicode, str, int, long, float, buffer and ``None``.
Example:
.. literalinclude:: ../includes/sqlite3/collation_reverse.py
- To remove a collation, call ``create_collation`` with None as callable::
+ To remove a collation, call ``create_collation`` with ``None`` as callable::
con.create_collation("reverse", None)
.. attribute:: lastrowid
This read-only attribute provides the rowid of the last modified row. It is
- only set if you issued a ``INSERT`` statement using the :meth:`execute`
+ only set if you issued an ``INSERT`` statement using the :meth:`execute`
method. For operations other than ``INSERT`` or when :meth:`executemany` is
called, :attr:`lastrowid` is set to :const:`None`.
(or none at all) via the *isolation_level* parameter to the :func:`connect`
call, or via the :attr:`isolation_level` property of connections.
-If you want **autocommit mode**, then set :attr:`isolation_level` to None.
+If you want **autocommit mode**, then set :attr:`isolation_level` to ``None``.
Otherwise leave it at its default, which will result in a plain "BEGIN"
statement, or set it to one of SQLite's supported isolation levels: "DEFERRED",
RC4 was dropped from the default cipher string.
+ .. versionchanged:: 2.7.13
+
+ ChaCha20/Poly1305 was added to the default cipher string.
+
+ 3DES was dropped from the default cipher string.
+
.. function:: _https_verify_certificates(enable=True)
Specifies whether or not server certificates are verified when creating
Random generation
^^^^^^^^^^^^^^^^^
+ .. deprecated:: 2.7.13
+
+ OpenSSL has deprecated :func:`ssl.RAND_pseudo_bytes`, use
+ :func:`ssl.RAND_bytes` instead.
+
+
.. function:: RAND_status()
Return ``True`` if the SSL pseudo-random number generator has been seeded
See http://egd.sourceforge.net/ or http://prngd.sourceforge.net/ for sources
of entropy-gathering daemons.
- Availability: not available with LibreSSL.
+ Availability: not available with LibreSSL and OpenSSL > 1.1.0
.. function:: RAND_add(bytes, entropy)
:meth:`SSLContext.set_default_verify_paths`. The return value is a
:term:`named tuple` ``DefaultVerifyPaths``:
- * :attr:`cafile` - resolved path to cafile or None if the file doesn't exist,
- * :attr:`capath` - resolved path to capath or None if the directory doesn't exist,
+ * :attr:`cafile` - resolved path to cafile or ``None`` if the file doesn't exist,
+ * :attr:`capath` - resolved path to capath or ``None`` if the directory doesn't exist,
* :attr:`openssl_cafile_env` - OpenSSL's environment key that points to a cafile,
* :attr:`openssl_cafile` - hard coded path to a cafile,
* :attr:`openssl_capath_env` - OpenSSL's environment key that points to a capath,
* :attr:`openssl_capath` - hard coded path to a capath directory
+ Availability: LibreSSL ignores the environment vars
+ :attr:`openssl_cafile_env` and :attr:`openssl_capath_env`
+
.. versionadded:: 2.7.9
.. function:: enum_certificates(store_name)
.. versionadded:: 2.7.10
-.. data:: PROTOCOL_SSLv23
+.. data:: PROTOCOL_TLS
Selects the highest protocol version that both the client and server support.
Despite the name, this option can select "TLS" protocols as well as "SSL".
+ .. versionadded:: 2.7.13
+
+.. data:: PROTOCOL_SSLv23
+
+ Alias for ``PROTOCOL_TLS``.
+
+ .. deprecated:: 2.7.13 Use ``PROTOCOL_TLS`` instead.
+
.. data:: PROTOCOL_SSLv2
Selects SSL version 2 as the channel encryption protocol.
SSL version 2 is insecure. Its use is highly discouraged.
+ .. deprecated:: 2.7.13 OpenSSL has removed support for SSLv2.
+
.. data:: PROTOCOL_SSLv3
Selects SSL version 3 as the channel encryption protocol.
SSL version 3 is insecure. Its use is highly discouraged.
+ .. deprecated:: 2.7.13
+
+ OpenSSL has deprecated all version specific protocols. Use the default
+ protocol with flags like ``OP_NO_SSLv3`` instead.
+
.. data:: PROTOCOL_TLSv1
Selects TLS version 1.0 as the channel encryption protocol.
+ .. deprecated:: 2.7.13
+
+ OpenSSL has deprecated all version specific protocols. Use the default
+ protocol with flags like ``OP_NO_SSLv3`` instead.
+
.. data:: PROTOCOL_TLSv1_1
Selects TLS version 1.1 as the channel encryption protocol.
.. versionadded:: 2.7.9
+ .. deprecated:: 2.7.13
+
+ OpenSSL has deprecated all version specific protocols. Use the default
+ protocol with flags like ``OP_NO_SSLv3`` instead.
+
.. data:: PROTOCOL_TLSv1_2
Selects TLS version 1.2 as the channel encryption protocol. This is the
.. versionadded:: 2.7.9
+ .. deprecated:: 2.7.13
+
+ OpenSSL has deprecated all version specific protocols. Use the default
+ protocol with flags like ``OP_NO_SSLv3`` instead.
+
+
.. data:: OP_ALL
Enables workarounds for various bugs present in other SSL implementations.
This method will raise :exc:`NotImplementedError` if :data:`HAS_ALPN` is
False.
+ OpenSSL 1.1.0+ will abort the handshake and raise :exc:`SSLError` when
+ both sides support ALPN but cannot agree on a protocol.
+
.. versionadded:: 2.7.10
.. method:: SSLContext.set_npn_protocols(protocols)
This setting doesn't apply to client sockets. You can also use the
:data:`OP_SINGLE_ECDH_USE` option to further improve security.
- This method is not available if :data:`HAS_ECDH` is False.
+ This method is not available if :data:`HAS_ECDH` is ``False``.
.. seealso::
`SSL/TLS & Perfect Forward Secrecy <http://vincent.bernat.im/en/blog/2011-ssl-perfect-forward-secrecy.html>`_
Integer literals with an ``'L'`` or ``'l'`` suffix yield long integers (``'L'``
is preferred because ``1l`` looks too much like eleven!). Numeric literals
containing a decimal point or an exponent sign yield floating point numbers.
-Appending ``'j'`` or ``'J'`` to a numeric literal yields a complex number with a
-zero real part. A complex numeric literal is the sum of a real and an imaginary
-part.
+Appending ``'j'`` or ``'J'`` to a numeric literal yields an imaginary number
+(a complex number with a zero real part) which you can add to an integer or
+float to get a complex number with real and imaginary parts.
.. index::
single: arithmetic
Line breaks are not included in the resulting list unless *keepends* is
given and true.
- For example, ``'ab c\n\nde fg\rkl\r\n'.splitlines()`` returns
- ``['ab c', '', 'de fg', 'kl']``, while the same call with ``splitlines(True)``
- returns ``['ab c\n', '\n', 'de fg\r', 'kl\r\n']``.
+ Python recognizes ``"\r"``, ``"\n"``, and ``"\r\n"`` as line boundaries for
+ 8-bit strings.
+
+ For example::
+
+ >>> 'ab c\n\nde fg\rkl\r\n'.splitlines()
+ ['ab c', '', 'de fg', 'kl']
+ >>> 'ab c\n\nde fg\rkl\r\n'.splitlines(True)
+ ['ab c\n', '\n', 'de fg\r', 'kl\r\n']
Unlike :meth:`~str.split` when a delimiter string *sep* is given, this
method returns an empty list for the empty string, and a terminal line
- break does not result in an extra line.
+ break does not result in an extra line::
+
+ >>> "".splitlines()
+ []
+ >>> "One line\n".splitlines()
+ ['One line']
+
+ For comparison, ``split('\n')`` gives::
+
+ >>> ''.split('\n')
+ ['']
+ >>> 'Two lines\n'.split('\n')
+ ['Two lines', '']
+
+.. method:: unicode.splitlines([keepends])
+
+ Return a list of the lines in the string, like :meth:`str.splitlines`.
+ However, the Unicode method splits on the following line boundaries,
+ which are a superset of the :term:`universal newlines` recognized for
+ 8-bit strings.
+
+ +-----------------------+-----------------------------+
+ | Representation | Description |
+ +=======================+=============================+
+ | ``\n`` | Line Feed |
+ +-----------------------+-----------------------------+
+ | ``\r`` | Carriage Return |
+ +-----------------------+-----------------------------+
+ | ``\r\n`` | Carriage Return + Line Feed |
+ +-----------------------+-----------------------------+
+ | ``\v`` or ``\x0b`` | Line Tabulation |
+ +-----------------------+-----------------------------+
+ | ``\f`` or ``\x0c`` | Form Feed |
+ +-----------------------+-----------------------------+
+ | ``\x1c`` | File Separator |
+ +-----------------------+-----------------------------+
+ | ``\x1d`` | Group Separator |
+ +-----------------------+-----------------------------+
+ | ``\x1e`` | Record Separator |
+ +-----------------------+-----------------------------+
+ | ``\x85`` | Next Line (C1 Control Code) |
+ +-----------------------+-----------------------------+
+ | ``\u2028`` | Line Separator |
+ +-----------------------+-----------------------------+
+ | ``\u2029`` | Paragraph Separator |
+ +-----------------------+-----------------------------+
+
+ .. versionchanged:: 2.7
+
+ ``\v`` and ``\f`` added to list of line boundaries.
.. method:: str.startswith(prefix[, start[, end]])
| ``s.append(x)`` | same as ``s[len(s):len(s)] = | \(2) |
| | [x]`` | |
+------------------------------+--------------------------------+---------------------+
-| ``s.extend(x)`` or | for the most part the same as | \(3) |
-| ``s += t`` | ``s[len(s):len(s)] = x`` | |
+| ``s.extend(t)`` or | for the most part the same as | \(3) |
+| ``s += t`` | ``s[len(s):len(s)] = t`` | |
+------------------------------+--------------------------------+---------------------+
| ``s *= n`` | updates *s* with its contents | \(11) |
| | repeated *n* times | |
this misfeature has been deprecated since Python 1.4.
(3)
- *x* can be any iterable object.
+ *t* can be any iterable object.
(4)
Raises :exc:`ValueError` when *x* is not found in *s*. When a negative index is
Test whether the set is a proper superset of *other*, that is, ``set >=
other and set != other``.
- .. method:: union(other, ...)
+ .. method:: union(*others)
set | other | ...
Return a new set with elements from the set and all others.
.. versionchanged:: 2.6
Accepts multiple input iterables.
- .. method:: intersection(other, ...)
+ .. method:: intersection(*others)
set & other & ...
Return a new set with elements common to the set and all others.
.. versionchanged:: 2.6
Accepts multiple input iterables.
- .. method:: difference(other, ...)
+ .. method:: difference(*others)
set - other - ...
Return a new set with elements in the set that are not in the others.
The following table lists operations available for :class:`set` that do not
apply to immutable instances of :class:`frozenset`:
- .. method:: update(other, ...)
+ .. method:: update(*others)
set |= other | ...
Update the set, adding elements from all others.
.. versionchanged:: 2.6
Accepts multiple input iterables.
- .. method:: intersection_update(other, ...)
+ .. method:: intersection_update(*others)
set &= other & ...
Update the set, keeping only elements found in it and all others.
.. versionchanged:: 2.6
Accepts multiple input iterables.
- .. method:: difference_update(other, ...)
+ .. method:: difference_update(*others)
set -= other | ...
Update the set, removing elements found in others.
A special attribute of every module is :attr:`~object.__dict__`. This is the
dictionary containing the module's symbol table. Modifying this dictionary will
actually change the module's symbol table, but direct assignment to the
-:attr:`__dict__` attribute is not possible (you can write
+:attr:`~object.__dict__` attribute is not possible (you can write
``m.__dict__['a'] = 1``, which defines ``m.a`` to be ``1``, but you can't write
-``m.__dict__ = {}``). Modifying :attr:`__dict__` directly is not recommended.
+``m.__dict__ = {}``). Modifying :attr:`~object.__dict__` directly is
+not recommended.
Modules built into the interpreter are written like this: ``<module 'sys'
(built-in)>``. If loaded from a file, they are written as ``<module 'os' from
The tuple of base classes of a class object.
-.. attribute:: class.__name__
+.. attribute:: definition.__name__
- The name of the class or type.
+ The name of the class, type, function, method, descriptor, or
+ generator instance.
The following attributes are only supported by :term:`new-style class`\ es.
In addition to the above presentation types, integers can be formatted
with the floating point presentation types listed below (except
-``'n'`` and None). When doing so, :func:`float` is used to convert the
+``'n'`` and ``None``). When doing so, :func:`float` is used to convert the
integer to a floating point number before formatting.
The available presentation types for floating point and decimal values are:
:synopsis: Read and write strings as if they were files.
-This module implements a file-like class, :class:`StringIO`, that reads and
+This module implements a file-like class, :class:`~StringIO.StringIO`, that reads and
writes a string buffer (also known as *memory files*). See the description of
file objects for operations (section :ref:`bltin-file-objects`). (For
standard strings, see :class:`str` and :class:`unicode`.)
.. class:: StringIO([buffer])
- When a :class:`StringIO` object is created, it can be initialized to an existing
+ When a :class:`~StringIO.StringIO` object is created, it can be initialized to an existing
string by passing the string to the constructor. If no string is given, the
- :class:`StringIO` will start empty. In both cases, the initial file position
+ :class:`~StringIO.StringIO` will start empty. In both cases, the initial file position
starts at zero.
- The :class:`StringIO` object can accept either Unicode or 8-bit strings, but
+ The :class:`~StringIO.StringIO` object can accept either Unicode or 8-bit strings, but
mixing the two may take some care. If both are used, 8-bit strings that cannot
be interpreted as 7-bit ASCII (that use the 8th bit) will cause a
:exc:`UnicodeError` to be raised when :meth:`getvalue` is called.
-The following methods of :class:`StringIO` objects require special mention:
+The following methods of :class:`~StringIO.StringIO` objects require special mention:
.. method:: StringIO.getvalue()
Retrieve the entire contents of the "file" at any time before the
- :class:`StringIO` object's :meth:`close` method is called. See the note above
+ :class:`~StringIO.StringIO` object's :meth:`close` method is called. See the note above
for information about mixing Unicode and 8-bit strings; such mixing can cause
this method to raise :exc:`UnicodeError`.
.. method:: StringIO.close()
Free the memory buffer. Attempting to do further operations with a closed
- :class:`StringIO` object will raise a :exc:`ValueError`.
+ :class:`~StringIO.StringIO` object will raise a :exc:`ValueError`.
Example usage::
manner described in :ref:`converting-argument-sequence`. This is because
the underlying ``CreateProcess()`` operates on strings.
- The *shell* argument (which defaults to *False*) specifies whether to use
- the shell as the program to execute. If *shell* is *True*, it is
+ The *shell* argument (which defaults to ``False``) specifies whether to use
+ the shell as the program to execute. If *shell* is ``True``, it is
recommended to pass *args* as a string rather than as a sequence.
On Unix with ``shell=True``, the shell defaults to :file:`/bin/sh`. If
Replacing /bin/sh shell backquote
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-::
+.. code-block:: bash
output=`mycmd myarg`
- # becomes
- output = check_output(["mycmd", "myarg"])
+becomes::
+
+ output = check_output(["mycmd", "myarg"])
Replacing shell pipeline
^^^^^^^^^^^^^^^^^^^^^^^^
-::
+.. code-block:: bash
output=`dmesg | grep hda`
- # becomes
+
+becomes::
+
p1 = Popen(["dmesg"], stdout=PIPE)
p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
to receive a SIGPIPE if p2 exits before p1.
Alternatively, for trusted input, the shell's own pipeline support may still
-be used directly::
+be used directly:
+
+.. code-block:: bash
output=`dmesg | grep hda`
- # becomes
+
+becomes::
+
output=check_output("dmesg | grep hda", shell=True)
Note that it does not allow read/write files.
- A *mode* of ``'r'`` returns a :class:`AU_read` object, while a *mode* of ``'w'``
- or ``'wb'`` returns a :class:`AU_write` object.
+ A *mode* of ``'r'`` returns an :class:`AU_read` object, while a *mode* of ``'w'``
+ or ``'wb'`` returns an :class:`AU_write` object.
.. function:: openfp(file, mode)
(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
+ 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
If *vars* is provided, it must be a dictionary of variables that will
update the dictionary used to expand the paths.
- If *expand* is set to False, the paths will not be expanded.
+ If *expand* is set to false, the paths will not be expanded.
If *scheme* is not an existing scheme, :func:`get_paths` will raise a
:exc:`KeyError`.
The code here doesn't try to hide it, but you should be aware of it. The
baseline overhead can be measured by invoking the program without arguments, and
it might differ between Python versions. Also, to fairly compare older Python
- versions to Python 2.3, you may want to use Python's :option:`-O` option for
+ versions to Python 2.3, you may want to use Python's :option:`!-O`
+ option (see :ref:`Optimizations <using-on-optimizations>`) for
the older versions to avoid timing ``SET_LINENO`` instructions.
Layouts
^^^^^^^
-A layout can be just None, if it takes no options, or a dict of
+A layout can be just ``None``, if it takes no options, or a dict of
options specifying how to arrange the element. The layout mechanism
uses a simplified version of the pack geometry manager: given an
initial cavity, each element is allocated a parcel. Valid
:param n: an integer (or ``None``)
- Delete all or first/last *n* of turtle's stamps. If *n* is None, delete
+ Delete all or first/last *n* of turtle's stamps. If *n* is ``None``, delete
all stamps, if *n* > 0 delete first *n* stamps, else if *n* < 0 delete
last *n* stamps.
:param height: if an integer, the height in pixels, if a float, a fraction of
the screen; default is 75% of screen
:param startx: if positive, starting position in pixels from the left
- edge of the screen, if negative from the right edge, if None,
+ edge of the screen, if negative from the right edge, if ``None``,
center window horizontally
:param starty: if positive, starting position in pixels from the top
- edge of the screen, if negative from the bottom edge, if None,
+ edge of the screen, if negative from the bottom edge, if ``None``,
center window vertically
.. doctest::
.. method:: assertIsNone(expr, msg=None)
assertIsNotNone(expr, msg=None)
- Test that *expr* is (or is not) None.
+ Test that *expr* is (or is not) ``None``.
.. versionadded:: 2.7
methods that delegate to it), :meth:`assertDictEqual` and
:meth:`assertMultiLineEqual`.
- Setting ``maxDiff`` to None means that there is no maximum length of
+ Setting ``maxDiff`` to ``None`` means that there is no maximum length of
diffs.
.. versionadded:: 2.7
two-element tuples is used as the *query* argument, the first element of
each tuple is a key and the second is a value. The value element in itself
can be a sequence and in that case, if the optional parameter *doseq* is
- evaluates to *True*, individual ``key=value`` pairs separated by ``'&'`` are
+ evaluates to ``True``, individual ``key=value`` pairs separated by ``'&'`` are
generated for each element of the value sequence for the key. The order of
parameters in the encoded string will match the order of parameter tuples in
the sequence. The :mod:`urlparse` module provides the functions
If both lowercase and uppercase environment variables exist (and disagree),
lowercase is preferred.
+ .. note::
+
+ If the environment variable ``REQUEST_METHOD`` is set, which usually
+ indicates your script is running in a CGI environment, the environment
+ variable ``HTTP_PROXY`` (uppercase ``_PROXY``) will be ignored. This is
+ because that variable can be injected by a client using the "Proxy:"
+ HTTP header. If you need to use an HTTP proxy in a CGI environment,
+ either use ``ProxyHandler`` explicitly, or make sure the variable name
+ is in lowercase (or at least the ``_proxy`` suffix).
+
.. note::
urllib also exposes certain utility functions like splittype, splithost and
others parsing URL into various components. But it is recommended to use
To disable autodetected proxy pass an empty dictionary.
+ .. note::
+
+ ``HTTP_PROXY`` will be ignored if a variable ``REQUEST_METHOD`` is set;
+ see the documentation on :func:`~urllib.getproxies`.
+
.. class:: HTTPPasswordMgr()
.. doctest::
- >>> urljoin('https://www.cwi.nl/%7Eguido/Python.html',
+ >>> urljoin('http://www.cwi.nl/%7Eguido/Python.html',
... '//www.python.org/%7Eguido')
'http://www.python.org/%7Eguido'
simplifies writing classes that need to be substitutable for dictionaries (such
as the shelve module).
-This module also defines a class, :class:`UserDict`, that acts as a wrapper
+This module also defines a class, :class:`~UserDict.UserDict`, that acts as a wrapper
around dictionary objects. The need for this class has been largely supplanted
by the ability to subclass directly from :class:`dict` (a feature that became
available starting with Python version 2.2). Prior to the introduction of
-:class:`dict`, the :class:`UserDict` class was used to create dictionary-like
+:class:`dict`, the :class:`~UserDict.UserDict` class was used to create dictionary-like
sub-classes that obtained new behaviors by overriding existing methods or adding
new ones.
-The :mod:`UserDict` module defines the :class:`UserDict` class and
+The :mod:`UserDict` module defines the :class:`~UserDict.UserDict` class and
:class:`DictMixin`:
Class that simulates a dictionary. The instance's contents are kept in a
regular dictionary, which is accessible via the :attr:`data` attribute of
- :class:`UserDict` instances. If *initialdata* is provided, :attr:`data` is
+ :class:`~UserDict.UserDict` instances. If *initialdata* is provided, :attr:`data` is
initialized with its contents; note that a reference to *initialdata* will not
be kept, allowing it be used for other purposes.
.. note::
- For backward compatibility, instances of :class:`UserDict` are not iterable.
+ For backward compatibility, instances of :class:`~UserDict.UserDict` are not iterable.
.. class:: IterableUserDict([initialdata])
- Subclass of :class:`UserDict` that supports direct iteration (e.g. ``for key in
+ Subclass of :class:`~UserDict.UserDict` that supports direct iteration (e.g. ``for key in
myDict``).
In addition to supporting the methods and operations of mappings (see section
-:ref:`typesmapping`), :class:`UserDict` and :class:`IterableUserDict` instances
+:ref:`typesmapping`), :class:`~UserDict.UserDict` and :class:`IterableUserDict` instances
provide the following attribute:
.. attribute:: IterableUserDict.data
- A real dictionary used to store the contents of the :class:`UserDict` class.
+ A real dictionary used to store the contents of the :class:`~UserDict.UserDict` class.
.. class:: DictMixin()
Starting with Python version 2.6, it is recommended to use
:class:`collections.MutableMapping` instead of :class:`DictMixin`.
+ Note that DictMixin does not implement the :meth:`~dict.viewkeys`,
+ :meth:`~dict.viewvalues`, or :meth:`~dict.viewitems` methods.
+
:mod:`UserList` --- Class wrapper for list objects
==================================================
In addition, this class can be mixed-in with built-in classes using multiple
inheritance. This can sometimes be useful. For example, you can inherit
- from :class:`UserList` and :class:`str` at the same time. That would not be
+ from :class:`~UserList.UserList` and :class:`str` at the same time. That would not be
possible with both a real :class:`list` and a real :class:`str`.
This module defines a class that acts as a wrapper around list objects. It is a
and override existing methods or add new ones. In this way one can add new
behaviors to lists.
-The :mod:`UserList` module defines the :class:`UserList` class:
+The :mod:`UserList` module defines the :class:`~UserList.UserList` class:
.. class:: UserList([list])
Class that simulates a list. The instance's contents are kept in a regular
- list, which is accessible via the :attr:`data` attribute of :class:`UserList`
+ list, which is accessible via the :attr:`data` attribute of :class:`~UserList.UserList`
instances. The instance's contents are initially set to a copy of *list*,
defaulting to the empty list ``[]``. *list* can be any iterable, e.g. a
- real Python list or a :class:`UserList` object.
+ real Python list or a :class:`~UserList.UserList` object.
.. note::
- The :class:`UserList` class has been moved to the :mod:`collections`
+ The :class:`~UserList.UserList` class has been moved to the :mod:`collections`
module in Python 3. The :term:`2to3` tool will automatically adapt
imports when converting your sources to Python 3.
In addition to supporting the methods and operations of mutable sequences (see
-section :ref:`typesseq`), :class:`UserList` instances provide the following
+section :ref:`typesseq`), :class:`~UserList.UserList` instances provide the following
attribute:
.. attribute:: UserList.data
- A real Python list object used to store the contents of the :class:`UserList`
+ A real Python list object used to store the contents of the :class:`~UserList.UserList`
class.
-**Subclassing requirements:** Subclasses of :class:`UserList` are expected to
+**Subclassing requirements:** Subclasses of :class:`~UserList.UserList` are expected to
offer a constructor which can be called with either no arguments or one
argument. List operations which return a new sequence attempt to create an
instance of the actual implementation class. To do so, it assumes that the
.. note::
- This :class:`UserString` class from this module is available for backward
+ This :class:`~UserString.UserString` class from this module is available for backward
compatibility only. If you are writing code that does not need to work with
versions of Python earlier than Python 2.2, please consider subclassing directly
- from the built-in :class:`str` type instead of using :class:`UserString` (there
+ from the built-in :class:`str` type instead of using :class:`~UserString.UserString` (there
is no built-in equivalent to :class:`MutableString`).
This module defines a class that acts as a wrapper around string objects. It is
Class that simulates a string or a Unicode string object. The instance's
content is kept in a regular string or Unicode string object, which is
- accessible via the :attr:`data` attribute of :class:`UserString` instances. The
+ accessible via the :attr:`data` attribute of :class:`~UserString.UserString` instances. The
instance's contents are initially set to a copy of *sequence*. *sequence* can
be either a regular Python string or Unicode string, an instance of
- :class:`UserString` (or a subclass) or an arbitrary sequence which can be
+ :class:`~UserString.UserString` (or a subclass) or an arbitrary sequence which can be
converted into a string using the built-in :func:`str` function.
.. note::
- The :class:`UserString` class has been moved to the :mod:`collections`
+ The :class:`~UserString.UserString` class has been moved to the :mod:`collections`
module in Python 3. The :term:`2to3` tool will automatically adapt
imports when converting your sources to Python 3.
.. class:: MutableString([sequence])
- This class is derived from the :class:`UserString` above and redefines strings
+ This class is derived from the :class:`~UserString.UserString` above and redefines strings
to be *mutable*. Mutable strings can't be used as dictionary keys, because
dictionaries require *immutable* objects as keys. The main intention of this
class is to serve as an educational example for inheritance and necessity to
The :class:`MutableString` class has been removed in Python 3.
In addition to supporting the methods and operations of string and Unicode
-objects (see section :ref:`string-methods`), :class:`UserString` instances
+objects (see section :ref:`string-methods`), :class:`~UserString.UserString` instances
provide the following attribute:
.. attribute:: MutableString.data
A real Python string or Unicode object used to store the content of the
- :class:`UserString` class.
+ :class:`~UserString.UserString` class.
| | warnings, regardless of location |
+---------------+----------------------------------------------+
-* *message* is a string containing a regular expression that the warning message
- must match (the match is compiled to always be case-insensitive).
+* *message* is a string containing a regular expression that the start of
+ the warning message must match. The expression is compiled to always be
+ case-insensitive.
* *category* is a class (a subclass of :exc:`Warning`) of which the warning
category must be a subclass in order to match.
* *module* is a string containing a regular expression that the module name must
- match (the match is compiled to be case-sensitive).
+ match. The expression is compiled to be case-sensitive.
* *lineno* is an integer that the line number where the warning occurred must
match, or ``0`` to match all line numbers.
Warnings that are only of interest to the developer are ignored by default. As
such you should make sure to test your code with typically ignored warnings
made visible. You can do this from the command-line by passing :option:`-Wd <-W>`
-to the interpreter (this is shorthand for :option:`-W default`). This enables
+to the interpreter (this is shorthand for :option:`!-W default`). This enables
default handling for all warnings, including those that are ignored by default.
To change what action is taken for encountered warnings you simply change what
-argument is passed to :option:`-W`, e.g. :option:`-W error`. See the
+argument is passed to :option:`-W`, e.g. :option:`!-W error`. See the
:option:`-W` flag for more details on what is possible.
-To programmatically do the same as :option:`-Wd`, use::
+To programmatically do the same as :option:`!-Wd`, use::
warnings.simplefilter('default')
Example
-------
-This simple example shows how an application can use objects IDs to retrieve
+This simple example shows how an application can use object IDs to retrieve
objects that it has seen before. The IDs of the objects can then be used in
other data structures without forcing the objects to remain alive, but the
objects can still be retrieved by ID if they do.
the user exits the browser.
If the environment variable :envvar:`BROWSER` exists, it is interpreted to
-override the platform default list of browsers, as a :data:`os.pathsep`-separated
+override the platform default list of browsers, as an :data:`os.pathsep`-separated
list of browsers to try in order. When the value of a list part contains the
string ``%s``, then it is interpreted as a literal browser command line to be
used with the argument URL substituted for ``%s``; if the part does not contain
The single function in this module attempts to guess which of the several simple
-database modules available--\ :mod:`dbm`, :mod:`gdbm`, or :mod:`dbhash`\
---should be used to open a given file.
+database modules available—:mod:`dbm`, :mod:`gdbm`, or :mod:`dbhash`\
+—should be used to open a given file.
.. function:: whichdb(filename)
# object that accepts two arguments. For that purpose, we're going to
# use a function (note that you're not limited to a function, you can
# use a class for example). The first argument passed to the function
- # is a dictionary containing CGI-style envrironment variables and the
+ # is a dictionary containing CGI-style environment variables and the
# second variable is the callable object (see PEP 333).
def hello_world_app(environ, start_response):
status = '200 OK' # HTTP Status
When you are finished with a DOM tree, you may optionally call the
:meth:`unlink` method to encourage early cleanup of the now-unneeded
-objects. :meth:`unlink` is a :mod:`xml.dom.minidom`\ -specific
+objects. :meth:`unlink` is an :mod:`xml.dom.minidom`\ -specific
extension to the DOM API that renders the node and its descendants are
essentially useless. Otherwise, Python's garbage collector will
eventually take care of the objects in the tree.
^^^^^^^^^^^^^^^^
A :class:`NodeList` represents a sequence of nodes. These objects are used in
-two ways in the DOM Core recommendation: the :class:`Element` objects provides
+two ways in the DOM Core recommendation: an :class:`Element` object provides
one as its list of child nodes, and the :meth:`getElementsByTagName` and
:meth:`getElementsByTagNameNS` methods of :class:`Node` return objects with this
interface to represent query results.
.. method:: clear()
Resets an element. This function removes all subelements, clears all
- attributes, and sets the text and tail attributes to None.
+ attributes, and sets the text and tail attributes to ``None``.
.. method:: get(key, default=None)
Writes the element tree to a file, as XML. *file* is a file name, or a
file object opened for writing. *encoding* [1]_ is the output encoding
(default is US-ASCII). *xml_declaration* controls if an XML declaration
- should be added to the file. Use False for never, True for always, None
- for only if not US-ASCII or UTF-8 (default is None). *default_namespace*
+ should be added to the file. Use ``False`` for never, ``True`` for always, ``None``
+ for only if not US-ASCII or UTF-8 (default is ``None``). *default_namespace*
sets the default XML namespace (for "xmlns"). *method* is either
``"xml"``, ``"html"`` or ``"text"`` (default is ``"xml"``). Returns an
encoded string.
The following table gives an overview of the known attacks and if the various
modules are vulnerable to them.
-========================= ======== ========= ========= ======== =========
-kind sax etree minidom pulldom xmlrpc
-========================= ======== ========= ========= ======== =========
-billion laughs **Yes** **Yes** **Yes** **Yes** **Yes**
-quadratic blowup **Yes** **Yes** **Yes** **Yes** **Yes**
-external entity expansion **Yes** No (1) No (2) **Yes** No (3)
-`DTD`_ retrieval **Yes** No No **Yes** No
-decompression bomb No No No No **Yes**
-========================= ======== ========= ========= ======== =========
+========================= ============== =============== ============== ============== ==============
+kind sax etree minidom pulldom xmlrpc
+========================= ============== =============== ============== ============== ==============
+billion laughs **Vulnerable** **Vulnerable** **Vulnerable** **Vulnerable** **Vulnerable**
+quadratic blowup **Vulnerable** **Vulnerable** **Vulnerable** **Vulnerable** **Vulnerable**
+external entity expansion **Vulnerable** Safe (1) Safe (2) **Vulnerable** Safe (3)
+`DTD`_ retrieval **Vulnerable** Safe Safe **Vulnerable** Safe
+decompression bomb Safe Safe Safe Safe **Vulnerable**
+========================= ============== =============== ============== ============== ==============
1. :mod:`xml.etree.ElementTree` doesn't expand external entities and raises a
ParserError when an entity occurs.
Get the byte stream for this input source.
The getEncoding method will return the character encoding for this byte stream,
- or None if unknown.
+ or ``None`` if unknown.
.. method:: InputSource.setCharacterStream(charfile)
Size of the uncompressed file.
+
+.. _zipfile-commandline:
+.. program:: zipfile
+
+Command-Line Interface
+----------------------
+
+The :mod:`zipfile` module provides a simple command-line interface to interact
+with ZIP archives.
+
+If you want to create a new ZIP archive, specify its name after the :option:`-c`
+option and then list the filename(s) that should be included:
+
+.. code-block:: shell-session
+
+ $ python -m zipfile -c monty.zip spam.txt eggs.txt
+
+Passing a directory is also acceptable:
+
+.. code-block:: shell-session
+
+ $ python -m zipfile -c monty.zip life-of-brian_1979/
+
+If you want to extract a ZIP archive into the specified directory, use
+the :option:`-e` option:
+
+.. code-block:: shell-session
+
+ $ python -m zipfile -e monty.zip target-dir/
+
+For a list of the files in a ZIP archive, use the :option:`-l` option:
+
+.. code-block:: shell-session
+
+ $ python -m zipfile -l monty.zip
+
+
+Command-line options
+~~~~~~~~~~~~~~~~~~~~
+
+.. cmdoption:: -l <zipfile>
+
+ List files in a zipfile.
+
+.. cmdoption:: -c <zipfile> <source1> ... <sourceN>
+
+ Create zipfile from source files.
+
+.. cmdoption:: -e <zipfile> <output_dir>
+
+ Extract zipfile into target directory.
+
+.. cmdoption:: -t <zipfile>
+
+ Test whether the zipfile is valid or not.
+
+
.. _PKZIP Application Note: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
--------
Here is an example that imports a module from a ZIP archive - note that the
-:mod:`zipimport` module is not explicitly used. ::
+:mod:`zipimport` module is not explicitly used.
+
+.. code-block:: shell-session
$ unzip -l example.zip
Archive: example.zip
character is represented by a string of one item. Characters represent (at
least) 8-bit bytes. The built-in functions :func:`chr` and :func:`ord` convert
between characters and nonnegative integers representing the byte values. Bytes
- with the values 0-127 usually represent the corresponding ASCII values, but the
+ with the values 0--127 usually represent the corresponding ASCII values, but the
interpretation of values is up to the program. The string data type is also
used to represent arrays of bytes, e.g., to hold data read from a file.
.. tabularcolumns:: |l|L|l|
+ .. index::
+ single: __doc__ (function attribute)
+ single: __name__ (function attribute)
+ single: __module__ (function attribute)
+ single: __dict__ (function attribute)
+ single: __defaults__ (function attribute)
+ single: __code__ (function attribute)
+ single: __globals__ (function attribute)
+ single: __closure__ (function attribute)
+ single: func_doc (function attribute)
+ single: func_name (function attribute)
+ single: func_dict (function attribute)
+ single: func_defaults (function attribute)
+ single: func_code (function attribute)
+ single: func_globals (function attribute)
+ single: func_closure (function attribute)
+ pair: global; namespace
+
+-----------------------+-------------------------------+-----------+
| Attribute | Meaning | |
+=======================+===============================+===========+
| :attr:`func_doc` | string, or ``None`` if | |
| | unavailable. | |
+-----------------------+-------------------------------+-----------+
- | :attr:`__name__` | The function's name. | Writable |
+ | :attr:`~definition.\ | The function's name | Writable |
+ | __name__` | | |
| :attr:`func_name` | | |
+-----------------------+-------------------------------+-----------+
| :attr:`__module__` | The name of the module the | Writable |
| | module in which the function | |
| | was defined. | |
+-----------------------+-------------------------------+-----------+
- | :attr:`__dict__` | The namespace supporting | Writable |
- | :attr:`func_dict` | arbitrary function | |
- | | attributes. | |
+ | :attr:`~object.\ | The namespace supporting | Writable |
+ | __dict__` | arbitrary function | |
+ | :attr:`func_dict` | attributes. | |
+-----------------------+-------------------------------+-----------+
| :attr:`__closure__` | ``None`` or a tuple of cells | Read-only |
| :attr:`func_closure` | that contain bindings for the | |
Additional information about a function's definition can be retrieved from its
code object; see the description of internal types below.
- .. index::
- single: __doc__ (function attribute)
- single: __name__ (function attribute)
- single: __module__ (function attribute)
- single: __dict__ (function attribute)
- single: __defaults__ (function attribute)
- single: __code__ (function attribute)
- single: __globals__ (function attribute)
- single: __closure__ (function attribute)
- single: func_doc (function attribute)
- single: func_name (function attribute)
- single: func_dict (function attribute)
- single: func_defaults (function attribute)
- single: func_code (function attribute)
- single: func_globals (function attribute)
- single: func_closure (function attribute)
- pair: global; namespace
-
User-defined methods
.. index::
object: method
:attr:`im_func` is the function object; :attr:`im_class` is the class of
:attr:`im_self` for bound methods or the class that asked for the method for
unbound methods; :attr:`__doc__` is the method's documentation (same as
- ``im_func.__doc__``); :attr:`__name__` is the method name (same as
+ ``im_func.__doc__``); :attr:`~definition.__name__` is the method name (same as
``im_func.__name__``); :attr:`__module__` is the name of the module the method
was defined in, or ``None`` if unavailable.
standard built-in module). The number and type of the arguments are
determined by the C function. Special read-only attributes:
:attr:`__doc__` is the function's documentation string, or ``None`` if
- unavailable; :attr:`__name__` is the function's name; :attr:`__self__` is
+ unavailable; :attr:`~definition.__name__` is the function's name; :attr:`__self__` is
set to ``None`` (but see the next item); :attr:`__module__` is the name of
the module the function was defined in or ``None`` if unavailable.
.. index:: single: __dict__ (module attribute)
- Special read-only attribute: :attr:`__dict__` is the module's namespace as a
+ Special read-only attribute: :attr:`~object.__dict__` is the module's namespace as a
dictionary object.
.. impl-detail::
static method object, it is transformed into the object wrapped by the static
method object. See section :ref:`descriptors` for another way in which
attributes retrieved from a class may differ from those actually contained in
- its :attr:`__dict__` (note that only new-style classes support descriptors).
+ its :attr:`~object.__dict__` (note that only new-style classes support descriptors).
.. index:: triple: class; attribute; assignment
single: __bases__ (class attribute)
single: __doc__ (class attribute)
- Special attributes: :attr:`__name__` is the class name; :attr:`__module__` is
- the module name in which the class was defined; :attr:`__dict__` is the
+ Special attributes: :attr:`~definition.__name__` is the class name; :attr:`__module__` is
+ the module name in which the class was defined; :attr:`~object.__dict__` is the
dictionary containing the class's namespace; :attr:`~class.__bases__` is a
tuple (possibly empty or a singleton) containing the base classes, in the
order of their occurrence in the base class list; :attr:`__doc__` is the
- class's documentation string, or None if undefined.
+ class's documentation string, or ``None`` if undefined.
Class instances
.. index::
objects are also transformed, as if they had been retrieved from class
:class:`C`; see above under "Classes". See section :ref:`descriptors` for
another way in which attributes of a class retrieved via its instances may
- differ from the objects actually stored in the class's :attr:`__dict__`. If no
+ differ from the objects actually stored in the class's :attr:`~object.__dict__`. If no
class attribute is found, and the object's class has a :meth:`__getattr__`
method, that is called to satisfy the lookup.
called at the start of each source code line (this is used by the debugger);
:attr:`f_exc_type`, :attr:`f_exc_value`, :attr:`f_exc_traceback` represent the
last exception raised in the parent frame provided another exception was ever
- raised in the current frame (in all other cases they are None); :attr:`f_lineno`
+ raised in the current frame (in all other cases they are ``None``); :attr:`f_lineno`
is the current line number of the frame --- writing to this from within a trace
function jumps to the given line (only for the bottom-most frame). A debugger
can implement a Jump command (aka Set Next Statement) by writing to f_lineno.
will not be usable in hashed collections. If a class defines mutable objects
and implements a :meth:`__cmp__` or :meth:`__eq__` method, it should not
implement :meth:`__hash__`, since hashable collection implementations require
- that a object's hash value is immutable (if the object's hash value changes,
+ that an object's hash value is immutable (if the object's hash value changes,
it will be in the wrong hash bucket).
User-defined classes have :meth:`__cmp__` and :meth:`__hash__` methods
descriptor must be in either the owner's class dictionary or in the class
dictionary for one of its parents). In the examples below, "the attribute"
refers to the attribute whose name is the key of the property in the owner
-class' :attr:`__dict__`.
+class' :attr:`~object.__dict__`.
.. method:: object.__get__(self, instance, owner)
.. index:: single: operators
-The following tokens are operators::
+The following tokens are operators:
+
+.. code-block:: none
+
+ - * ** / // %
<< >> & | ^ ~
.. index:: single: delimiters
-The following tokens serve as delimiters in the grammar::
+The following tokens serve as delimiters in the grammar:
+
+.. code-block:: none
( ) [ ] { } @
, : . ` = ;
but also perform an operation.
The following printing ASCII characters have special meaning as part of other
-tokens or are otherwise significant to the lexical analyzer::
+tokens or are otherwise significant to the lexical analyzer:
+
+.. code-block:: none
' " # \
.. index:: single: ASCII@ASCII
The following printing ASCII characters are not used in Python. Their
-occurrence outside string literals and comments is an unconditional error::
+occurrence outside string literals and comments is an unconditional error:
+
+.. code-block:: none
$ ?
# ignore comments -- too much false positives.
# (although doing this could miss some errors;
# there were two sections "commented-out" by mistake
- # in the Python docs that would not be catched)
+ # in the Python docs that would not be caught)
raise nodes.SkipNode
'use strict';
var all_versions = {
- '3.6': 'dev (3.6)',
+ '3.7': 'dev (3.7)',
+ '3.6': '3.6',
'3.5': '3.5',
'3.4': '3.4',
'3.3': '3.3',
- '3.2': '3.2',
'2.7': '2.7',
- '2.6': '2.6'
};
function build_select(current_version, current_release) {
.. rubric:: Footnotes
.. [#] Except for one thing. Module objects have a secret read-only attribute called
- :attr:`__dict__` which returns the dictionary used to implement the module's
- namespace; the name :attr:`__dict__` is an attribute but not a global name.
+ :attr:`~object.__dict__` which returns the dictionary used to implement the module's
+ namespace; the name :attr:`~object.__dict__` is an attribute but not a global name.
Obviously, using this violates the abstraction of namespace implementation, and
should be restricted to things like post-mortem debuggers.
client="John Cleese",
sketch="Cheese Shop Sketch")
-and of course it would print::
+and of course it would print:
+
+.. code-block:: none
-- Do you have any Limburger ?
-- I'm sorry, we're all out of Limburger
complaint you get while you are still learning Python::
>>> while True print 'Hello world'
- File "<stdin>", line 1, in ?
+ File "<stdin>", line 1
while True print 'Hello world'
^
SyntaxError: invalid syntax
>>> 10 * (1/0)
Traceback (most recent call last):
- File "<stdin>", line 1, in ?
+ File "<stdin>", line 1, in <module>
ZeroDivisionError: integer division or modulo by zero
>>> 4 + spam*3
Traceback (most recent call last):
- File "<stdin>", line 1, in ?
+ File "<stdin>", line 1, in <module>
NameError: name 'spam' is not defined
>>> '2' + 2
Traceback (most recent call last):
- File "<stdin>", line 1, in ?
+ File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects
The last line of the error message indicates what happened. Exceptions come in
>>> raise NameError('HiThere')
Traceback (most recent call last):
- File "<stdin>", line 1, in ?
+ File "<stdin>", line 1, in <module>
NameError: HiThere
The sole argument to :keyword:`raise` indicates the exception to be raised.
...
An exception flew by!
Traceback (most recent call last):
- File "<stdin>", line 2, in ?
+ File "<stdin>", line 2, in <module>
NameError: HiThere
My exception occurred, value: 4
>>> raise MyError('oops!')
Traceback (most recent call last):
- File "<stdin>", line 1, in ?
+ File "<stdin>", line 1, in <module>
__main__.MyError: 'oops!'
In this example, the default :meth:`__init__` of :class:`Exception` has been
...
Goodbye, world!
Traceback (most recent call last):
- File "<stdin>", line 2, in ?
+ File "<stdin>", line 2, in <module>
KeyboardInterrupt
A *finally clause* is always executed before leaving the :keyword:`try`
statement, whether an exception has occurred or not. When an exception has
occurred in the :keyword:`try` clause and has not been handled by an
-:keyword:`except` clause (or it has occurred in a :keyword:`except` or
+:keyword:`except` clause (or it has occurred in an :keyword:`except` or
:keyword:`else` clause), it is re-raised after the :keyword:`finally` clause has
been executed. The :keyword:`finally` clause is also executed "on the way out"
when any other clause of the :keyword:`try` statement is left via a
>>> divide("2", "1")
executing finally clause
Traceback (most recent call last):
- File "<stdin>", line 1, in ?
+ File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in divide
TypeError: unsupported operand type(s) for /: 'str' and 'str'
usually three greater-than signs (``>>>``); for continuation lines it prompts
with the *secondary prompt*, by default three dots (``...``). The interpreter
prints a welcome message stating its version number and a copyright notice
-before printing the first prompt::
+before printing the first prompt:
+
+.. code-block:: shell-session
python
Python 2.7 (#1, Feb 28 2010, 00:02:06)
you can make the file usable as a script as well as an importable module,
because the code that parses the command line only runs if the module is
-executed as the "main" file::
+executed as the "main" file:
+
+.. code-block:: shell-session
$ python fibo.py 50
1 1 2 3 5 8 13 21 34
``__all__`` is defined.)
Although certain modules are designed to export only names that follow certain
-patterns when you use ``import *``, it is still considered bad practise in
+patterns when you use ``import *``, it is still considered bad practice in
production code.
Remember, there is nothing wrong with using ``from Package import
raises an exception. See also :envvar:`PYTHONINSPECT`.
+.. _using-on-optimizations:
.. cmdoption:: -O
Turn on basic optimizations. This changes the filename extension for
Issue a warning when a source file mixes tabs and spaces for indentation in a
way that makes it depend on the worth of a tab expressed in spaces. Issue an
- error when the option is given twice (:option:`-tt`).
+ error when the option is given twice (:option:`!-tt`).
.. cmdoption:: -u
Print a message each time a module is initialized, showing the place
(filename or built-in module) from which it is loaded. When given twice
- (:option:`-vv`), print a message for each file that is checked for when
+ (:option:`!-vv`), print a message for each file that is checked for when
searching for a module. Also provides information on module cleanup at exit.
See also :envvar:`PYTHONVERBOSE`.
invalid options when the first warning is issued).
Starting from Python 2.7, :exc:`DeprecationWarning` and its descendants
- are ignored by default. The :option:`-Wd` option can be used to re-enable
+ are ignored by default. The :option:`!-Wd` option can be used to re-enable
them.
Warnings can also be controlled from within a Python program using the
program creates and destroys objects. The detection of cycles can be disabled
when Python is compiled, if you can't afford even a tiny speed penalty or
suspect that the cycle collection is buggy, by specifying the
-:option:`--without-cycle-gc` switch when running the :program:`configure`
+:option:`!--without-cycle-gc` switch when running the :program:`configure`
script.
Several people tackled this problem and contributed to a solution. An early
you'd use the :func:`apply` built-in function: ``apply(f, args, kw)`` calls the
function :func:`f` with the argument tuple *args* and the keyword arguments in
the dictionary *kw*. :func:`apply` is the same in 2.0, but thanks to a patch
-from Greg Ewing, ``f(*args, **kw)`` as a shorter and clearer way to achieve the
+from Greg Ewing, ``f(*args, **kw)`` is a shorter and clearer way to achieve the
same effect. This syntax is symmetrical with the syntax for defining
functions::
f.grammar = "A ::= B (C D)*"
The dictionary containing attributes can be accessed as the function's
-:attr:`__dict__`. Unlike the :attr:`__dict__` attribute of class instances, in
-functions you can actually assign a new dictionary to :attr:`__dict__`, though
+:attr:`~object.__dict__`. Unlike the :attr:`~object.__dict__` attribute of class instances, in
+functions you can actually assign a new dictionary to :attr:`~object.__dict__`, though
the new value is restricted to a regular Python dictionary; you *can't* be
-tricky and set it to a :class:`UserDict` instance, or any other random object
+tricky and set it to a :class:`~UserDict.UserDict` instance, or any other random object
that behaves like a mapping.
and experiment with them. With the result experience, perhaps it'll be possible
to design a really good catalog and then build support for it into Python 2.2.
For example, the Distutils :command:`sdist` and :command:`bdist_\*` commands
-could support a ``upload`` option that would automatically upload your
+could support an ``upload`` option that would automatically upload your
package to a catalog server.
You can start creating packages containing :file:`PKG-INFO` even if you're not
faster than the system :func:`malloc` and have less memory overhead. The
allocator uses C's :func:`malloc` function to get large pools of memory, and
then fulfills smaller memory requests from these pools. It can be enabled by
- providing the :option:`--with-pymalloc` option to the :program:`configure`
+ providing the :option:`!--with-pymalloc` option to the :program:`configure`
script; see :file:`Objects/obmalloc.c` for the implementation details.
Authors of C extension modules should test their code with the object allocator
...
For a fuller discussion of the line I/O changes, see the python-dev summary for
- January 1-15, 2001 at https://mail.python.org/pipermail/python-dev/2001-January/.
+ January 1--15, 2001 at https://mail.python.org/pipermail/python-dev/2001-January/.
* A new method, :meth:`popitem`, was added to dictionaries to enable
destructively iterating through the contents of a dictionary; this can be faster
so you can't just subclass, say, lists in order to add a single useful method to
them. The :mod:`UserList` module provides a class that supports all of the
methods of lists and that can be subclassed further, but there's lots of C code
-that expects a regular Python list and won't accept a :class:`UserList`
+that expects a regular Python list and won't accept a :class:`~UserList.UserList`
instance.
Python 2.2 fixes this, and in the process adds some exciting new capabilities.
conventions, such as defining :attr:`__members__` and :attr:`__methods__`
attributes that were lists of names, but often the author of an extension type
or a class wouldn't bother to define them. You could fall back on inspecting
-the :attr:`__dict__` of an object, but when class inheritance or an arbitrary
+the :attr:`~object.__dict__` of an object, but when class inheritance or an arbitrary
:meth:`__getattr__` hook were in use this could still be inaccurate.
The one big idea underlying the new class model is that an API for describing
Attribute descriptors are objects that live inside class objects, and have a few
attributes of their own:
-* :attr:`__name__` is the attribute's name.
+* :attr:`~definition.__name__` is the attribute's name.
* :attr:`__doc__` is the attribute's docstring.
to trap attribute references. Writing a :meth:`__getattr__` method is
complicated because to avoid recursion you can't use regular attribute accesses
inside them, and instead have to mess around with the contents of
-:attr:`__dict__`. :meth:`__getattr__` methods also end up being called by Python
+:attr:`~object.__dict__`. :meth:`__getattr__` methods also end up being called by Python
when it checks for other methods such as :meth:`__repr__` or :meth:`__coerce__`,
and so have to be written with this in mind. Finally, calling a function on
every attribute access results in a sizable performance loss.
That is certainly clearer and easier to write than a pair of
:meth:`__getattr__`/:meth:`__setattr__` methods that check for the :attr:`size`
attribute and handle it specially while retrieving all other attributes from the
-instance's :attr:`__dict__`. Accesses to :attr:`size` are also the only ones
+instance's :attr:`~object.__dict__`. Accesses to :attr:`size` are also the only ones
which have to perform the work of calling a function, so references to other
attributes run at their usual speed.
Finally, it's possible to constrain the list of attributes that can be
-referenced on an object using the new :attr:`__slots__` class attribute. Python
+referenced on an object using the new :attr:`~object.__slots__` class attribute. Python
objects are usually very dynamic; at any time it's possible to define a new
attribute on an instance by just doing ``obj.new_attr=1``. A new-style class
-can define a class attribute named :attr:`__slots__` to limit the legal
+can define a class attribute named :attr:`~object.__slots__` to limit the legal
attributes to a particular set of names. An example will make this clear::
>>> class C(object):
AttributeError: 'C' object has no attribute 'newattr'
Note how you get an :exc:`AttributeError` on the attempt to assign to an
-attribute not listed in :attr:`__slots__`.
+attribute not listed in :attr:`~object.__slots__`.
.. _sect-rellinks:
Python's Unicode support has been enhanced a bit in 2.2. Unicode strings are
usually stored as UCS-2, as 16-bit unsigned integers. Python 2.2 can also be
compiled to use UCS-4, 32-bit unsigned integers, as its internal encoding by
-supplying :option:`--enable-unicode=ucs4` to the configure script. (It's also
-possible to specify :option:`--disable-unicode` to completely disable Unicode
+supplying :option:`!--enable-unicode=ucs4` to the configure script. (It's also
+possible to specify :option:`!--disable-unicode` to completely disable Unicode
support.)
When built to use UCS-4 (a "wide Python"), the interpreter can natively handle
output have been corrected. (Contributed by Fred L. Drake, Jr. and Tim Peters.)
* The :mod:`socket` module can be compiled to support IPv6; specify the
- :option:`--enable-ipv6` option to Python's configure script. (Contributed by
+ :option:`!--enable-ipv6` option to Python's configure script. (Contributed by
Jun-ichiro "itojun" Hagino.)
* Two new format characters were added to the :mod:`struct` module for 64-bit
in the main Python CVS tree, and many changes have been made to support MacOS X.
The most significant change is the ability to build Python as a framework,
- enabled by supplying the :option:`--enable-framework` option to the configure
+ enabled by supplying the :option:`!--enable-framework` option to the configure
script when compiling Python. According to Jack Jansen, "This installs a self-
contained Python installation plus the OS X framework "glue" into
:file:`/Library/Frameworks/Python.framework` (or another location of choice).
The main change is the possibility to build Python as a
framework. This installs a self-contained Python installation plus the
OSX framework "glue" into /Library/Frameworks/Python.framework (or
- another location of choice). For now there is little immedeate added
+ another location of choice). For now there is little immediate added
benefit to this (actually, there is the disadvantage that you have to
change your PATH to be able to find Python), but it is the basis for
creating a fullblown Python application, porting the MacPython IDE,
The other change is that most MacPython toolbox modules, which
interface to all the MacOS APIs such as windowing, quicktime,
scripting, etc. have been ported. Again, most of these are not of
- immedeate use, as they need a full application to be really useful, so
+ immediate use, as they need a full application to be really useful, so
they have been commented out in setup.py. People wanting to experiment
can uncomment them. Gestalt and Internet Config modules are enabled by
default.
The new :mod:`zipimport` module adds support for importing modules from a ZIP-
format archive. You don't need to import the module explicitly; it will be
automatically imported if a ZIP archive's filename is added to ``sys.path``.
-For example::
+For example:
+
+.. code-block:: shell-session
amk@nyman:~/src/python$ unzip -l /tmp/example.zip
Archive: /tmp/example.zip
line-endings.
This feature can be disabled when compiling Python by specifying the
-:option:`--without-universal-newlines` switch when running Python's
+:option:`!--without-universal-newlines` switch when running Python's
:program:`configure` script.
<type '_socket.socket'>
* One of the noted incompatibilities between old- and new-style classes has been
- removed: you can now assign to the :attr:`__name__` and :attr:`__bases__`
+ removed: you can now assign to the :attr:`~definition.__name__` and :attr:`~class.__bases__`
attributes of new-style classes. There are some restrictions on what can be
- assigned to :attr:`__bases__` along the lines of those relating to assigning to
- an instance's :attr:`__class__` attribute.
+ assigned to :attr:`~class.__bases__` along the lines of those relating to assigning to
+ an instance's :attr:`~instance.__class__` attribute.
.. ======================================================================
fancy features, and just stick to the basics of representing time.
The three primary types are: :class:`date`, representing a day, month, and year;
-:class:`time`, consisting of hour, minute, and second; and :class:`datetime`,
-which contains all the attributes of both :class:`date` and :class:`time`.
+:class:`~datetime.time`, consisting of hour, minute, and second; and :class:`~datetime.datetime`,
+which contains all the attributes of both :class:`date` and :class:`~datetime.time`.
There's also a :class:`timedelta` class representing differences between two
points in time, and time zone logic is implemented by classes inheriting from
the abstract :class:`tzinfo` class.
-You can create instances of :class:`date` and :class:`time` by either supplying
+You can create instances of :class:`date` and :class:`~datetime.time` by either supplying
keyword arguments to the appropriate constructor, e.g.
``datetime.date(year=1972, month=10, day=15)``, or by using one of a number of
class methods. For example, the :meth:`date.today` class method returns the
'2002 30 Dec'
The :meth:`replace` method allows modifying one or more fields of a
-:class:`date` or :class:`datetime` instance, returning a new instance::
+:class:`date` or :class:`~datetime.datetime` instance, returning a new instance::
>>> d = datetime.datetime.now()
>>> d
>>>
Instances can be compared, hashed, and converted to strings (the result is the
-same as that of :meth:`isoformat`). :class:`date` and :class:`datetime`
+same as that of :meth:`isoformat`). :class:`date` and :class:`~datetime.datetime`
instances can be subtracted from each other, and added to :class:`timedelta`
instances. The largest missing feature is that there's no standard library
support for parsing strings and getting back a :class:`date` or
-:class:`datetime`.
+:class:`~datetime.datetime`.
For more information, refer to the module's reference documentation.
(Contributed by Tim Peters.)
strings containing the remaining arguments.
Invoking the script with the various arguments now works as you'd expect it to.
-Note that the length argument is automatically converted to an integer. ::
+Note that the length argument is automatically converted to an integer.
+
+.. code-block:: shell-session
$ ./python opt.py -i data arg1
<Values at 0x400cad4c: {'input': 'data', 'length': None}>
[]
$
-The help message is automatically generated for you::
+The help message is automatically generated for you:
+
+.. code-block:: shell-session
$ ./python opt.py --help
usage: opt.py [options]
In 2.1 and 2.2, pymalloc was an experimental feature and wasn't enabled by
default; you had to explicitly enable it when compiling Python by providing the
-:option:`--with-pymalloc` option to the :program:`configure` script. In 2.3,
+:option:`!--with-pymalloc` option to the :program:`configure` script. In 2.3,
pymalloc has had further enhancements and is now enabled by default; you'll have
-to supply :option:`--without-pymalloc` to disable it.
+to supply :option:`!--without-pymalloc` to disable it.
This change is transparent to code written in Python; however, pymalloc may
expose bugs in C extensions. Authors of C extension modules should test their
features to catch memory overwrites and doubled frees in both extension modules
and in the interpreter itself. To enable this support, compile a debugging
version of the Python interpreter by running :program:`configure` with
-:option:`--with-pydebug`.
+:option:`!--with-pydebug`.
To aid extension writers, a header file :file:`Misc/pymemcompat.h` is
distributed with the source to Python 2.3 that allows Python extensions to use
* The cycle detection implementation used by the garbage collection has proven
to be stable, so it's now been made mandatory. You can no longer compile Python
- without it, and the :option:`--with-cycle-gc` switch to :program:`configure` has
+ without it, and the :option:`!--with-cycle-gc` switch to :program:`configure` has
been removed.
* Python can now optionally be built as a shared library
- (:file:`libpython2.3.so`) by supplying :option:`--enable-shared` when running
+ (:file:`libpython2.3.so`) by supplying :option:`!--enable-shared` when running
Python's :program:`configure` script. (Contributed by Ondrej Palkovsky.)
* The :c:macro:`DL_EXPORT` and :c:macro:`DL_IMPORT` macros are now deprecated.
generally use the :c:macro:`PyAPI_FUNC` and :c:macro:`PyAPI_DATA` macros.
* The interpreter can be compiled without any docstrings for the built-in
- functions and modules by supplying :option:`--without-doc-strings` to the
+ functions and modules by supplying :option:`!--without-doc-strings` to the
:program:`configure` script. This makes the Python executable about 10% smaller,
but will also mean that you can't get help for Python's built-ins. (Contributed
by Gustavo Niemeyer.)
* If you dynamically allocate type objects in your extension, you should be
aware of a change in the rules relating to the :attr:`__module__` and
- :attr:`__name__` attributes. In summary, you will want to ensure the type's
+ :attr:`~definition.__name__` attributes. In summary, you will want to ensure the type's
dictionary contains a ``'__module__'`` key; making the module name the part of
the type name leading up to the final period will no longer have the desired
effect. For more detail, read the API reference documentation or the source.
MacIntyre, Lalo Martins, Chad Netzer, Gustavo Niemeyer, Neal Norwitz, Hans
Nowak, Chris Reedy, Francesco Ricciardi, Vinay Sajip, Neil Schemenauer, Roman
Suzi, Jason Tishler, Just van Rossum.
-
print word
Running the above function's tests with :const:`doctest.REPORT_UDIFF` specified,
-you get the following output::
+you get the following output:
+
+.. code-block:: none
**********************************************************************
File "t.py", line 15, in g
* Python can now be built with additional profiling for the interpreter itself,
intended as an aid to people developing the Python core. Providing
- :option:`--enable-profiling` to the :program:`configure` script will let you
+ :option:`!--enable-profiling` to the :program:`configure` script will let you
profile the interpreter with :program:`gprof`, and providing the
- :option:`--with-tsc` switch enables profiling using the Pentium's Time-Stamp-
- Counter register. Note that the :option:`--with-tsc` switch is slightly
+ :option:`!--with-tsc` switch enables profiling using the Pentium's Time-Stamp-
+ Counter register. Note that the :option:`!--with-tsc` switch is slightly
misnamed, because the profiling feature also works on the PowerPC platform,
though that processor architecture doesn't call that register "the TSC
register". (Contributed by Jeremy Hylton.)
empty list instead of raising a :exc:`TypeError` exception if called with no
arguments.
-* You can no longer compare the :class:`date` and :class:`datetime` instances
+* You can no longer compare the :class:`date` and :class:`~datetime.datetime` instances
provided by the :mod:`datetime` module. Two instances of different classes
will now always be unequal, and relative comparisons (``<``, ``>``) will raise
a :exc:`TypeError`.
Before a package can be uploaded, you must be able to build a distribution using
the :command:`sdist` Distutils command. Once that works, you can run ``python
setup.py upload`` to add your package to the PyPI archive. Optionally you can
-GPG-sign the package by supplying the :option:`--sign` and :option:`--identity`
+GPG-sign the package by supplying the :option:`!--sign` and :option:`!--identity`
options.
Package uploading was implemented by Martin von Löwis and Richard Jones.
(Contributed by Skip Montanaro and Andrew McNamara.)
-* The :class:`datetime` class in the :mod:`datetime` module now has a
+* The :class:`~datetime.datetime` class in the :mod:`datetime` module now has a
:meth:`strptime(string, format)` method for parsing date strings, contributed
by Josh Spoerri. It uses the same format characters as :func:`time.strptime` and
:func:`time.strftime`::
* The :mod:`pyexpat` module now uses version 2.0 of the Expat parser.
(Contributed by Trent Mick.)
-* The :class:`Queue` class provided by the :mod:`Queue` module gained two new
+* The :class:`~Queue.Queue` class provided by the :mod:`Queue` module gained two new
methods. :meth:`join` blocks until all items in the queue have been retrieved
and all processing work on the items have been completed. Worker threads call
the other new method, :meth:`task_done`, to signal that processing for an item
* The :mod:`webbrowser` module received a number of enhancements. It's now
usable as a script with ``python -m webbrowser``, taking a URL as the argument;
- there are a number of switches to control the behaviour (:option:`-n` for a new
+ there are a number of switches to control the behaviour (:option:`!-n` for a new
browser window, :option:`!-t` for a new tab). New module-level functions,
:func:`open_new` and :func:`open_new_tab`, were added to support this. The
module's :func:`open` function supports an additional feature, an *autoraise*
.. Patch #754022
-* The :mod:`xmlrpclib` module now supports returning :class:`datetime` objects
+* The :mod:`xmlrpclib` module now supports returning :class:`~datetime.datetime` objects
for the XML-RPC date type. Supply ``use_datetime=True`` to the :func:`loads`
function or the :class:`Unmarshaller` class to enable this feature. (Contributed
by Skip Montanaro.)
* MacOS X (10.3 and higher): dynamic loading of modules now uses the
:c:func:`dlopen` function instead of MacOS-specific functions.
-* MacOS X: an :option:`--enable-universalsdk` switch was added to the
+* MacOS X: an :option:`!--enable-universalsdk` switch was added to the
:program:`configure` script that compiles the interpreter as a universal binary
able to run on both PowerPC and Intel processors. (Contributed by Ronald
Oussoren; :issue:`2573`.)
result = queue.get()
print 'Factorial', N, '=', result
-A :class:`Queue` is used to communicate the result of the factorial.
-The :class:`Queue` object is stored in a global variable.
+A :class:`~Queue.Queue` is used to communicate the result of the factorial.
+The :class:`~Queue.Queue` object is stored in a global variable.
The child process will use the value of the variable when the child
-was created; because it's a :class:`Queue`, parent and child can use
+was created; because it's a :class:`~Queue.Queue`, parent and child can use
the object to communicate. (If the parent were to change the value of
the global variable, the child's value would be unaffected, and vice
versa.)
There are two concrete implementations. :class:`TextIOWrapper`
wraps a buffered I/O object, supporting all of the methods for
text I/O and adding a :attr:`buffer` attribute for access
- to the underlying object. :class:`StringIO` simply buffers
+ to the underlying object. :class:`~StringIO.StringIO` simply buffers
everything in memory without ever writing anything to disk.
(In Python 2.6, :class:`io.StringIO` is implemented in
(Contributed by Christian Heimes and Mark Dickinson.)
-* :class:`mmap` objects now have a :meth:`rfind` method that searches for a
+* :class:`~mmap.mmap` objects now have a :meth:`rfind` method that searches for a
substring beginning at the end of the string and searching
backwards. The :meth:`find` method also gained an *end* parameter
giving an index at which to stop searching.
intended for testing purposes that lets you temporarily modify the
warning filters and then restore their original values (:issue:`3781`).
-* The XML-RPC :class:`SimpleXMLRPCServer` and :class:`DocXMLRPCServer`
+* The XML-RPC :class:`~SimpleXMLRPCServer.SimpleXMLRPCServer` and :class:`~DocXMLRPCServer.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
open the socket and begin listening for connections.
(Contributed by Peter Parente; :issue:`1599845`.)
- :class:`SimpleXMLRPCServer` also has a :attr:`_send_traceback_header`
+ :class:`~SimpleXMLRPCServer.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
:class:`datetime.date` and :class:`datetime.time` to the
:class:`xmlrpclib.DateTime` type; the conversion semantics were
not necessarily correct for all applications. Code using
- :mod:`xmlrpclib` should convert :class:`date` and :class:`time`
+ :mod:`xmlrpclib` should convert :class:`date` and :class:`~datetime.time`
instances. (:issue:`1330538`) The code can also handle
dates before 1900 (contributed by Ralf Schmitt; :issue:`2014`)
and 64-bit integers represented by using ``<i8>`` in XML-RPC responses
* On Mac OS X, Python 2.6 can be compiled as a 4-way universal build.
The :program:`configure` script
- can take a :option:`--with-universal-archs=[32-bit|64-bit|all]`
+ can take a :option:`!--with-universal-archs=[32-bit|64-bit|all]`
switch, controlling whether the binaries are built for 32-bit
architectures (x86, PowerPC), 64-bit (x86-64 and PPC-64), or both.
(Contributed by Ronald Oussoren.)
* When compiling a framework build of Python, you can now specify the
framework name to be used by providing the
- :option:`--with-framework-name=` option to the
+ :option:`!--with-framework-name=` option to the
:program:`configure` script.
* The :mod:`macfs` module has been removed. This in turn required the
:class:`datetime.date` and :class:`datetime.time` to the
:class:`xmlrpclib.DateTime` type; the conversion semantics were
not necessarily correct for all applications. Code using
- :mod:`xmlrpclib` should convert :class:`date` and :class:`time`
+ :mod:`xmlrpclib` should convert :class:`date` and :class:`~datetime.time`
instances. (:issue:`1330538`)
* (3.0-warning mode) The :class:`Exception` class now warns
when compared to earlier 2.x versions. Python 2.7 is currently expected to
remain supported by the core development team (receiving security updates
and other bug fixes) until at least 2020 (10 years after its initial
- release, compared to the more typical support period of 18-24 months).
+ release, compared to the more typical support period of 18--24 months).
* As the Python 2.7 standard library ages, making effective use of the
Python Package Index (either directly or via a redistributor) becomes
[('first', 1), ('third', 3), ('second', 5)]
The :meth:`~collections.OrderedDict.popitem` method has an optional *last*
-argument that defaults to True. If *last* is True, the most recently
-added key is returned and removed; if it's False, the
+argument that defaults to ``True``. If *last* is true, the most recently
+added key is returned and removed; if it's false, the
oldest key is selected::
>>> od = OrderedDict([(x,0) for x in range(20)])
args = parser.parse_args()
print args.__dict__
-Unless you override it, :option:`-h` and :option:`--help` switches
+Unless you override it, :option:`!-h` and :option:`!--help` switches
are automatically added, and produce neatly formatted output::
-> ./python.exe argparse-example.py --help
calling ``log.getChild('network.listen')`` is equivalent to
``getLogger('app.network.listen')``.
-* The :class:`~logging.LoggerAdapter` class gained a
+* The :class:`~logging.LoggerAdapter` class gained an
:meth:`~logging.LoggerAdapter.isEnabledFor` method that takes a
*level* and returns whether the underlying logger would
process a message of that level of importance.
benchmark results on 32-bit machines have been mixed. Therefore,
the default is to use base 2**30 on 64-bit machines and base 2**15
on 32-bit machines; on Unix, there's a new configure option
- :option:`--enable-big-digits` that can be used to override this default.
+ :option:`!--enable-big-digits` that can be used to override this default.
Apart from the performance improvements this change should be
invisible to end users, with one exception: for testing and
Gregory Smith; :issue:`1087418`).
* The implementation of ``%`` checks for the left-side operand being
- a Python string and special-cases it; this results in a 1-3%
+ a Python string and special-cases it; this results in a 1--3%
performance increase for applications that frequently use ``%``
with strings, such as templating libraries.
(Implemented by Collin Winter; :issue:`5176`.)
* The :mod:`SocketServer` module's :class:`~SocketServer.TCPServer` class now
supports socket timeouts and disabling the Nagle algorithm.
The :attr:`~SocketServer.TCPServer.disable_nagle_algorithm` class attribute
- defaults to False; if overridden to be True,
+ defaults to ``False``; if overridden to be true,
new request connections will have the TCP_NODELAY option set to
prevent buffering many small sends into a single TCP packet.
The :attr:`~SocketServer.BaseServer.timeout` class attribute can hold
The :func:`~unittest.main` function supports some other new options:
-* :option:`-b <unittest -b>` or :option:`--buffer` will buffer the standard output
+* :option:`-b <unittest -b>` or :option:`!--buffer` will buffer the standard output
and standard error streams during each test. If the test passes,
any resulting output will be discarded; on failure, the buffered
output will be displayed.
-* :option:`-c <unittest -c>` or :option:`--catch` will cause the control-C interrupt
+* :option:`-c <unittest -c>` or :option:`!--catch` will cause the control-C interrupt
to be handled more gracefully. Instead of interrupting the test
process immediately, the currently running test will be completed
and then the partial results up to the interruption will be reported.
:func:`~unittest.removeHandler` decorator that can be used to mark tests that
should have the control-C handling disabled.
-* :option:`-f <unittest -f>` or :option:`--failfast` makes
+* :option:`-f <unittest -f>` or :option:`!--failfast` makes
test execution stop immediately when a test fails instead of
continuing to execute further tests. (Suggested by Cliff Dyer and
implemented by Michael Foord; :issue:`8074`.)
:meth:`~unittest.TestCase.assertTrue`, and :meth:`~unittest.TestCase.assertFalse`
failures now provide more information. If you set the
:attr:`~unittest.TestCase.longMessage` attribute of your :class:`~unittest.TestCase` classes to
-True, both the standard error message and any additional message you
+true, both the standard error message and any additional message you
provide will be printed for failures. (Added by Michael Foord; :issue:`5663`.)
The :meth:`~unittest.TestCase.assertRaises` method now
sequence comparison methods do.
:func:`unittest.main` now takes an optional ``exit`` argument. If
-False, :func:`~unittest.main` doesn't call :func:`sys.exit`, allowing
+false, :func:`~unittest.main` doesn't call :func:`sys.exit`, allowing
:func:`~unittest.main` to be used from the interactive interpreter.
(Contributed by J. Pablo Fernández; :issue:`3379`.)
with ``Py``, or with ``_ctypes``. (Implemented by Thomas
Heller; :issue:`3102`.)
-* New configure option: the :option:`--with-system-expat` switch allows
+* New configure option: the :option:`!--with-system-expat` switch allows
building the :mod:`pyexpat` module to use the system Expat library.
(Contributed by Arfrever Frehtes Taifersar Arahesis; :issue:`7609`.)
* New configure option: the
- :option:`--with-valgrind` option will now disable the pymalloc
+ :option:`!--with-valgrind` option will now disable the pymalloc
allocator, which is difficult for the Valgrind memory-error detector
to analyze correctly.
Valgrind will therefore be better at detecting memory leaks and
overruns. (Contributed by James Henstridge; :issue:`2422`.)
* New configure option: you can now supply an empty string to
- :option:`--with-dbmliborder=` in order to disable all of the various
+ :option:`!--with-dbmliborder=` in order to disable all of the various
DBM modules. (Added by Arfrever Frehtes Taifersar Arahesis;
:issue:`6491`.)
written in pure Python could cause a segmentation fault by taking a
:c:type:`PyCObject` from module A and somehow substituting it for the
:c:type:`PyCObject` in module B. Capsules know their own name,
-and getting the pointer requires providing the name::
+and getting the pointer requires providing the name:
+
+.. code-block:: c
void *vtable;
installation and a user-installed copy of the same version.
(Changed by Ronald Oussoren; :issue:`4865`.)
+ .. versionchanged:: 2.7.13
+
+ As of 2.7.13, this change was removed.
+ ``/Library/Python/2.7/site-packages``, the site-packages directory
+ used by the Apple-supplied system Python 2.7 is no longer appended to
+ ``sys.path`` for user-installed Pythons such as from the python.org
+ installers. As of macOS 10.12, Apple changed how the system
+ site-packages directory is configured, which could cause installation
+ of pip components, like setuptools, to fail. Packages installed for
+ the system Python will no longer be shared with user-installed
+ Pythons. (:issue:`28440`)
+
Port-Specific Changes: FreeBSD
-----------------------------------
renamed, moved, or is accessed through different paths. (Patch by
Ziga Seilnacht and Jean-Paul Calderone; :issue:`1180193`.)
-* The :file:`regrtest.py` script now takes a :option:`--randseed=`
+* The :file:`regrtest.py` script now takes a :option:`!--randseed=`
switch that takes an integer that will be used as the random seed
- for the :option:`-r` option that executes tests in random order.
- The :option:`-r` option also reports the seed that was used
+ for the :option:`!-r` option that executes tests in random order.
+ The :option:`!-r` option also reports the seed that was used
(Added by Collin Winter.)
-* Another :file:`regrtest.py` switch is :option:`-j`, which
+* Another :file:`regrtest.py` switch is :option:`!-j`, which
takes an integer specifying how many tests run in parallel. This
allows reducing the total runtime on multi-core machines.
This option is compatible with several other options, including the
:option:`!-R` switch which is known to produce long runtimes.
(Added by Antoine Pitrou, :issue:`6152`.) This can also be used
- with a new :option:`-F` switch that runs selected tests in a loop
+ with a new :option:`!-F` switch that runs selected tests in a loop
until they fail. (Added by Antoine Pitrou; :issue:`7312`.)
* When executed as a script, the :file:`py_compile.py` module now
suggestions, corrections and assistance with various drafts of this
article: Nick Coghlan, Philip Jenvey, Ryan Lovett, R. David Murray,
Hugh Secker-Walker.
-
numeric, sequence, and mapping. Each protocol consists of a
collection of related operations. If an operation that is not
provided by a particular type is invoked, then a standard exception,
- NotImplementedError is raised with a operation name as an argument.
+ NotImplementedError is raised with an operation name as an argument.
In addition, for convenience this interface defines a set of
constructors for building objects of built-in types. This is needed
so new objects can be returned from C functions that otherwise treat
int PyObject_SetAttrString(PyObject *o, 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.
+ to the value v. Raise an exception and return -1 on failure; return 0 on
+ success. This is the equivalent of the Python statement o.attr_name=v.
*/
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.
+ to the value v. Raise an exception and return -1 on failure; return 0 on
+ success. This is the equivalent of the Python statement o.attr_name=v.
*/
PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v);
/*
- Map the object, key, to the value, v. Returns
- -1 on failure. This is the equivalent of the Python
- statement: o[key]=v.
+ Map the object key to the value v. Raise an exception and return -1
+ on failure; return 0 on success. This is the equivalent of the Python
+ statement o[key]=v.
*/
PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, char *key);
PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v);
/*
- Assign object v to the ith element of o. Returns
- -1 on failure. This is the equivalent of the Python
- statement: o[i]=v.
-
+ Assign object v to the ith element of o. Raise an exception and return
+ -1 on failure; return 0 on success. This is the equivalent of the
+ Python statement o[i]=v.
*/
PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i);
/*
Assign the sequence object, v, to the slice in sequence
- object, o, from i1 to i2. Returns -1 on failure. This is the
+ object, o, from i1 to i2. Raise an exception and return
+ -1 on failure; return 0 on success. This is the
equivalent of the Python statement: o[i1:i2]=v.
*/
const char *encoding
);
-/* Get a IncrementalEncoder object for the given encoding. */
+/* Get an IncrementalEncoder object for the given encoding. */
PyAPI_FUNC(PyObject *) PyCodec_IncrementalEncoder(
const char *encoding,
const char *errors
);
-/* Get a IncrementalDecoder object function for the given encoding. */
+/* Get an IncrementalDecoder object function for the given encoding. */
PyAPI_FUNC(PyObject *) PyCodec_IncrementalDecoder(
const char *encoding,
example, if is_signed is 0 and there are more digits in the v than
fit in n; or if is_signed is 1, v < 0, and n is just 1 bit shy of
being large enough to hold a sign bit. OverflowError is set in this
- case, but bytes holds the least-signficant n bytes of the true value.
+ case, but bytes holds the least-significant n bytes of the true value.
*/
PyAPI_FUNC(int) _PyLong_AsByteArray(PyLongObject* v,
unsigned char* bytes, size_t n,
} while (0)
/* Safely decref `op` and set `op` to NULL, especially useful in tp_clear
- * and tp_dealloc implementatons.
+ * and tp_dealloc implementations.
*
* Note that "the obvious" code can be deadly:
*
/*--start constants--*/
#define PY_MAJOR_VERSION 2
#define PY_MINOR_VERSION 7
-#define PY_MICRO_VERSION 12
+#define PY_MICRO_VERSION 13
#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_FINAL
#define PY_RELEASE_SERIAL 0
/* Version as a string */
-#define PY_VERSION "2.7.12"
+#define PY_VERSION "2.7.13"
/*--end constants--*/
/* Subversion Revision number of this file (not of the repository). Empty
* Define macros for handling SIGFPE.
* Lee Busby, LLNL, November, 1996
* busby1@llnl.gov
- *
+ *
*********************************************
* Overview of the system for handling SIGFPE:
- *
+ *
* This file (Include/pyfpe.h) defines a couple of "wrapper" macros for
* insertion into your Python C code of choice. Their proper use is
* discussed below. The file Python/pyfpe.c defines a pair of global
* named fpectl. This module is standard in every respect. It can be loaded
* either statically or dynamically as you choose, and like any other
* Python module, has no effect until you import it.
- *
+ *
* In the general case, there are three steps toward handling SIGFPE in any
* Python code:
- *
+ *
* 1) Add the *_PROTECT macros to your C code as required to protect
* dangerous floating point sections.
- *
+ *
* 2) Turn on the inclusion of the code by adding the ``--with-fpectl''
* flag at the time you run configure. If the fpectl or other modules
* which use the *_PROTECT macros are to be dynamically loaded, be
* sure they are compiled with WANT_SIGFPE_HANDLER defined.
- *
+ *
* 3) When python is built and running, import fpectl, and execute
* fpectl.turnon_sigfpe(). This sets up the signal handler and enables
* generation of SIGFPE whenever an exception occurs. From this point
* on, any properly trapped SIGFPE should result in the Python
* FloatingPointError exception.
- *
+ *
* Step 1 has been done already for the Python kernel code, and should be
* done soon for the NumPy array package. Step 2 is usually done once at
* python install time. Python's behavior with respect to SIGFPE is not
* changed unless you also do step 3. Thus you can control this new
* facility at compile time, or run time, or both.
- *
- ********************************
+ *
+ ********************************
* Using the macros in your code:
- *
+ *
* static PyObject *foobar(PyObject *self,PyObject *args)
* {
* ....
* PyFPE_END_PROTECT(result)
* ....
* }
- *
+ *
* If a floating point error occurs in dangerous_op, foobar returns 0 (NULL),
* after setting the associated value of the FloatingPointError exception to
* "Error in foobar". ``Dangerous_op'' can be a single operation, or a block
* of code, function calls, or any combination, so long as no alternate
* return is possible before the PyFPE_END_PROTECT macro is reached.
- *
+ *
* The macros can only be used in a function context where an error return
* can be recognized as signaling a Python exception. (Generally, most
* functions that return a PyObject * will qualify.)
- *
+ *
* Guido's original design suggestion for PyFPE_START_PROTECT and
* PyFPE_END_PROTECT had them open and close a local block, with a locally
* defined jmp_buf and jmp_buf pointer. This would allow recursive nesting
* variables need to be declared with the "volatile" type qualifier to keep
* setjmp from corrupting their values. Some current implementations seem
* to be more restrictive. For example, the HPUX man page for setjmp says
- *
+ *
* Upon the return from a setjmp() call caused by a longjmp(), the
* values of any non-static local variables belonging to the routine
* from which setjmp() was called are undefined. Code which depends on
* such values is not guaranteed to be portable.
- *
+ *
* I therefore decided on a more limited form of nesting, using a counter
* variable (PyFPE_counter) to keep track of any recursion. If an exception
* occurs in an ``inner'' pair of macros, the return will apparently
* come from the outermost level.
- *
+ *
*/
#ifdef WANT_SIGFPE_HANDLER
* this statement so that it gets executed *before* the unsafe expression
* which we're trying to protect. That pretty well messes things up,
* of course.
- *
+ *
* If the expression(s) you're trying to protect don't happen to return a
* value, you will need to manufacture a dummy result just to preserve the
* correct ordering of statements. Note that the macro passes the address
* of its argument (so you need to give it something which is addressable).
* If your expression returns multiple results, pass the last such result
* to PyFPE_END_PROTECT.
- *
+ *
* Note that PyFPE_dummy returns a double, which is cast to int.
* This seeming insanity is to tickle the Floating Point Unit (FPU).
* If an exception has occurred in a preceding floating point operation,
# if defined(__LP64__)
/* MacOSX 10.4 (the first release to support 64-bit code
* at all) only supports 64-bit in the UNIX layer.
- * Therefore surpress the toolbox-glue in 64-bit mode.
+ * Therefore suppress the toolbox-glue in 64-bit mode.
*/
/* In 64-bit mode setpgrp always has no arguments, in 32-bit
*
* Specifically: OSX 10.4 has limited supported for '%zd', while
* 10.5 has full support for '%zd'. A binary built on 10.5 won't
- * work properly on 10.4 unless we surpress the definition
+ * work properly on 10.4 unless we suppress the definition
* of PY_FORMAT_SIZE_T
*/
#undef PY_FORMAT_SIZE_T
#include <Carbon/Carbon.h>
-#ifndef __LP64__
+/*
+** Issue #27806: Workaround for gcc 4.x which does not have _has_include.
+*/
+#ifndef __has_include
+#define __has_include(x) 0
+#endif
+/* Workaround */
+
+#if __has_include(<Availability.h>)
+#include <Availability.h>
+#define APPLE_SUPPORTS_QUICKTIME (__MAC_OS_X_VERSION_MAX_ALLOWED < 101200) && !__LP64__
+#else
+#define APPLE_SUPPORTS_QUICKTIME !__LP64__
+#endif
+
+#if APPLE_SUPPORTS_QUICKTIME
#include <QuickTime/QuickTime.h>
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
/*
** Helper routines for error codes and such.
PyObject *PyMac_GetOSErrException(void); /* Initialize & return it */
PyObject *PyErr_Mac(PyObject *, int); /* Exception with a mac error */
PyObject *PyMac_Error(OSErr); /* Uses PyMac_GetOSErrException */
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
extern OSErr PyMac_GetFullPathname(FSSpec *, char *, int); /* convert
fsspec->path */
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
/*
** These conversion routines are defined in mactoolboxglue.c itself.
extern int CmpInstObj_Convert(PyObject *, ComponentInstance *);
/* Ctl exports */
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
extern PyObject *CtlObj_New(ControlHandle);
extern int CtlObj_Convert(PyObject *, ControlHandle *);
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
/* Dlg exports */
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
extern PyObject *DlgObj_New(DialogPtr);
extern int DlgObj_Convert(PyObject *, DialogPtr *);
extern PyObject *DlgObj_WhichDialog(DialogPtr);
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
/* Drag exports */
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
extern PyObject *DragObj_New(DragReference);
extern int DragObj_Convert(PyObject *, DragReference *);
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
/* List exports */
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
extern PyObject *ListObj_New(ListHandle);
extern int ListObj_Convert(PyObject *, ListHandle *);
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
/* Menu exports */
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
extern PyObject *MenuObj_New(MenuHandle);
extern int MenuObj_Convert(PyObject *, MenuHandle *);
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
/* Qd exports */
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
extern PyObject *GrafObj_New(GrafPtr);
extern int GrafObj_Convert(PyObject *, GrafPtr *);
extern PyObject *BMObj_New(BitMapPtr);
extern int BMObj_Convert(PyObject *, BitMapPtr *);
extern PyObject *QdRGB_New(RGBColor *);
extern int QdRGB_Convert(PyObject *, RGBColor *);
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
/* Qdoffs exports */
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
extern PyObject *GWorldObj_New(GWorldPtr);
extern int GWorldObj_Convert(PyObject *, GWorldPtr *);
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
/* Qt exports */
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
extern PyObject *TrackObj_New(Track);
extern int TrackObj_Convert(PyObject *, Track *);
extern PyObject *MovieObj_New(Movie);
extern int UserDataObj_Convert(PyObject *, UserData *);
extern PyObject *MediaObj_New(Media);
extern int MediaObj_Convert(PyObject *, Media *);
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
/* Res exports */
extern PyObject *ResObj_New(Handle);
extern int OptResObj_Convert(PyObject *, Handle *);
/* TE exports */
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
extern PyObject *TEObj_New(TEHandle);
extern int TEObj_Convert(PyObject *, TEHandle *);
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
/* Win exports */
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
extern PyObject *WinObj_New(WindowPtr);
extern int WinObj_Convert(PyObject *, WindowPtr *);
extern PyObject *WinObj_WhichWindow(WindowPtr);
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
/* CF exports */
extern PyObject *CFObj_New(CFTypeRef);
extern double copysign(double, double);
#endif
-/* High precision defintion of pi and e (Euler)
+/* High precision definition of pi and e (Euler)
* The values are taken from libc6's math.h.
*/
#ifndef Py_MATH_PIl
* for platforms that support that.
*
* If PY_LOCAL_AGGRESSIVE is defined before python.h is included, more
- * "aggressive" inlining/optimizaion is enabled for the entire module. This
+ * "aggressive" inlining/optimization is enabled for the entire module. This
* may lead to code bloat, and may slow things down for those reasons. It may
* also lead to errors, if the code relies on pointer aliasing. Use with
* care.
#ifdef __FreeBSD__
#include <osreldate.h>
-#if __FreeBSD_version > 500039
+#if (__FreeBSD_version >= 500040 && __FreeBSD_version < 602113) || \
+ (__FreeBSD_version >= 700000 && __FreeBSD_version < 700054) || \
+ (__FreeBSD_version >= 800000 && __FreeBSD_version < 800001)
# define _PY_PORT_CTYPE_UTF8_ISSUE
#endif
#endif
#endif
#ifdef _PY_PORT_CTYPE_UTF8_ISSUE
+#ifndef __cplusplus
+ /* The workaround below is unsafe in C++ because
+ * the <locale> defines these symbols as real functions,
+ * with a slightly different signature.
+ * See issue #10910
+ */
#include <ctype.h>
#include <wctype.h>
#undef isalnum
#undef toupper
#define toupper(c) towupper(btowc(c))
#endif
+#endif
/* Declarations for symbol visibility.
#define Py_UNICODE_FILL(target, value, length) \
do {Py_ssize_t i_; Py_UNICODE *t_ = (target); Py_UNICODE v_ = (value);\
- for (i_ = 0; i_ < (length); i_++) t_[i_] = v_;\
+ for (i_ = 0; i_ < (length); i_++) t_[i_] = v_;\
} while (0)
/* Check if substring matches at given offset. the offset must be
These are capable of handling Unicode objects and strings on input
(we refer to them as strings in the descriptions) and return
- Unicode objects or integers as apporpriate. */
+ Unicode objects or integers as appropriate. */
/* Concat two strings giving a new Unicode string. */
/* Rich compare two strings and return one of the following:
- NULL in case an exception was raised
- - Py_True or Py_False for successfuly comparisons
+ - Py_True or Py_False for successful comparisons
- Py_NotImplemented in case the type combination is unknown
Note that Py_EQ and Py_NE comparisons can cause a UnicodeWarning in
are considered private and will not be called by
SimpleXMLRPCServer.
- If a registered function matches a XML-RPC request, then it
+ If a registered function matches an XML-RPC request, then it
will be called instead of the registered instance.
If the optional allow_dotted_names argument is true and the
Even though IOBase does not declare read, readinto, or write because
their signatures will vary, implementations and clients should
consider those methods part of the interface. Also, implementations
- may raise a IOError when operations they do not support are called.
+ may raise an IOError when operations they do not support are called.
The basic type used for binary data read from or written to a file is
the bytes type. Method arguments may also be bytearray or memoryview of
Like itermonthdates(), but will yield (day number, weekday number)
tuples. For days outside the specified month the day number is 0.
"""
- for date in self.itermonthdates(year, month):
- if date.month != month:
- yield (0, date.weekday())
- else:
- yield (date.day, date.weekday())
+ for i, d in enumerate(self.itermonthdays(year, month), self.firstweekday):
+ yield d, i % 7
def itermonthdays(self, year, month):
"""
Like itermonthdates(), but will yield day numbers. For days outside
the specified month the day number is 0.
"""
- for date in self.itermonthdates(year, month):
- if date.month != month:
- yield 0
- else:
- yield date.day
+ day1, ndays = monthrange(year, month)
+ days_before = (day1 - self.firstweekday) % 7
+ for _ in range(days_before):
+ yield 0
+ for d in range(1, ndays + 1):
+ yield d
+ days_after = (self.firstweekday - day1 - ndays) % 7
+ for _ in range(days_after):
+ yield 0
def monthdatescalendar(self, year, month):
"""
usage of the Chunk class defined here is to instantiate an instance at
the start of each chunk and read from the instance until it reaches
the end, after which a new instance can be instantiated. At the end
-of the file, creating a new instance will fail with a EOFError
+of the file, creating a new instance will fail with an EOFError
exception.
Usage:
"""
def __init__(self, errors='strict'):
"""
- Creates a IncrementalDecoder instance.
+ Creates an IncrementalDecoder instance.
The IncrementalDecoder may use different error handling schemes by
providing the errors keyword argument. See the module docstring
"""
Encoding iterator.
- Encodes the input strings from the iterator using a IncrementalEncoder.
+ Encodes the input strings from the iterator using an IncrementalEncoder.
errors and kwargs are passed through to the IncrementalEncoder
constructor.
"""
Decoding iterator.
- Decodes the input strings from the iterator using a IncrementalDecoder.
+ Decodes the input strings from the iterator using an IncrementalDecoder.
errors and kwargs are passed through to the IncrementalDecoder
constructor.
"""
if t is None: t = time.time()
year, mon, mday, hour, min, sec, wday = time.gmtime(t)[:7]
- return "%s %02d-%s-%04d %02d:%02d:%02d GMT" % (
+ return "%s, %02d-%s-%04d %02d:%02d:%02d GMT" % (
DAYS[wday], mday, MONTHS[mon-1], year, hour, min, sec)
+import functools
import unittest
from ctypes import *
from ctypes.test import need_symbol
self.assertEqual(result,
callback(1.1*1.1, 2.2*2.2, 3.3*3.3, 4.4*4.4, 5.5*5.5))
+ def test_callback_large_struct(self):
+ class Check: pass
+
+ class X(Structure):
+ _fields_ = [
+ ('first', c_ulong),
+ ('second', c_ulong),
+ ('third', c_ulong),
+ ]
+
+ def callback(check, s):
+ check.first = s.first
+ check.second = s.second
+ check.third = s.third
+
+ check = Check()
+ s = X()
+ s.first = 0xdeadbeef
+ s.second = 0xcafebabe
+ s.third = 0x0bad1dea
+
+ CALLBACK = CFUNCTYPE(None, X)
+ dll = CDLL(_ctypes_test.__file__)
+ func = dll._testfunc_cbk_large_struct
+ func.argtypes = (X, CALLBACK)
+ func.restype = None
+ # the function just calls the callback with the passed structure
+ func(s, CALLBACK(functools.partial(callback, check)))
+ self.assertEqual(check.first, s.first)
+ self.assertEqual(check.second, s.second)
+ self.assertEqual(check.third, s.third)
+ self.assertEqual(check.first, 0xdeadbeef)
+ self.assertEqual(check.second, 0xcafebabe)
+ self.assertEqual(check.third, 0x0bad1dea)
################################################################
import unittest
-import os
+import os.path
import sys
+from test import test_support
from ctypes import *
from ctypes.util import find_library
from ctypes.test import is_resource_enabled
if self.gle:
self.gle.gleGetJoinStyle
-# On platforms where the default shared library suffix is '.so',
-# at least some libraries can be loaded as attributes of the cdll
-# object, since ctypes now tries loading the lib again
-# with '.so' appended of the first try fails.
-#
-# Won't work for libc, unfortunately. OTOH, it isn't
-# needed for libc since this is already mapped into the current
-# process (?)
-#
-# On MAC OSX, it won't work either, because dlopen() needs a full path,
-# and the default suffix is either none or '.dylib'.
-@unittest.skip('test disabled')
-@unittest.skipUnless(os.name=="posix" and sys.platform != "darwin",
- 'test not suitable for this platform')
-class LoadLibs(unittest.TestCase):
- def test_libm(self):
- import math
- libm = cdll.libm
- sqrt = libm.sqrt
- sqrt.argtypes = (c_double,)
- sqrt.restype = c_double
- self.assertEqual(sqrt(2), math.sqrt(2))
+ def test_shell_injection(self):
+ result = find_library('; echo Hello shell > ' + test_support.TESTFN)
+ self.assertFalse(os.path.lexists(test_support.TESTFN))
+ self.assertIsNone(result)
if __name__ == "__main__":
unittest.main()
self.assertRaises(ValueError,
(c_int * 1).from_buffer_copy, a, 16 * sizeof(c_int))
+ def test_abstract(self):
+ self.assertRaises(TypeError, Array.from_buffer, bytearray(10))
+ self.assertRaises(TypeError, Structure.from_buffer, bytearray(10))
+ self.assertRaises(TypeError, Union.from_buffer, bytearray(10))
+ self.assertRaises(TypeError, Array.from_buffer_copy, b"123")
+ self.assertRaises(TypeError, Structure.from_buffer_copy, b"123")
+ self.assertRaises(TypeError, Union.from_buffer_copy, b"123")
+
if __name__ == '__main__':
unittest.main()
self.assertEqual(t(v).value, truth(v))
def test_typeerror(self):
- # Only numbers are allowed in the contructor,
+ # Only numbers are allowed in the constructor,
# otherwise TypeError is raised
for t in signed_types + unsigned_types + float_types:
self.assertRaises(TypeError, t, "")
self.assertEqual(alignment(XX), alignment(X))
self.assertEqual(sizeof(XX), calcsize("3s 3s 0s"))
- def test_emtpy(self):
+ def test_empty(self):
# I had problems with these
#
# Although these are pathological cases: Empty Structures!
-import sys, os
+import os
+import subprocess
+import sys
# find_library(name) returns the pathname of a library, or None.
if os.name == "nt":
import re, tempfile, errno
def _findLib_gcc(name):
+ # Run GCC's linker with the -t (aka --trace) option and examine the
+ # library name it prints out. The GCC command will fail because we
+ # haven't supplied a proper program with main(), but that does not
+ # matter.
expr = r'[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name)
- fdout, ccout = tempfile.mkstemp()
- os.close(fdout)
- cmd = 'if type gcc >/dev/null 2>&1; then CC=gcc; elif type cc >/dev/null 2>&1; then CC=cc;else exit 10; fi;' \
- 'LANG=C LC_ALL=C $CC -Wl,-t -o ' + ccout + ' 2>&1 -l' + name
+ cmd = 'if type gcc >/dev/null 2>&1; then CC=gcc; elif type cc >/dev/null 2>&1; then CC=cc;else exit; fi;' \
+ 'LANG=C LC_ALL=C $CC -Wl,-t -o "$2" 2>&1 -l"$1"'
+
+ temp = tempfile.NamedTemporaryFile()
try:
- f = os.popen(cmd)
- try:
- trace = f.read()
- finally:
- rv = f.close()
+ proc = subprocess.Popen((cmd, '_findLib_gcc', name, temp.name),
+ shell=True,
+ stdout=subprocess.PIPE)
+ [trace, _] = proc.communicate()
finally:
try:
- os.unlink(ccout)
+ temp.close()
except OSError, e:
+ # ENOENT is raised if the file was already removed, which is
+ # the normal behaviour of GCC if linking fails
if e.errno != errno.ENOENT:
raise
- if rv == 10:
- raise OSError, 'gcc or cc command not found'
res = re.search(expr, trace)
if not res:
return None
def _get_soname(f):
if not f:
return None
- cmd = "/usr/ccs/bin/dump -Lpv 2>/dev/null " + f
- f = os.popen(cmd)
+
+ null = open(os.devnull, "wb")
try:
- data = f.read()
- finally:
- f.close()
- res = re.search(r'\[.*\]\sSONAME\s+([^\s]+)', data)
+ with null:
+ proc = subprocess.Popen(("/usr/ccs/bin/dump", "-Lpv", f),
+ stdout=subprocess.PIPE,
+ stderr=null)
+ except OSError: # E.g. command not found
+ return None
+ [data, _] = proc.communicate()
+ res = re.search(br'\[.*\]\sSONAME\s+([^\s]+)', data)
if not res:
return None
return res.group(1)
# assuming GNU binutils / ELF
if not f:
return None
- cmd = 'if ! type objdump >/dev/null 2>&1; then exit 10; fi;' \
- "objdump -p -j .dynamic 2>/dev/null " + f
- f = os.popen(cmd)
- try:
- dump = f.read()
- finally:
- rv = f.close()
- if rv == 10:
- raise OSError, 'objdump command not found'
- res = re.search(r'\sSONAME\s+([^\s]+)', dump)
+ cmd = 'if ! type objdump >/dev/null 2>&1; then exit; fi;' \
+ 'objdump -p -j .dynamic 2>/dev/null "$1"'
+ proc = subprocess.Popen((cmd, '_get_soname', f), shell=True,
+ stdout=subprocess.PIPE)
+ [dump, _] = proc.communicate()
+ res = re.search(br'\sSONAME\s+([^\s]+)', dump)
if not res:
return None
return res.group(1)
def _num_version(libname):
# "libxyz.so.MAJOR.MINOR" => [ MAJOR, MINOR ]
- parts = libname.split(".")
+ parts = libname.split(b".")
nums = []
try:
while parts:
nums.insert(0, int(parts.pop()))
except ValueError:
pass
- return nums or [ sys.maxint ]
+ return nums or [sys.maxint]
def find_library(name):
ename = re.escape(name)
expr = r':-l%s\.\S+ => \S*/(lib%s\.\S+)' % (ename, ename)
- f = os.popen('/sbin/ldconfig -r 2>/dev/null')
+
+ null = open(os.devnull, 'wb')
try:
- data = f.read()
- finally:
- f.close()
+ with null:
+ proc = subprocess.Popen(('/sbin/ldconfig', '-r'),
+ stdout=subprocess.PIPE,
+ stderr=null)
+ except OSError: # E.g. command not found
+ data = b''
+ else:
+ [data, _] = proc.communicate()
+
res = re.findall(expr, data)
if not res:
return _get_soname(_findLib_gcc(name))
if not os.path.exists('/usr/bin/crle'):
return None
+ env = dict(os.environ)
+ env['LC_ALL'] = 'C'
+
if is64:
- cmd = 'env LC_ALL=C /usr/bin/crle -64 2>/dev/null'
+ args = ('/usr/bin/crle', '-64')
else:
- cmd = 'env LC_ALL=C /usr/bin/crle 2>/dev/null'
+ args = ('/usr/bin/crle',)
paths = None
- for line in os.popen(cmd).readlines():
- line = line.strip()
- if line.startswith('Default Library Path (ELF):'):
- paths = line.split()[4]
+ null = open(os.devnull, 'wb')
+ try:
+ with null:
+ proc = subprocess.Popen(args,
+ stdout=subprocess.PIPE,
+ stderr=null,
+ env=env)
+ except OSError: # E.g. bad executable
+ return None
+ try:
+ for line in proc.stdout:
+ line = line.strip()
+ if line.startswith(b'Default Library Path (ELF):'):
+ paths = line.split()[4]
+ finally:
+ proc.stdout.close()
+ proc.wait()
if not paths:
return None
# XXX assuming GLIBC's ldconfig (with option -p)
expr = r'\s+(lib%s\.[^\s]+)\s+\(%s' % (re.escape(name), abi_type)
- f = os.popen('LC_ALL=C LANG=C /sbin/ldconfig -p 2>/dev/null')
+
+ env = dict(os.environ)
+ env['LC_ALL'] = 'C'
+ env['LANG'] = 'C'
+ null = open(os.devnull, 'wb')
try:
- data = f.read()
- finally:
- f.close()
+ with null:
+ p = subprocess.Popen(['/sbin/ldconfig', '-p'],
+ stderr=null,
+ stdout=subprocess.PIPE,
+ env=env)
+ except OSError: # E.g. command not found
+ return None
+ [data, _] = p.communicate()
res = re.search(expr, data)
if not res:
return None
def isalnum(c): return isalpha(c) or isdigit(c)
def isalpha(c): return isupper(c) or islower(c)
def isascii(c): return _ctoi(c) <= 127 # ?
-def isblank(c): return _ctoi(c) in (8,32)
-def iscntrl(c): return _ctoi(c) <= 31
+def isblank(c): return _ctoi(c) in (9, 32)
+def iscntrl(c): return _ctoi(c) <= 31 or _ctoi(c) == 127
def isdigit(c): return _ctoi(c) >= 48 and _ctoi(c) <= 57
def isgraph(c): return _ctoi(c) >= 33 and _ctoi(c) <= 126
def islower(c): return _ctoi(c) >= 97 and _ctoi(c) <= 122
def isprint(c): return _ctoi(c) >= 32 and _ctoi(c) <= 126
-def ispunct(c): return _ctoi(c) != 32 and not isalnum(c)
+def ispunct(c): return isgraph(c) and not isalnum(c)
def isspace(c): return _ctoi(c) in (9, 10, 11, 12, 13, 32)
def isupper(c): return _ctoi(c) >= 65 and _ctoi(c) <= 90
def isxdigit(c): return isdigit(c) or \
return sign + intpart + fracpart + exp
def to_eng_string(self, context=None):
- """Convert to engineering-type string.
+ """Convert to a string, using engineering notation if an exponent is needed.
- Engineering notation has an exponent which is a multiple of 3, so there
- are up to 3 digits left of the decimal place.
-
- Same rules for when in exponential and when as a value as in __str__.
+ Engineering notation has an exponent which is a multiple of 3. This
+ can leave up to 3 digits to the left of the decimal place and may
+ require the addition of either one or two trailing zeros.
"""
return self.__str__(eng=True, context=context)
return r
def to_eng_string(self, a):
- """Converts a number to a string, using scientific notation.
+ """Convert to a string, using engineering notation if an exponent is needed.
+
+ Engineering notation has an exponent which is a multiple of 3. This
+ can leave up to 3 digits to the left of the decimal place and may
+ require the addition of either one or two trailing zeros.
The operation is not affected by the context.
+
+ >>> ExtendedContext.to_eng_string(Decimal('123E+1'))
+ '1.23E+3'
+ >>> ExtendedContext.to_eng_string(Decimal('123E+3'))
+ '123E+3'
+ >>> ExtendedContext.to_eng_string(Decimal('123E-10'))
+ '12.3E-9'
+ >>> ExtendedContext.to_eng_string(Decimal('-123E-12'))
+ '-123E-12'
+ >>> ExtendedContext.to_eng_string(Decimal('7E-7'))
+ '700E-9'
+ >>> ExtendedContext.to_eng_string(Decimal('7E+1'))
+ '70'
+ >>> ExtendedContext.to_eng_string(Decimal('0E+1'))
+ '0.00E+3'
+
"""
a = _convert_other(a, raiseit=True)
return a.to_eng_string(context=self)
self.include_dirs.append(plat_py_include)
self.ensure_string_list('libraries')
+ self.ensure_string_list('link_objects')
# Life is easier if we're not forever checking for None, so
# simplify these options to empty lists if unset
class PyPIRCCommand(Command):
"""Base command that knows how to handle the .pypirc file
"""
- DEFAULT_REPOSITORY = 'https://pypi.python.org/pypi'
+ DEFAULT_REPOSITORY = 'https://upload.pypi.org/legacy/'
DEFAULT_REALM = 'pypi'
repository = None
realm = None
# class Mingw32CCompiler
# Because these compilers aren't configured in Python's pyconfig.h file by
-# default, we should at least warn the user if he is using a unmodified
+# default, we should at least warn the user if he is using an unmodified
# version.
CONFIG_H_OK = "ok"
from test.test_support import run_unittest
+try:
+ import zlib
+except ImportError:
+ zlib = None
+
from distutils.core import Distribution
from distutils.command.bdist_rpm import bdist_rpm
from distutils.tests import support
# spurious sdtout/stderr output under Mac OS X
@unittest.skipUnless(sys.platform.startswith('linux'),
'spurious sdtout/stderr output under Mac OS X')
+ @unittest.skipUnless(zlib, "requires zlib")
@unittest.skipIf(find_executable('rpm') is None,
'the rpm command is not found')
@unittest.skipIf(find_executable('rpmbuild') is None,
# spurious sdtout/stderr output under Mac OS X
@unittest.skipUnless(sys.platform.startswith('linux'),
'spurious sdtout/stderr output under Mac OS X')
+ @unittest.skipUnless(zlib, "requires zlib")
# http://bugs.python.org/issue1533164
@unittest.skipIf(find_executable('rpm') is None,
'the rpm command is not found')
cmd.finalize_options()
self.assertEqual(cmd.rpath, ['one', 'two'])
+ # make sure cmd.link_objects is turned into a list
+ # if it's a string
+ cmd = build_ext(dist)
+ cmd.link_objects = 'one two,three'
+ cmd.finalize_options()
+ self.assertEqual(cmd.link_objects, ['one', 'two', 'three'])
+
# XXX more tests to perform for win32
# make sure define is turned into 2-tuples
self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
# second element of each tuple in 'ext_modules'
- # must be a ary (build info)
+ # must be a dictionary (build info)
exts = [('foo.bar', '')]
self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
config = config.items()
config.sort()
waited = [('password', 'secret'), ('realm', 'pypi'),
- ('repository', 'https://pypi.python.org/pypi'),
+ ('repository', 'https://upload.pypi.org/legacy/'),
('server', 'server1'), ('username', 'me')]
self.assertEqual(config, waited)
config = config.items()
config.sort()
waited = [('password', 'secret'), ('realm', 'pypi'),
- ('repository', 'https://pypi.python.org/pypi'),
+ ('repository', 'https://upload.pypi.org/legacy/'),
('server', 'server-login'), ('username', 'tarek')]
self.assertEqual(config, waited)
self.assertRaises(KeyError, Reg.get_value, 'xxx', 'xxx')
# looking for values that should exist on all
- # windows registeries versions.
+ # windows registry versions.
path = r'Control Panel\Desktop'
v = Reg.get_value(path, u'dragfullwindows')
self.assertIn(v, (u'0', u'1', u'2'))
cmd.finalize_options()
for attr, waited in (('username', 'me'), ('password', 'secret'),
('realm', 'pypi'),
- ('repository', 'https://pypi.python.org/pypi')):
+ ('repository', 'https://upload.pypi.org/legacy/')):
self.assertEqual(getattr(cmd, attr), waited)
def test_saved_password(self):
self.assertTrue(headers['Content-type'].startswith('multipart/form-data'))
self.assertEqual(self.last_open.req.get_method(), 'POST')
self.assertEqual(self.last_open.req.get_full_url(),
- 'https://pypi.python.org/pypi')
+ 'https://upload.pypi.org/legacy/')
self.assertIn('xxx', self.last_open.req.data)
auth = self.last_open.req.headers['Authorization']
self.assertNotIn('\n', auth)
if sys.platform[:6] == "darwin":
# MacOSX's linker doesn't understand the -R flag at all
return "-L" + dir
+ elif sys.platform[:7] == "freebsd":
+ return "-Wl,-rpath=" + dir
elif sys.platform[:5] == "hp-ux":
if self._is_gcc(compiler):
return ["-Wl,+s", "-L" + dir]
with open(filename, 'U') as f:
return f.read(), filename
-# Use sys.stdout encoding for ouput.
+# Use sys.stdout encoding for output.
_encoding = getattr(sys.__stdout__, 'encoding', None) or 'utf-8'
def _indent(s, indent=4):
_os = _os # for _commit()
_open = _open # for _commit()
- def __init__(self, filebasename, mode):
+ def __init__(self, filebasename, mode, flag='c'):
self._mode = mode
+ self._readonly = (flag == 'r')
# The directory file is a text file. Each line looks like
# "%r, (%d, %d)\n" % (key, pos, siz)
try:
f = _open(self._dirfile)
except IOError:
- pass
+ self._modified = not self._readonly
else:
+ self._modified = False
with f:
for line in f:
line = line.rstrip()
# CAUTION: It's vital that _commit() succeed, and _commit() can
# be called from __del__(). Therefore we must never reference a
# global in this routine.
- if self._index is None:
+ if self._index is None or not self._modified:
return # nothing to do
try:
def __setitem__(self, key, val):
if not type(key) == type('') == type(val):
raise TypeError, "keys and values must be strings"
+ self._modified = True
if key not in self._index:
self._addkey(key, self._addval(val))
else:
# (so that _commit() never gets called).
def __delitem__(self, key):
+ self._modified = True
# The blocks used by the associated value are lost.
del self._index[key]
# XXX It's unclear why we do a _commit() here (the code always
# Turn off any bits that are set in the umask
mode = mode & (~um)
- return _Database(file, mode)
+ return _Database(file, mode, flag)
decoding a text attachment.
This function does not parse a full MIME header value encoded with
- base64 (like =?iso-8895-1?b?bmloISBuaWgh?=) -- please use the high
+ base64 (like =?iso-8859-1?b?bmloISBuaWgh?=) -- please use the high
level email.header class for that functionality.
"""
if not s:
"""Decode a string encoded with RFC 2045 MIME header `Q' encoding.
This function does not parse a full MIME header value encoded with
- quoted-printable (like =?iso-8895-1?q?Hello_World?=) -- please use
+ quoted-printable (like =?iso-8859-1?q?Hello_World?=) -- please use
the high level email.header class for that functionality.
"""
s = s.replace('_', ' ')
# Issue 5871: reject an attempt to embed a header inside a header value
# (header injection attack).
- def test_embeded_header_via_Header_rejected(self):
+ def test_embedded_header_via_Header_rejected(self):
msg = Message()
msg['Dummy'] = Header('dummy\nX-Injected-Header: test')
self.assertRaises(Errors.HeaderParseError, msg.as_string)
- def test_embeded_header_via_string_rejected(self):
+ def test_embedded_header_via_string_rejected(self):
msg = Message()
msg['Dummy'] = 'dummy\nX-Injected-Header: test'
self.assertRaises(Errors.HeaderParseError, msg.as_string)
def test_rfc2047_Q_invalid_digits(self):
# issue 10004.
- s = '=?iso-8659-1?Q?andr=e9=zz?='
+ s = '=?iso-8859-1?Q?andr=e9=zz?='
self.assertEqual(decode_header(s),
- [(b'andr\xe9=zz', 'iso-8659-1')])
+ [(b'andr\xe9=zz', 'iso-8859-1')])
# Test the MIMEMessage class
__all__ = ["version", "bootstrap"]
-_SETUPTOOLS_VERSION = "20.10.1"
+_SETUPTOOLS_VERSION = "28.8.0"
-_PIP_VERSION = "8.1.1"
-
-# pip currently requires ssl support, so we try to provide a nicer
-# error message when that is missing (http://bugs.python.org/issue19744)
-_MISSING_SSL_MESSAGE = ("pip {} requires SSL/TLS".format(_PIP_VERSION))
-try:
- import ssl
-except ImportError:
- ssl = None
-
- def _require_ssl_for_pip():
- raise RuntimeError(_MISSING_SSL_MESSAGE)
-else:
- def _require_ssl_for_pip():
- pass
+_PIP_VERSION = "9.0.1"
_PROJECTS = [
("setuptools", _SETUPTOOLS_VERSION),
if altinstall and default_pip:
raise ValueError("Cannot use altinstall and default_pip together")
- _require_ssl_for_pip()
_disable_pip_configuration_settings()
# By default, installing pip and setuptools installs all of the
print(msg.format(pip.__version__, _PIP_VERSION), file=sys.stderr)
return
- _require_ssl_for_pip()
_disable_pip_configuration_settings()
# Construct the arguments to be passed to the pip command
def _main(argv=None):
- if ssl is None:
- print("Ignoring ensurepip failure: {}".format(_MISSING_SSL_MESSAGE),
- file=sys.stderr)
- return
-
import argparse
parser = argparse.ArgumentParser(prog="python -m ensurepip")
parser.add_argument(
return self.voidcmd(cmd)
def sendeprt(self, host, port):
- '''Send a EPRT command with the current host and the given port number.'''
+ '''Send an EPRT command with the current host and the given port number.'''
af = 0
if self.af == socket.AF_INET:
af = 1
def parse229(resp, peer):
- '''Parse the '229' response for a EPSV request.
+ '''Parse the '229' response for an EPSV request.
Raises error_proto if it does not contain '(|||port|)'
Return ('host.addr.as.numbers', port#) tuple.'''
_default_localedir = os.path.join(sys.prefix, 'share', 'locale')
-
-def test(condition, true, false):
- """
- Implements the C expression:
-
- condition ? true : false
-
- Required to correctly interpret plural forms.
- """
- if condition:
- return true
+# Expression parsing for plural form selection.
+#
+# The gettext library supports a small subset of C syntax. The only
+# incompatible difference is that integer literals starting with zero are
+# decimal.
+#
+# https://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms
+# http://git.savannah.gnu.org/cgit/gettext.git/tree/gettext-runtime/intl/plural.y
+
+_token_pattern = re.compile(r"""
+ (?P<WHITESPACES>[ \t]+) | # spaces and horizontal tabs
+ (?P<NUMBER>[0-9]+\b) | # decimal integer
+ (?P<NAME>n\b) | # only n is allowed
+ (?P<PARENTHESIS>[()]) |
+ (?P<OPERATOR>[-*/%+?:]|[><!]=?|==|&&|\|\|) | # !, *, /, %, +, -, <, >,
+ # <=, >=, ==, !=, &&, ||,
+ # ? :
+ # unary and bitwise ops
+ # not allowed
+ (?P<INVALID>\w+|.) # invalid token
+ """, re.VERBOSE|re.DOTALL)
+
+def _tokenize(plural):
+ for mo in re.finditer(_token_pattern, plural):
+ kind = mo.lastgroup
+ if kind == 'WHITESPACES':
+ continue
+ value = mo.group(kind)
+ if kind == 'INVALID':
+ raise ValueError('invalid token in plural form: %s' % value)
+ yield value
+ yield ''
+
+def _error(value):
+ if value:
+ return ValueError('unexpected token in plural form: %s' % value)
else:
- return false
-
+ return ValueError('unexpected end of plural form')
+
+_binary_ops = (
+ ('||',),
+ ('&&',),
+ ('==', '!='),
+ ('<', '>', '<=', '>='),
+ ('+', '-'),
+ ('*', '/', '%'),
+)
+_binary_ops = {op: i for i, ops in enumerate(_binary_ops, 1) for op in ops}
+_c2py_ops = {'||': 'or', '&&': 'and', '/': '//'}
+
+def _parse(tokens, priority=-1):
+ result = ''
+ nexttok = next(tokens)
+ while nexttok == '!':
+ result += 'not '
+ nexttok = next(tokens)
+
+ if nexttok == '(':
+ sub, nexttok = _parse(tokens)
+ result = '%s(%s)' % (result, sub)
+ if nexttok != ')':
+ raise ValueError('unbalanced parenthesis in plural form')
+ elif nexttok == 'n':
+ result = '%s%s' % (result, nexttok)
+ else:
+ try:
+ value = int(nexttok, 10)
+ except ValueError:
+ raise _error(nexttok)
+ result = '%s%d' % (result, value)
+ nexttok = next(tokens)
+
+ j = 100
+ while nexttok in _binary_ops:
+ i = _binary_ops[nexttok]
+ if i < priority:
+ break
+ # Break chained comparisons
+ if i in (3, 4) and j in (3, 4): # '==', '!=', '<', '>', '<=', '>='
+ result = '(%s)' % result
+ # Replace some C operators by their Python equivalents
+ op = _c2py_ops.get(nexttok, nexttok)
+ right, nexttok = _parse(tokens, i + 1)
+ result = '%s %s %s' % (result, op, right)
+ j = i
+ if j == priority == 4: # '<', '>', '<=', '>='
+ result = '(%s)' % result
+
+ if nexttok == '?' and priority <= 0:
+ if_true, nexttok = _parse(tokens, 0)
+ if nexttok != ':':
+ raise _error(nexttok)
+ if_false, nexttok = _parse(tokens)
+ result = '%s if %s else %s' % (if_true, result, if_false)
+ if priority == 0:
+ result = '(%s)' % result
+
+ return result, nexttok
+
+def _as_int(n):
+ try:
+ i = round(n)
+ except TypeError:
+ raise TypeError('Plural value must be an integer, got %s' %
+ (n.__class__.__name__,))
+ return n
def c2py(plural):
"""Gets a C expression as used in PO files for plural forms and returns a
- Python lambda function that implements an equivalent expression.
+ Python function that implements an equivalent expression.
"""
- # Security check, allow only the "n" identifier
- try:
- from cStringIO import StringIO
- except ImportError:
- from StringIO import StringIO
- import token, tokenize
- tokens = tokenize.generate_tokens(StringIO(plural).readline)
- try:
- danger = [x for x in tokens if x[0] == token.NAME and x[1] != 'n']
- except tokenize.TokenError:
- raise ValueError, \
- 'plural forms expression error, maybe unbalanced parenthesis'
- else:
- if danger:
- raise ValueError, 'plural forms expression could be dangerous'
-
- # Replace some C operators by their Python equivalents
- plural = plural.replace('&&', ' and ')
- plural = plural.replace('||', ' or ')
-
- expr = re.compile(r'\!([^=])')
- plural = expr.sub(' not \\1', plural)
-
- # Regular expression and replacement function used to transform
- # "a?b:c" to "test(a,b,c)".
- expr = re.compile(r'(.*?)\?(.*?):(.*)')
- def repl(x):
- return "test(%s, %s, %s)" % (x.group(1), x.group(2),
- expr.sub(repl, x.group(3)))
-
- # Code to transform the plural expression, taking care of parentheses
- stack = ['']
- for c in plural:
- if c == '(':
- stack.append('')
- elif c == ')':
- if len(stack) == 1:
- # Actually, we never reach this code, because unbalanced
- # parentheses get caught in the security check at the
- # beginning.
- raise ValueError, 'unbalanced parenthesis in plural form'
- s = expr.sub(repl, stack.pop())
- stack[-1] += '(%s)' % s
- else:
- stack[-1] += c
- plural = expr.sub(repl, stack.pop())
-
- return eval('lambda n: int(%s)' % plural)
+ if len(plural) > 1000:
+ raise ValueError('plural form expression is too long')
+ try:
+ result, nexttok = _parse(_tokenize(plural))
+ if nexttok:
+ raise _error(nexttok)
+
+ depth = 0
+ for c in result:
+ if c == '(':
+ depth += 1
+ if depth > 20:
+ # Python compiler limit is about 90.
+ # The most complex example has 2.
+ raise ValueError('plural form expression is too complex')
+ elif c == ')':
+ depth -= 1
+
+ ns = {'_as_int': _as_int}
+ exec('''if 1:
+ def func(n):
+ if not isinstance(n, int):
+ n = _as_int(n)
+ return int(%s)
+ ''' % result, ns)
+ return ns['func']
+ except RuntimeError:
+ # Recursion error can be raised in _parse() or exec().
+ raise ValueError('plural form expression is too complex')
def _expand_lang(locale):
#
# VCHAR defined in http://tools.ietf.org/html/rfc5234#appendix-B.1
-# the patterns for both name and value are more leniant than RFC
+# the patterns for both name and value are more lenient than RFC
# definitions to allow for backwards compatibility
_is_legal_header_name = re.compile(r'\A[^:\s][^:\r\n]*\Z').match
_is_illegal_header_value = re.compile(r'\n(?![ \t])|\r(?![ \t\n])').search
Read header lines up to the entirely blank line that terminates them.
The (normally blank) line that ends the headers is skipped, but not
- included in the returned list. If a non-header line ends the headers,
- (which is an error), an attempt is made to backspace over it; it is
- never included in the returned list.
+ included in the returned list. If an invalid line is found in the
+ header section, it is skipped, and further lines are processed.
The variable self.status is set to the empty string if all went well,
otherwise it is an error message. The variable self.headers is a
self.status = ''
headerseen = ""
firstline = 1
- startofline = unread = tell = None
- if hasattr(self.fp, 'unread'):
- unread = self.fp.unread
- elif self.seekable:
+ tell = None
+ if not hasattr(self.fp, 'unread') and self.seekable:
tell = self.fp.tell
while True:
if len(hlist) > _MAXHEADERS:
raise HTTPException("got more than %d headers" % _MAXHEADERS)
if tell:
try:
- startofline = tell()
+ tell()
except IOError:
- startofline = tell = None
+ tell = None
self.seekable = 0
line = self.fp.readline(_MAXLINE + 1)
if len(line) > _MAXLINE:
# It's a legal header line, save it.
hlist.append(line)
self.addheader(headerseen, line[len(headerseen)+1:].strip())
- continue
elif headerseen is not None:
# An empty header name. These aren't allowed in HTTP, but it's
# probably a benign mistake. Don't add the header, just keep
# going.
- continue
+ pass
else:
- # It's not a header line; throw it back and stop here.
- if not self.dict:
- self.status = 'No headers'
- else:
- self.status = 'Non-header line where header expected'
- # Try to undo the read.
- if unread:
- unread(line)
- elif tell:
- self.fp.seek(startofline)
- else:
- self.status = self.status + '; bad seek'
- break
+ # It's not a header line; skip it and try the next line.
+ self.status = 'Non-header line where header expected'
class HTTPResponse:
('shell', [
('_View Last Restart', '<<view-restart>>'),
('_Restart Shell', '<<restart-shell>>'),
+ None,
+ ('_Interrupt Execution', '<<interrupt-execution>>'),
]),
('debug', [
('_Go to File/Line', '<<goto-file-line>>'),
HIDE_SEQUENCES = ("<Key-Escape>", "<FocusOut>")
CHECKHIDE_VIRTUAL_EVENT_NAME = "<<calltipwindow-checkhide>>"
CHECKHIDE_SEQUENCES = ("<KeyRelease>", "<ButtonRelease>")
-CHECKHIDE_TIME = 100 # miliseconds
+CHECKHIDE_TIME = 100 # milliseconds
MARK_RIGHT = "calltipwindowregion_right"
text.see("insert")
text.undo_block_stop()
- # Our editwin provides a is_char_in_string function that works
+ # Our editwin provides an is_char_in_string function that works
# with a Tk text index, but PyParse only knows about offsets into
# a string. This builds a function for PyParse that accepts an
# offset.
import sys
import tempfile
+from Tkinter import *
import tkFileDialog
import tkMessageBox
from SimpleDialog import SimpleDialog
# l2['state'] = DISABLED
l2.pack(side=TOP, anchor = W, fill=X)
l3 = Label(top, text="to your file\n"
+ "See Language Reference, 2.1.4 Encoding declarations.\n"
"Choose OK to save this file as %s\n"
"Edit your general options to silence this warning" % enc)
l3.pack(side=TOP, anchor = W)
+What's New in IDLE 2.7.13?
+==========================
+*Release date: 2017-01-01?*
+
+- Issue #27854: Make Help => IDLE Help work again on Windows.
+ Include idlelib/help.html in 2.7 Windows installer.
+
+- Issue #25507: Add back import needed for 2.x encoding warning box.
+ Add pointer to 'Encoding declaration' in Language Reference.
+
+- Issue #15308: Add 'interrupt execution' (^C) to Shell menu.
+ Patch by Roger Serwy, updated by Bayard Randel.
+
+- Issue #27922: Stop IDLE tests from 'flashing' gui widgets on the screen.
+
+- Issue #17642: add larger font sizes for classroom projection.
+
+- Add version to title of IDLE help window.
+
+- Issue #25564: In section on IDLE -- console differences, mention that
+ using exec means that __builtins__ is defined for each statement.
+
+- Issue #27714: text_textview and test_autocomplete now pass when re-run
+ in the same process. This occurs when test_idle fails when run with the
+ -w option but without -jn. Fix warning from test_config.
+
+- Issue #27452: add line counter and crc to IDLE configHandler test dump.
+
+- Issue #27365: Allow non-ascii chars in IDLE NEWS.txt, for contributor names.
+
+- Issue #27245: IDLE: Cleanly delete custom themes and key bindings.
+ Previously, when IDLE was started from a console or by import, a cascade
+ of warnings was emitted. Patch by Serhiy Storchaka.
+
+
What's New in IDLE 2.7.12?
==========================
-*Release date: 2015-06-30?*
+*Release date: 2015-06-25*
- Issue #5124: Paste with text selected now replaces the selection on X11.
This matches how paste works on Windows, Mac, most modern Linux apps,
Changes are written to HOME/.idlerc/config-extensions.cfg.
Original patch by Tal Einat.
-- Issue #16233: A module browser (File : Class Browser, Alt+C) requires a
+- Issue #16233: A module browser (File : Class Browser, Alt+C) requires an
editor window with a filename. When Class Browser is requested otherwise,
from a shell, output window, or 'Untitled' editor, Idle no longer displays
an error box. It now pops up an Open Module box (Alt+M). If a valid name
from idlelib.configHandler import idleConf
_openers = {')':'(',']':'[','}':'{'}
-CHECK_DELAY = 100 # miliseconds
+CHECK_DELAY = 100 # milliseconds
class ParenMatch:
"""Highlight matching parentheses
Show surrounding parens # ParenMatch (& Hyperparser)
Shell # PyShell
- View Last Restart # PyShell.?
- Restart Shell # PyShell.?
+ View Last Restart # PyShell.PyShell.view_restart_mark
+ Restart Shell # PyShell.PyShell.restart_shell
+ Interrupt Execution # pyshell.PyShell.cancel_callback
Debug (Shell only)
Go to File/Line
- Debugger # Debugger, RemoteDebugger
- Stack Viewer # StackViewer
- Auto-open Stack Viewer # StackViewer
+ Debugger # Debugger, RemoteDebugger, PyShell.toggle_debuger
+ Stack Viewer # StackViewer, PyShell.open_stack_viewer
+ Auto-open Stack Viewer # StackViewer
Format (Editor only)
Indent Region
def default_command(self, event=None):
if self.do_find(self.ok):
if self.do_replace(): # Only find next match if replace succeeded.
- # A bad re can cause a it to fail.
+ # A bad re can cause it to fail.
self.do_find(0)
def _replace_expand(self, m, repl):
It directly return the result of that call.
Text is a text widget. Prog is a precompiled pattern.
- The ok parameteris a bit complicated as it has two effects.
+ The ok parameter is a bit complicated as it has two effects.
If there is a selection, the search begin at either end,
depending on the direction setting and ok, with ok meaning that
if not tkMessageBox.askyesno(
'Delete Key Set', delmsg % keySetName, parent=self):
return
+ self.DeactivateCurrentConfig()
#remove key set from config
idleConf.userCfg['keys'].remove_section(keySetName)
if keySetName in self.changedItems['keys']:
self.keysAreBuiltin.set(idleConf.defaultCfg['main'].Get('Keys', 'default'))
self.builtinKeys.set(idleConf.defaultCfg['main'].Get('Keys', 'name'))
#user can't back out of these changes, they must be applied now
- self.Apply()
+ self.SaveAllChangedConfigs()
+ self.ActivateConfigChanges()
self.SetKeysType()
def DeleteCustomTheme(self):
if not tkMessageBox.askyesno(
'Delete Theme', delmsg % themeName, parent=self):
return
+ self.DeactivateCurrentConfig()
#remove theme from config
idleConf.userCfg['highlight'].remove_section(themeName)
if themeName in self.changedItems['highlight']:
self.themeIsBuiltin.set(idleConf.defaultCfg['main'].Get('Theme', 'default'))
self.builtinTheme.set(idleConf.defaultCfg['main'].Get('Theme', 'name'))
#user can't back out of these changes, they must be applied now
- self.Apply()
+ self.SaveAllChangedConfigs()
+ self.ActivateConfigChanges()
self.SetThemeType()
def GetColour(self):
pass
##font size dropdown
self.optMenuFontSize.SetMenu(('7', '8', '9', '10', '11', '12', '13',
- '14', '16', '18', '20', '22'), fontSize )
+ '14', '16', '18', '20', '22',
+ '25', '29', '34', '40'), fontSize )
##fontWeight
self.fontBold.set(fontBold)
##font sample
idleConf = IdleConf()
# TODO Revise test output, write expanded unittest
-### module test
+#
if __name__ == '__main__':
+ from zlib import crc32
+ line, crc = 0, 0
+
+ def sprint(obj):
+ global line, crc
+ txt = str(obj)
+ line += 1
+ crc = crc32(txt.encode(encoding='utf-8'), crc)
+ print(txt)
+ #print('***', line, crc, '***') # uncomment for diagnosis
+
def dumpCfg(cfg):
- print('\n', cfg, '\n')
- for key in cfg:
+ print('\n', cfg, '\n') # has variable '0xnnnnnnnn' addresses
+ for key in sorted(cfg.keys()):
sections = cfg[key].sections()
- print(key)
- print(sections)
+ sprint(key)
+ sprint(sections)
for section in sections:
options = cfg[key].options(section)
- print(section)
- print(options)
+ sprint(section)
+ sprint(options)
for option in options:
- print(option, '=', cfg[key].Get(section, option))
+ sprint(option + ' = ' + cfg[key].Get(section, option))
+
dumpCfg(idleConf.defaultCfg)
dumpCfg(idleConf.userCfg)
- print(idleConf.userCfg['main'].Get('Theme', 'name'))
- #print(idleConf.userCfg['highlight'].GetDefHighlight('Foo','normal'))
+ print('\nlines = ', line, ', crc = ', crc, sep='')
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>24.6. IDLE — Python 2.7.11 documentation</title>
+ <title>24.6. IDLE — Python 2.7.12 documentation</title>
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
- VERSION: '2.7.11',
+ VERSION: '2.7.12',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
- title="Search within Python 2.7.11 documentation"
+ title="Search within Python 2.7.12 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
- <link rel="top" title="Python 2.7.11 documentation" href="../contents.html" />
+ <link rel="top" title="Python 2.7.12 documentation" href="../contents.html" />
<link rel="up" title="24. Graphical User Interfaces with Tk" href="tk.html" />
<link rel="next" title="24.7. Other Graphical User Interface Packages" href="othergui.html" />
<link rel="prev" title="24.5. turtle — Turtle graphics for Tk" href="turtle.html" />
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
- <a href="../index.html">Python 2.7.11 documentation</a> »
+ <a href="../index.html">Python 2.7.12 documentation</a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
<dd>Scroll the shell window to the last Shell restart.</dd>
<dt>Restart Shell</dt>
<dd>Restart the shell to clean the environment.</dd>
+<dt>Interrupt Execution</dt>
+<dd>Stop a running program.</dd>
</dl>
</div>
<div class="section" id="debug-menu-shell-window-only">
functions to be used from IDLE’s Python shell.</p>
<div class="section" id="command-line-usage">
<h3>24.6.3.1. Command line usage<a class="headerlink" href="#command-line-usage" title="Permalink to this headline">¶</a></h3>
-<div class="highlight-python"><div class="highlight"><pre>idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
+<div class="highlight-none"><div class="highlight"><pre><span></span>idle.py [-c command] [-d] [-e] [-h] [-i] [-r file] [-s] [-t title] [-] [arg] ...
-c command run command in the shell window
-d enable debugger and open shell window
-e open editor window
--h print help message with legal combinatios and exit
+-h print help message with legal combinations and exit
-i open shell window
-r file run file in shell window
-s run $IDLESTARTUP or $PYTHONSTARTUP first, in shell window
IDLE’s changes are lost and things like <code class="docutils literal"><span class="pre">input</span></code>, <code class="docutils literal"><span class="pre">raw_input</span></code>, and
<code class="docutils literal"><span class="pre">print</span></code> will not work correctly.</p>
<p>With IDLE’s Shell, one enters, edits, and recalls complete statements.
-Some consoles only work with a single physical line at a time.</p>
+Some consoles only work with a single physical line at a time. IDLE uses
+<code class="docutils literal"><span class="pre">exec</span></code> to run each statement. As a result, <code class="docutils literal"><span class="pre">'__builtins__'</span></code> is always
+defined for each statement.</p>
</div>
<div class="section" id="running-without-a-subprocess">
<h3>24.6.3.3. Running without a subprocess<a class="headerlink" href="#running-without-a-subprocess" title="Permalink to this headline">¶</a></h3>
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
- <a href="../index.html">Python 2.7.11 documentation</a> »
+ <a href="../index.html">Python 2.7.12 documentation</a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
- Last updated on May 02, 2016.
+ Last updated on Sep 12, 2016.
<a href="../bugs.html">Found a bug</a>?
<br />
- Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
+ Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.6.
</div>
</body>
"""
from HTMLParser import HTMLParser
from os.path import abspath, dirname, isdir, isfile, join
+from platform import python_version
from Tkinter import Tk, Toplevel, Frame, Text, Scrollbar, Menu, Menubutton
import tkFont as tkfont
from idlelib.configHandler import idleConf
self.text.insert('end', d, (self.tags, self.chartags))
def handle_charref(self, name):
- self.text.insert('end', unichr(int(name)))
+ if self.show:
+ self.text.insert('end', unichr(int(name)))
class HelpText(Text):
if not isfile(filename):
# try copy_strip, present message
return
- HelpWindow(parent, filename, 'IDLE Help')
+ HelpWindow(parent, filename, 'IDLE Help (%s)' % python_version())
if __name__ == '__main__':
from idlelib.idle_test.htest import run
import os.path
import sys
-# If we are working on a development version of IDLE, we need to prepend the
-# parent of this idlelib dir to sys.path. Otherwise, importing idlelib gets
-# the version installed with the Python used to call this module:
+# Enable running IDLE with idlelib in a non-standard location.
+# This was once used to run development versions of IDLE.
+# Because PEP 434 declared idle.py a public interface,
+# removal should require deprecation.
idlelib_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-sys.path.insert(0, idlelib_dir)
+if idlelib_dir not in sys.path:
+ sys.path.insert(0, idlelib_dir)
-import idlelib.PyShell
-idlelib.PyShell.main()
+from idlelib.PyShell import main # This is subject to change
+main()
"""Classes that replace tkinter gui objects used by an object being tested.
-A gui object is anything with a master or parent paramenter, which is
+A gui object is anything with a master or parent parameter, which is
typically required in spite of what the doc strings say.
"""
import idlelib.AutoComplete as ac
import idlelib.AutoCompleteWindow as acw
-import idlelib.macosxSupport as mac
from idlelib.idle_test.mock_idle import Func
from idlelib.idle_test.mock_tk import Event
def setUpClass(cls):
requires('gui')
cls.root = Tk()
- mac.setupApp(cls.root, None)
cls.text = Text(cls.root)
cls.editor = DummyEditwin(cls.root, cls.text)
def setUpClass(cls):
requires('gui')
cls.root = Tk()
+ cls.root.withdraw()
_initializeTkVariantTests(cls.root)
@classmethod
import unittest
from idlelib import PyShell
+
class PasteTest(unittest.TestCase):
'''Test pasting into widgets that allow pasting.
On X11, replacing selections requires tk fix.
'''
+
@classmethod
def setUpClass(cls):
requires('gui')
cls.root = root = tk.Tk()
+ root.withdraw()
PyShell.fix_x11_paste(root)
cls.text = tk.Text(root)
cls.entry = tk.Entry(root)
class ReformatFunctionTest(unittest.TestCase):
"""Test the reformat_paragraph function without the editor window."""
- def test_reformat_paragrah(self):
+ def test_reformat_paragraph(self):
Equal = self.assertEqual
reform = fp.reformat_paragraph
hw = "O hello world"
def setUpClass(cls):
requires('gui')
cls.root = Tk()
+ cls.root.withdraw()
cls.text = Text(cls.root)
cls.editwin = DummyEditwin(cls.text)
def setUpClass(cls):
requires('gui')
cls.root = tk.Tk()
+ cls.root.withdraw()
def setUp(self):
self.text = text = TextWrapper(self.root)
from idlelib.idle_test.mock_idle import Func
from idlelib.idle_test.mock_tk import Mbox
-orig_mbox = tv.tkMessageBox
+
+class TV(tv.TextViewer): # Use in TextViewTest
+ transient = Func()
+ grab_set = Func()
+ wait_window = Func()
class textviewClassTest(unittest.TestCase):
def setUpClass(cls):
requires('gui')
cls.root = Tk()
- cls.TV = TV = tv.TextViewer
- TV.transient = Func()
- TV.grab_set = Func()
- TV.wait_window = Func()
+ cls.root.withdraw()
@classmethod
def tearDownClass(cls):
- del cls.TV
cls.root.destroy()
del cls.root
def setUp(self):
- TV = self.TV
TV.transient.__init__()
TV.grab_set.__init__()
TV.wait_window.__init__()
-
def test_init_modal(self):
- TV = self.TV
view = TV(self.root, 'Title', 'test text')
self.assertTrue(TV.transient.called)
self.assertTrue(TV.grab_set.called)
view.Ok()
def test_init_nonmodal(self):
- TV = self.TV
view = TV(self.root, 'Title', 'test text', modal=False)
self.assertFalse(TV.transient.called)
self.assertFalse(TV.grab_set.called)
view.Ok()
def test_ok(self):
- view = self.TV(self.root, 'Title', 'test text', modal=False)
+ view = TV(self.root, 'Title', 'test text', modal=False)
view.destroy = Func()
view.Ok()
self.assertTrue(view.destroy.called)
- del view.destroy # unmask real function
- view.destroy
+ del view.destroy # Unmask the real function.
+ view.destroy()
-class textviewTest(unittest.TestCase):
+class ViewFunctionTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
requires('gui')
cls.root = Tk()
+ cls.root.withdraw()
+ cls.orig_mbox = tv.tkMessageBox
tv.tkMessageBox = Mbox
@classmethod
def tearDownClass(cls):
cls.root.destroy()
del cls.root
- tv.tkMessageBox = orig_mbox
+ tv.tkMessageBox = cls.orig_mbox
+ del cls.orig_mbox
def test_view_text(self):
- # If modal True, tkinter will error with 'can't invoke "event" command'
+ # If modal True, get tkinter error 'can't invoke "event" command'.
view = tv.view_text(self.root, 'Title', 'test text', modal=False)
self.assertIsInstance(view, tv.TextViewer)
+ view.Ok()
def test_view_file(self):
test_dir = os.path.dirname(__file__)
self.assertIn('Test', view.textView.get('1.0', '1.end'))
view.Ok()
- # Mock messagebox will be used and view_file will not return anything
+ # Mock messagebox will be used; view_file will return None.
testfile = os.path.join(test_dir, '../notthere.py')
view = tv.view_file(self.root, 'Title', testfile, modal=False)
self.assertIsNone(view)
+
if __name__ == '__main__':
unittest.main(verbosity=2)
def setUpClass(cls):
requires('gui')
cls.root = Tk()
+ cls.root.withdraw()
cls.text = Text(cls.root)
@classmethod
def setUpClass(cls):
requires('gui')
cls.root = Tk()
+ cls.root.withdraw()
cls.text = Text(cls.root)
@classmethod
def isgeneratorfunction(object):
"""Return true if the object is a user-defined generator function.
- Generator function objects provides same attributes as functions.
-
- See help(isfunction) for attributes listing."""
+ Generator function objects provide the same attributes as functions.
+ See help(isfunction) for a list of attributes."""
return bool((isfunction(object) or ismethod(object)) and
object.func_code.co_flags & CO_GENERATOR)
Another IOBase subclass, TextIOBase, deals with the encoding and decoding
of streams into text. TextIOWrapper, which extends it, is a buffered text
interface to a buffered raw stream (`BufferedIOBase`). Finally, StringIO
-is a in-memory stream for text.
+is an in-memory stream for text.
Argument names are not part of the specification, and only the arguments
of open() are intended to be used as keyword arguments.
If ``ensure_ascii`` is true (the default), all non-ASCII characters in the
output are escaped with ``\uXXXX`` sequences, and the result is a ``str``
instance consisting of ASCII characters only. If ``ensure_ascii`` is
- ``False``, some chunks written to ``fp`` may be ``unicode`` instances.
+ false, some chunks written to ``fp`` may be ``unicode`` instances.
This usually happens because the input contains unicode strings or the
``encoding`` parameter is used. Unless ``fp.write()`` explicitly
understands ``unicode`` (as in ``codecs.getwriter``) this is likely to
``default(obj)`` is a function that should return a serializable version
of obj or raise TypeError. The default simply raises TypeError.
- If *sort_keys* is ``True`` (default: ``False``), then the output of
+ If *sort_keys* is true (default: ``False``), then the output of
dictionaries will be sorted by key.
To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
``default(obj)`` is a function that should return a serializable version
of obj or raise TypeError. The default simply raises TypeError.
- If *sort_keys* is ``True`` (default: ``False``), then the output of
+ If *sort_keys* is true (default: ``False``), then the output of
dictionaries will be sorted by key.
To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
for JSON integers (e.g. float).
``parse_constant``, if specified, will be called with one of the
- following strings: -Infinity, Infinity, NaN, null, true, false.
+ following strings: -Infinity, Infinity, NaN.
This can be used to raise an exception if invalid JSON numbers
are encountered.
#ESCAPE_DCT.setdefault(chr(i), '\\u%04x' % (i,))
INFINITY = float('inf')
-FLOAT_REPR = repr
+FLOAT_REPR = float.__repr__
def encode_basestring(s):
"""Return a JSON representation of a Python string
self.assertEqual(self.loads(s, object_pairs_hook=OrderedDict,
object_hook=lambda x: None),
OrderedDict(p))
- # check that empty objects literals work (see #17368)
+ # check that empty object literals work (see #17368)
self.assertEqual(self.loads('{}', object_pairs_hook=OrderedDict),
OrderedDict())
self.assertEqual(self.loads('{"empty": {}}',
self.assertNotEqual(res[0], res[0])
self.assertRaises(ValueError, self.dumps, [val], allow_nan=False)
+ def test_float_subclasses_use_float_repr(self):
+ # Issue 27934.
+ class PeculiarFloat(float):
+ def __repr__(self):
+ return "I'm not valid JSON"
+ def __str__(self):
+ return "Neither am I"
+
+ val = PeculiarFloat(3.2)
+ self.assertEqual(self.loads(self.dumps(val)), val)
+
class TestPyFloat(TestFloat, PyTest): pass
class TestCFloat(TestFloat, CTest): pass
# appreciate the advantages.
#
+import os
+import Tkinter
from Tkinter import *
-from Tkinter import _flatten, _cnfmerge, _default_root
+from Tkinter import _flatten, _cnfmerge
# WARNING - TkVersion is a limited precision floating point number
if TkVersion < 3.999:
# BEWARE - this is implemented by copying some code from the Widget class
# in Tkinter (to override Widget initialization) and is therefore
# liable to break.
-import Tkinter, os
# Could probably add this to Tkinter.Misc
class tixCommand:
(multiple) Display Items"""
def __init__(self, itemtype, cnf={}, **kw):
- master = _default_root # global from Tkinter
- if not master and 'refwindow' in cnf: master=cnf['refwindow']
- elif not master and 'refwindow' in kw: master= kw['refwindow']
- elif not master: raise RuntimeError, "Too early to create display style: no root window"
+ if 'refwindow' in kw:
+ master = kw['refwindow']
+ elif 'refwindow' in cnf:
+ master = cnf['refwindow']
+ else:
+ master = Tkinter._default_root
+ if not master:
+ raise RuntimeError("Too early to create display style: no root window")
self.tk = master.tk
self.stylename = self.tk.call('tixDisplayStyle', itemtype,
*self._options(cnf,kw) )
return self.tk.call(self._w, 'header', 'cget', col, opt)
def header_exists(self, col):
- return self.tk.call(self._w, 'header', 'exists', col)
+ # A workaround to Tix library bug (issue #25464).
+ # The documented command is "exists", but only erroneous "exist" is
+ # accepted.
+ return self.tk.getboolean(self.tk.call(self._w, 'header', 'exist', col))
+ header_exist = header_exists
def header_delete(self, col):
self.tk.call(self._w, 'header', 'delete', col)
CBNAME is the name of the callback returned from trace_variable or trace.
"""
self._tk.call("trace", "vdelete", self._name, mode, cbname)
- self._tk.deletecommand(cbname)
- try:
- self._tclCommands.remove(cbname)
- except ValueError:
- pass
+ cbname = self._tk.splitlist(cbname)[0]
+ for m, ca in self.trace_vinfo():
+ if self._tk.splitlist(ca)[0] == cbname:
+ break
+ else:
+ self._tk.deletecommand(cbname)
+ try:
+ self._tclCommands.remove(cbname)
+ except ValueError:
+ pass
def trace_vinfo(self):
"""Return all trace callback information."""
- return map(self._tk.split, self._tk.splitlist(
+ return map(self._tk.splitlist, self._tk.splitlist(
self._tk.call("trace", "vinfo", self._name)))
def __eq__(self, other):
"""Comparison for equality (==).
import unittest
-
+import gc
from Tkinter import (Variable, StringVar, IntVar, DoubleVar, BooleanVar, Tcl,
TclError)
with self.assertRaises(ValueError):
self.root.setvar('var\x00name', "value")
+ def test_trace(self):
+ v = Variable(self.root)
+ vname = str(v)
+ trace = []
+ def read_tracer(*args):
+ trace.append(('read',) + args)
+ def write_tracer(*args):
+ trace.append(('write',) + args)
+ cb1 = v.trace_variable('r', read_tracer)
+ cb2 = v.trace_variable('wu', write_tracer)
+ self.assertEqual(sorted(v.trace_vinfo()), [('r', cb1), ('wu', cb2)])
+ self.assertEqual(trace, [])
+
+ v.set('spam')
+ self.assertEqual(trace, [('write', vname, '', 'w')])
+
+ trace = []
+ v.get()
+ self.assertEqual(trace, [('read', vname, '', 'r')])
+
+ trace = []
+ info = sorted(v.trace_vinfo())
+ v.trace_vdelete('w', cb1) # Wrong mode
+ self.assertEqual(sorted(v.trace_vinfo()), info)
+ with self.assertRaises(TclError):
+ v.trace_vdelete('r', 'spam') # Wrong command name
+ self.assertEqual(sorted(v.trace_vinfo()), info)
+ v.trace_vdelete('r', (cb1, 43)) # Wrong arguments
+ self.assertEqual(sorted(v.trace_vinfo()), info)
+ v.get()
+ self.assertEqual(trace, [('read', vname, '', 'r')])
+
+ trace = []
+ v.trace_vdelete('r', cb1)
+ self.assertEqual(v.trace_vinfo(), [('wu', cb2)])
+ v.get()
+ self.assertEqual(trace, [])
+
+ trace = []
+ del write_tracer
+ gc.collect()
+ v.set('eggs')
+ self.assertEqual(trace, [('write', vname, '', 'w')])
+
+ #trace = []
+ #del v
+ #gc.collect()
+ #self.assertEqual(trace, [('write', vname, '', 'u')])
+
class TestStringVar(TestBase):
import Tkinter as tkinter
from Tkinter import TclError
import ttk
-from test.test_support import requires, run_unittest
+from test.test_support import requires, run_unittest, have_unicode, u
import sys
from test_functions import MockTclObj
value)
+ def test_selection(self):
+ # item 'none' doesn't exist
+ self.assertRaises(tkinter.TclError, self.tv.selection_set, 'none')
+ self.assertRaises(tkinter.TclError, self.tv.selection_add, 'none')
+ self.assertRaises(tkinter.TclError, self.tv.selection_remove, 'none')
+ self.assertRaises(tkinter.TclError, self.tv.selection_toggle, 'none')
+
+ item1 = self.tv.insert('', 'end')
+ item2 = self.tv.insert('', 'end')
+ c1 = self.tv.insert(item1, 'end')
+ c2 = self.tv.insert(item1, 'end')
+ c3 = self.tv.insert(item1, 'end')
+ self.assertEqual(self.tv.selection(), ())
+
+ self.tv.selection_set((c1, item2))
+ self.assertEqual(self.tv.selection(), (c1, item2))
+ self.tv.selection_set(c2)
+ self.assertEqual(self.tv.selection(), (c2,))
+
+ self.tv.selection_add((c1, item2))
+ self.assertEqual(self.tv.selection(), (c1, c2, item2))
+ self.tv.selection_add(item1)
+ self.assertEqual(self.tv.selection(), (item1, c1, c2, item2))
+
+ self.tv.selection_remove((item1, c3))
+ self.assertEqual(self.tv.selection(), (c1, c2, item2))
+ self.tv.selection_remove(c2)
+ self.assertEqual(self.tv.selection(), (c1, item2))
+
+ self.tv.selection_toggle((c1, c3))
+ self.assertEqual(self.tv.selection(), (c3, item2))
+ self.tv.selection_toggle(item2)
+ self.assertEqual(self.tv.selection(), (c3,))
+
+ self.tv.insert('', 'end', id='with spaces')
+ self.tv.selection_set('with spaces')
+ self.assertEqual(self.tv.selection(), ('with spaces',))
+
+ self.tv.insert('', 'end', id='{brace')
+ self.tv.selection_set('{brace')
+ self.assertEqual(self.tv.selection(), ('{brace',))
+
+ if have_unicode:
+ self.tv.insert('', 'end', id=u(r'unicode\u20ac'))
+ self.tv.selection_set(u(r'unicode\u20ac'))
+ self.assertEqual(self.tv.selection(), (u(r'unicode\u20ac'),))
+
+ self.tv.insert('', 'end', id='bytes\xe2\x82\xac')
+ self.tv.selection_set('bytes\xe2\x82\xac')
+ self.assertEqual(self.tv.selection(),
+ (u(r'bytes\u20ac') if have_unicode else
+ 'bytes\xe2\x82\xac',))
+
+
def test_set(self):
self.tv['columns'] = ['A', 'B']
item = self.tv.insert('', 'end', values=['a', 'b'])
SizegripTest, TreeviewTest, WidgetTest,
)
+tests_gui = (
+ TreeviewTest,
+ )
+
if __name__ == "__main__":
run_unittest(*tests_gui)
def _format_layoutlist(layout, indent=0, indent_size=2):
"""Formats a layout list so we can pass the result to ttk::style
- layout and ttk::style settings. Note that the layout doesn't has to
+ layout and ttk::style settings. Note that the layout doesn't have to
be a list necessarily.
E.g.:
def selection(self, selop=None, items=None):
"""If selop is not specified, returns selected items."""
- return self.tk.call(self._w, "selection", selop, items)
+ if isinstance(items, basestring):
+ items = (items,)
+ return self.tk.splitlist(self.tk.call(self._w, "selection", selop, items))
def selection_set(self, items):
continue
try:
key, value = line.split("=")
- except:
+ except ValueError:
print "Bad line in config-file %s:\n%s" % (filename,line)
continue
key = key.strip()
value = float(value)
else:
value = int(value)
- except:
+ except ValueError:
pass # value need not be converted
cfgdict[key] = value
return cfgdict
try:
head, tail = split(__file__)
cfg_file2 = join(head, default_cfg)
- except:
+ except BaseException:
cfg_file2 = ""
if isfile(cfg_file2):
#print "2. Loading config-file %s:" % cfg_file2
try:
readconfig(_CFG)
-except:
+except BaseException:
print "No configfile read, reason unknown"
x, y = (self.cv.canvasx(event.x)/self.xscale,
-self.cv.canvasy(event.y)/self.yscale)
fun(x, y)
- except:
+ except BaseException:
pass
self.cv.tag_bind(item, "<Button%s-Motion>" % num, eventfun, add)
"""
return self.cv.create_image(0, 0, image=image)
- def _drawimage(self, item, (x, y), image):
+ def _drawimage(self, item, pos, image):
"""Configure image item as to draw image object
at position (x,y) on canvas)
"""
+ x, y = pos
self.cv.coords(item, (x * self.xscale, -y * self.yscale))
self.cv.itemconfig(item, image=image)
"""Set turtle-mode ('standard', 'logo' or 'world') and perform reset.
Optional argument:
- mode -- on of the strings 'standard', 'logo' or 'world'
+ mode -- one of the strings 'standard', 'logo' or 'world'
Mode 'standard' is compatible with turtle.py.
Mode 'logo' is compatible with most Logo-Turtle-Graphics.
raise TurtleGraphicsError("bad color string: %s" % str(color))
try:
r, g, b = color
- except:
+ except (TypeError, ValueError):
raise TurtleGraphicsError("bad color arguments: %s" % str(color))
if self._colormode == 1.0:
r, g, b = [round(255.0*x) for x in (r, g, b)]
return args
try:
r, g, b = args
- except:
+ except (TypeError, ValueError):
raise TurtleGraphicsError("bad color arguments: %s" % str(args))
if self.screen._colormode == 1.0:
r, g, b = [round(255.0*x) for x in (r, g, b)]
#print key
try:
eval(key).im_func.__doc__ = docsdict[key]
- except:
+ except BaseException:
print "Bad docstring-entry: %s" % key
_LANGUAGE = _CFG["language"]
read_docstrings(_LANGUAGE)
except ImportError:
print "Cannot find docsdict for", _LANGUAGE
-except:
+except BaseException:
print ("Unknown Error when trying to import %s-docstring-dictionary" %
_LANGUAGE)
sliceop: ':' [test]
exprlist: (expr|star_expr) (',' (expr|star_expr))* [',']
testlist: test (',' test)* [',']
-dictsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) |
- (test (comp_for | (',' test)* [','])) )
+dictsetmaker: ( ((test ':' test | '**' expr)
+ (comp_for | (',' (test ':' test | '**' expr))* [','])) |
+ ((test | star_expr)
+ (comp_for | (',' (test | star_expr))* [','])) )
classdef: 'class' NAME ['(' [arglist] ')'] ':' suite
-arglist: (argument ',')* (argument [',']
- |'*' test (',' argument)* [',' '**' test]
- |'**' test)
-argument: test [comp_for] | test '=' test # Really [keyword '='] test
+arglist: argument (',' argument)* [',']
+
+# "test '=' test" is really "keyword '=' test", but we have no such token.
+# These need to be in a single rule to avoid grammar that is ambiguous
+# to our LL(1) parser. Even though 'test' includes '*expr' in star_expr,
+# we explicitly match '*' here, too, to give it proper precedence.
+# Illegal combinations and orderings are blocked in ast.c:
+# multiple (test comp_for) arguments are blocked; keyword unpackings
+# that precede iterable unpackings are blocked; etc.
+argument: ( test [comp_for] |
+ test '=' test |
+ '**' expr |
+ star_expr )
comp_iter: comp_for | comp_if
comp_for: 'for' exprlist 'in' testlist_safe [comp_iter]
func = results["func"]
args = results["args"]
kwds = results.get("kwds")
+ # I feel like we should be able to express this logic in the
+ # PATTERN above but I don't know how to do it so...
+ if args:
+ if args.type == self.syms.star_expr:
+ return # Make no change.
+ if (args.type == self.syms.argument and
+ args.children[0].value == '**'):
+ return # Make no change.
+ if kwds and (kwds.type == self.syms.argument and
+ kwds.children[0].value == '**'):
+ return # Make no change.
prefix = node.prefix
func = func.clone()
if (func.type not in (token.NAME, syms.atom) and
+++ /dev/null
-# Copyright 2007 Google, Inc. All Rights Reserved.
-# Licensed to PSF under a Contributor Agreement.
-
-"""Fixer for callable().
-
-This converts callable(obj) into isinstance(obj, collections.Callable), adding a
-collections import if needed."""
-
-# Local imports
-from lib2to3 import fixer_base
-from lib2to3.fixer_util import Call, Name, String, Attr, touch_import
-
-class FixCallable(fixer_base.BaseFix):
- BM_compatible = True
-
- order = "pre"
-
- # Ignore callable(*args) or use of keywords.
- # Either could be a hint that the builtin callable() is not being used.
- PATTERN = """
- power< 'callable'
- trailer< lpar='('
- ( not(arglist | argument<any '=' any>) func=any
- | func=arglist<(not argument<any '=' any>) any ','> )
- rpar=')' >
- after=any*
- >
- """
-
- def transform(self, node, results):
- func = results['func']
-
- touch_import(None, u'collections', node=node)
-
- args = [func.clone(), String(u', ')]
- args.extend(Attr(Name(u'collections'), Name(u'Callable')))
- return Call(Name(u'isinstance'), args, prefix=node.prefix)
"""
def transform(self, node, results):
- # If we're already wrapped in a eval() call, we're done.
+ # If we're already wrapped in an eval() call, we're done.
if context.match(node.parent.parent):
return
"""
def transform(self, node, results):
+ if results:
+ # I feel like we should be able to express this logic in the
+ # PATTERN above but I don't know how to do it so...
+ obj = results['obj']
+ if obj:
+ if obj.type == self.syms.star_expr:
+ return # Make no change.
+ if (obj.type == self.syms.argument and
+ obj.children[0].value == '**'):
+ return # Make no change.
syms = self.syms
obj = results["obj"].clone()
if obj.type == syms.arglist:
return self.parse_tokens(tokens, debug)
+def _generate_pickle_name(gt):
+ head, tail = os.path.splitext(gt)
+ if tail == ".txt":
+ tail = ""
+ return head + tail + ".".join(map(str, sys.version_info)) + ".pickle"
+
+
def load_grammar(gt="Grammar.txt", gp=None,
save=True, force=False, logger=None):
"""Load the grammar (maybe from a pickle)."""
if logger is None:
logger = logging.getLogger()
- if gp is None:
- head, tail = os.path.splitext(gt)
- if tail == ".txt":
- tail = ""
- gp = head + tail + ".".join(map(str, sys.version_info)) + ".pickle"
+ gp = _generate_pickle_name(gt) if gp is None else gp
if force or not _newer(gp, gt):
logger.info("Generating grammar tables from %s", gt)
g = pgen.generate_grammar(gt)
logger.info("Writing grammar tables to %s", gp)
try:
g.dump(gp)
- except IOError, e:
- logger.info("Writing failed:"+str(e))
+ except IOError as e:
+ logger.info("Writing failed: %s", e)
else:
g = grammar.Grammar()
g.load(gp)
"""
# Python imports
+import collections
import pickle
# Local imports
self.start = 256
def dump(self, filename):
- """Dump the grammar tables to a pickle file."""
- f = open(filename, "wb")
- pickle.dump(self.__dict__, f, 2)
- f.close()
+ """Dump the grammar tables to a pickle file.
+
+ dump() recursively changes all dict to OrderedDict, so the pickled file
+ is not exactly the same as what was passed in to dump(). load() uses the
+ pickled file to create the tables, but only changes OrderedDict to dict
+ at the top level; it does not recursively change OrderedDict to dict.
+ So, the loaded tables are different from the original tables that were
+ passed to load() in that some of the OrderedDict (from the pickled file)
+ are not changed back to dict. For parsing, this has no effect on
+ performance because OrderedDict uses dict's __getitem__ with nothing in
+ between.
+ """
+ with open(filename, "wb") as f:
+ d = _make_deterministic(self.__dict__)
+ pickle.dump(d, f, 2)
def load(self, filename):
"""Load the grammar tables from a pickle file."""
print "start", self.start
+def _make_deterministic(top):
+ if isinstance(top, dict):
+ return collections.OrderedDict(
+ sorted(((k, _make_deterministic(v)) for k, v in top.iteritems())))
+ if isinstance(top, list):
+ return [_make_deterministic(e) for e in top]
+ if isinstance(top, tuple):
+ return tuple(_make_deterministic(e) for e in top)
+ return top
+
+
# Map from operator to number (since tokenize doesn't do this)
opmap_raw = """
states = []
for state in dfa:
arcs = []
- for label, next in state.arcs.iteritems():
+ for label, next in sorted(state.arcs.iteritems()):
arcs.append((self.make_label(c, label), dfa.index(next)))
if state.isfinal:
arcs.append((0, dfa.index(state)))
def make_first(self, c, name):
rawfirst = self.first[name]
first = {}
- for label in rawfirst:
+ for label in sorted(rawfirst):
ilabel = self.make_label(c, label)
##assert ilabel not in first # XXX failed on <> ... !=
first[ilabel] = 1
for label, next in nfastate.arcs:
if label is not None:
addclosure(next, arcs.setdefault(label, {}))
- for label, nfaset in arcs.iteritems():
+ for label, nfaset in sorted(arcs.iteritems()):
for st in states:
if st.nfaset == nfaset:
break
print "Dump of DFA for", name
for i, state in enumerate(dfa):
print " State", i, state.isfinal and "(final)" or ""
- for label, next in state.arcs.iteritems():
+ for label, next in sorted(state.arcs.iteritems()):
print " %s -> %d" % (label, dfa.index(next))
def simplify_dfa(self, dfa):
# Local imports
from lib2to3 import pytree, refactor
-from lib2to3.pgen2 import driver
+from lib2to3.pgen2 import driver as pgen2_driver
test_dir = os.path.dirname(__file__)
proj_dir = os.path.normpath(os.path.join(test_dir, ".."))
grammar_path = os.path.join(test_dir, "..", "Grammar.txt")
-grammar = driver.load_grammar(grammar_path)
-driver = driver.Driver(grammar, convert=pytree.convert)
+grammar = pgen2_driver.load_grammar(grammar_path)
+driver = pgen2_driver.Driver(grammar, convert=pytree.convert)
def parse_string(string):
return driver.parse_string(reformat(string), debug=True)
s = """apply(f, *args)"""
self.unchanged(s)
+ def test_unchanged_6b(self):
+ s = """apply(f, **kwds)"""
+ self.unchanged(s)
+
def test_unchanged_7(self):
s = """apply(func=f, args=args, kwds=kwds)"""
self.unchanged(s)
a = f + """r'\\\\\\u20ac\\U0001d121\\\\u20ac'"""
self.check(b, a)
-class Test_callable(FixerTestCase):
- fixer = "callable"
-
- def test_prefix_preservation(self):
- b = """callable( x)"""
- a = """import collections\nisinstance( x, collections.Callable)"""
- self.check(b, a)
-
- b = """if callable(x): pass"""
- a = """import collections
-if isinstance(x, collections.Callable): pass"""
- self.check(b, a)
-
- def test_callable_call(self):
- b = """callable(x)"""
- a = """import collections\nisinstance(x, collections.Callable)"""
- self.check(b, a)
-
- def test_global_import(self):
- b = """
-def spam(foo):
- callable(foo)"""[1:]
- a = """
-import collections
-def spam(foo):
- isinstance(foo, collections.Callable)"""[1:]
- self.check(b, a)
-
- b = """
-import collections
-def spam(foo):
- callable(foo)"""[1:]
- # same output if it was already imported
- self.check(b, a)
-
- b = """
-from collections import *
-def spam(foo):
- callable(foo)"""[1:]
- a = """
-from collections import *
-import collections
-def spam(foo):
- isinstance(foo, collections.Callable)"""[1:]
- self.check(b, a)
-
- b = """
-do_stuff()
-do_some_other_stuff()
-assert callable(do_stuff)"""[1:]
- a = """
-import collections
-do_stuff()
-do_some_other_stuff()
-assert isinstance(do_stuff, collections.Callable)"""[1:]
- self.check(b, a)
-
- b = """
-if isinstance(do_stuff, Callable):
- assert callable(do_stuff)
- do_stuff(do_stuff)
- if not callable(do_stuff):
- exit(1)
- else:
- assert callable(do_stuff)
-else:
- assert not callable(do_stuff)"""[1:]
- a = """
-import collections
-if isinstance(do_stuff, Callable):
- assert isinstance(do_stuff, collections.Callable)
- do_stuff(do_stuff)
- if not isinstance(do_stuff, collections.Callable):
- exit(1)
- else:
- assert isinstance(do_stuff, collections.Callable)
-else:
- assert not isinstance(do_stuff, collections.Callable)"""[1:]
- self.check(b, a)
-
- def test_callable_should_not_change(self):
- a = """callable(*x)"""
- self.unchanged(a)
-
- a = """callable(x, y)"""
- self.unchanged(a)
-
- a = """callable(x, kw=y)"""
- self.unchanged(a)
-
- a = """callable()"""
- self.unchanged(a)
class Test_filter(FixerTestCase):
fixer = "filter"
test_grammar.py files from both Python 2 and Python 3.
"""
-from __future__ import with_statement
-
# Testing imports
from . import support
from .support import driver, test_dir
# Python imports
import os
+import shutil
+import subprocess
import sys
+import tempfile
+import unittest
# Local imports
+from lib2to3.pgen2 import driver as pgen2_driver
from lib2to3.pgen2 import tokenize
from ..pgen2.parse import ParseError
from lib2to3.pygram import python_symbols as syms
self.assertEqual(t.children[1].children[0].type, syms.print_stmt)
+class TestPgen2Caching(support.TestCase):
+ def test_load_grammar_from_txt_file(self):
+ pgen2_driver.load_grammar(support.grammar_path, save=False, force=True)
+
+ def test_load_grammar_from_pickle(self):
+ # Make a copy of the grammar file in a temp directory we are
+ # guaranteed to be able to write to.
+ tmpdir = tempfile.mkdtemp()
+ try:
+ grammar_copy = os.path.join(
+ tmpdir, os.path.basename(support.grammar_path))
+ shutil.copy(support.grammar_path, grammar_copy)
+ pickle_name = pgen2_driver._generate_pickle_name(grammar_copy)
+
+ pgen2_driver.load_grammar(grammar_copy, save=True, force=True)
+ self.assertTrue(os.path.exists(pickle_name))
+
+ os.unlink(grammar_copy) # Only the pickle remains...
+ pgen2_driver.load_grammar(grammar_copy, save=False, force=False)
+ finally:
+ shutil.rmtree(tmpdir)
+
+ @unittest.skipIf(sys.executable is None, 'sys.executable required')
+ def test_load_grammar_from_subprocess(self):
+ tmpdir = tempfile.mkdtemp()
+ tmpsubdir = os.path.join(tmpdir, 'subdir')
+ try:
+ os.mkdir(tmpsubdir)
+ grammar_base = os.path.basename(support.grammar_path)
+ grammar_copy = os.path.join(tmpdir, grammar_base)
+ grammar_sub_copy = os.path.join(tmpsubdir, grammar_base)
+ shutil.copy(support.grammar_path, grammar_copy)
+ shutil.copy(support.grammar_path, grammar_sub_copy)
+ pickle_name = pgen2_driver._generate_pickle_name(grammar_copy)
+ pickle_sub_name = pgen2_driver._generate_pickle_name(
+ grammar_sub_copy)
+ self.assertNotEqual(pickle_name, pickle_sub_name)
+
+ # Generate a pickle file from this process.
+ pgen2_driver.load_grammar(grammar_copy, save=True, force=True)
+ self.assertTrue(os.path.exists(pickle_name))
+
+ # Generate a new pickle file in a subprocess with a most likely
+ # different hash randomization seed.
+ sub_env = dict(os.environ)
+ sub_env['PYTHONHASHSEED'] = 'random'
+ subprocess.check_call(
+ [sys.executable, '-c', """
+from lib2to3.pgen2 import driver as pgen2_driver
+pgen2_driver.load_grammar(%r, save=True, force=True)
+ """ % (grammar_sub_copy,)],
+ env=sub_env)
+ self.assertTrue(os.path.exists(pickle_sub_name))
+
+ with open(pickle_name, 'rb') as pickle_f_1, \
+ open(pickle_sub_name, 'rb') as pickle_f_2:
+ self.assertEqual(
+ pickle_f_1.read(), pickle_f_2.read(),
+ msg='Grammar caches generated using different hash seeds'
+ ' were not identical.')
+ finally:
+ shutil.rmtree(tmpdir)
+
+
+
class GrammarTest(support.TestCase):
def validate(self, code):
support.parse_string(code)
self.invalid_syntax("raise E from")
+# Modelled after Lib/test/test_grammar.py:TokenTests.test_funcdef issue2292
+# and Lib/test/text_parser.py test_list_displays, test_set_displays,
+# test_dict_displays, test_argument_unpacking, ... changes.
+class TestUnpackingGeneralizations(GrammarTest):
+ def test_mid_positional_star(self):
+ self.validate("""func(1, *(2, 3), 4)""")
+
+ def test_double_star_dict_literal(self):
+ self.validate("""func(**{'eggs':'scrambled', 'spam':'fried'})""")
+
+ def test_double_star_dict_literal_after_keywords(self):
+ self.validate("""func(spam='fried', **{'eggs':'scrambled'})""")
+
+ def test_list_display(self):
+ self.validate("""[*{2}, 3, *[4]]""")
+
+ def test_set_display(self):
+ self.validate("""{*{2}, 3, *[4]}""")
+
+ def test_dict_display_1(self):
+ self.validate("""{**{}}""")
+
+ def test_dict_display_2(self):
+ self.validate("""{**{}, 3:4, **{5:6, 7:8}}""")
+
+ def test_argument_unpacking_1(self):
+ self.validate("""f(a, *b, *c, d)""")
+
+ def test_argument_unpacking_2(self):
+ self.validate("""f(**a, **b)""")
+
+ def test_argument_unpacking_3(self):
+ self.validate("""f(2, *a, *b, **b, **c, **d)""")
+
+
# Adaptated from Python 3's Lib/test/test_grammar.py:GrammarTests.testFuncdef
class TestFunctionAnnotations(GrammarTest):
def test_1(self):
import os
import codecs
import operator
+import re
import StringIO
import tempfile
import shutil
actually_write=False)
# Testing that it logged this message when write=False was passed is
# sufficient to see that it did not bail early after "No changes".
- message_regex = r"Not writing changes to .*%s%s" % (
- os.sep, os.path.basename(test_file))
+ message_regex = r"Not writing changes to .*%s" % \
+ re.escape(os.sep + os.path.basename(test_file))
for message in debug_messages:
if "Not writing changes" in message:
self.assertRegexpMatches(message, message_regex)
(u'CustomAction',u'Source',u'Y',None, None, None, None, u'CustomSource',None, u'The table reference of the source of the code.',),
(u'CustomAction',u'Target',u'Y',None, None, None, None, u'Formatted',None, u'Execution parameter, depends on the type of custom action',),
(u'DrLocator',u'Signature_',u'N',None, None, None, None, u'Identifier',None, u'The Signature_ represents a unique file signature and is also the foreign key in the Signature table.',),
-(u'DrLocator',u'Path',u'Y',None, None, None, None, u'AnyPath',None, u'The path on the user system. This is a either a subpath below the value of the Parent or a full path. The path may contain properties enclosed within [ ] that will be expanded.',),
+(u'DrLocator',u'Path',u'Y',None, None, None, None, u'AnyPath',None, u'The path on the user system. This is either a subpath below the value of the Parent or a full path. The path may contain properties enclosed within [ ] that will be expanded.',),
(u'DrLocator',u'Depth',u'Y',0,32767,None, None, None, None, u'The depth below the path to which the Signature_ is recursively searched. If absent, the depth is assumed to be 0.',),
(u'DrLocator',u'Parent',u'Y',None, None, None, None, u'Identifier',None, u'The parent file signature. It is also a foreign key in the Signature table. If null and the Path column does not expand to a full path, then all the fixed drives of the user system are searched using the Path.',),
(u'DuplicateFile',u'File_',u'N',None, None, u'File',1,u'Identifier',None, u'Foreign key referencing the source file to be duplicated.',),
try:
send(msg)
except Exception, e:
- send(('#UNSERIALIZABLE', repr(msg)))
+ send(('#UNSERIALIZABLE', format_exc()))
except Exception, e:
util.info('exception in thread serving %r',
threading.current_thread().name)
def mountvolume(volume, server=None, username=None, password=None):
"""mount a volume, local or on a server on AppleTalk.
- Note: mounting a ASIP server requires a different operation.
+ Note: mounting an ASIP server requires a different operation.
server is the name of the server where the volume belongs
username, password belong to a registered user of the volume."""
finder = _getfinder()
"""Open a resource file given by pathname, possibly decoding an
AppleSingle file"""
# No resource fork. We may be on OSX, and this may be either
- # a data-fork based resource file or a AppleSingle file
+ # a data-fork based resource file or an AppleSingle file
# from the CVS repository.
try:
refno = Res.FSOpenResourceFile(pathname, u'', 1)
If the pathname given already refers to such a file simply return it,
otherwise first decode it."""
# No resource fork. We may be on OSX, and this may be either
- # a data-fork based resource file or a AppleSingle file
+ # a data-fork based resource file or an AppleSingle file
# from the CVS repository.
try:
refno = Res.FSOpenResourceFile(pathname, u'', 1)
# though
# 0.5.2 - fixed uname() to return '' instead of 'unknown' in all
# return values (the system uname command tends to return
-# 'unknown' instead of just leaving the field emtpy)
+# 'unknown' instead of just leaving the field empty)
# 0.5.1 - included code for slackware dist; added exception handlers
# to cover up situations where platforms don't have os.popen
# (e.g. Mac) or fail on socket.gethostname(); fixed libc
return maj, min, build
from ctypes import (c_buffer, POINTER, byref, create_unicode_buffer,
- Structure, WinDLL)
+ Structure, WinDLL, _Pointer)
from ctypes.wintypes import DWORD, HANDLE
class VS_FIXEDFILEINFO(Structure):
("dwFileDateMS", DWORD),
("dwFileDateLS", DWORD),
]
+ class PVS_FIXEDFILEINFO(_Pointer):
+ _type_ = VS_FIXEDFILEINFO
kernel32 = WinDLL('kernel32')
version = WinDLL('version')
not ver_block):
return maj, min, build
- pvi = POINTER(VS_FIXEDFILEINFO)()
+ pvi = PVS_FIXEDFILEINFO()
if not version.VerQueryValueW(ver_block, "", byref(pvi), byref(DWORD())):
return maj, min, build
csd = 'SP' + csd[13:]
# VER_NT_SERVER = 3
- if getattr(winver, 'product', None) == 3:
+ if getattr(winver, 'product_type', None) == 3:
release = (_WIN32_SERVER_RELEASES.get((maj, min)) or
_WIN32_SERVER_RELEASES.get((maj, None)) or
release)
return False
try:
s1 = os.lstat(path)
- s2 = os.lstat(join(path, '..'))
+ s2 = os.lstat(realpath(join(path, '..')))
except os.error:
return False # It doesn't exist -- so not a mount point :-)
dev1 = s1.st_dev
Module docs for core modules are assumed to be in
- http://docs.python.org/library/
+ https://docs.python.org/library/
This can be overridden by setting the PYTHONDOCS environment variable
to a different URL or to a local directory containing the Library
docmodule = docclass = docroutine = docother = docproperty = docdata = fail
- def getdocloc(self, object):
+ def getdocloc(self, object,
+ basedir=os.path.join(sys.exec_prefix, "lib",
+ "python"+sys.version[0:3])):
"""Return the location of module docs or None"""
try:
file = '(built-in)'
docloc = os.environ.get("PYTHONDOCS",
- "http://docs.python.org/library")
- basedir = os.path.join(sys.exec_prefix, "lib",
- "python"+sys.version[0:3])
+ "https://docs.python.org/library")
+ basedir = os.path.normcase(basedir)
if (isinstance(object, type(os)) and
(object.__name__ in ('errno', 'exceptions', 'gc', 'imp',
'marshal', 'posix', 'signal', 'sys',
(file.startswith(basedir) and
not file.startswith(os.path.join(basedir, 'site-packages')))) and
object.__name__ not in ('xml.etree', 'test.pydoc_mod')):
- if docloc.startswith("http://"):
- docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__)
+ if docloc.startswith(("http://", "https://")):
+ docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__.lower())
else:
- docloc = os.path.join(docloc, object.__name__ + ".html")
+ docloc = os.path.join(docloc, object.__name__.lower() + ".html")
else:
docloc = None
return docloc
# -*- coding: utf-8 -*-
-# Autogenerated by Sphinx on Sat Jun 11 14:41:12 2016
-topics = {'assert': '\n'
- 'The "assert" statement\n'
- '**********************\n'
- '\n'
- 'Assert statements are a convenient way to insert debugging '
- 'assertions\n'
- 'into a program:\n'
- '\n'
- ' assert_stmt ::= "assert" expression ["," expression]\n'
- '\n'
- 'The simple form, "assert expression", is equivalent to\n'
- '\n'
- ' if __debug__:\n'
- ' if not expression: raise AssertionError\n'
- '\n'
- 'The extended form, "assert expression1, expression2", is '
- 'equivalent to\n'
- '\n'
- ' if __debug__:\n'
- ' if not expression1: raise AssertionError(expression2)\n'
- '\n'
- 'These equivalences assume that "__debug__" and "AssertionError" '
- 'refer\n'
- 'to the built-in variables with those names. In the current\n'
- 'implementation, the built-in variable "__debug__" is "True" under\n'
- 'normal circumstances, "False" when optimization is requested '
- '(command\n'
- 'line option -O). The current code generator emits no code for an\n'
- 'assert statement when optimization is requested at compile time. '
- 'Note\n'
- 'that it is unnecessary to include the source code for the '
- 'expression\n'
- 'that failed in the error message; it will be displayed as part of '
- 'the\n'
- 'stack trace.\n'
- '\n'
- 'Assignments to "__debug__" are illegal. The value for the '
- 'built-in\n'
- 'variable is determined when the interpreter starts.\n',
- 'assignment': '\n'
- 'Assignment statements\n'
- '*********************\n'
- '\n'
- 'Assignment statements are used to (re)bind names to values and '
- 'to\n'
- 'modify attributes or items of mutable objects:\n'
- '\n'
- ' assignment_stmt ::= (target_list "=")+ (expression_list | '
- 'yield_expression)\n'
- ' target_list ::= target ("," target)* [","]\n'
- ' target ::= identifier\n'
- ' | "(" target_list ")"\n'
- ' | "[" [target_list] "]"\n'
- ' | attributeref\n'
- ' | subscription\n'
- ' | slicing\n'
- '\n'
- '(See section Primaries for the syntax definitions for the last '
- 'three\n'
- 'symbols.)\n'
- '\n'
- 'An assignment statement evaluates the expression list '
- '(remember that\n'
- 'this can be a single expression or a comma-separated list, the '
- 'latter\n'
- 'yielding a tuple) and assigns the single resulting object to '
- 'each of\n'
- 'the target lists, from left to right.\n'
- '\n'
- 'Assignment is defined recursively depending on the form of the '
- 'target\n'
- '(list). When a target is part of a mutable object (an '
- 'attribute\n'
- 'reference, subscription or slicing), the mutable object must\n'
- 'ultimately perform the assignment and decide about its '
- 'validity, and\n'
- 'may raise an exception if the assignment is unacceptable. The '
- 'rules\n'
- 'observed by various types and the exceptions raised are given '
- 'with the\n'
- 'definition of the object types (see section The standard type\n'
- 'hierarchy).\n'
- '\n'
- 'Assignment of an object to a target list is recursively '
- 'defined as\n'
- 'follows.\n'
- '\n'
- '* If the target list is a single target: The object is '
- 'assigned to\n'
- ' that target.\n'
- '\n'
- '* If the target list is a comma-separated list of targets: '
- 'The\n'
- ' object must be an iterable with the same number of items as '
- 'there\n'
- ' are targets in the target list, and the items are assigned, '
- 'from\n'
- ' left to right, to the corresponding targets.\n'
- '\n'
- 'Assignment of an object to a single target is recursively '
- 'defined as\n'
- 'follows.\n'
- '\n'
- '* If the target is an identifier (name):\n'
- '\n'
- ' * If the name does not occur in a "global" statement in the\n'
- ' current code block: the name is bound to the object in the '
- 'current\n'
- ' local namespace.\n'
- '\n'
- ' * Otherwise: the name is bound to the object in the current '
- 'global\n'
- ' namespace.\n'
- '\n'
- ' The name is rebound if it was already bound. This may cause '
- 'the\n'
- ' reference count for the object previously bound to the name '
- 'to reach\n'
- ' zero, causing the object to be deallocated and its '
- 'destructor (if it\n'
- ' has one) to be called.\n'
- '\n'
- '* If the target is a target list enclosed in parentheses or '
- 'in\n'
- ' square brackets: The object must be an iterable with the '
- 'same number\n'
- ' of items as there are targets in the target list, and its '
- 'items are\n'
- ' assigned, from left to right, to the corresponding targets.\n'
- '\n'
- '* If the target is an attribute reference: The primary '
- 'expression in\n'
- ' the reference is evaluated. It should yield an object with\n'
- ' assignable attributes; if this is not the case, "TypeError" '
- 'is\n'
- ' raised. That object is then asked to assign the assigned '
- 'object to\n'
- ' the given attribute; if it cannot perform the assignment, it '
- 'raises\n'
- ' an exception (usually but not necessarily '
- '"AttributeError").\n'
- '\n'
- ' Note: If the object is a class instance and the attribute '
- 'reference\n'
- ' occurs on both sides of the assignment operator, the RHS '
- 'expression,\n'
- ' "a.x" can access either an instance attribute or (if no '
- 'instance\n'
- ' attribute exists) a class attribute. The LHS target "a.x" '
- 'is always\n'
- ' set as an instance attribute, creating it if necessary. '
- 'Thus, the\n'
- ' two occurrences of "a.x" do not necessarily refer to the '
- 'same\n'
- ' attribute: if the RHS expression refers to a class '
- 'attribute, the\n'
- ' LHS creates a new instance attribute as the target of the\n'
- ' assignment:\n'
- '\n'
- ' class Cls:\n'
- ' x = 3 # class variable\n'
- ' inst = Cls()\n'
- ' inst.x = inst.x + 1 # writes inst.x as 4 leaving Cls.x '
- 'as 3\n'
- '\n'
- ' This description does not necessarily apply to descriptor\n'
- ' attributes, such as properties created with "property()".\n'
- '\n'
- '* If the target is a subscription: The primary expression in '
- 'the\n'
- ' reference is evaluated. It should yield either a mutable '
- 'sequence\n'
- ' object (such as a list) or a mapping object (such as a '
- 'dictionary).\n'
- ' Next, the subscript expression is evaluated.\n'
- '\n'
- ' If the primary is a mutable sequence object (such as a '
- 'list), the\n'
- ' subscript must yield a plain integer. If it is negative, '
- 'the\n'
- " sequence's length is added to it. The resulting value must "
- 'be a\n'
- " nonnegative integer less than the sequence's length, and "
- 'the\n'
- ' sequence is asked to assign the assigned object to its item '
- 'with\n'
- ' that index. If the index is out of range, "IndexError" is '
- 'raised\n'
- ' (assignment to a subscripted sequence cannot add new items '
- 'to a\n'
- ' list).\n'
- '\n'
- ' If the primary is a mapping object (such as a dictionary), '
- 'the\n'
- " subscript must have a type compatible with the mapping's key "
- 'type,\n'
- ' and the mapping is then asked to create a key/datum pair '
- 'which maps\n'
- ' the subscript to the assigned object. This can either '
- 'replace an\n'
- ' existing key/value pair with the same key value, or insert a '
- 'new\n'
- ' key/value pair (if no key with the same value existed).\n'
- '\n'
- '* If the target is a slicing: The primary expression in the\n'
- ' reference is evaluated. It should yield a mutable sequence '
- 'object\n'
- ' (such as a list). The assigned object should be a sequence '
- 'object\n'
- ' of the same type. Next, the lower and upper bound '
- 'expressions are\n'
- ' evaluated, insofar they are present; defaults are zero and '
- 'the\n'
- " sequence's length. The bounds should evaluate to (small) "
- 'integers.\n'
- " If either bound is negative, the sequence's length is added "
- 'to it.\n'
- ' The resulting bounds are clipped to lie between zero and '
- 'the\n'
- " sequence's length, inclusive. Finally, the sequence object "
- 'is asked\n'
- ' to replace the slice with the items of the assigned '
- 'sequence. The\n'
- ' length of the slice may be different from the length of the '
- 'assigned\n'
- ' sequence, thus changing the length of the target sequence, '
- 'if the\n'
- ' object allows it.\n'
- '\n'
- '**CPython implementation detail:** In the current '
- 'implementation, the\n'
- 'syntax for targets is taken to be the same as for expressions, '
- 'and\n'
- 'invalid syntax is rejected during the code generation phase, '
- 'causing\n'
- 'less detailed error messages.\n'
- '\n'
- 'WARNING: Although the definition of assignment implies that '
- 'overlaps\n'
- "between the left-hand side and the right-hand side are 'safe' "
- '(for\n'
- 'example "a, b = b, a" swaps two variables), overlaps *within* '
- 'the\n'
- 'collection of assigned-to variables are not safe! For '
- 'instance, the\n'
- 'following program prints "[0, 2]":\n'
- '\n'
- ' x = [0, 1]\n'
- ' i = 0\n'
- ' i, x[i] = 1, 2\n'
- ' print x\n'
- '\n'
- '\n'
- 'Augmented assignment statements\n'
- '===============================\n'
- '\n'
- 'Augmented assignment is the combination, in a single '
- 'statement, of a\n'
- 'binary operation and an assignment statement:\n'
- '\n'
- ' augmented_assignment_stmt ::= augtarget augop '
- '(expression_list | yield_expression)\n'
- ' augtarget ::= identifier | attributeref | '
- 'subscription | slicing\n'
- ' augop ::= "+=" | "-=" | "*=" | "/=" | '
- '"//=" | "%=" | "**="\n'
- ' | ">>=" | "<<=" | "&=" | "^=" | "|="\n'
- '\n'
- '(See section Primaries for the syntax definitions for the last '
- 'three\n'
- 'symbols.)\n'
- '\n'
- 'An augmented assignment evaluates the target (which, unlike '
- 'normal\n'
- 'assignment statements, cannot be an unpacking) and the '
- 'expression\n'
- 'list, performs the binary operation specific to the type of '
- 'assignment\n'
- 'on the two operands, and assigns the result to the original '
- 'target.\n'
- 'The target is only evaluated once.\n'
- '\n'
- 'An augmented assignment expression like "x += 1" can be '
- 'rewritten as\n'
- '"x = x + 1" to achieve a similar, but not exactly equal '
- 'effect. In the\n'
- 'augmented version, "x" is only evaluated once. Also, when '
- 'possible,\n'
- 'the actual operation is performed *in-place*, meaning that '
- 'rather than\n'
- 'creating a new object and assigning that to the target, the '
- 'old object\n'
- 'is modified instead.\n'
- '\n'
- 'With the exception of assigning to tuples and multiple targets '
- 'in a\n'
- 'single statement, the assignment done by augmented assignment\n'
- 'statements is handled the same way as normal assignments. '
- 'Similarly,\n'
- 'with the exception of the possible *in-place* behavior, the '
- 'binary\n'
- 'operation performed by augmented assignment is the same as the '
- 'normal\n'
- 'binary operations.\n'
- '\n'
- 'For targets which are attribute references, the same caveat '
- 'about\n'
- 'class and instance attributes applies as for regular '
- 'assignments.\n',
- 'atom-identifiers': '\n'
- 'Identifiers (Names)\n'
- '*******************\n'
- '\n'
- 'An identifier occurring as an atom is a name. See '
- 'section Identifiers\n'
- 'and keywords for lexical definition and section Naming '
- 'and binding for\n'
- 'documentation of naming and binding.\n'
- '\n'
- 'When the name is bound to an object, evaluation of the '
- 'atom yields\n'
- 'that object. When a name is not bound, an attempt to '
- 'evaluate it\n'
- 'raises a "NameError" exception.\n'
- '\n'
- '**Private name mangling:** When an identifier that '
- 'textually occurs in\n'
- 'a class definition begins with two or more underscore '
- 'characters and\n'
- 'does not end in two or more underscores, it is '
- 'considered a *private\n'
- 'name* of that class. Private names are transformed to a '
- 'longer form\n'
- 'before code is generated for them. The transformation '
- 'inserts the\n'
- 'class name, with leading underscores removed and a '
- 'single underscore\n'
- 'inserted, in front of the name. For example, the '
- 'identifier "__spam"\n'
- 'occurring in a class named "Ham" will be transformed to '
- '"_Ham__spam".\n'
- 'This transformation is independent of the syntactical '
- 'context in which\n'
- 'the identifier is used. If the transformed name is '
- 'extremely long\n'
- '(longer than 255 characters), implementation defined '
- 'truncation may\n'
- 'happen. If the class name consists only of underscores, '
- 'no\n'
- 'transformation is done.\n',
- 'atom-literals': '\n'
- 'Literals\n'
- '********\n'
- '\n'
- 'Python supports string literals and various numeric '
- 'literals:\n'
- '\n'
- ' literal ::= stringliteral | integer | longinteger\n'
- ' | floatnumber | imagnumber\n'
- '\n'
- 'Evaluation of a literal yields an object of the given type '
- '(string,\n'
- 'integer, long integer, floating point number, complex '
- 'number) with the\n'
- 'given value. The value may be approximated in the case of '
- 'floating\n'
- 'point and imaginary (complex) literals. See section '
- 'Literals for\n'
- 'details.\n'
- '\n'
- 'All literals correspond to immutable data types, and hence '
- 'the\n'
- "object's identity is less important than its value. "
- 'Multiple\n'
- 'evaluations of literals with the same value (either the '
- 'same\n'
- 'occurrence in the program text or a different occurrence) '
- 'may obtain\n'
- 'the same object or a different object with the same '
- 'value.\n',
- 'attribute-access': '\n'
- 'Customizing attribute access\n'
- '****************************\n'
- '\n'
- 'The following methods can be defined to customize the '
- 'meaning of\n'
- 'attribute access (use of, assignment to, or deletion of '
- '"x.name") for\n'
- 'class instances.\n'
- '\n'
- 'object.__getattr__(self, name)\n'
- '\n'
- ' Called when an attribute lookup has not found the '
- 'attribute in the\n'
- ' usual places (i.e. it is not an instance attribute '
- 'nor is it found\n'
- ' in the class tree for "self"). "name" is the '
- 'attribute name. This\n'
- ' method should return the (computed) attribute value '
- 'or raise an\n'
- ' "AttributeError" exception.\n'
- '\n'
- ' Note that if the attribute is found through the '
- 'normal mechanism,\n'
- ' "__getattr__()" is not called. (This is an '
- 'intentional asymmetry\n'
- ' between "__getattr__()" and "__setattr__()".) This is '
- 'done both for\n'
- ' efficiency reasons and because otherwise '
- '"__getattr__()" would have\n'
- ' no way to access other attributes of the instance. '
- 'Note that at\n'
- ' least for instance variables, you can fake total '
- 'control by not\n'
- ' inserting any values in the instance attribute '
- 'dictionary (but\n'
- ' instead inserting them in another object). See the\n'
- ' "__getattribute__()" method below for a way to '
- 'actually get total\n'
- ' control in new-style classes.\n'
- '\n'
- 'object.__setattr__(self, name, value)\n'
- '\n'
- ' Called when an attribute assignment is attempted. '
- 'This is called\n'
- ' instead of the normal mechanism (i.e. store the value '
- 'in the\n'
- ' instance dictionary). *name* is the attribute name, '
- '*value* is the\n'
- ' value to be assigned to it.\n'
- '\n'
- ' If "__setattr__()" wants to assign to an instance '
- 'attribute, it\n'
- ' should not simply execute "self.name = value" --- '
- 'this would cause\n'
- ' a recursive call to itself. Instead, it should '
- 'insert the value in\n'
- ' the dictionary of instance attributes, e.g., '
- '"self.__dict__[name] =\n'
- ' value". For new-style classes, rather than accessing '
- 'the instance\n'
- ' dictionary, it should call the base class method with '
- 'the same\n'
- ' name, for example, "object.__setattr__(self, name, '
- 'value)".\n'
- '\n'
- 'object.__delattr__(self, name)\n'
- '\n'
- ' Like "__setattr__()" but for attribute deletion '
- 'instead of\n'
- ' assignment. This should only be implemented if "del '
- 'obj.name" is\n'
- ' meaningful for the object.\n'
- '\n'
- '\n'
- 'More attribute access for new-style classes\n'
- '===========================================\n'
- '\n'
- 'The following methods only apply to new-style classes.\n'
- '\n'
- 'object.__getattribute__(self, name)\n'
- '\n'
- ' Called unconditionally to implement attribute '
- 'accesses for\n'
- ' instances of the class. If the class also defines '
- '"__getattr__()",\n'
- ' the latter will not be called unless '
- '"__getattribute__()" either\n'
- ' calls it explicitly or raises an "AttributeError". '
- 'This method\n'
- ' should return the (computed) attribute value or raise '
- 'an\n'
- ' "AttributeError" exception. In order to avoid '
- 'infinite recursion in\n'
- ' this method, its implementation should always call '
- 'the base class\n'
- ' method with the same name to access any attributes it '
- 'needs, for\n'
- ' example, "object.__getattribute__(self, name)".\n'
- '\n'
- ' Note: This method may still be bypassed when looking '
- 'up special\n'
- ' methods as the result of implicit invocation via '
- 'language syntax\n'
- ' or built-in functions. See Special method lookup '
- 'for new-style\n'
- ' classes.\n'
- '\n'
- '\n'
- 'Implementing Descriptors\n'
- '========================\n'
- '\n'
- 'The following methods only apply when an instance of the '
- 'class\n'
- 'containing the method (a so-called *descriptor* class) '
- 'appears in an\n'
- '*owner* class (the descriptor must be in either the '
- "owner's class\n"
- 'dictionary or in the class dictionary for one of its '
- 'parents). In the\n'
- 'examples below, "the attribute" refers to the attribute '
- 'whose name is\n'
- "the key of the property in the owner class' "
- '"__dict__".\n'
- '\n'
- 'object.__get__(self, instance, owner)\n'
- '\n'
- ' Called to get the attribute of the owner class (class '
- 'attribute\n'
- ' access) or of an instance of that class (instance '
- 'attribute\n'
- ' access). *owner* is always the owner class, while '
- '*instance* is the\n'
- ' instance that the attribute was accessed through, or '
- '"None" when\n'
- ' the attribute is accessed through the *owner*. This '
- 'method should\n'
- ' return the (computed) attribute value or raise an '
- '"AttributeError"\n'
- ' exception.\n'
- '\n'
- 'object.__set__(self, instance, value)\n'
- '\n'
- ' Called to set the attribute on an instance *instance* '
- 'of the owner\n'
- ' class to a new value, *value*.\n'
- '\n'
- 'object.__delete__(self, instance)\n'
- '\n'
- ' Called to delete the attribute on an instance '
- '*instance* of the\n'
- ' owner class.\n'
- '\n'
- '\n'
- 'Invoking Descriptors\n'
- '====================\n'
- '\n'
- 'In general, a descriptor is an object attribute with '
- '"binding\n'
- 'behavior", one whose attribute access has been '
- 'overridden by methods\n'
- 'in the descriptor protocol: "__get__()", "__set__()", '
- 'and\n'
- '"__delete__()". If any of those methods are defined for '
- 'an object, it\n'
- 'is said to be a descriptor.\n'
- '\n'
- 'The default behavior for attribute access is to get, '
- 'set, or delete\n'
- "the attribute from an object's dictionary. For instance, "
- '"a.x" has a\n'
- 'lookup chain starting with "a.__dict__[\'x\']", then\n'
- '"type(a).__dict__[\'x\']", and continuing through the '
- 'base classes of\n'
- '"type(a)" excluding metaclasses.\n'
- '\n'
- 'However, if the looked-up value is an object defining '
- 'one of the\n'
- 'descriptor methods, then Python may override the default '
- 'behavior and\n'
- 'invoke the descriptor method instead. Where this occurs '
- 'in the\n'
- 'precedence chain depends on which descriptor methods '
- 'were defined and\n'
- 'how they were called. Note that descriptors are only '
- 'invoked for new\n'
- 'style objects or classes (ones that subclass "object()" '
- 'or "type()").\n'
- '\n'
- 'The starting point for descriptor invocation is a '
- 'binding, "a.x". How\n'
- 'the arguments are assembled depends on "a":\n'
- '\n'
- 'Direct Call\n'
- ' The simplest and least common call is when user code '
- 'directly\n'
- ' invokes a descriptor method: "x.__get__(a)".\n'
- '\n'
- 'Instance Binding\n'
- ' If binding to a new-style object instance, "a.x" is '
- 'transformed\n'
- ' into the call: "type(a).__dict__[\'x\'].__get__(a, '
- 'type(a))".\n'
- '\n'
- 'Class Binding\n'
- ' If binding to a new-style class, "A.x" is transformed '
- 'into the\n'
- ' call: "A.__dict__[\'x\'].__get__(None, A)".\n'
- '\n'
- 'Super Binding\n'
- ' If "a" is an instance of "super", then the binding '
- '"super(B,\n'
- ' obj).m()" searches "obj.__class__.__mro__" for the '
- 'base class "A"\n'
- ' immediately preceding "B" and then invokes the '
- 'descriptor with the\n'
- ' call: "A.__dict__[\'m\'].__get__(obj, '
- 'obj.__class__)".\n'
- '\n'
- 'For instance bindings, the precedence of descriptor '
- 'invocation depends\n'
- 'on the which descriptor methods are defined. A '
- 'descriptor can define\n'
- 'any combination of "__get__()", "__set__()" and '
- '"__delete__()". If it\n'
- 'does not define "__get__()", then accessing the '
- 'attribute will return\n'
- 'the descriptor object itself unless there is a value in '
- "the object's\n"
- 'instance dictionary. If the descriptor defines '
- '"__set__()" and/or\n'
- '"__delete__()", it is a data descriptor; if it defines '
- 'neither, it is\n'
- 'a non-data descriptor. Normally, data descriptors '
- 'define both\n'
- '"__get__()" and "__set__()", while non-data descriptors '
- 'have just the\n'
- '"__get__()" method. Data descriptors with "__set__()" '
- 'and "__get__()"\n'
- 'defined always override a redefinition in an instance '
- 'dictionary. In\n'
- 'contrast, non-data descriptors can be overridden by '
- 'instances.\n'
- '\n'
- 'Python methods (including "staticmethod()" and '
- '"classmethod()") are\n'
- 'implemented as non-data descriptors. Accordingly, '
- 'instances can\n'
- 'redefine and override methods. This allows individual '
- 'instances to\n'
- 'acquire behaviors that differ from other instances of '
- 'the same class.\n'
- '\n'
- 'The "property()" function is implemented as a data '
- 'descriptor.\n'
- 'Accordingly, instances cannot override the behavior of a '
- 'property.\n'
- '\n'
- '\n'
- '__slots__\n'
- '=========\n'
- '\n'
- 'By default, instances of both old and new-style classes '
- 'have a\n'
- 'dictionary for attribute storage. This wastes space for '
- 'objects\n'
- 'having very few instance variables. The space '
- 'consumption can become\n'
- 'acute when creating large numbers of instances.\n'
- '\n'
- 'The default can be overridden by defining *__slots__* in '
- 'a new-style\n'
- 'class definition. The *__slots__* declaration takes a '
- 'sequence of\n'
- 'instance variables and reserves just enough space in '
- 'each instance to\n'
- 'hold a value for each variable. Space is saved because '
- '*__dict__* is\n'
- 'not created for each instance.\n'
- '\n'
- '__slots__\n'
- '\n'
- ' This class variable can be assigned a string, '
- 'iterable, or sequence\n'
- ' of strings with variable names used by instances. If '
- 'defined in a\n'
- ' new-style class, *__slots__* reserves space for the '
- 'declared\n'
- ' variables and prevents the automatic creation of '
- '*__dict__* and\n'
- ' *__weakref__* for each instance.\n'
- '\n'
- ' New in version 2.2.\n'
- '\n'
- 'Notes on using *__slots__*\n'
- '\n'
- '* When inheriting from a class without *__slots__*, the '
- '*__dict__*\n'
- ' attribute of that class will always be accessible, so '
- 'a *__slots__*\n'
- ' definition in the subclass is meaningless.\n'
- '\n'
- '* Without a *__dict__* variable, instances cannot be '
- 'assigned new\n'
- ' variables not listed in the *__slots__* definition. '
- 'Attempts to\n'
- ' assign to an unlisted variable name raises '
- '"AttributeError". If\n'
- ' dynamic assignment of new variables is desired, then '
- 'add\n'
- ' "\'__dict__\'" to the sequence of strings in the '
- '*__slots__*\n'
- ' declaration.\n'
- '\n'
- ' Changed in version 2.3: Previously, adding '
- '"\'__dict__\'" to the\n'
- ' *__slots__* declaration would not enable the '
- 'assignment of new\n'
- ' attributes not specifically listed in the sequence of '
- 'instance\n'
- ' variable names.\n'
- '\n'
- '* Without a *__weakref__* variable for each instance, '
- 'classes\n'
- ' defining *__slots__* do not support weak references to '
- 'its\n'
- ' instances. If weak reference support is needed, then '
- 'add\n'
- ' "\'__weakref__\'" to the sequence of strings in the '
- '*__slots__*\n'
- ' declaration.\n'
- '\n'
- ' Changed in version 2.3: Previously, adding '
- '"\'__weakref__\'" to the\n'
- ' *__slots__* declaration would not enable support for '
- 'weak\n'
- ' references.\n'
- '\n'
- '* *__slots__* are implemented at the class level by '
- 'creating\n'
- ' descriptors (Implementing Descriptors) for each '
- 'variable name. As a\n'
- ' result, class attributes cannot be used to set default '
- 'values for\n'
- ' instance variables defined by *__slots__*; otherwise, '
- 'the class\n'
- ' attribute would overwrite the descriptor assignment.\n'
- '\n'
- '* The action of a *__slots__* declaration is limited to '
- 'the class\n'
- ' where it is defined. As a result, subclasses will '
- 'have a *__dict__*\n'
- ' unless they also define *__slots__* (which must only '
- 'contain names\n'
- ' of any *additional* slots).\n'
- '\n'
- '* If a class defines a slot also defined in a base '
- 'class, the\n'
- ' instance variable defined by the base class slot is '
- 'inaccessible\n'
- ' (except by retrieving its descriptor directly from the '
- 'base class).\n'
- ' This renders the meaning of the program undefined. In '
- 'the future, a\n'
- ' check may be added to prevent this.\n'
- '\n'
- '* Nonempty *__slots__* does not work for classes derived '
- 'from\n'
- ' "variable-length" built-in types such as "long", "str" '
- 'and "tuple".\n'
- '\n'
- '* Any non-string iterable may be assigned to '
- '*__slots__*. Mappings\n'
- ' may also be used; however, in the future, special '
- 'meaning may be\n'
- ' assigned to the values corresponding to each key.\n'
- '\n'
- '* *__class__* assignment works only if both classes have '
- 'the same\n'
- ' *__slots__*.\n'
- '\n'
- ' Changed in version 2.6: Previously, *__class__* '
- 'assignment raised an\n'
- ' error if either new or old class had *__slots__*.\n',
- 'attribute-references': '\n'
- 'Attribute references\n'
- '********************\n'
- '\n'
- 'An attribute reference is a primary followed by a '
- 'period and a name:\n'
- '\n'
- ' attributeref ::= primary "." identifier\n'
- '\n'
- 'The primary must evaluate to an object of a type '
- 'that supports\n'
- 'attribute references, e.g., a module, list, or an '
- 'instance. This\n'
- 'object is then asked to produce the attribute whose '
- 'name is the\n'
- 'identifier. If this attribute is not available, the '
- 'exception\n'
- '"AttributeError" is raised. Otherwise, the type and '
- 'value of the\n'
- 'object produced is determined by the object. '
- 'Multiple evaluations of\n'
- 'the same attribute reference may yield different '
- 'objects.\n',
- 'augassign': '\n'
- 'Augmented assignment statements\n'
- '*******************************\n'
- '\n'
- 'Augmented assignment is the combination, in a single statement, '
- 'of a\n'
- 'binary operation and an assignment statement:\n'
- '\n'
- ' augmented_assignment_stmt ::= augtarget augop '
- '(expression_list | yield_expression)\n'
- ' augtarget ::= identifier | attributeref | '
- 'subscription | slicing\n'
- ' augop ::= "+=" | "-=" | "*=" | "/=" | '
- '"//=" | "%=" | "**="\n'
- ' | ">>=" | "<<=" | "&=" | "^=" | "|="\n'
- '\n'
- '(See section Primaries for the syntax definitions for the last '
- 'three\n'
- 'symbols.)\n'
- '\n'
- 'An augmented assignment evaluates the target (which, unlike '
- 'normal\n'
- 'assignment statements, cannot be an unpacking) and the '
- 'expression\n'
- 'list, performs the binary operation specific to the type of '
- 'assignment\n'
- 'on the two operands, and assigns the result to the original '
- 'target.\n'
- 'The target is only evaluated once.\n'
- '\n'
- 'An augmented assignment expression like "x += 1" can be '
- 'rewritten as\n'
- '"x = x + 1" to achieve a similar, but not exactly equal effect. '
- 'In the\n'
- 'augmented version, "x" is only evaluated once. Also, when '
- 'possible,\n'
- 'the actual operation is performed *in-place*, meaning that '
- 'rather than\n'
- 'creating a new object and assigning that to the target, the old '
- 'object\n'
- 'is modified instead.\n'
- '\n'
- 'With the exception of assigning to tuples and multiple targets '
- 'in a\n'
- 'single statement, the assignment done by augmented assignment\n'
- 'statements is handled the same way as normal assignments. '
- 'Similarly,\n'
- 'with the exception of the possible *in-place* behavior, the '
- 'binary\n'
- 'operation performed by augmented assignment is the same as the '
- 'normal\n'
- 'binary operations.\n'
- '\n'
- 'For targets which are attribute references, the same caveat '
- 'about\n'
- 'class and instance attributes applies as for regular '
- 'assignments.\n',
- 'binary': '\n'
- 'Binary arithmetic operations\n'
- '****************************\n'
- '\n'
- 'The binary arithmetic operations have the conventional priority\n'
- 'levels. Note that some of these operations also apply to certain '
- 'non-\n'
- 'numeric types. Apart from the power operator, there are only two\n'
- 'levels, one for multiplicative operators and one for additive\n'
- 'operators:\n'
- '\n'
- ' m_expr ::= u_expr | m_expr "*" u_expr | m_expr "//" u_expr | '
- 'm_expr "/" u_expr\n'
- ' | m_expr "%" u_expr\n'
- ' a_expr ::= m_expr | a_expr "+" m_expr | a_expr "-" m_expr\n'
- '\n'
- 'The "*" (multiplication) operator yields the product of its '
- 'arguments.\n'
- 'The arguments must either both be numbers, or one argument must be '
- 'an\n'
- 'integer (plain or long) and the other must be a sequence. In the\n'
- 'former case, the numbers are converted to a common type and then\n'
- 'multiplied together. In the latter case, sequence repetition is\n'
- 'performed; a negative repetition factor yields an empty sequence.\n'
- '\n'
- 'The "/" (division) and "//" (floor division) operators yield the\n'
- 'quotient of their arguments. The numeric arguments are first\n'
- 'converted to a common type. Plain or long integer division yields '
- 'an\n'
- 'integer of the same type; the result is that of mathematical '
- 'division\n'
- "with the 'floor' function applied to the result. Division by zero\n"
- 'raises the "ZeroDivisionError" exception.\n'
- '\n'
- 'The "%" (modulo) operator yields the remainder from the division '
- 'of\n'
- 'the first argument by the second. The numeric arguments are '
- 'first\n'
- 'converted to a common type. A zero right argument raises the\n'
- '"ZeroDivisionError" exception. The arguments may be floating '
- 'point\n'
- 'numbers, e.g., "3.14%0.7" equals "0.34" (since "3.14" equals '
- '"4*0.7 +\n'
- '0.34".) The modulo operator always yields a result with the same '
- 'sign\n'
- 'as its second operand (or zero); the absolute value of the result '
- 'is\n'
- 'strictly smaller than the absolute value of the second operand '
- '[2].\n'
- '\n'
- 'The integer division and modulo operators are connected by the\n'
- 'following identity: "x == (x/y)*y + (x%y)". Integer division and\n'
- 'modulo are also connected with the built-in function "divmod()":\n'
- '"divmod(x, y) == (x/y, x%y)". These identities don\'t hold for\n'
- 'floating point numbers; there similar identities hold '
- 'approximately\n'
- 'where "x/y" is replaced by "floor(x/y)" or "floor(x/y) - 1" [3].\n'
- '\n'
- 'In addition to performing the modulo operation on numbers, the '
- '"%"\n'
- 'operator is also overloaded by string and unicode objects to '
- 'perform\n'
- 'string formatting (also known as interpolation). The syntax for '
- 'string\n'
- 'formatting is described in the Python Library Reference, section\n'
- 'String Formatting Operations.\n'
- '\n'
- 'Deprecated since version 2.3: The floor division operator, the '
- 'modulo\n'
- 'operator, and the "divmod()" function are no longer defined for\n'
- 'complex numbers. Instead, convert to a floating point number '
- 'using\n'
- 'the "abs()" function if appropriate.\n'
- '\n'
- 'The "+" (addition) operator yields the sum of its arguments. The\n'
- 'arguments must either both be numbers or both sequences of the '
- 'same\n'
- 'type. In the former case, the numbers are converted to a common '
- 'type\n'
- 'and then added together. In the latter case, the sequences are\n'
- 'concatenated.\n'
- '\n'
- 'The "-" (subtraction) operator yields the difference of its '
- 'arguments.\n'
- 'The numeric arguments are first converted to a common type.\n',
- 'bitwise': '\n'
- 'Binary bitwise operations\n'
- '*************************\n'
- '\n'
- 'Each of the three bitwise operations has a different priority '
- 'level:\n'
- '\n'
- ' and_expr ::= shift_expr | and_expr "&" shift_expr\n'
- ' xor_expr ::= and_expr | xor_expr "^" and_expr\n'
- ' or_expr ::= xor_expr | or_expr "|" xor_expr\n'
- '\n'
- 'The "&" operator yields the bitwise AND of its arguments, which '
- 'must\n'
- 'be plain or long integers. The arguments are converted to a '
- 'common\n'
- 'type.\n'
- '\n'
- 'The "^" operator yields the bitwise XOR (exclusive OR) of its\n'
- 'arguments, which must be plain or long integers. The arguments '
- 'are\n'
- 'converted to a common type.\n'
- '\n'
- 'The "|" operator yields the bitwise (inclusive) OR of its '
- 'arguments,\n'
- 'which must be plain or long integers. The arguments are '
- 'converted to\n'
- 'a common type.\n',
- 'bltin-code-objects': '\n'
- 'Code Objects\n'
- '************\n'
- '\n'
- 'Code objects are used by the implementation to '
- 'represent "pseudo-\n'
- 'compiled" executable Python code such as a function '
- 'body. They differ\n'
- "from function objects because they don't contain a "
- 'reference to their\n'
- 'global execution environment. Code objects are '
- 'returned by the built-\n'
- 'in "compile()" function and can be extracted from '
- 'function objects\n'
- 'through their "func_code" attribute. See also the '
- '"code" module.\n'
- '\n'
- 'A code object can be executed or evaluated by passing '
- 'it (instead of a\n'
- 'source string) to the "exec" statement or the built-in '
- '"eval()"\n'
- 'function.\n'
- '\n'
- 'See The standard type hierarchy for more '
- 'information.\n',
- 'bltin-ellipsis-object': '\n'
- 'The Ellipsis Object\n'
- '*******************\n'
- '\n'
- 'This object is used by extended slice notation (see '
- 'Slicings). It\n'
- 'supports no special operations. There is exactly '
- 'one ellipsis object,\n'
- 'named "Ellipsis" (a built-in name).\n'
- '\n'
- 'It is written as "Ellipsis". When in a subscript, '
- 'it can also be\n'
- 'written as "...", for example "seq[...]".\n',
- 'bltin-file-objects': '\n'
- 'File Objects\n'
- '************\n'
- '\n'
- 'File objects are implemented using C\'s "stdio" '
- 'package and can be\n'
- 'created with the built-in "open()" function. File '
- 'objects are also\n'
- 'returned by some other built-in functions and methods, '
- 'such as\n'
- '"os.popen()" and "os.fdopen()" and the "makefile()" '
- 'method of socket\n'
- 'objects. Temporary files can be created using the '
- '"tempfile" module,\n'
- 'and high-level file operations such as copying, '
- 'moving, and deleting\n'
- 'files and directories can be achieved with the '
- '"shutil" module.\n'
- '\n'
- 'When a file operation fails for an I/O-related reason, '
- 'the exception\n'
- '"IOError" is raised. This includes situations where '
- 'the operation is\n'
- 'not defined for some reason, like "seek()" on a tty '
- 'device or writing\n'
- 'a file opened for reading.\n'
- '\n'
- 'Files have the following methods:\n'
- '\n'
- 'file.close()\n'
- '\n'
- ' Close the file. A closed file cannot be read or '
- 'written any more.\n'
- ' Any operation which requires that the file be open '
- 'will raise a\n'
- ' "ValueError" after the file has been closed. '
- 'Calling "close()"\n'
- ' more than once is allowed.\n'
- '\n'
- ' As of Python 2.5, you can avoid having to call this '
- 'method\n'
- ' explicitly if you use the "with" statement. For '
- 'example, the\n'
- ' following code will automatically close *f* when '
- 'the "with" block\n'
- ' is exited:\n'
- '\n'
- ' from __future__ import with_statement # This '
- "isn't required in Python 2.6\n"
- '\n'
- ' with open("hello.txt") as f:\n'
- ' for line in f:\n'
- ' print line,\n'
- '\n'
- ' In older versions of Python, you would have needed '
- 'to do this to\n'
- ' get the same effect:\n'
- '\n'
- ' f = open("hello.txt")\n'
- ' try:\n'
- ' for line in f:\n'
- ' print line,\n'
- ' finally:\n'
- ' f.close()\n'
- '\n'
- ' Note: Not all "file-like" types in Python support '
- 'use as a\n'
- ' context manager for the "with" statement. If '
- 'your code is\n'
- ' intended to work with any file-like object, you '
- 'can use the\n'
- ' function "contextlib.closing()" instead of using '
- 'the object\n'
- ' directly.\n'
- '\n'
- 'file.flush()\n'
- '\n'
- ' Flush the internal buffer, like "stdio"\'s '
- '"fflush()". This may be\n'
- ' a no-op on some file-like objects.\n'
- '\n'
- ' Note: "flush()" does not necessarily write the '
- "file's data to\n"
- ' disk. Use "flush()" followed by "os.fsync()" to '
- 'ensure this\n'
- ' behavior.\n'
- '\n'
- 'file.fileno()\n'
- '\n'
- ' Return the integer "file descriptor" that is used '
- 'by the underlying\n'
- ' implementation to request I/O operations from the '
- 'operating system.\n'
- ' This can be useful for other, lower level '
- 'interfaces that use file\n'
- ' descriptors, such as the "fcntl" module or '
- '"os.read()" and friends.\n'
- '\n'
- ' Note: File-like objects which do not have a real '
- 'file descriptor\n'
- ' should *not* provide this method!\n'
- '\n'
- 'file.isatty()\n'
- '\n'
- ' Return "True" if the file is connected to a '
- 'tty(-like) device, else\n'
- ' "False".\n'
- '\n'
- ' Note: If a file-like object is not associated with '
- 'a real file,\n'
- ' this method should *not* be implemented.\n'
- '\n'
- 'file.next()\n'
- '\n'
- ' A file object is its own iterator, for example '
- '"iter(f)" returns\n'
- ' *f* (unless *f* is closed). When a file is used as '
- 'an iterator,\n'
- ' typically in a "for" loop (for example, "for line '
- 'in f: print\n'
- ' line.strip()"), the "next()" method is called '
- 'repeatedly. This\n'
- ' method returns the next input line, or raises '
- '"StopIteration" when\n'
- ' EOF is hit when the file is open for reading '
- '(behavior is undefined\n'
- ' when the file is open for writing). In order to '
- 'make a "for" loop\n'
- ' the most efficient way of looping over the lines of '
- 'a file (a very\n'
- ' common operation), the "next()" method uses a '
- 'hidden read-ahead\n'
- ' buffer. As a consequence of using a read-ahead '
- 'buffer, combining\n'
- ' "next()" with other file methods (like '
- '"readline()") does not work\n'
- ' right. However, using "seek()" to reposition the '
- 'file to an\n'
- ' absolute position will flush the read-ahead '
- 'buffer.\n'
- '\n'
- ' New in version 2.3.\n'
- '\n'
- 'file.read([size])\n'
- '\n'
- ' Read at most *size* bytes from the file (less if '
- 'the read hits EOF\n'
- ' before obtaining *size* bytes). If the *size* '
- 'argument is negative\n'
- ' or omitted, read all data until EOF is reached. '
- 'The bytes are\n'
- ' returned as a string object. An empty string is '
- 'returned when EOF\n'
- ' is encountered immediately. (For certain files, '
- 'like ttys, it\n'
- ' makes sense to continue reading after an EOF is '
- 'hit.) Note that\n'
- ' this method may call the underlying C function '
- '"fread()" more than\n'
- ' once in an effort to acquire as close to *size* '
- 'bytes as possible.\n'
- ' Also note that when in non-blocking mode, less data '
- 'than was\n'
- ' requested may be returned, even if no *size* '
- 'parameter was given.\n'
- '\n'
- ' Note: This function is simply a wrapper for the '
- 'underlying\n'
- ' "fread()" C function, and will behave the same in '
- 'corner cases,\n'
- ' such as whether the EOF value is cached.\n'
- '\n'
- 'file.readline([size])\n'
- '\n'
- ' Read one entire line from the file. A trailing '
- 'newline character\n'
- ' is kept in the string (but may be absent when a '
- 'file ends with an\n'
- ' incomplete line). [6] If the *size* argument is '
- 'present and non-\n'
- ' negative, it is a maximum byte count (including the '
- 'trailing\n'
- ' newline) and an incomplete line may be returned. '
- 'When *size* is not\n'
- ' 0, an empty string is returned *only* when EOF is '
- 'encountered\n'
- ' immediately.\n'
- '\n'
- ' Note: Unlike "stdio"\'s "fgets()", the returned '
- 'string contains\n'
- ' null characters ("\'\\0\'") if they occurred in '
- 'the input.\n'
- '\n'
- 'file.readlines([sizehint])\n'
- '\n'
- ' Read until EOF using "readline()" and return a list '
- 'containing the\n'
- ' lines thus read. If the optional *sizehint* '
- 'argument is present,\n'
- ' instead of reading up to EOF, whole lines totalling '
- 'approximately\n'
- ' *sizehint* bytes (possibly after rounding up to an '
- 'internal buffer\n'
- ' size) are read. Objects implementing a file-like '
- 'interface may\n'
- ' choose to ignore *sizehint* if it cannot be '
- 'implemented, or cannot\n'
- ' be implemented efficiently.\n'
- '\n'
- 'file.xreadlines()\n'
- '\n'
- ' This method returns the same thing as "iter(f)".\n'
- '\n'
- ' New in version 2.1.\n'
- '\n'
- ' Deprecated since version 2.3: Use "for line in '
- 'file" instead.\n'
- '\n'
- 'file.seek(offset[, whence])\n'
- '\n'
- ' Set the file\'s current position, like "stdio"\'s '
- '"fseek()". The\n'
- ' *whence* argument is optional and defaults to '
- '"os.SEEK_SET" or "0"\n'
- ' (absolute file positioning); other values are '
- '"os.SEEK_CUR" or "1"\n'
- ' (seek relative to the current position) and '
- '"os.SEEK_END" or "2"\n'
- " (seek relative to the file's end). There is no "
- 'return value.\n'
- '\n'
- ' For example, "f.seek(2, os.SEEK_CUR)" advances the '
- 'position by two\n'
- ' and "f.seek(-3, os.SEEK_END)" sets the position to '
- 'the third to\n'
- ' last.\n'
- '\n'
- ' Note that if the file is opened for appending (mode '
- '"\'a\'" or\n'
- ' "\'a+\'"), any "seek()" operations will be undone '
- 'at the next write.\n'
- ' If the file is only opened for writing in append '
- 'mode (mode "\'a\'"),\n'
- ' this method is essentially a no-op, but it remains '
- 'useful for files\n'
- ' opened in append mode with reading enabled (mode '
- '"\'a+\'"). If the\n'
- ' file is opened in text mode (without "\'b\'"), only '
- 'offsets returned\n'
- ' by "tell()" are legal. Use of other offsets causes '
- 'undefined\n'
- ' behavior.\n'
- '\n'
- ' Note that not all file objects are seekable.\n'
- '\n'
- ' Changed in version 2.6: Passing float values as '
- 'offset has been\n'
- ' deprecated.\n'
- '\n'
- 'file.tell()\n'
- '\n'
- " Return the file's current position, like "
- '"stdio"\'s "ftell()".\n'
- '\n'
- ' Note: On Windows, "tell()" can return illegal '
- 'values (after an\n'
- ' "fgets()") when reading files with Unix-style '
- 'line-endings. Use\n'
- ' binary mode ("\'rb\'") to circumvent this '
- 'problem.\n'
- '\n'
- 'file.truncate([size])\n'
- '\n'
- " Truncate the file's size. If the optional *size* "
- 'argument is\n'
- ' present, the file is truncated to (at most) that '
- 'size. The size\n'
- ' defaults to the current position. The current file '
- 'position is not\n'
- ' changed. Note that if a specified size exceeds the '
- "file's current\n"
- ' size, the result is platform-dependent: '
- 'possibilities include that\n'
- ' the file may remain unchanged, increase to the '
- 'specified size as if\n'
- ' zero-filled, or increase to the specified size with '
- 'undefined new\n'
- ' content. Availability: Windows, many Unix '
- 'variants.\n'
- '\n'
- 'file.write(str)\n'
- '\n'
- ' Write a string to the file. There is no return '
- 'value. Due to\n'
- ' buffering, the string may not actually show up in '
- 'the file until\n'
- ' the "flush()" or "close()" method is called.\n'
- '\n'
- 'file.writelines(sequence)\n'
- '\n'
- ' Write a sequence of strings to the file. The '
- 'sequence can be any\n'
- ' iterable object producing strings, typically a list '
- 'of strings.\n'
- ' There is no return value. (The name is intended to '
- 'match\n'
- ' "readlines()"; "writelines()" does not add line '
- 'separators.)\n'
- '\n'
- 'Files support the iterator protocol. Each iteration '
- 'returns the same\n'
- 'result as "readline()", and iteration ends when the '
- '"readline()"\n'
- 'method returns an empty string.\n'
- '\n'
- 'File objects also offer a number of other interesting '
- 'attributes.\n'
- 'These are not required for file-like objects, but '
- 'should be\n'
- 'implemented if they make sense for the particular '
- 'object.\n'
- '\n'
- 'file.closed\n'
- '\n'
- ' bool indicating the current state of the file '
- 'object. This is a\n'
- ' read-only attribute; the "close()" method changes '
- 'the value. It may\n'
- ' not be available on all file-like objects.\n'
- '\n'
- 'file.encoding\n'
- '\n'
- ' The encoding that this file uses. When Unicode '
- 'strings are written\n'
- ' to a file, they will be converted to byte strings '
- 'using this\n'
- ' encoding. In addition, when the file is connected '
- 'to a terminal,\n'
- ' the attribute gives the encoding that the terminal '
- 'is likely to use\n'
- ' (that information might be incorrect if the user '
- 'has misconfigured\n'
- ' the terminal). The attribute is read-only and may '
- 'not be present\n'
- ' on all file-like objects. It may also be "None", in '
- 'which case the\n'
- ' file uses the system default encoding for '
- 'converting Unicode\n'
- ' strings.\n'
- '\n'
- ' New in version 2.3.\n'
- '\n'
- 'file.errors\n'
- '\n'
- ' The Unicode error handler used along with the '
- 'encoding.\n'
- '\n'
- ' New in version 2.6.\n'
- '\n'
- 'file.mode\n'
- '\n'
- ' The I/O mode for the file. If the file was created '
- 'using the\n'
- ' "open()" built-in function, this will be the value '
- 'of the *mode*\n'
- ' parameter. This is a read-only attribute and may '
- 'not be present on\n'
- ' all file-like objects.\n'
- '\n'
- 'file.name\n'
- '\n'
- ' If the file object was created using "open()", the '
- 'name of the\n'
- ' file. Otherwise, some string that indicates the '
- 'source of the file\n'
- ' object, of the form "<...>". This is a read-only '
- 'attribute and may\n'
- ' not be present on all file-like objects.\n'
- '\n'
- 'file.newlines\n'
- '\n'
- ' If Python was built with *universal newlines* '
- 'enabled (the default)\n'
- ' this read-only attribute exists, and for files '
- 'opened in universal\n'
- ' newline read mode it keeps track of the types of '
- 'newlines\n'
- ' encountered while reading the file. The values it '
- 'can take are\n'
- ' "\'\\r\'", "\'\\n\'", "\'\\r\\n\'", "None" '
- '(unknown, no newlines read yet) or\n'
- ' a tuple containing all the newline types seen, to '
- 'indicate that\n'
- ' multiple newline conventions were encountered. For '
- 'files not opened\n'
- ' in universal newlines read mode the value of this '
- 'attribute will be\n'
- ' "None".\n'
- '\n'
- 'file.softspace\n'
- '\n'
- ' Boolean that indicates whether a space character '
- 'needs to be\n'
- ' printed before another value when using the "print" '
- 'statement.\n'
- ' Classes that are trying to simulate a file object '
- 'should also have\n'
- ' a writable "softspace" attribute, which should be '
- 'initialized to\n'
- ' zero. This will be automatic for most classes '
- 'implemented in\n'
- ' Python (care may be needed for objects that '
- 'override attribute\n'
- ' access); types implemented in C will have to '
- 'provide a writable\n'
- ' "softspace" attribute.\n'
- '\n'
- ' Note: This attribute is not used to control the '
- '"print"\n'
- ' statement, but to allow the implementation of '
- '"print" to keep\n'
- ' track of its internal state.\n',
- 'bltin-null-object': '\n'
- 'The Null Object\n'
- '***************\n'
- '\n'
- "This object is returned by functions that don't "
- 'explicitly return a\n'
- 'value. It supports no special operations. There is '
- 'exactly one null\n'
- 'object, named "None" (a built-in name).\n'
- '\n'
- 'It is written as "None".\n',
- 'bltin-type-objects': '\n'
- 'Type Objects\n'
- '************\n'
- '\n'
- 'Type objects represent the various object types. An '
- "object's type is\n"
- 'accessed by the built-in function "type()". There are '
- 'no special\n'
- 'operations on types. The standard module "types" '
- 'defines names for\n'
- 'all standard built-in types.\n'
- '\n'
- 'Types are written like this: "<type \'int\'>".\n',
- 'booleans': '\n'
- 'Boolean operations\n'
- '******************\n'
- '\n'
- ' or_test ::= and_test | or_test "or" and_test\n'
- ' and_test ::= not_test | and_test "and" not_test\n'
- ' not_test ::= comparison | "not" not_test\n'
- '\n'
- 'In the context of Boolean operations, and also when expressions '
- 'are\n'
- 'used by control flow statements, the following values are '
- 'interpreted\n'
- 'as false: "False", "None", numeric zero of all types, and empty\n'
- 'strings and containers (including strings, tuples, lists,\n'
- 'dictionaries, sets and frozensets). All other values are '
- 'interpreted\n'
- 'as true. (See the "__nonzero__()" special method for a way to '
- 'change\n'
- 'this.)\n'
- '\n'
- 'The operator "not" yields "True" if its argument is false, '
- '"False"\n'
- 'otherwise.\n'
- '\n'
- 'The expression "x and y" first evaluates *x*; if *x* is false, '
- 'its\n'
- 'value is returned; otherwise, *y* is evaluated and the resulting '
- 'value\n'
- 'is returned.\n'
- '\n'
- 'The expression "x or y" first evaluates *x*; if *x* is true, its '
- 'value\n'
- 'is returned; otherwise, *y* is evaluated and the resulting value '
- 'is\n'
- 'returned.\n'
- '\n'
- '(Note that neither "and" nor "or" restrict the value and type '
- 'they\n'
- 'return to "False" and "True", but rather return the last '
- 'evaluated\n'
- 'argument. This is sometimes useful, e.g., if "s" is a string '
- 'that\n'
- 'should be replaced by a default value if it is empty, the '
- 'expression\n'
- '"s or \'foo\'" yields the desired value. Because "not" has to '
- 'invent a\n'
- 'value anyway, it does not bother to return a value of the same '
- 'type as\n'
- 'its argument, so e.g., "not \'foo\'" yields "False", not '
- '"\'\'".)\n',
- 'break': '\n'
- 'The "break" statement\n'
- '*********************\n'
- '\n'
- ' break_stmt ::= "break"\n'
- '\n'
- '"break" may only occur syntactically nested in a "for" or "while"\n'
- 'loop, but not nested in a function or class definition within that\n'
- 'loop.\n'
- '\n'
- 'It terminates the nearest enclosing loop, skipping the optional '
- '"else"\n'
- 'clause if the loop has one.\n'
- '\n'
- 'If a "for" loop is terminated by "break", the loop control target\n'
- 'keeps its current value.\n'
- '\n'
- 'When "break" passes control out of a "try" statement with a '
- '"finally"\n'
- 'clause, that "finally" clause is executed before really leaving '
- 'the\n'
- 'loop.\n',
- 'callable-types': '\n'
- 'Emulating callable objects\n'
- '**************************\n'
- '\n'
- 'object.__call__(self[, args...])\n'
- '\n'
- ' Called when the instance is "called" as a function; if '
- 'this method\n'
- ' is defined, "x(arg1, arg2, ...)" is a shorthand for\n'
- ' "x.__call__(arg1, arg2, ...)".\n',
- 'calls': '\n'
- 'Calls\n'
- '*****\n'
- '\n'
- 'A call calls a callable object (e.g., a *function*) with a '
- 'possibly\n'
- 'empty series of *arguments*:\n'
- '\n'
- ' call ::= primary "(" [argument_list [","]\n'
- ' | expression genexpr_for] ")"\n'
- ' argument_list ::= positional_arguments ["," '
- 'keyword_arguments]\n'
- ' ["," "*" expression] ["," '
- 'keyword_arguments]\n'
- ' ["," "**" expression]\n'
- ' | keyword_arguments ["," "*" expression]\n'
- ' ["," "**" expression]\n'
- ' | "*" expression ["," keyword_arguments] ["," '
- '"**" expression]\n'
- ' | "**" expression\n'
- ' positional_arguments ::= expression ("," expression)*\n'
- ' keyword_arguments ::= keyword_item ("," keyword_item)*\n'
- ' keyword_item ::= identifier "=" expression\n'
- '\n'
- 'A trailing comma may be present after the positional and keyword\n'
- 'arguments but does not affect the semantics.\n'
- '\n'
- 'The primary must evaluate to a callable object (user-defined\n'
- 'functions, built-in functions, methods of built-in objects, class\n'
- 'objects, methods of class instances, and certain class instances\n'
- 'themselves are callable; extensions may define additional callable\n'
- 'object types). All argument expressions are evaluated before the '
- 'call\n'
- 'is attempted. Please refer to section Function definitions for '
- 'the\n'
- 'syntax of formal *parameter* lists.\n'
- '\n'
- 'If keyword arguments are present, they are first converted to\n'
- 'positional arguments, as follows. First, a list of unfilled slots '
- 'is\n'
- 'created for the formal parameters. If there are N positional\n'
- 'arguments, they are placed in the first N slots. Next, for each\n'
- 'keyword argument, the identifier is used to determine the\n'
- 'corresponding slot (if the identifier is the same as the first '
- 'formal\n'
- 'parameter name, the first slot is used, and so on). If the slot '
- 'is\n'
- 'already filled, a "TypeError" exception is raised. Otherwise, the\n'
- 'value of the argument is placed in the slot, filling it (even if '
- 'the\n'
- 'expression is "None", it fills the slot). When all arguments have\n'
- 'been processed, the slots that are still unfilled are filled with '
- 'the\n'
- 'corresponding default value from the function definition. '
- '(Default\n'
- 'values are calculated, once, when the function is defined; thus, a\n'
- 'mutable object such as a list or dictionary used as default value '
- 'will\n'
- "be shared by all calls that don't specify an argument value for "
- 'the\n'
- 'corresponding slot; this should usually be avoided.) If there are '
- 'any\n'
- 'unfilled slots for which no default value is specified, a '
- '"TypeError"\n'
- 'exception is raised. Otherwise, the list of filled slots is used '
- 'as\n'
- 'the argument list for the call.\n'
- '\n'
- '**CPython implementation detail:** An implementation may provide\n'
- 'built-in functions whose positional parameters do not have names, '
- 'even\n'
- "if they are 'named' for the purpose of documentation, and which\n"
- 'therefore cannot be supplied by keyword. In CPython, this is the '
- 'case\n'
- 'for functions implemented in C that use "PyArg_ParseTuple()" to '
- 'parse\n'
- 'their arguments.\n'
- '\n'
- 'If there are more positional arguments than there are formal '
- 'parameter\n'
- 'slots, a "TypeError" exception is raised, unless a formal '
- 'parameter\n'
- 'using the syntax "*identifier" is present; in this case, that '
- 'formal\n'
- 'parameter receives a tuple containing the excess positional '
- 'arguments\n'
- '(or an empty tuple if there were no excess positional arguments).\n'
- '\n'
- 'If any keyword argument does not correspond to a formal parameter\n'
- 'name, a "TypeError" exception is raised, unless a formal parameter\n'
- 'using the syntax "**identifier" is present; in this case, that '
- 'formal\n'
- 'parameter receives a dictionary containing the excess keyword\n'
- 'arguments (using the keywords as keys and the argument values as\n'
- 'corresponding values), or a (new) empty dictionary if there were '
- 'no\n'
- 'excess keyword arguments.\n'
- '\n'
- 'If the syntax "*expression" appears in the function call, '
- '"expression"\n'
- 'must evaluate to an iterable. Elements from this iterable are '
- 'treated\n'
- 'as if they were additional positional arguments; if there are\n'
- 'positional arguments *x1*, ..., *xN*, and "expression" evaluates to '
- 'a\n'
- 'sequence *y1*, ..., *yM*, this is equivalent to a call with M+N\n'
- 'positional arguments *x1*, ..., *xN*, *y1*, ..., *yM*.\n'
- '\n'
- 'A consequence of this is that although the "*expression" syntax '
- 'may\n'
- 'appear *after* some keyword arguments, it is processed *before* '
- 'the\n'
- 'keyword arguments (and the "**expression" argument, if any -- see\n'
- 'below). So:\n'
- '\n'
- ' >>> def f(a, b):\n'
- ' ... print a, b\n'
- ' ...\n'
- ' >>> f(b=1, *(2,))\n'
- ' 2 1\n'
- ' >>> f(a=1, *(2,))\n'
- ' Traceback (most recent call last):\n'
- ' File "<stdin>", line 1, in ?\n'
- " TypeError: f() got multiple values for keyword argument 'a'\n"
- ' >>> f(1, *(2,))\n'
- ' 1 2\n'
- '\n'
- 'It is unusual for both keyword arguments and the "*expression" '
- 'syntax\n'
- 'to be used in the same call, so in practice this confusion does '
- 'not\n'
- 'arise.\n'
- '\n'
- 'If the syntax "**expression" appears in the function call,\n'
- '"expression" must evaluate to a mapping, the contents of which are\n'
- 'treated as additional keyword arguments. In the case of a keyword\n'
- 'appearing in both "expression" and as an explicit keyword argument, '
- 'a\n'
- '"TypeError" exception is raised.\n'
- '\n'
- 'Formal parameters using the syntax "*identifier" or "**identifier"\n'
- 'cannot be used as positional argument slots or as keyword argument\n'
- 'names. Formal parameters using the syntax "(sublist)" cannot be '
- 'used\n'
- 'as keyword argument names; the outermost sublist corresponds to a\n'
- 'single unnamed argument slot, and the argument value is assigned '
- 'to\n'
- 'the sublist using the usual tuple assignment rules after all other\n'
- 'parameter processing is done.\n'
- '\n'
- 'A call always returns some value, possibly "None", unless it raises '
- 'an\n'
- 'exception. How this value is computed depends on the type of the\n'
- 'callable object.\n'
- '\n'
- 'If it is---\n'
- '\n'
- 'a user-defined function:\n'
- ' The code block for the function is executed, passing it the\n'
- ' argument list. The first thing the code block will do is bind '
- 'the\n'
- ' formal parameters to the arguments; this is described in '
- 'section\n'
- ' Function definitions. When the code block executes a "return"\n'
- ' statement, this specifies the return value of the function '
- 'call.\n'
- '\n'
- 'a built-in function or method:\n'
- ' The result is up to the interpreter; see Built-in Functions for '
- 'the\n'
- ' descriptions of built-in functions and methods.\n'
- '\n'
- 'a class object:\n'
- ' A new instance of that class is returned.\n'
- '\n'
- 'a class instance method:\n'
- ' The corresponding user-defined function is called, with an '
- 'argument\n'
- ' list that is one longer than the argument list of the call: the\n'
- ' instance becomes the first argument.\n'
- '\n'
- 'a class instance:\n'
- ' The class must define a "__call__()" method; the effect is then '
- 'the\n'
- ' same as if that method was called.\n',
- 'class': '\n'
- 'Class definitions\n'
- '*****************\n'
- '\n'
- 'A class definition defines a class object (see section The '
- 'standard\n'
- 'type hierarchy):\n'
- '\n'
- ' classdef ::= "class" classname [inheritance] ":" suite\n'
- ' inheritance ::= "(" [expression_list] ")"\n'
- ' classname ::= identifier\n'
- '\n'
- 'A class definition is an executable statement. It first evaluates '
- 'the\n'
- 'inheritance list, if present. Each item in the inheritance list\n'
- 'should evaluate to a class object or class type which allows\n'
- "subclassing. The class's suite is then executed in a new "
- 'execution\n'
- 'frame (see section Naming and binding), using a newly created '
- 'local\n'
- 'namespace and the original global namespace. (Usually, the suite\n'
- "contains only function definitions.) When the class's suite "
- 'finishes\n'
- 'execution, its execution frame is discarded but its local namespace '
- 'is\n'
- 'saved. [4] A class object is then created using the inheritance '
- 'list\n'
- 'for the base classes and the saved local namespace for the '
- 'attribute\n'
- 'dictionary. The class name is bound to this class object in the\n'
- 'original local namespace.\n'
- '\n'
- "**Programmer's note:** Variables defined in the class definition "
- 'are\n'
- 'class variables; they are shared by all instances. To create '
- 'instance\n'
- 'variables, they can be set in a method with "self.name = value". '
- 'Both\n'
- 'class and instance variables are accessible through the notation\n'
- '""self.name"", and an instance variable hides a class variable '
- 'with\n'
- 'the same name when accessed in this way. Class variables can be '
- 'used\n'
- 'as defaults for instance variables, but using mutable values there '
- 'can\n'
- 'lead to unexpected results. For *new-style class*es, descriptors '
- 'can\n'
- 'be used to create instance variables with different implementation\n'
- 'details.\n'
- '\n'
- 'Class definitions, like function definitions, may be wrapped by one '
- 'or\n'
- 'more *decorator* expressions. The evaluation rules for the '
- 'decorator\n'
- 'expressions are the same as for functions. The result must be a '
- 'class\n'
- 'object, which is then bound to the class name.\n'
- '\n'
- '-[ Footnotes ]-\n'
- '\n'
- '[1] The exception is propagated to the invocation stack unless\n'
- ' there is a "finally" clause which happens to raise another\n'
- ' exception. That new exception causes the old one to be lost.\n'
- '\n'
- '[2] Currently, control "flows off the end" except in the case of\n'
- ' an exception or the execution of a "return", "continue", or\n'
- ' "break" statement.\n'
- '\n'
- '[3] A string literal appearing as the first statement in the\n'
- ' function body is transformed into the function\'s "__doc__"\n'
- " attribute and therefore the function's *docstring*.\n"
- '\n'
- '[4] A string literal appearing as the first statement in the class\n'
- ' body is transformed into the namespace\'s "__doc__" item and\n'
- " therefore the class's *docstring*.\n",
- 'comparisons': '\n'
- 'Comparisons\n'
- '***********\n'
- '\n'
- 'Unlike C, all comparison operations in Python have the same '
- 'priority,\n'
- 'which is lower than that of any arithmetic, shifting or '
- 'bitwise\n'
- 'operation. Also unlike C, expressions like "a < b < c" have '
- 'the\n'
- 'interpretation that is conventional in mathematics:\n'
- '\n'
- ' comparison ::= or_expr ( comp_operator or_expr )*\n'
- ' comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "<>" | '
- '"!="\n'
- ' | "is" ["not"] | ["not"] "in"\n'
- '\n'
- 'Comparisons yield boolean values: "True" or "False".\n'
- '\n'
- 'Comparisons can be chained arbitrarily, e.g., "x < y <= z" '
- 'is\n'
- 'equivalent to "x < y and y <= z", except that "y" is '
- 'evaluated only\n'
- 'once (but in both cases "z" is not evaluated at all when "x < '
- 'y" is\n'
- 'found to be false).\n'
- '\n'
- 'Formally, if *a*, *b*, *c*, ..., *y*, *z* are expressions and '
- '*op1*,\n'
- '*op2*, ..., *opN* are comparison operators, then "a op1 b op2 '
- 'c ... y\n'
- 'opN z" is equivalent to "a op1 b and b op2 c and ... y opN '
- 'z", except\n'
- 'that each expression is evaluated at most once.\n'
- '\n'
- 'Note that "a op1 b op2 c" doesn\'t imply any kind of '
- 'comparison between\n'
- '*a* and *c*, so that, e.g., "x < y > z" is perfectly legal '
- '(though\n'
- 'perhaps not pretty).\n'
- '\n'
- 'The forms "<>" and "!=" are equivalent; for consistency with '
- 'C, "!="\n'
- 'is preferred; where "!=" is mentioned below "<>" is also '
- 'accepted.\n'
- 'The "<>" spelling is considered obsolescent.\n'
- '\n'
- 'The operators "<", ">", "==", ">=", "<=", and "!=" compare '
- 'the values\n'
- 'of two objects. The objects need not have the same type. If '
- 'both are\n'
- 'numbers, they are converted to a common type. Otherwise, '
- 'objects of\n'
- 'different types *always* compare unequal, and are ordered '
- 'consistently\n'
- 'but arbitrarily. You can control comparison behavior of '
- 'objects of\n'
- 'non-built-in types by defining a "__cmp__" method or rich '
- 'comparison\n'
- 'methods like "__gt__", described in section Special method '
- 'names.\n'
- '\n'
- '(This unusual definition of comparison was used to simplify '
- 'the\n'
- 'definition of operations like sorting and the "in" and "not '
- 'in"\n'
- 'operators. In the future, the comparison rules for objects '
- 'of\n'
- 'different types are likely to change.)\n'
- '\n'
- 'Comparison of objects of the same type depends on the type:\n'
- '\n'
- '* Numbers are compared arithmetically.\n'
- '\n'
- '* Strings are compared lexicographically using the numeric\n'
- ' equivalents (the result of the built-in function "ord()") '
- 'of their\n'
- ' characters. Unicode and 8-bit strings are fully '
- 'interoperable in\n'
- ' this behavior. [4]\n'
- '\n'
- '* Tuples and lists are compared lexicographically using '
- 'comparison\n'
- ' of corresponding elements. This means that to compare '
- 'equal, each\n'
- ' element must compare equal and the two sequences must be of '
- 'the same\n'
- ' type and have the same length.\n'
- '\n'
- ' If not equal, the sequences are ordered the same as their '
- 'first\n'
- ' differing elements. For example, "cmp([1,2,x], [1,2,y])" '
- 'returns\n'
- ' the same as "cmp(x,y)". If the corresponding element does '
- 'not\n'
- ' exist, the shorter sequence is ordered first (for example, '
- '"[1,2] <\n'
- ' [1,2,3]").\n'
- '\n'
- '* Mappings (dictionaries) compare equal if and only if their '
- 'sorted\n'
- ' (key, value) lists compare equal. [5] Outcomes other than '
- 'equality\n'
- ' are resolved consistently, but are not otherwise defined. '
- '[6]\n'
- '\n'
- '* Most other objects of built-in types compare unequal unless '
- 'they\n'
- ' are the same object; the choice whether one object is '
- 'considered\n'
- ' smaller or larger than another one is made arbitrarily but\n'
- ' consistently within one execution of a program.\n'
- '\n'
- 'The operators "in" and "not in" test for collection '
- 'membership. "x in\n'
- 's" evaluates to true if *x* is a member of the collection '
- '*s*, and\n'
- 'false otherwise. "x not in s" returns the negation of "x in '
- 's". The\n'
- 'collection membership test has traditionally been bound to '
- 'sequences;\n'
- 'an object is a member of a collection if the collection is a '
- 'sequence\n'
- 'and contains an element equal to that object. However, it '
- 'make sense\n'
- 'for many other object types to support membership tests '
- 'without being\n'
- 'a sequence. In particular, dictionaries (for keys) and sets '
- 'support\n'
- 'membership testing.\n'
- '\n'
- 'For the list and tuple types, "x in y" is true if and only if '
- 'there\n'
- 'exists an index *i* such that either "x is y[i]" or "x == '
- 'y[i]" is\n'
- 'true.\n'
- '\n'
- 'For the Unicode and string types, "x in y" is true if and '
- 'only if *x*\n'
- 'is a substring of *y*. An equivalent test is "y.find(x) != '
- '-1".\n'
- 'Note, *x* and *y* need not be the same type; consequently, '
- '"u\'ab\' in\n'
- '\'abc\'" will return "True". Empty strings are always '
- 'considered to be a\n'
- 'substring of any other string, so """ in "abc"" will return '
- '"True".\n'
- '\n'
- 'Changed in version 2.3: Previously, *x* was required to be a '
- 'string of\n'
- 'length "1".\n'
- '\n'
- 'For user-defined classes which define the "__contains__()" '
- 'method, "x\n'
- 'in y" is true if and only if "y.__contains__(x)" is true.\n'
- '\n'
- 'For user-defined classes which do not define "__contains__()" '
- 'but do\n'
- 'define "__iter__()", "x in y" is true if some value "z" with '
- '"x == z"\n'
- 'is produced while iterating over "y". If an exception is '
- 'raised\n'
- 'during the iteration, it is as if "in" raised that '
- 'exception.\n'
- '\n'
- 'Lastly, the old-style iteration protocol is tried: if a class '
- 'defines\n'
- '"__getitem__()", "x in y" is true if and only if there is a '
- 'non-\n'
- 'negative integer index *i* such that "x == y[i]", and all '
- 'lower\n'
- 'integer indices do not raise "IndexError" exception. (If any '
- 'other\n'
- 'exception is raised, it is as if "in" raised that '
- 'exception).\n'
- '\n'
- 'The operator "not in" is defined to have the inverse true '
- 'value of\n'
- '"in".\n'
- '\n'
- 'The operators "is" and "is not" test for object identity: "x '
- 'is y" is\n'
- 'true if and only if *x* and *y* are the same object. "x is '
- 'not y"\n'
- 'yields the inverse truth value. [7]\n',
- 'compound': '\n'
- 'Compound statements\n'
- '*******************\n'
- '\n'
- 'Compound statements contain (groups of) other statements; they '
- 'affect\n'
- 'or control the execution of those other statements in some way. '
- 'In\n'
- 'general, compound statements span multiple lines, although in '
- 'simple\n'
- 'incarnations a whole compound statement may be contained in one '
- 'line.\n'
- '\n'
- 'The "if", "while" and "for" statements implement traditional '
- 'control\n'
- 'flow constructs. "try" specifies exception handlers and/or '
- 'cleanup\n'
- 'code for a group of statements. Function and class definitions '
- 'are\n'
- 'also syntactically compound statements.\n'
- '\n'
- "Compound statements consist of one or more 'clauses.' A clause\n"
- "consists of a header and a 'suite.' The clause headers of a\n"
- 'particular compound statement are all at the same indentation '
- 'level.\n'
- 'Each clause header begins with a uniquely identifying keyword '
- 'and ends\n'
- 'with a colon. A suite is a group of statements controlled by a\n'
- 'clause. A suite can be one or more semicolon-separated simple\n'
- 'statements on the same line as the header, following the '
- "header's\n"
- 'colon, or it can be one or more indented statements on '
- 'subsequent\n'
- 'lines. Only the latter form of suite can contain nested '
- 'compound\n'
- "statements; the following is illegal, mostly because it wouldn't "
- 'be\n'
- 'clear to which "if" clause a following "else" clause would '
- 'belong:\n'
- '\n'
- ' if test1: if test2: print x\n'
- '\n'
- 'Also note that the semicolon binds tighter than the colon in '
- 'this\n'
- 'context, so that in the following example, either all or none of '
- 'the\n'
- '"print" statements are executed:\n'
- '\n'
- ' if x < y < z: print x; print y; print z\n'
- '\n'
- 'Summarizing:\n'
- '\n'
- ' compound_stmt ::= if_stmt\n'
- ' | while_stmt\n'
- ' | for_stmt\n'
- ' | try_stmt\n'
- ' | with_stmt\n'
- ' | funcdef\n'
- ' | classdef\n'
- ' | decorated\n'
- ' suite ::= stmt_list NEWLINE | NEWLINE INDENT '
- 'statement+ DEDENT\n'
- ' statement ::= stmt_list NEWLINE | compound_stmt\n'
- ' stmt_list ::= simple_stmt (";" simple_stmt)* [";"]\n'
- '\n'
- 'Note that statements always end in a "NEWLINE" possibly followed '
- 'by a\n'
- '"DEDENT". Also note that optional continuation clauses always '
- 'begin\n'
- 'with a keyword that cannot start a statement, thus there are no\n'
- 'ambiguities (the \'dangling "else"\' problem is solved in Python '
- 'by\n'
- 'requiring nested "if" statements to be indented).\n'
- '\n'
- 'The formatting of the grammar rules in the following sections '
- 'places\n'
- 'each clause on a separate line for clarity.\n'
- '\n'
- '\n'
- 'The "if" statement\n'
- '==================\n'
- '\n'
- 'The "if" statement is used for conditional execution:\n'
- '\n'
- ' if_stmt ::= "if" expression ":" suite\n'
- ' ( "elif" expression ":" suite )*\n'
- ' ["else" ":" suite]\n'
- '\n'
- 'It selects exactly one of the suites by evaluating the '
- 'expressions one\n'
- 'by one until one is found to be true (see section Boolean '
- 'operations\n'
- 'for the definition of true and false); then that suite is '
- 'executed\n'
- '(and no other part of the "if" statement is executed or '
- 'evaluated).\n'
- 'If all expressions are false, the suite of the "else" clause, '
- 'if\n'
- 'present, is executed.\n'
- '\n'
- '\n'
- 'The "while" statement\n'
- '=====================\n'
- '\n'
- 'The "while" statement is used for repeated execution as long as '
- 'an\n'
- 'expression is true:\n'
- '\n'
- ' while_stmt ::= "while" expression ":" suite\n'
- ' ["else" ":" suite]\n'
- '\n'
- 'This repeatedly tests the expression and, if it is true, '
- 'executes the\n'
- 'first suite; if the expression is false (which may be the first '
- 'time\n'
- 'it is tested) the suite of the "else" clause, if present, is '
- 'executed\n'
- 'and the loop terminates.\n'
- '\n'
- 'A "break" statement executed in the first suite terminates the '
- 'loop\n'
- 'without executing the "else" clause\'s suite. A "continue" '
- 'statement\n'
- 'executed in the first suite skips the rest of the suite and goes '
- 'back\n'
- 'to testing the expression.\n'
- '\n'
- '\n'
- 'The "for" statement\n'
- '===================\n'
- '\n'
- 'The "for" statement is used to iterate over the elements of a '
- 'sequence\n'
- '(such as a string, tuple or list) or other iterable object:\n'
- '\n'
- ' for_stmt ::= "for" target_list "in" expression_list ":" '
- 'suite\n'
- ' ["else" ":" suite]\n'
- '\n'
- 'The expression list is evaluated once; it should yield an '
- 'iterable\n'
- 'object. An iterator is created for the result of the\n'
- '"expression_list". The suite is then executed once for each '
- 'item\n'
- 'provided by the iterator, in the order of ascending indices. '
- 'Each\n'
- 'item in turn is assigned to the target list using the standard '
- 'rules\n'
- 'for assignments, and then the suite is executed. When the items '
- 'are\n'
- 'exhausted (which is immediately when the sequence is empty), the '
- 'suite\n'
- 'in the "else" clause, if present, is executed, and the loop\n'
- 'terminates.\n'
- '\n'
- 'A "break" statement executed in the first suite terminates the '
- 'loop\n'
- 'without executing the "else" clause\'s suite. A "continue" '
- 'statement\n'
- 'executed in the first suite skips the rest of the suite and '
- 'continues\n'
- 'with the next item, or with the "else" clause if there was no '
- 'next\n'
- 'item.\n'
- '\n'
- 'The suite may assign to the variable(s) in the target list; this '
- 'does\n'
- 'not affect the next item assigned to it.\n'
- '\n'
- 'The target list is not deleted when the loop is finished, but if '
- 'the\n'
- 'sequence is empty, it will not have been assigned to at all by '
- 'the\n'
- 'loop. Hint: the built-in function "range()" returns a sequence '
- 'of\n'
- 'integers suitable to emulate the effect of Pascal\'s "for i := a '
- 'to b\n'
- 'do"; e.g., "range(3)" returns the list "[0, 1, 2]".\n'
- '\n'
- 'Note: There is a subtlety when the sequence is being modified by '
- 'the\n'
- ' loop (this can only occur for mutable sequences, i.e. lists). '
- 'An\n'
- ' internal counter is used to keep track of which item is used '
- 'next,\n'
- ' and this is incremented on each iteration. When this counter '
- 'has\n'
- ' reached the length of the sequence the loop terminates. This '
- 'means\n'
- ' that if the suite deletes the current (or a previous) item '
- 'from the\n'
- ' sequence, the next item will be skipped (since it gets the '
- 'index of\n'
- ' the current item which has already been treated). Likewise, '
- 'if the\n'
- ' suite inserts an item in the sequence before the current item, '
- 'the\n'
- ' current item will be treated again the next time through the '
- 'loop.\n'
- ' This can lead to nasty bugs that can be avoided by making a\n'
- ' temporary copy using a slice of the whole sequence, e.g.,\n'
- '\n'
- ' for x in a[:]:\n'
- ' if x < 0: a.remove(x)\n'
- '\n'
- '\n'
- 'The "try" statement\n'
- '===================\n'
- '\n'
- 'The "try" statement specifies exception handlers and/or cleanup '
- 'code\n'
- 'for a group of statements:\n'
- '\n'
- ' try_stmt ::= try1_stmt | try2_stmt\n'
- ' try1_stmt ::= "try" ":" suite\n'
- ' ("except" [expression [("as" | ",") '
- 'identifier]] ":" suite)+\n'
- ' ["else" ":" suite]\n'
- ' ["finally" ":" suite]\n'
- ' try2_stmt ::= "try" ":" suite\n'
- ' "finally" ":" suite\n'
- '\n'
- 'Changed in version 2.5: In previous versions of Python,\n'
- '"try"..."except"..."finally" did not work. "try"..."except" had '
- 'to be\n'
- 'nested in "try"..."finally".\n'
- '\n'
- 'The "except" clause(s) specify one or more exception handlers. '
- 'When no\n'
- 'exception occurs in the "try" clause, no exception handler is\n'
- 'executed. When an exception occurs in the "try" suite, a search '
- 'for an\n'
- 'exception handler is started. This search inspects the except '
- 'clauses\n'
- 'in turn until one is found that matches the exception. An '
- 'expression-\n'
- 'less except clause, if present, must be last; it matches any\n'
- 'exception. For an except clause with an expression, that '
- 'expression\n'
- 'is evaluated, and the clause matches the exception if the '
- 'resulting\n'
- 'object is "compatible" with the exception. An object is '
- 'compatible\n'
- 'with an exception if it is the class or a base class of the '
- 'exception\n'
- 'object, or a tuple containing an item compatible with the '
- 'exception.\n'
- '\n'
- 'If no except clause matches the exception, the search for an '
- 'exception\n'
- 'handler continues in the surrounding code and on the invocation '
- 'stack.\n'
- '[1]\n'
- '\n'
- 'If the evaluation of an expression in the header of an except '
- 'clause\n'
- 'raises an exception, the original search for a handler is '
- 'canceled and\n'
- 'a search starts for the new exception in the surrounding code '
- 'and on\n'
- 'the call stack (it is treated as if the entire "try" statement '
- 'raised\n'
- 'the exception).\n'
- '\n'
- 'When a matching except clause is found, the exception is '
- 'assigned to\n'
- 'the target specified in that except clause, if present, and the '
- 'except\n'
- "clause's suite is executed. All except clauses must have an\n"
- 'executable block. When the end of this block is reached, '
- 'execution\n'
- 'continues normally after the entire try statement. (This means '
- 'that\n'
- 'if two nested handlers exist for the same exception, and the '
- 'exception\n'
- 'occurs in the try clause of the inner handler, the outer handler '
- 'will\n'
- 'not handle the exception.)\n'
- '\n'
- "Before an except clause's suite is executed, details about the\n"
- 'exception are assigned to three variables in the "sys" module:\n'
- '"sys.exc_type" receives the object identifying the exception;\n'
- '"sys.exc_value" receives the exception\'s parameter;\n'
- '"sys.exc_traceback" receives a traceback object (see section '
- 'The\n'
- 'standard type hierarchy) identifying the point in the program '
- 'where\n'
- 'the exception occurred. These details are also available through '
- 'the\n'
- '"sys.exc_info()" function, which returns a tuple "(exc_type,\n'
- 'exc_value, exc_traceback)". Use of the corresponding variables '
- 'is\n'
- 'deprecated in favor of this function, since their use is unsafe '
- 'in a\n'
- 'threaded program. As of Python 1.5, the variables are restored '
- 'to\n'
- 'their previous values (before the call) when returning from a '
- 'function\n'
- 'that handled an exception.\n'
- '\n'
- 'The optional "else" clause is executed if and when control flows '
- 'off\n'
- 'the end of the "try" clause. [2] Exceptions in the "else" clause '
- 'are\n'
- 'not handled by the preceding "except" clauses.\n'
- '\n'
- 'If "finally" is present, it specifies a \'cleanup\' handler. '
- 'The "try"\n'
- 'clause is executed, including any "except" and "else" clauses. '
- 'If an\n'
- 'exception occurs in any of the clauses and is not handled, the\n'
- 'exception is temporarily saved. The "finally" clause is '
- 'executed. If\n'
- 'there is a saved exception, it is re-raised at the end of the\n'
- '"finally" clause. If the "finally" clause raises another '
- 'exception or\n'
- 'executes a "return" or "break" statement, the saved exception '
- 'is\n'
- 'discarded:\n'
- '\n'
- ' >>> def f():\n'
- ' ... try:\n'
- ' ... 1/0\n'
- ' ... finally:\n'
- ' ... return 42\n'
- ' ...\n'
- ' >>> f()\n'
- ' 42\n'
- '\n'
- 'The exception information is not available to the program '
- 'during\n'
- 'execution of the "finally" clause.\n'
- '\n'
- 'When a "return", "break" or "continue" statement is executed in '
- 'the\n'
- '"try" suite of a "try"..."finally" statement, the "finally" '
- 'clause is\n'
- 'also executed \'on the way out.\' A "continue" statement is '
- 'illegal in\n'
- 'the "finally" clause. (The reason is a problem with the current\n'
- 'implementation --- this restriction may be lifted in the '
- 'future).\n'
- '\n'
- 'The return value of a function is determined by the last '
- '"return"\n'
- 'statement executed. Since the "finally" clause always executes, '
- 'a\n'
- '"return" statement executed in the "finally" clause will always '
- 'be the\n'
- 'last one executed:\n'
- '\n'
- ' >>> def foo():\n'
- ' ... try:\n'
- " ... return 'try'\n"
- ' ... finally:\n'
- " ... return 'finally'\n"
- ' ...\n'
- ' >>> foo()\n'
- " 'finally'\n"
- '\n'
- 'Additional information on exceptions can be found in section\n'
- 'Exceptions, and information on using the "raise" statement to '
- 'generate\n'
- 'exceptions may be found in section The raise statement.\n'
- '\n'
- '\n'
- 'The "with" statement\n'
- '====================\n'
- '\n'
- 'New in version 2.5.\n'
- '\n'
- 'The "with" statement is used to wrap the execution of a block '
- 'with\n'
- 'methods defined by a context manager (see section With '
- 'Statement\n'
- 'Context Managers). This allows common '
- '"try"..."except"..."finally"\n'
- 'usage patterns to be encapsulated for convenient reuse.\n'
- '\n'
- ' with_stmt ::= "with" with_item ("," with_item)* ":" suite\n'
- ' with_item ::= expression ["as" target]\n'
- '\n'
- 'The execution of the "with" statement with one "item" proceeds '
- 'as\n'
- 'follows:\n'
- '\n'
- '1. The context expression (the expression given in the '
- '"with_item")\n'
- ' is evaluated to obtain a context manager.\n'
- '\n'
- '2. The context manager\'s "__exit__()" is loaded for later use.\n'
- '\n'
- '3. The context manager\'s "__enter__()" method is invoked.\n'
- '\n'
- '4. If a target was included in the "with" statement, the return\n'
- ' value from "__enter__()" is assigned to it.\n'
- '\n'
- ' Note: The "with" statement guarantees that if the '
- '"__enter__()"\n'
- ' method returns without an error, then "__exit__()" will '
- 'always be\n'
- ' called. Thus, if an error occurs during the assignment to '
- 'the\n'
- ' target list, it will be treated the same as an error '
- 'occurring\n'
- ' within the suite would be. See step 6 below.\n'
- '\n'
- '5. The suite is executed.\n'
- '\n'
- '6. The context manager\'s "__exit__()" method is invoked. If an\n'
- ' exception caused the suite to be exited, its type, value, '
- 'and\n'
- ' traceback are passed as arguments to "__exit__()". Otherwise, '
- 'three\n'
- ' "None" arguments are supplied.\n'
- '\n'
- ' If the suite was exited due to an exception, and the return '
- 'value\n'
- ' from the "__exit__()" method was false, the exception is '
- 'reraised.\n'
- ' If the return value was true, the exception is suppressed, '
- 'and\n'
- ' execution continues with the statement following the "with"\n'
- ' statement.\n'
- '\n'
- ' If the suite was exited for any reason other than an '
- 'exception, the\n'
- ' return value from "__exit__()" is ignored, and execution '
- 'proceeds\n'
- ' at the normal location for the kind of exit that was taken.\n'
- '\n'
- 'With more than one item, the context managers are processed as '
- 'if\n'
- 'multiple "with" statements were nested:\n'
- '\n'
- ' with A() as a, B() as b:\n'
- ' suite\n'
- '\n'
- 'is equivalent to\n'
- '\n'
- ' with A() as a:\n'
- ' with B() as b:\n'
- ' suite\n'
- '\n'
- 'Note: In Python 2.5, the "with" statement is only allowed when '
- 'the\n'
- ' "with_statement" feature has been enabled. It is always '
- 'enabled in\n'
- ' Python 2.6.\n'
- '\n'
- 'Changed in version 2.7: Support for multiple context '
- 'expressions.\n'
- '\n'
- 'See also:\n'
- '\n'
- ' **PEP 343** - The "with" statement\n'
- ' The specification, background, and examples for the Python '
- '"with"\n'
- ' statement.\n'
- '\n'
- '\n'
- 'Function definitions\n'
- '====================\n'
- '\n'
- 'A function definition defines a user-defined function object '
- '(see\n'
- 'section The standard type hierarchy):\n'
- '\n'
- ' decorated ::= decorators (classdef | funcdef)\n'
- ' decorators ::= decorator+\n'
- ' decorator ::= "@" dotted_name ["(" [argument_list [","]] '
- '")"] NEWLINE\n'
- ' funcdef ::= "def" funcname "(" [parameter_list] ")" '
- '":" suite\n'
- ' dotted_name ::= identifier ("." identifier)*\n'
- ' parameter_list ::= (defparameter ",")*\n'
- ' ( "*" identifier ["," "**" identifier]\n'
- ' | "**" identifier\n'
- ' | defparameter [","] )\n'
- ' defparameter ::= parameter ["=" expression]\n'
- ' sublist ::= parameter ("," parameter)* [","]\n'
- ' parameter ::= identifier | "(" sublist ")"\n'
- ' funcname ::= identifier\n'
- '\n'
- 'A function definition is an executable statement. Its execution '
- 'binds\n'
- 'the function name in the current local namespace to a function '
- 'object\n'
- '(a wrapper around the executable code for the function). This\n'
- 'function object contains a reference to the current global '
- 'namespace\n'
- 'as the global namespace to be used when the function is called.\n'
- '\n'
- 'The function definition does not execute the function body; this '
- 'gets\n'
- 'executed only when the function is called. [3]\n'
- '\n'
- 'A function definition may be wrapped by one or more *decorator*\n'
- 'expressions. Decorator expressions are evaluated when the '
- 'function is\n'
- 'defined, in the scope that contains the function definition. '
- 'The\n'
- 'result must be a callable, which is invoked with the function '
- 'object\n'
- 'as the only argument. The returned value is bound to the '
- 'function name\n'
- 'instead of the function object. Multiple decorators are applied '
- 'in\n'
- 'nested fashion. For example, the following code:\n'
- '\n'
- ' @f1(arg)\n'
- ' @f2\n'
- ' def func(): pass\n'
- '\n'
- 'is equivalent to:\n'
- '\n'
- ' def func(): pass\n'
- ' func = f1(arg)(f2(func))\n'
- '\n'
- 'When one or more top-level *parameters* have the form '
- '*parameter* "="\n'
- '*expression*, the function is said to have "default parameter '
- 'values."\n'
- 'For a parameter with a default value, the corresponding '
- '*argument* may\n'
- "be omitted from a call, in which case the parameter's default "
- 'value is\n'
- 'substituted. If a parameter has a default value, all following\n'
- 'parameters must also have a default value --- this is a '
- 'syntactic\n'
- 'restriction that is not expressed by the grammar.\n'
- '\n'
- '**Default parameter values are evaluated when the function '
- 'definition\n'
- 'is executed.** This means that the expression is evaluated '
- 'once, when\n'
- 'the function is defined, and that the same "pre-computed" value '
- 'is\n'
- 'used for each call. This is especially important to understand '
- 'when a\n'
- 'default parameter is a mutable object, such as a list or a '
- 'dictionary:\n'
- 'if the function modifies the object (e.g. by appending an item '
- 'to a\n'
- 'list), the default value is in effect modified. This is '
- 'generally not\n'
- 'what was intended. A way around this is to use "None" as the\n'
- 'default, and explicitly test for it in the body of the function, '
- 'e.g.:\n'
- '\n'
- ' def whats_on_the_telly(penguin=None):\n'
- ' if penguin is None:\n'
- ' penguin = []\n'
- ' penguin.append("property of the zoo")\n'
- ' return penguin\n'
- '\n'
- 'Function call semantics are described in more detail in section '
- 'Calls.\n'
- 'A function call always assigns values to all parameters '
- 'mentioned in\n'
- 'the parameter list, either from position arguments, from '
- 'keyword\n'
- 'arguments, or from default values. If the form ""*identifier"" '
- 'is\n'
- 'present, it is initialized to a tuple receiving any excess '
- 'positional\n'
- 'parameters, defaulting to the empty tuple. If the form\n'
- '""**identifier"" is present, it is initialized to a new '
- 'dictionary\n'
- 'receiving any excess keyword arguments, defaulting to a new '
- 'empty\n'
- 'dictionary.\n'
- '\n'
- 'It is also possible to create anonymous functions (functions not '
- 'bound\n'
- 'to a name), for immediate use in expressions. This uses lambda\n'
- 'expressions, described in section Lambdas. Note that the '
- 'lambda\n'
- 'expression is merely a shorthand for a simplified function '
- 'definition;\n'
- 'a function defined in a ""def"" statement can be passed around '
- 'or\n'
- 'assigned to another name just like a function defined by a '
- 'lambda\n'
- 'expression. The ""def"" form is actually more powerful since '
- 'it\n'
- 'allows the execution of multiple statements.\n'
- '\n'
- "**Programmer's note:** Functions are first-class objects. A "
- '""def""\n'
- 'form executed inside a function definition defines a local '
- 'function\n'
- 'that can be returned or passed around. Free variables used in '
- 'the\n'
- 'nested function can access the local variables of the function\n'
- 'containing the def. See section Naming and binding for '
- 'details.\n'
- '\n'
- '\n'
- 'Class definitions\n'
- '=================\n'
- '\n'
- 'A class definition defines a class object (see section The '
- 'standard\n'
- 'type hierarchy):\n'
- '\n'
- ' classdef ::= "class" classname [inheritance] ":" suite\n'
- ' inheritance ::= "(" [expression_list] ")"\n'
- ' classname ::= identifier\n'
- '\n'
- 'A class definition is an executable statement. It first '
- 'evaluates the\n'
- 'inheritance list, if present. Each item in the inheritance '
- 'list\n'
- 'should evaluate to a class object or class type which allows\n'
- "subclassing. The class's suite is then executed in a new "
- 'execution\n'
- 'frame (see section Naming and binding), using a newly created '
- 'local\n'
- 'namespace and the original global namespace. (Usually, the '
- 'suite\n'
- "contains only function definitions.) When the class's suite "
- 'finishes\n'
- 'execution, its execution frame is discarded but its local '
- 'namespace is\n'
- 'saved. [4] A class object is then created using the inheritance '
- 'list\n'
- 'for the base classes and the saved local namespace for the '
- 'attribute\n'
- 'dictionary. The class name is bound to this class object in '
- 'the\n'
- 'original local namespace.\n'
- '\n'
- "**Programmer's note:** Variables defined in the class definition "
- 'are\n'
- 'class variables; they are shared by all instances. To create '
- 'instance\n'
- 'variables, they can be set in a method with "self.name = '
- 'value". Both\n'
- 'class and instance variables are accessible through the '
- 'notation\n'
- '""self.name"", and an instance variable hides a class variable '
- 'with\n'
- 'the same name when accessed in this way. Class variables can be '
- 'used\n'
- 'as defaults for instance variables, but using mutable values '
- 'there can\n'
- 'lead to unexpected results. For *new-style class*es, '
- 'descriptors can\n'
- 'be used to create instance variables with different '
- 'implementation\n'
- 'details.\n'
- '\n'
- 'Class definitions, like function definitions, may be wrapped by '
- 'one or\n'
- 'more *decorator* expressions. The evaluation rules for the '
- 'decorator\n'
- 'expressions are the same as for functions. The result must be a '
- 'class\n'
- 'object, which is then bound to the class name.\n'
- '\n'
- '-[ Footnotes ]-\n'
- '\n'
- '[1] The exception is propagated to the invocation stack unless\n'
- ' there is a "finally" clause which happens to raise another\n'
- ' exception. That new exception causes the old one to be '
- 'lost.\n'
- '\n'
- '[2] Currently, control "flows off the end" except in the case '
- 'of\n'
- ' an exception or the execution of a "return", "continue", or\n'
- ' "break" statement.\n'
- '\n'
- '[3] A string literal appearing as the first statement in the\n'
- ' function body is transformed into the function\'s "__doc__"\n'
- " attribute and therefore the function's *docstring*.\n"
- '\n'
- '[4] A string literal appearing as the first statement in the '
- 'class\n'
- ' body is transformed into the namespace\'s "__doc__" item '
- 'and\n'
- " therefore the class's *docstring*.\n",
- 'context-managers': '\n'
- 'With Statement Context Managers\n'
- '*******************************\n'
- '\n'
- 'New in version 2.5.\n'
- '\n'
- 'A *context manager* is an object that defines the '
- 'runtime context to\n'
- 'be established when executing a "with" statement. The '
- 'context manager\n'
- 'handles the entry into, and the exit from, the desired '
- 'runtime context\n'
- 'for the execution of the block of code. Context '
- 'managers are normally\n'
- 'invoked using the "with" statement (described in section '
- 'The with\n'
- 'statement), but can also be used by directly invoking '
- 'their methods.\n'
- '\n'
- 'Typical uses of context managers include saving and '
- 'restoring various\n'
- 'kinds of global state, locking and unlocking resources, '
- 'closing opened\n'
- 'files, etc.\n'
- '\n'
- 'For more information on context managers, see Context '
- 'Manager Types.\n'
- '\n'
- 'object.__enter__(self)\n'
- '\n'
- ' Enter the runtime context related to this object. The '
- '"with"\n'
- " statement will bind this method's return value to the "
- 'target(s)\n'
- ' specified in the "as" clause of the statement, if '
- 'any.\n'
- '\n'
- 'object.__exit__(self, exc_type, exc_value, traceback)\n'
- '\n'
- ' Exit the runtime context related to this object. The '
- 'parameters\n'
- ' describe the exception that caused the context to be '
- 'exited. If the\n'
- ' context was exited without an exception, all three '
- 'arguments will\n'
- ' be "None".\n'
- '\n'
- ' If an exception is supplied, and the method wishes to '
- 'suppress the\n'
- ' exception (i.e., prevent it from being propagated), '
- 'it should\n'
- ' return a true value. Otherwise, the exception will be '
- 'processed\n'
- ' normally upon exit from this method.\n'
- '\n'
- ' Note that "__exit__()" methods should not reraise the '
- 'passed-in\n'
- " exception; this is the caller's responsibility.\n"
- '\n'
- 'See also:\n'
- '\n'
- ' **PEP 343** - The "with" statement\n'
- ' The specification, background, and examples for the '
- 'Python "with"\n'
- ' statement.\n',
- 'continue': '\n'
- 'The "continue" statement\n'
- '************************\n'
- '\n'
- ' continue_stmt ::= "continue"\n'
- '\n'
- '"continue" may only occur syntactically nested in a "for" or '
- '"while"\n'
- 'loop, but not nested in a function or class definition or '
- '"finally"\n'
- 'clause within that loop. It continues with the next cycle of '
- 'the\n'
- 'nearest enclosing loop.\n'
- '\n'
- 'When "continue" passes control out of a "try" statement with a\n'
- '"finally" clause, that "finally" clause is executed before '
- 'really\n'
- 'starting the next loop cycle.\n',
- 'conversions': '\n'
- 'Arithmetic conversions\n'
- '**********************\n'
- '\n'
- 'When a description of an arithmetic operator below uses the '
- 'phrase\n'
- '"the numeric arguments are converted to a common type," the '
- 'arguments\n'
- 'are coerced using the coercion rules listed at Coercion '
- 'rules. If\n'
- 'both arguments are standard numeric types, the following '
- 'coercions are\n'
- 'applied:\n'
- '\n'
- '* If either argument is a complex number, the other is '
- 'converted to\n'
- ' complex;\n'
- '\n'
- '* otherwise, if either argument is a floating point number, '
- 'the\n'
- ' other is converted to floating point;\n'
- '\n'
- '* otherwise, if either argument is a long integer, the other '
- 'is\n'
- ' converted to long integer;\n'
- '\n'
- '* otherwise, both must be plain integers and no conversion '
- 'is\n'
- ' necessary.\n'
- '\n'
- 'Some additional rules apply for certain operators (e.g., a '
- 'string left\n'
- "argument to the '%' operator). Extensions can define their "
- 'own\n'
- 'coercions.\n',
- 'customization': '\n'
- 'Basic customization\n'
- '*******************\n'
- '\n'
- 'object.__new__(cls[, ...])\n'
- '\n'
- ' Called to create a new instance of class *cls*. '
- '"__new__()" is a\n'
- ' static method (special-cased so you need not declare it '
- 'as such)\n'
- ' that takes the class of which an instance was requested '
- 'as its\n'
- ' first argument. The remaining arguments are those '
- 'passed to the\n'
- ' object constructor expression (the call to the class). '
- 'The return\n'
- ' value of "__new__()" should be the new object instance '
- '(usually an\n'
- ' instance of *cls*).\n'
- '\n'
- ' Typical implementations create a new instance of the '
- 'class by\n'
- ' invoking the superclass\'s "__new__()" method using\n'
- ' "super(currentclass, cls).__new__(cls[, ...])" with '
- 'appropriate\n'
- ' arguments and then modifying the newly-created instance '
- 'as\n'
- ' necessary before returning it.\n'
- '\n'
- ' If "__new__()" returns an instance of *cls*, then the '
- 'new\n'
- ' instance\'s "__init__()" method will be invoked like\n'
- ' "__init__(self[, ...])", where *self* is the new '
- 'instance and the\n'
- ' remaining arguments are the same as were passed to '
- '"__new__()".\n'
- '\n'
- ' If "__new__()" does not return an instance of *cls*, '
- 'then the new\n'
- ' instance\'s "__init__()" method will not be invoked.\n'
- '\n'
- ' "__new__()" is intended mainly to allow subclasses of '
- 'immutable\n'
- ' types (like int, str, or tuple) to customize instance '
- 'creation. It\n'
- ' is also commonly overridden in custom metaclasses in '
- 'order to\n'
- ' customize class creation.\n'
- '\n'
- 'object.__init__(self[, ...])\n'
- '\n'
- ' Called after the instance has been created (by '
- '"__new__()"), but\n'
- ' before it is returned to the caller. The arguments are '
- 'those\n'
- ' passed to the class constructor expression. If a base '
- 'class has an\n'
- ' "__init__()" method, the derived class\'s "__init__()" '
- 'method, if\n'
- ' any, must explicitly call it to ensure proper '
- 'initialization of the\n'
- ' base class part of the instance; for example:\n'
- ' "BaseClass.__init__(self, [args...])".\n'
- '\n'
- ' Because "__new__()" and "__init__()" work together in '
- 'constructing\n'
- ' objects ("__new__()" to create it, and "__init__()" to '
- 'customise\n'
- ' it), no non-"None" value may be returned by '
- '"__init__()"; doing so\n'
- ' will cause a "TypeError" to be raised at runtime.\n'
- '\n'
- 'object.__del__(self)\n'
- '\n'
- ' Called when the instance is about to be destroyed. This '
- 'is also\n'
- ' called a destructor. If a base class has a "__del__()" '
- 'method, the\n'
- ' derived class\'s "__del__()" method, if any, must '
- 'explicitly call it\n'
- ' to ensure proper deletion of the base class part of the '
- 'instance.\n'
- ' Note that it is possible (though not recommended!) for '
- 'the\n'
- ' "__del__()" method to postpone destruction of the '
- 'instance by\n'
- ' creating a new reference to it. It may then be called '
- 'at a later\n'
- ' time when this new reference is deleted. It is not '
- 'guaranteed that\n'
- ' "__del__()" methods are called for objects that still '
- 'exist when\n'
- ' the interpreter exits.\n'
- '\n'
- ' Note: "del x" doesn\'t directly call "x.__del__()" --- '
- 'the former\n'
- ' decrements the reference count for "x" by one, and the '
- 'latter is\n'
- ' only called when "x"\'s reference count reaches zero. '
- 'Some common\n'
- ' situations that may prevent the reference count of an '
- 'object from\n'
- ' going to zero include: circular references between '
- 'objects (e.g.,\n'
- ' a doubly-linked list or a tree data structure with '
- 'parent and\n'
- ' child pointers); a reference to the object on the '
- 'stack frame of\n'
- ' a function that caught an exception (the traceback '
- 'stored in\n'
- ' "sys.exc_traceback" keeps the stack frame alive); or a '
- 'reference\n'
- ' to the object on the stack frame that raised an '
- 'unhandled\n'
- ' exception in interactive mode (the traceback stored '
- 'in\n'
- ' "sys.last_traceback" keeps the stack frame alive). '
- 'The first\n'
- ' situation can only be remedied by explicitly breaking '
- 'the cycles;\n'
- ' the latter two situations can be resolved by storing '
- '"None" in\n'
- ' "sys.exc_traceback" or "sys.last_traceback". Circular '
- 'references\n'
- ' which are garbage are detected when the option cycle '
- 'detector is\n'
- " enabled (it's on by default), but can only be cleaned "
- 'up if there\n'
- ' are no Python-level "__del__()" methods involved. '
- 'Refer to the\n'
- ' documentation for the "gc" module for more information '
- 'about how\n'
- ' "__del__()" methods are handled by the cycle '
- 'detector,\n'
- ' particularly the description of the "garbage" value.\n'
- '\n'
- ' Warning: Due to the precarious circumstances under '
- 'which\n'
- ' "__del__()" methods are invoked, exceptions that occur '
- 'during\n'
- ' their execution are ignored, and a warning is printed '
- 'to\n'
- ' "sys.stderr" instead. Also, when "__del__()" is '
- 'invoked in\n'
- ' response to a module being deleted (e.g., when '
- 'execution of the\n'
- ' program is done), other globals referenced by the '
- '"__del__()"\n'
- ' method may already have been deleted or in the process '
- 'of being\n'
- ' torn down (e.g. the import machinery shutting down). '
- 'For this\n'
- ' reason, "__del__()" methods should do the absolute '
- 'minimum needed\n'
- ' to maintain external invariants. Starting with '
- 'version 1.5,\n'
- ' Python guarantees that globals whose name begins with '
- 'a single\n'
- ' underscore are deleted from their module before other '
- 'globals are\n'
- ' deleted; if no other references to such globals exist, '
- 'this may\n'
- ' help in assuring that imported modules are still '
- 'available at the\n'
- ' time when the "__del__()" method is called.\n'
- '\n'
- ' See also the "-R" command-line option.\n'
- '\n'
- 'object.__repr__(self)\n'
- '\n'
- ' Called by the "repr()" built-in function and by string '
- 'conversions\n'
- ' (reverse quotes) to compute the "official" string '
- 'representation of\n'
- ' an object. If at all possible, this should look like a '
- 'valid\n'
- ' Python expression that could be used to recreate an '
- 'object with the\n'
- ' same value (given an appropriate environment). If this '
- 'is not\n'
- ' possible, a string of the form "<...some useful '
- 'description...>"\n'
- ' should be returned. The return value must be a string '
- 'object. If a\n'
- ' class defines "__repr__()" but not "__str__()", then '
- '"__repr__()"\n'
- ' is also used when an "informal" string representation of '
- 'instances\n'
- ' of that class is required.\n'
- '\n'
- ' This is typically used for debugging, so it is important '
- 'that the\n'
- ' representation is information-rich and unambiguous.\n'
- '\n'
- 'object.__str__(self)\n'
- '\n'
- ' Called by the "str()" built-in function and by the '
- '"print"\n'
- ' statement to compute the "informal" string '
- 'representation of an\n'
- ' object. This differs from "__repr__()" in that it does '
- 'not have to\n'
- ' be a valid Python expression: a more convenient or '
- 'concise\n'
- ' representation may be used instead. The return value '
- 'must be a\n'
- ' string object.\n'
- '\n'
- 'object.__lt__(self, other)\n'
- 'object.__le__(self, other)\n'
- 'object.__eq__(self, other)\n'
- 'object.__ne__(self, other)\n'
- 'object.__gt__(self, other)\n'
- 'object.__ge__(self, other)\n'
- '\n'
- ' New in version 2.1.\n'
- '\n'
- ' These are the so-called "rich comparison" methods, and '
- 'are called\n'
- ' for comparison operators in preference to "__cmp__()" '
- 'below. The\n'
- ' correspondence between operator symbols and method names '
- 'is as\n'
- ' follows: "x<y" calls "x.__lt__(y)", "x<=y" calls '
- '"x.__le__(y)",\n'
- ' "x==y" calls "x.__eq__(y)", "x!=y" and "x<>y" call '
- '"x.__ne__(y)",\n'
- ' "x>y" calls "x.__gt__(y)", and "x>=y" calls '
- '"x.__ge__(y)".\n'
- '\n'
- ' A rich comparison method may return the singleton '
- '"NotImplemented"\n'
- ' if it does not implement the operation for a given pair '
- 'of\n'
- ' arguments. By convention, "False" and "True" are '
- 'returned for a\n'
- ' successful comparison. However, these methods can return '
- 'any value,\n'
- ' so if the comparison operator is used in a Boolean '
- 'context (e.g.,\n'
- ' in the condition of an "if" statement), Python will call '
- '"bool()"\n'
- ' on the value to determine if the result is true or '
- 'false.\n'
- '\n'
- ' There are no implied relationships among the comparison '
- 'operators.\n'
- ' The truth of "x==y" does not imply that "x!=y" is '
- 'false.\n'
- ' Accordingly, when defining "__eq__()", one should also '
- 'define\n'
- ' "__ne__()" so that the operators will behave as '
- 'expected. See the\n'
- ' paragraph on "__hash__()" for some important notes on '
- 'creating\n'
- ' *hashable* objects which support custom comparison '
- 'operations and\n'
- ' are usable as dictionary keys.\n'
- '\n'
- ' There are no swapped-argument versions of these methods '
- '(to be used\n'
- ' when the left argument does not support the operation '
- 'but the right\n'
- ' argument does); rather, "__lt__()" and "__gt__()" are '
- "each other's\n"
- ' reflection, "__le__()" and "__ge__()" are each other\'s '
- 'reflection,\n'
- ' and "__eq__()" and "__ne__()" are their own reflection.\n'
- '\n'
- ' Arguments to rich comparison methods are never coerced.\n'
- '\n'
- ' To automatically generate ordering operations from a '
- 'single root\n'
- ' operation, see "functools.total_ordering()".\n'
- '\n'
- 'object.__cmp__(self, other)\n'
- '\n'
- ' Called by comparison operations if rich comparison (see '
- 'above) is\n'
- ' not defined. Should return a negative integer if "self '
- '< other",\n'
- ' zero if "self == other", a positive integer if "self > '
- 'other". If\n'
- ' no "__cmp__()", "__eq__()" or "__ne__()" operation is '
- 'defined,\n'
- ' class instances are compared by object identity '
- '("address"). See\n'
- ' also the description of "__hash__()" for some important '
- 'notes on\n'
- ' creating *hashable* objects which support custom '
- 'comparison\n'
- ' operations and are usable as dictionary keys. (Note: '
- 'the\n'
- ' restriction that exceptions are not propagated by '
- '"__cmp__()" has\n'
- ' been removed since Python 1.5.)\n'
- '\n'
- 'object.__rcmp__(self, other)\n'
- '\n'
- ' Changed in version 2.1: No longer supported.\n'
- '\n'
- 'object.__hash__(self)\n'
- '\n'
- ' Called by built-in function "hash()" and for operations '
- 'on members\n'
- ' of hashed collections including "set", "frozenset", and '
- '"dict".\n'
- ' "__hash__()" should return an integer. The only '
- 'required property\n'
- ' is that objects which compare equal have the same hash '
- 'value; it is\n'
- ' advised to somehow mix together (e.g. using exclusive '
- 'or) the hash\n'
- ' values for the components of the object that also play a '
- 'part in\n'
- ' comparison of objects.\n'
- '\n'
- ' If a class does not define a "__cmp__()" or "__eq__()" '
- 'method it\n'
- ' should not define a "__hash__()" operation either; if it '
- 'defines\n'
- ' "__cmp__()" or "__eq__()" but not "__hash__()", its '
- 'instances will\n'
- ' not be usable in hashed collections. If a class defines '
- 'mutable\n'
- ' objects and implements a "__cmp__()" or "__eq__()" '
- 'method, it\n'
- ' should not implement "__hash__()", since hashable '
- 'collection\n'
- " implementations require that a object's hash value is "
- 'immutable (if\n'
- " the object's hash value changes, it will be in the wrong "
- 'hash\n'
- ' bucket).\n'
- '\n'
- ' User-defined classes have "__cmp__()" and "__hash__()" '
- 'methods by\n'
- ' default; with them, all objects compare unequal (except '
- 'with\n'
- ' themselves) and "x.__hash__()" returns a result derived '
- 'from\n'
- ' "id(x)".\n'
- '\n'
- ' Classes which inherit a "__hash__()" method from a '
- 'parent class but\n'
- ' change the meaning of "__cmp__()" or "__eq__()" such '
- 'that the hash\n'
- ' value returned is no longer appropriate (e.g. by '
- 'switching to a\n'
- ' value-based concept of equality instead of the default '
- 'identity\n'
- ' based equality) can explicitly flag themselves as being '
- 'unhashable\n'
- ' by setting "__hash__ = None" in the class definition. '
- 'Doing so\n'
- ' means that not only will instances of the class raise '
- 'an\n'
- ' appropriate "TypeError" when a program attempts to '
- 'retrieve their\n'
- ' hash value, but they will also be correctly identified '
- 'as\n'
- ' unhashable when checking "isinstance(obj, '
- 'collections.Hashable)"\n'
- ' (unlike classes which define their own "__hash__()" to '
- 'explicitly\n'
- ' raise "TypeError").\n'
- '\n'
- ' Changed in version 2.5: "__hash__()" may now also return '
- 'a long\n'
- ' integer object; the 32-bit integer is then derived from '
- 'the hash of\n'
- ' that object.\n'
- '\n'
- ' Changed in version 2.6: "__hash__" may now be set to '
- '"None" to\n'
- ' explicitly flag instances of a class as unhashable.\n'
- '\n'
- 'object.__nonzero__(self)\n'
- '\n'
- ' Called to implement truth value testing and the built-in '
- 'operation\n'
- ' "bool()"; should return "False" or "True", or their '
- 'integer\n'
- ' equivalents "0" or "1". When this method is not '
- 'defined,\n'
- ' "__len__()" is called, if it is defined, and the object '
- 'is\n'
- ' considered true if its result is nonzero. If a class '
- 'defines\n'
- ' neither "__len__()" nor "__nonzero__()", all its '
- 'instances are\n'
- ' considered true.\n'
- '\n'
- 'object.__unicode__(self)\n'
- '\n'
- ' Called to implement "unicode()" built-in; should return '
- 'a Unicode\n'
- ' object. When this method is not defined, string '
- 'conversion is\n'
- ' attempted, and the result of string conversion is '
- 'converted to\n'
- ' Unicode using the system default encoding.\n',
- 'debugger': '\n'
- '"pdb" --- The Python Debugger\n'
- '*****************************\n'
- '\n'
- '**Source code:** Lib/pdb.py\n'
- '\n'
- '======================================================================\n'
- '\n'
- 'The module "pdb" defines an interactive source code debugger '
- 'for\n'
- 'Python programs. It supports setting (conditional) breakpoints '
- 'and\n'
- 'single stepping at the source line level, inspection of stack '
- 'frames,\n'
- 'source code listing, and evaluation of arbitrary Python code in '
- 'the\n'
- 'context of any stack frame. It also supports post-mortem '
- 'debugging\n'
- 'and can be called under program control.\n'
- '\n'
- 'The debugger is extensible --- it is actually defined as the '
- 'class\n'
- '"Pdb". This is currently undocumented but easily understood by '
- 'reading\n'
- 'the source. The extension interface uses the modules "bdb" and '
- '"cmd".\n'
- '\n'
- 'The debugger\'s prompt is "(Pdb)". Typical usage to run a '
- 'program under\n'
- 'control of the debugger is:\n'
- '\n'
- ' >>> import pdb\n'
- ' >>> import mymodule\n'
- " >>> pdb.run('mymodule.test()')\n"
- ' > <string>(0)?()\n'
- ' (Pdb) continue\n'
- ' > <string>(1)?()\n'
- ' (Pdb) continue\n'
- " NameError: 'spam'\n"
- ' > <string>(1)?()\n'
- ' (Pdb)\n'
- '\n'
- '"pdb.py" can also be invoked as a script to debug other '
- 'scripts. For\n'
- 'example:\n'
- '\n'
- ' python -m pdb myscript.py\n'
- '\n'
- 'When invoked as a script, pdb will automatically enter '
- 'post-mortem\n'
- 'debugging if the program being debugged exits abnormally. After '
- 'post-\n'
- 'mortem debugging (or after normal exit of the program), pdb '
- 'will\n'
- "restart the program. Automatic restarting preserves pdb's state "
- '(such\n'
- 'as breakpoints) and in most cases is more useful than quitting '
- 'the\n'
- "debugger upon program's exit.\n"
- '\n'
- 'New in version 2.4: Restarting post-mortem behavior added.\n'
- '\n'
- 'The typical usage to break into the debugger from a running '
- 'program is\n'
- 'to insert\n'
- '\n'
- ' import pdb; pdb.set_trace()\n'
- '\n'
- 'at the location you want to break into the debugger. You can '
- 'then\n'
- 'step through the code following this statement, and continue '
- 'running\n'
- 'without the debugger using the "c" command.\n'
- '\n'
- 'The typical usage to inspect a crashed program is:\n'
- '\n'
- ' >>> import pdb\n'
- ' >>> import mymodule\n'
- ' >>> mymodule.test()\n'
- ' Traceback (most recent call last):\n'
- ' File "<stdin>", line 1, in ?\n'
- ' File "./mymodule.py", line 4, in test\n'
- ' test2()\n'
- ' File "./mymodule.py", line 3, in test2\n'
- ' print spam\n'
- ' NameError: spam\n'
- ' >>> pdb.pm()\n'
- ' > ./mymodule.py(3)test2()\n'
- ' -> print spam\n'
- ' (Pdb)\n'
- '\n'
- 'The module defines the following functions; each enters the '
- 'debugger\n'
- 'in a slightly different way:\n'
- '\n'
- 'pdb.run(statement[, globals[, locals]])\n'
- '\n'
- ' Execute the *statement* (given as a string) under debugger '
- 'control.\n'
- ' The debugger prompt appears before any code is executed; you '
- 'can\n'
- ' set breakpoints and type "continue", or you can step through '
- 'the\n'
- ' statement using "step" or "next" (all these commands are '
- 'explained\n'
- ' below). The optional *globals* and *locals* arguments '
- 'specify the\n'
- ' environment in which the code is executed; by default the\n'
- ' dictionary of the module "__main__" is used. (See the '
- 'explanation\n'
- ' of the "exec" statement or the "eval()" built-in function.)\n'
- '\n'
- 'pdb.runeval(expression[, globals[, locals]])\n'
- '\n'
- ' Evaluate the *expression* (given as a string) under debugger\n'
- ' control. When "runeval()" returns, it returns the value of '
- 'the\n'
- ' expression. Otherwise this function is similar to "run()".\n'
- '\n'
- 'pdb.runcall(function[, argument, ...])\n'
- '\n'
- ' Call the *function* (a function or method object, not a '
- 'string)\n'
- ' with the given arguments. When "runcall()" returns, it '
- 'returns\n'
- ' whatever the function call returned. The debugger prompt '
- 'appears\n'
- ' as soon as the function is entered.\n'
- '\n'
- 'pdb.set_trace()\n'
- '\n'
- ' Enter the debugger at the calling stack frame. This is '
- 'useful to\n'
- ' hard-code a breakpoint at a given point in a program, even if '
- 'the\n'
- ' code is not otherwise being debugged (e.g. when an assertion\n'
- ' fails).\n'
- '\n'
- 'pdb.post_mortem([traceback])\n'
- '\n'
- ' Enter post-mortem debugging of the given *traceback* object. '
- 'If no\n'
- ' *traceback* is given, it uses the one of the exception that '
- 'is\n'
- ' currently being handled (an exception must be being handled '
- 'if the\n'
- ' default is to be used).\n'
- '\n'
- 'pdb.pm()\n'
- '\n'
- ' Enter post-mortem debugging of the traceback found in\n'
- ' "sys.last_traceback".\n'
- '\n'
- 'The "run*" functions and "set_trace()" are aliases for '
- 'instantiating\n'
- 'the "Pdb" class and calling the method of the same name. If you '
- 'want\n'
- 'to access further features, you have to do this yourself:\n'
- '\n'
- "class pdb.Pdb(completekey='tab', stdin=None, stdout=None, "
- 'skip=None)\n'
- '\n'
- ' "Pdb" is the debugger class.\n'
- '\n'
- ' The *completekey*, *stdin* and *stdout* arguments are passed '
- 'to the\n'
- ' underlying "cmd.Cmd" class; see the description there.\n'
- '\n'
- ' The *skip* argument, if given, must be an iterable of '
- 'glob-style\n'
- ' module name patterns. The debugger will not step into frames '
- 'that\n'
- ' originate in a module that matches one of these patterns. '
- '[1]\n'
- '\n'
- ' Example call to enable tracing with *skip*:\n'
- '\n'
- " import pdb; pdb.Pdb(skip=['django.*']).set_trace()\n"
- '\n'
- ' New in version 2.7: The *skip* argument.\n'
- '\n'
- ' run(statement[, globals[, locals]])\n'
- ' runeval(expression[, globals[, locals]])\n'
- ' runcall(function[, argument, ...])\n'
- ' set_trace()\n'
- '\n'
- ' See the documentation for the functions explained above.\n',
- 'del': '\n'
- 'The "del" statement\n'
- '*******************\n'
- '\n'
- ' del_stmt ::= "del" target_list\n'
- '\n'
- 'Deletion is recursively defined very similar to the way assignment '
- 'is\n'
- 'defined. Rather than spelling it out in full details, here are some\n'
- 'hints.\n'
- '\n'
- 'Deletion of a target list recursively deletes each target, from left\n'
- 'to right.\n'
- '\n'
- 'Deletion of a name removes the binding of that name from the local '
- 'or\n'
- 'global namespace, depending on whether the name occurs in a "global"\n'
- 'statement in the same code block. If the name is unbound, a\n'
- '"NameError" exception will be raised.\n'
- '\n'
- 'It is illegal to delete a name from the local namespace if it occurs\n'
- 'as a free variable in a nested block.\n'
- '\n'
- 'Deletion of attribute references, subscriptions and slicings is '
- 'passed\n'
- 'to the primary object involved; deletion of a slicing is in general\n'
- 'equivalent to assignment of an empty slice of the right type (but '
- 'even\n'
- 'this is determined by the sliced object).\n',
- 'dict': '\n'
- 'Dictionary displays\n'
- '*******************\n'
- '\n'
- 'A dictionary display is a possibly empty series of key/datum pairs\n'
- 'enclosed in curly braces:\n'
- '\n'
- ' dict_display ::= "{" [key_datum_list | dict_comprehension] '
- '"}"\n'
- ' key_datum_list ::= key_datum ("," key_datum)* [","]\n'
- ' key_datum ::= expression ":" expression\n'
- ' dict_comprehension ::= expression ":" expression comp_for\n'
- '\n'
- 'A dictionary display yields a new dictionary object.\n'
- '\n'
- 'If a comma-separated sequence of key/datum pairs is given, they are\n'
- 'evaluated from left to right to define the entries of the '
- 'dictionary:\n'
- 'each key object is used as a key into the dictionary to store the\n'
- 'corresponding datum. This means that you can specify the same key\n'
- "multiple times in the key/datum list, and the final dictionary's "
- 'value\n'
- 'for that key will be the last one given.\n'
- '\n'
- 'A dict comprehension, in contrast to list and set comprehensions,\n'
- 'needs two expressions separated with a colon followed by the usual\n'
- '"for" and "if" clauses. When the comprehension is run, the '
- 'resulting\n'
- 'key and value elements are inserted in the new dictionary in the '
- 'order\n'
- 'they are produced.\n'
- '\n'
- 'Restrictions on the types of the key values are listed earlier in\n'
- 'section The standard type hierarchy. (To summarize, the key type\n'
- 'should be *hashable*, which excludes all mutable objects.) Clashes\n'
- 'between duplicate keys are not detected; the last datum (textually\n'
- 'rightmost in the display) stored for a given key value prevails.\n',
- 'dynamic-features': '\n'
- 'Interaction with dynamic features\n'
- '*********************************\n'
- '\n'
- 'There are several cases where Python statements are '
- 'illegal when used\n'
- 'in conjunction with nested scopes that contain free '
- 'variables.\n'
- '\n'
- 'If a variable is referenced in an enclosing scope, it is '
- 'illegal to\n'
- 'delete the name. An error will be reported at compile '
- 'time.\n'
- '\n'
- 'If the wild card form of import --- "import *" --- is '
- 'used in a\n'
- 'function and the function contains or is a nested block '
- 'with free\n'
- 'variables, the compiler will raise a "SyntaxError".\n'
- '\n'
- 'If "exec" is used in a function and the function '
- 'contains or is a\n'
- 'nested block with free variables, the compiler will '
- 'raise a\n'
- '"SyntaxError" unless the exec explicitly specifies the '
- 'local namespace\n'
- 'for the "exec". (In other words, "exec obj" would be '
- 'illegal, but\n'
- '"exec obj in ns" would be legal.)\n'
- '\n'
- 'The "eval()", "execfile()", and "input()" functions and '
- 'the "exec"\n'
- 'statement do not have access to the full environment for '
- 'resolving\n'
- 'names. Names may be resolved in the local and global '
- 'namespaces of\n'
- 'the caller. Free variables are not resolved in the '
- 'nearest enclosing\n'
- 'namespace, but in the global namespace. [1] The "exec" '
- 'statement and\n'
- 'the "eval()" and "execfile()" functions have optional '
- 'arguments to\n'
- 'override the global and local namespace. If only one '
- 'namespace is\n'
- 'specified, it is used for both.\n',
- 'else': '\n'
- 'The "if" statement\n'
- '******************\n'
- '\n'
- 'The "if" statement is used for conditional execution:\n'
- '\n'
- ' if_stmt ::= "if" expression ":" suite\n'
- ' ( "elif" expression ":" suite )*\n'
- ' ["else" ":" suite]\n'
- '\n'
- 'It selects exactly one of the suites by evaluating the expressions '
- 'one\n'
- 'by one until one is found to be true (see section Boolean '
- 'operations\n'
- 'for the definition of true and false); then that suite is executed\n'
- '(and no other part of the "if" statement is executed or evaluated).\n'
- 'If all expressions are false, the suite of the "else" clause, if\n'
- 'present, is executed.\n',
- 'exceptions': '\n'
- 'Exceptions\n'
- '**********\n'
- '\n'
- 'Exceptions are a means of breaking out of the normal flow of '
- 'control\n'
- 'of a code block in order to handle errors or other '
- 'exceptional\n'
- 'conditions. An exception is *raised* at the point where the '
- 'error is\n'
- 'detected; it may be *handled* by the surrounding code block or '
- 'by any\n'
- 'code block that directly or indirectly invoked the code block '
- 'where\n'
- 'the error occurred.\n'
- '\n'
- 'The Python interpreter raises an exception when it detects a '
- 'run-time\n'
- 'error (such as division by zero). A Python program can also\n'
- 'explicitly raise an exception with the "raise" statement. '
- 'Exception\n'
- 'handlers are specified with the "try" ... "except" statement. '
- 'The\n'
- '"finally" clause of such a statement can be used to specify '
- 'cleanup\n'
- 'code which does not handle the exception, but is executed '
- 'whether an\n'
- 'exception occurred or not in the preceding code.\n'
- '\n'
- 'Python uses the "termination" model of error handling: an '
- 'exception\n'
- 'handler can find out what happened and continue execution at '
- 'an outer\n'
- 'level, but it cannot repair the cause of the error and retry '
- 'the\n'
- 'failing operation (except by re-entering the offending piece '
- 'of code\n'
- 'from the top).\n'
- '\n'
- 'When an exception is not handled at all, the interpreter '
- 'terminates\n'
- 'execution of the program, or returns to its interactive main '
- 'loop. In\n'
- 'either case, it prints a stack backtrace, except when the '
- 'exception is\n'
- '"SystemExit".\n'
- '\n'
- 'Exceptions are identified by class instances. The "except" '
- 'clause is\n'
- 'selected depending on the class of the instance: it must '
- 'reference the\n'
- 'class of the instance or a base class thereof. The instance '
- 'can be\n'
- 'received by the handler and can carry additional information '
- 'about the\n'
- 'exceptional condition.\n'
- '\n'
- 'Exceptions can also be identified by strings, in which case '
- 'the\n'
- '"except" clause is selected by object identity. An arbitrary '
- 'value\n'
- 'can be raised along with the identifying string which can be '
- 'passed to\n'
- 'the handler.\n'
- '\n'
- 'Note: Messages to exceptions are not part of the Python API. '
- 'Their\n'
- ' contents may change from one version of Python to the next '
- 'without\n'
- ' warning and should not be relied on by code which will run '
- 'under\n'
- ' multiple versions of the interpreter.\n'
- '\n'
- 'See also the description of the "try" statement in section The '
- 'try\n'
- 'statement and "raise" statement in section The raise '
- 'statement.\n'
- '\n'
- '-[ Footnotes ]-\n'
- '\n'
- '[1] This limitation occurs because the code that is executed '
- 'by\n'
- ' these operations is not available at the time the module '
- 'is\n'
- ' compiled.\n',
- 'exec': '\n'
- 'The "exec" statement\n'
- '********************\n'
- '\n'
- ' exec_stmt ::= "exec" or_expr ["in" expression ["," expression]]\n'
- '\n'
- 'This statement supports dynamic execution of Python code. The '
- 'first\n'
- 'expression should evaluate to either a Unicode string, a *Latin-1*\n'
- 'encoded string, an open file object, a code object, or a tuple. If '
- 'it\n'
- 'is a string, the string is parsed as a suite of Python statements\n'
- 'which is then executed (unless a syntax error occurs). [1] If it is '
- 'an\n'
- 'open file, the file is parsed until EOF and executed. If it is a '
- 'code\n'
- 'object, it is simply executed. For the interpretation of a tuple, '
- 'see\n'
- "below. In all cases, the code that's executed is expected to be "
- 'valid\n'
- 'as file input (see section File input). Be aware that the "return"\n'
- 'and "yield" statements may not be used outside of function '
- 'definitions\n'
- 'even within the context of code passed to the "exec" statement.\n'
- '\n'
- 'In all cases, if the optional parts are omitted, the code is '
- 'executed\n'
- 'in the current scope. If only the first expression after "in" is\n'
- 'specified, it should be a dictionary, which will be used for both '
- 'the\n'
- 'global and the local variables. If two expressions are given, they\n'
- 'are used for the global and local variables, respectively. If\n'
- 'provided, *locals* can be any mapping object. Remember that at '
- 'module\n'
- 'level, globals and locals are the same dictionary. If two separate\n'
- 'objects are given as *globals* and *locals*, the code will be '
- 'executed\n'
- 'as if it were embedded in a class definition.\n'
- '\n'
- 'The first expression may also be a tuple of length 2 or 3. In this\n'
- 'case, the optional parts must be omitted. The form "exec(expr,\n'
- 'globals)" is equivalent to "exec expr in globals", while the form\n'
- '"exec(expr, globals, locals)" is equivalent to "exec expr in '
- 'globals,\n'
- 'locals". The tuple form of "exec" provides compatibility with '
- 'Python\n'
- '3, where "exec" is a function rather than a statement.\n'
- '\n'
- 'Changed in version 2.4: Formerly, *locals* was required to be a\n'
- 'dictionary.\n'
- '\n'
- 'As a side effect, an implementation may insert additional keys into\n'
- 'the dictionaries given besides those corresponding to variable '
- 'names\n'
- 'set by the executed code. For example, the current implementation '
- 'may\n'
- 'add a reference to the dictionary of the built-in module '
- '"__builtin__"\n'
- 'under the key "__builtins__" (!).\n'
- '\n'
- "**Programmer's hints:** dynamic evaluation of expressions is "
- 'supported\n'
- 'by the built-in function "eval()". The built-in functions '
- '"globals()"\n'
- 'and "locals()" return the current global and local dictionary,\n'
- 'respectively, which may be useful to pass around for use by "exec".\n'
- '\n'
- '-[ Footnotes ]-\n'
- '\n'
- '[1] Note that the parser only accepts the Unix-style end of line\n'
- ' convention. If you are reading the code from a file, make sure '
- 'to\n'
- ' use *universal newlines* mode to convert Windows or Mac-style\n'
- ' newlines.\n',
- 'execmodel': '\n'
- 'Execution model\n'
- '***************\n'
- '\n'
- '\n'
- 'Naming and binding\n'
- '==================\n'
- '\n'
- '*Names* refer to objects. Names are introduced by name '
- 'binding\n'
- 'operations. Each occurrence of a name in the program text '
- 'refers to\n'
- 'the *binding* of that name established in the innermost '
- 'function block\n'
- 'containing the use.\n'
- '\n'
- 'A *block* is a piece of Python program text that is executed as '
- 'a\n'
- 'unit. The following are blocks: a module, a function body, and '
- 'a class\n'
- 'definition. Each command typed interactively is a block. A '
- 'script\n'
- 'file (a file given as standard input to the interpreter or '
- 'specified\n'
- 'on the interpreter command line the first argument) is a code '
- 'block.\n'
- 'A script command (a command specified on the interpreter '
- 'command line\n'
- "with the '**-c**' option) is a code block. The file read by "
- 'the\n'
- 'built-in function "execfile()" is a code block. The string '
- 'argument\n'
- 'passed to the built-in function "eval()" and to the "exec" '
- 'statement\n'
- 'is a code block. The expression read and evaluated by the '
- 'built-in\n'
- 'function "input()" is a code block.\n'
- '\n'
- 'A code block is executed in an *execution frame*. A frame '
- 'contains\n'
- 'some administrative information (used for debugging) and '
- 'determines\n'
- "where and how execution continues after the code block's "
- 'execution has\n'
- 'completed.\n'
- '\n'
- 'A *scope* defines the visibility of a name within a block. If '
- 'a local\n'
- 'variable is defined in a block, its scope includes that block. '
- 'If the\n'
- 'definition occurs in a function block, the scope extends to any '
- 'blocks\n'
- 'contained within the defining one, unless a contained block '
- 'introduces\n'
- 'a different binding for the name. The scope of names defined '
- 'in a\n'
- 'class block is limited to the class block; it does not extend '
- 'to the\n'
- 'code blocks of methods -- this includes generator expressions '
- 'since\n'
- 'they are implemented using a function scope. This means that '
- 'the\n'
- 'following will fail:\n'
- '\n'
- ' class A:\n'
- ' a = 42\n'
- ' b = list(a + i for i in range(10))\n'
- '\n'
- 'When a name is used in a code block, it is resolved using the '
- 'nearest\n'
- 'enclosing scope. The set of all such scopes visible to a code '
- 'block\n'
- "is called the block's *environment*.\n"
- '\n'
- 'If a name is bound in a block, it is a local variable of that '
- 'block.\n'
- 'If a name is bound at the module level, it is a global '
- 'variable. (The\n'
- 'variables of the module code block are local and global.) If '
- 'a\n'
- 'variable is used in a code block but not defined there, it is a '
- '*free\n'
- 'variable*.\n'
- '\n'
- 'When a name is not found at all, a "NameError" exception is '
- 'raised.\n'
- 'If the name refers to a local variable that has not been bound, '
- 'a\n'
- '"UnboundLocalError" exception is raised. "UnboundLocalError" '
- 'is a\n'
- 'subclass of "NameError".\n'
- '\n'
- 'The following constructs bind names: formal parameters to '
- 'functions,\n'
- '"import" statements, class and function definitions (these bind '
- 'the\n'
- 'class or function name in the defining block), and targets that '
- 'are\n'
- 'identifiers if occurring in an assignment, "for" loop header, '
- 'in the\n'
- 'second position of an "except" clause header or after "as" in a '
- '"with"\n'
- 'statement. The "import" statement of the form "from ... import '
- '*"\n'
- 'binds all names defined in the imported module, except those '
- 'beginning\n'
- 'with an underscore. This form may only be used at the module '
- 'level.\n'
- '\n'
- 'A target occurring in a "del" statement is also considered '
- 'bound for\n'
- 'this purpose (though the actual semantics are to unbind the '
- 'name). It\n'
- 'is illegal to unbind a name that is referenced by an enclosing '
- 'scope;\n'
- 'the compiler will report a "SyntaxError".\n'
- '\n'
- 'Each assignment or import statement occurs within a block '
- 'defined by a\n'
- 'class or function definition or at the module level (the '
- 'top-level\n'
- 'code block).\n'
- '\n'
- 'If a name binding operation occurs anywhere within a code '
- 'block, all\n'
- 'uses of the name within the block are treated as references to '
- 'the\n'
- 'current block. This can lead to errors when a name is used '
- 'within a\n'
- 'block before it is bound. This rule is subtle. Python lacks\n'
- 'declarations and allows name binding operations to occur '
- 'anywhere\n'
- 'within a code block. The local variables of a code block can '
- 'be\n'
- 'determined by scanning the entire text of the block for name '
- 'binding\n'
- 'operations.\n'
- '\n'
- 'If the global statement occurs within a block, all uses of the '
- 'name\n'
- 'specified in the statement refer to the binding of that name in '
- 'the\n'
- 'top-level namespace. Names are resolved in the top-level '
- 'namespace by\n'
- 'searching the global namespace, i.e. the namespace of the '
- 'module\n'
- 'containing the code block, and the builtins namespace, the '
- 'namespace\n'
- 'of the module "__builtin__". The global namespace is searched '
- 'first.\n'
- 'If the name is not found there, the builtins namespace is '
- 'searched.\n'
- 'The global statement must precede all uses of the name.\n'
- '\n'
- 'The builtins namespace associated with the execution of a code '
- 'block\n'
- 'is actually found by looking up the name "__builtins__" in its '
- 'global\n'
- 'namespace; this should be a dictionary or a module (in the '
- 'latter case\n'
- "the module's dictionary is used). By default, when in the "
- '"__main__"\n'
- 'module, "__builtins__" is the built-in module "__builtin__" '
- '(note: no\n'
- '\'s\'); when in any other module, "__builtins__" is an alias '
- 'for the\n'
- 'dictionary of the "__builtin__" module itself. "__builtins__" '
- 'can be\n'
- 'set to a user-created dictionary to create a weak form of '
- 'restricted\n'
- 'execution.\n'
- '\n'
- '**CPython implementation detail:** Users should not touch\n'
- '"__builtins__"; it is strictly an implementation detail. '
- 'Users\n'
- 'wanting to override values in the builtins namespace should '
- '"import"\n'
- 'the "__builtin__" (no \'s\') module and modify its attributes\n'
- 'appropriately.\n'
- '\n'
- 'The namespace for a module is automatically created the first '
- 'time a\n'
- 'module is imported. The main module for a script is always '
- 'called\n'
- '"__main__".\n'
- '\n'
- 'The "global" statement has the same scope as a name binding '
- 'operation\n'
- 'in the same block. If the nearest enclosing scope for a free '
- 'variable\n'
- 'contains a global statement, the free variable is treated as a '
- 'global.\n'
- '\n'
- 'A class definition is an executable statement that may use and '
- 'define\n'
- 'names. These references follow the normal rules for name '
- 'resolution.\n'
- 'The namespace of the class definition becomes the attribute '
- 'dictionary\n'
- 'of the class. Names defined at the class scope are not visible '
- 'in\n'
- 'methods.\n'
- '\n'
- '\n'
- 'Interaction with dynamic features\n'
- '---------------------------------\n'
- '\n'
- 'There are several cases where Python statements are illegal '
- 'when used\n'
- 'in conjunction with nested scopes that contain free variables.\n'
- '\n'
- 'If a variable is referenced in an enclosing scope, it is '
- 'illegal to\n'
- 'delete the name. An error will be reported at compile time.\n'
- '\n'
- 'If the wild card form of import --- "import *" --- is used in '
- 'a\n'
- 'function and the function contains or is a nested block with '
- 'free\n'
- 'variables, the compiler will raise a "SyntaxError".\n'
- '\n'
- 'If "exec" is used in a function and the function contains or is '
- 'a\n'
- 'nested block with free variables, the compiler will raise a\n'
- '"SyntaxError" unless the exec explicitly specifies the local '
- 'namespace\n'
- 'for the "exec". (In other words, "exec obj" would be illegal, '
- 'but\n'
- '"exec obj in ns" would be legal.)\n'
- '\n'
- 'The "eval()", "execfile()", and "input()" functions and the '
- '"exec"\n'
- 'statement do not have access to the full environment for '
- 'resolving\n'
- 'names. Names may be resolved in the local and global '
- 'namespaces of\n'
- 'the caller. Free variables are not resolved in the nearest '
- 'enclosing\n'
- 'namespace, but in the global namespace. [1] The "exec" '
- 'statement and\n'
- 'the "eval()" and "execfile()" functions have optional arguments '
- 'to\n'
- 'override the global and local namespace. If only one namespace '
- 'is\n'
- 'specified, it is used for both.\n'
- '\n'
- '\n'
- 'Exceptions\n'
- '==========\n'
- '\n'
- 'Exceptions are a means of breaking out of the normal flow of '
- 'control\n'
- 'of a code block in order to handle errors or other exceptional\n'
- 'conditions. An exception is *raised* at the point where the '
- 'error is\n'
- 'detected; it may be *handled* by the surrounding code block or '
- 'by any\n'
- 'code block that directly or indirectly invoked the code block '
- 'where\n'
- 'the error occurred.\n'
- '\n'
- 'The Python interpreter raises an exception when it detects a '
- 'run-time\n'
- 'error (such as division by zero). A Python program can also\n'
- 'explicitly raise an exception with the "raise" statement. '
- 'Exception\n'
- 'handlers are specified with the "try" ... "except" statement. '
- 'The\n'
- '"finally" clause of such a statement can be used to specify '
- 'cleanup\n'
- 'code which does not handle the exception, but is executed '
- 'whether an\n'
- 'exception occurred or not in the preceding code.\n'
- '\n'
- 'Python uses the "termination" model of error handling: an '
- 'exception\n'
- 'handler can find out what happened and continue execution at an '
- 'outer\n'
- 'level, but it cannot repair the cause of the error and retry '
- 'the\n'
- 'failing operation (except by re-entering the offending piece of '
- 'code\n'
- 'from the top).\n'
- '\n'
- 'When an exception is not handled at all, the interpreter '
- 'terminates\n'
- 'execution of the program, or returns to its interactive main '
- 'loop. In\n'
- 'either case, it prints a stack backtrace, except when the '
- 'exception is\n'
- '"SystemExit".\n'
- '\n'
- 'Exceptions are identified by class instances. The "except" '
- 'clause is\n'
- 'selected depending on the class of the instance: it must '
- 'reference the\n'
- 'class of the instance or a base class thereof. The instance '
- 'can be\n'
- 'received by the handler and can carry additional information '
- 'about the\n'
- 'exceptional condition.\n'
- '\n'
- 'Exceptions can also be identified by strings, in which case '
- 'the\n'
- '"except" clause is selected by object identity. An arbitrary '
- 'value\n'
- 'can be raised along with the identifying string which can be '
- 'passed to\n'
- 'the handler.\n'
- '\n'
- 'Note: Messages to exceptions are not part of the Python API. '
- 'Their\n'
- ' contents may change from one version of Python to the next '
- 'without\n'
- ' warning and should not be relied on by code which will run '
- 'under\n'
- ' multiple versions of the interpreter.\n'
- '\n'
- 'See also the description of the "try" statement in section The '
- 'try\n'
- 'statement and "raise" statement in section The raise '
- 'statement.\n'
- '\n'
- '-[ Footnotes ]-\n'
- '\n'
- '[1] This limitation occurs because the code that is executed '
- 'by\n'
- ' these operations is not available at the time the module '
- 'is\n'
- ' compiled.\n',
- 'exprlists': '\n'
- 'Expression lists\n'
- '****************\n'
- '\n'
- ' expression_list ::= expression ( "," expression )* [","]\n'
- '\n'
- 'An expression list containing at least one comma yields a '
- 'tuple. The\n'
- 'length of the tuple is the number of expressions in the list. '
- 'The\n'
- 'expressions are evaluated from left to right.\n'
- '\n'
- 'The trailing comma is required only to create a single tuple '
- '(a.k.a. a\n'
- '*singleton*); it is optional in all other cases. A single '
- 'expression\n'
- "without a trailing comma doesn't create a tuple, but rather "
- 'yields the\n'
- 'value of that expression. (To create an empty tuple, use an '
- 'empty pair\n'
- 'of parentheses: "()".)\n',
- 'floating': '\n'
- 'Floating point literals\n'
- '***********************\n'
- '\n'
- 'Floating point literals are described by the following lexical\n'
- 'definitions:\n'
- '\n'
- ' floatnumber ::= pointfloat | exponentfloat\n'
- ' pointfloat ::= [intpart] fraction | intpart "."\n'
- ' exponentfloat ::= (intpart | pointfloat) exponent\n'
- ' intpart ::= digit+\n'
- ' fraction ::= "." digit+\n'
- ' exponent ::= ("e" | "E") ["+" | "-"] digit+\n'
- '\n'
- 'Note that the integer and exponent parts of floating point '
- 'numbers can\n'
- 'look like octal integers, but are interpreted using radix 10. '
- 'For\n'
- 'example, "077e010" is legal, and denotes the same number as '
- '"77e10".\n'
- 'The allowed range of floating point literals is implementation-\n'
- 'dependent. Some examples of floating point literals:\n'
- '\n'
- ' 3.14 10. .001 1e100 3.14e-10 0e0\n'
- '\n'
- 'Note that numeric literals do not include a sign; a phrase like '
- '"-1"\n'
- 'is actually an expression composed of the unary operator "-" and '
- 'the\n'
- 'literal "1".\n',
- 'for': '\n'
- 'The "for" statement\n'
- '*******************\n'
- '\n'
- 'The "for" statement is used to iterate over the elements of a '
- 'sequence\n'
- '(such as a string, tuple or list) or other iterable object:\n'
- '\n'
- ' for_stmt ::= "for" target_list "in" expression_list ":" suite\n'
- ' ["else" ":" suite]\n'
- '\n'
- 'The expression list is evaluated once; it should yield an iterable\n'
- 'object. An iterator is created for the result of the\n'
- '"expression_list". The suite is then executed once for each item\n'
- 'provided by the iterator, in the order of ascending indices. Each\n'
- 'item in turn is assigned to the target list using the standard rules\n'
- 'for assignments, and then the suite is executed. When the items are\n'
- 'exhausted (which is immediately when the sequence is empty), the '
- 'suite\n'
- 'in the "else" clause, if present, is executed, and the loop\n'
- 'terminates.\n'
- '\n'
- 'A "break" statement executed in the first suite terminates the loop\n'
- 'without executing the "else" clause\'s suite. A "continue" '
- 'statement\n'
- 'executed in the first suite skips the rest of the suite and '
- 'continues\n'
- 'with the next item, or with the "else" clause if there was no next\n'
- 'item.\n'
- '\n'
- 'The suite may assign to the variable(s) in the target list; this '
- 'does\n'
- 'not affect the next item assigned to it.\n'
- '\n'
- 'The target list is not deleted when the loop is finished, but if the\n'
- 'sequence is empty, it will not have been assigned to at all by the\n'
- 'loop. Hint: the built-in function "range()" returns a sequence of\n'
- 'integers suitable to emulate the effect of Pascal\'s "for i := a to '
- 'b\n'
- 'do"; e.g., "range(3)" returns the list "[0, 1, 2]".\n'
- '\n'
- 'Note: There is a subtlety when the sequence is being modified by the\n'
- ' loop (this can only occur for mutable sequences, i.e. lists). An\n'
- ' internal counter is used to keep track of which item is used next,\n'
- ' and this is incremented on each iteration. When this counter has\n'
- ' reached the length of the sequence the loop terminates. This '
- 'means\n'
- ' that if the suite deletes the current (or a previous) item from '
- 'the\n'
- ' sequence, the next item will be skipped (since it gets the index '
- 'of\n'
- ' the current item which has already been treated). Likewise, if '
- 'the\n'
- ' suite inserts an item in the sequence before the current item, the\n'
- ' current item will be treated again the next time through the loop.\n'
- ' This can lead to nasty bugs that can be avoided by making a\n'
- ' temporary copy using a slice of the whole sequence, e.g.,\n'
- '\n'
- ' for x in a[:]:\n'
- ' if x < 0: a.remove(x)\n',
- 'formatstrings': '\n'
- 'Format String Syntax\n'
- '********************\n'
- '\n'
- 'The "str.format()" method and the "Formatter" class share '
- 'the same\n'
- 'syntax for format strings (although in the case of '
- '"Formatter",\n'
- 'subclasses can define their own format string syntax).\n'
- '\n'
- 'Format strings contain "replacement fields" surrounded by '
- 'curly braces\n'
- '"{}". Anything that is not contained in braces is '
- 'considered literal\n'
- 'text, which is copied unchanged to the output. If you need '
- 'to include\n'
- 'a brace character in the literal text, it can be escaped by '
- 'doubling:\n'
- '"{{" and "}}".\n'
- '\n'
- 'The grammar for a replacement field is as follows:\n'
- '\n'
- ' replacement_field ::= "{" [field_name] ["!" '
- 'conversion] [":" format_spec] "}"\n'
- ' field_name ::= arg_name ("." attribute_name | '
- '"[" element_index "]")*\n'
- ' arg_name ::= [identifier | integer]\n'
- ' attribute_name ::= identifier\n'
- ' element_index ::= integer | index_string\n'
- ' index_string ::= <any source character except '
- '"]"> +\n'
- ' conversion ::= "r" | "s"\n'
- ' format_spec ::= <described in the next '
- 'section>\n'
- '\n'
- 'In less formal terms, the replacement field can start with '
- 'a\n'
- '*field_name* that specifies the object whose value is to be '
- 'formatted\n'
- 'and inserted into the output instead of the replacement '
- 'field. The\n'
- '*field_name* is optionally followed by a *conversion* '
- 'field, which is\n'
- 'preceded by an exclamation point "\'!\'", and a '
- '*format_spec*, which is\n'
- 'preceded by a colon "\':\'". These specify a non-default '
- 'format for the\n'
- 'replacement value.\n'
- '\n'
- 'See also the Format Specification Mini-Language section.\n'
- '\n'
- 'The *field_name* itself begins with an *arg_name* that is '
- 'either a\n'
- "number or a keyword. If it's a number, it refers to a "
- 'positional\n'
- "argument, and if it's a keyword, it refers to a named "
- 'keyword\n'
- 'argument. If the numerical arg_names in a format string '
- 'are 0, 1, 2,\n'
- '... in sequence, they can all be omitted (not just some) '
- 'and the\n'
- 'numbers 0, 1, 2, ... will be automatically inserted in that '
- 'order.\n'
- 'Because *arg_name* is not quote-delimited, it is not '
- 'possible to\n'
- 'specify arbitrary dictionary keys (e.g., the strings '
- '"\'10\'" or\n'
- '"\':-]\'") within a format string. The *arg_name* can be '
- 'followed by any\n'
- 'number of index or attribute expressions. An expression of '
- 'the form\n'
- '"\'.name\'" selects the named attribute using "getattr()", '
- 'while an\n'
- 'expression of the form "\'[index]\'" does an index lookup '
- 'using\n'
- '"__getitem__()".\n'
- '\n'
- 'Changed in version 2.7: The positional argument specifiers '
- 'can be\n'
- 'omitted, so "\'{} {}\'" is equivalent to "\'{0} {1}\'".\n'
- '\n'
- 'Some simple format string examples:\n'
- '\n'
- ' "First, thou shalt count to {0}" # References first '
- 'positional argument\n'
- ' "Bring me a {}" # Implicitly '
- 'references the first positional argument\n'
- ' "From {} to {}" # Same as "From {0} to '
- '{1}"\n'
- ' "My quest is {name}" # References keyword '
- "argument 'name'\n"
- ' "Weight in tons {0.weight}" # \'weight\' attribute '
- 'of first positional arg\n'
- ' "Units destroyed: {players[0]}" # First element of '
- "keyword argument 'players'.\n"
- '\n'
- 'The *conversion* field causes a type coercion before '
- 'formatting.\n'
- 'Normally, the job of formatting a value is done by the '
- '"__format__()"\n'
- 'method of the value itself. However, in some cases it is '
- 'desirable to\n'
- 'force a type to be formatted as a string, overriding its '
- 'own\n'
- 'definition of formatting. By converting the value to a '
- 'string before\n'
- 'calling "__format__()", the normal formatting logic is '
- 'bypassed.\n'
- '\n'
- 'Two conversion flags are currently supported: "\'!s\'" '
- 'which calls\n'
- '"str()" on the value, and "\'!r\'" which calls "repr()".\n'
- '\n'
- 'Some examples:\n'
- '\n'
- ' "Harold\'s a clever {0!s}" # Calls str() on the '
- 'argument first\n'
- ' "Bring out the holy {name!r}" # Calls repr() on the '
- 'argument first\n'
- '\n'
- 'The *format_spec* field contains a specification of how the '
- 'value\n'
- 'should be presented, including such details as field width, '
- 'alignment,\n'
- 'padding, decimal precision and so on. Each value type can '
- 'define its\n'
- 'own "formatting mini-language" or interpretation of the '
- '*format_spec*.\n'
- '\n'
- 'Most built-in types support a common formatting '
- 'mini-language, which\n'
- 'is described in the next section.\n'
- '\n'
- 'A *format_spec* field can also include nested replacement '
- 'fields\n'
- 'within it. These nested replacement fields may contain a '
- 'field name,\n'
- 'conversion flag and format specification, but deeper '
- 'nesting is not\n'
- 'allowed. The replacement fields within the format_spec '
- 'are\n'
- 'substituted before the *format_spec* string is interpreted. '
- 'This\n'
- 'allows the formatting of a value to be dynamically '
- 'specified.\n'
- '\n'
- 'See the Format examples section for some examples.\n'
- '\n'
- '\n'
- 'Format Specification Mini-Language\n'
- '==================================\n'
- '\n'
- '"Format specifications" are used within replacement fields '
- 'contained\n'
- 'within a format string to define how individual values are '
- 'presented\n'
- '(see Format String Syntax). They can also be passed '
- 'directly to the\n'
- 'built-in "format()" function. Each formattable type may '
- 'define how\n'
- 'the format specification is to be interpreted.\n'
- '\n'
- 'Most built-in types implement the following options for '
- 'format\n'
- 'specifications, although some of the formatting options are '
- 'only\n'
- 'supported by the numeric types.\n'
- '\n'
- 'A general convention is that an empty format string ("""") '
- 'produces\n'
- 'the same result as if you had called "str()" on the value. '
- 'A non-empty\n'
- 'format string typically modifies the result.\n'
- '\n'
- 'The general form of a *standard format specifier* is:\n'
- '\n'
- ' format_spec ::= '
- '[[fill]align][sign][#][0][width][,][.precision][type]\n'
- ' fill ::= <any character>\n'
- ' align ::= "<" | ">" | "=" | "^"\n'
- ' sign ::= "+" | "-" | " "\n'
- ' width ::= integer\n'
- ' precision ::= integer\n'
- ' type ::= "b" | "c" | "d" | "e" | "E" | "f" | "F" '
- '| "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"\n'
- '\n'
- 'If a valid *align* value is specified, it can be preceded '
- 'by a *fill*\n'
- 'character that can be any character and defaults to a space '
- 'if\n'
- 'omitted. It is not possible to use a literal curly brace '
- '(""{"" or\n'
- '""}"") as the *fill* character when using the '
- '"str.format()" method.\n'
- 'However, it is possible to insert a curly brace with a '
- 'nested\n'
- "replacement field. This limitation doesn't affect the "
- '"format()"\n'
- 'function.\n'
- '\n'
- 'The meaning of the various alignment options is as '
- 'follows:\n'
- '\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | Option | '
- 'Meaning '
- '|\n'
- ' '
- '+===========+============================================================+\n'
- ' | "\'<\'" | Forces the field to be left-aligned '
- 'within the available |\n'
- ' | | space (this is the default for most '
- 'objects). |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | "\'>\'" | Forces the field to be right-aligned '
- 'within the available |\n'
- ' | | space (this is the default for '
- 'numbers). |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | "\'=\'" | Forces the padding to be placed after '
- 'the sign (if any) |\n'
- ' | | but before the digits. This is used for '
- 'printing fields |\n'
- " | | in the form '+000000120'. This alignment "
- 'option is only |\n'
- ' | | valid for numeric types. It becomes the '
- "default when '0' |\n"
- ' | | immediately precedes the field '
- 'width. |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | "\'^\'" | Forces the field to be centered within '
- 'the available |\n'
- ' | | '
- 'space. '
- '|\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- '\n'
- 'Note that unless a minimum field width is defined, the '
- 'field width\n'
- 'will always be the same size as the data to fill it, so '
- 'that the\n'
- 'alignment option has no meaning in this case.\n'
- '\n'
- 'The *sign* option is only valid for number types, and can '
- 'be one of\n'
- 'the following:\n'
- '\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | Option | '
- 'Meaning '
- '|\n'
- ' '
- '+===========+============================================================+\n'
- ' | "\'+\'" | indicates that a sign should be used for '
- 'both positive as |\n'
- ' | | well as negative '
- 'numbers. |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | "\'-\'" | indicates that a sign should be used '
- 'only for negative |\n'
- ' | | numbers (this is the default '
- 'behavior). |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | space | indicates that a leading space should be '
- 'used on positive |\n'
- ' | | numbers, and a minus sign on negative '
- 'numbers. |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- '\n'
- 'The "\'#\'" option is only valid for integers, and only for '
- 'binary,\n'
- 'octal, or hexadecimal output. If present, it specifies '
- 'that the\n'
- 'output will be prefixed by "\'0b\'", "\'0o\'", or "\'0x\'", '
- 'respectively.\n'
- '\n'
- 'The "\',\'" option signals the use of a comma for a '
- 'thousands separator.\n'
- 'For a locale aware separator, use the "\'n\'" integer '
- 'presentation type\n'
- 'instead.\n'
- '\n'
- 'Changed in version 2.7: Added the "\',\'" option (see also '
- '**PEP 378**).\n'
- '\n'
- '*width* is a decimal integer defining the minimum field '
- 'width. If not\n'
- 'specified, then the field width will be determined by the '
- 'content.\n'
- '\n'
- 'When no explicit alignment is given, preceding the *width* '
- 'field by a\n'
- 'zero ("\'0\'") character enables sign-aware zero-padding '
- 'for numeric\n'
- 'types. This is equivalent to a *fill* character of "\'0\'" '
- 'with an\n'
- '*alignment* type of "\'=\'".\n'
- '\n'
- 'The *precision* is a decimal number indicating how many '
- 'digits should\n'
- 'be displayed after the decimal point for a floating point '
- 'value\n'
- 'formatted with "\'f\'" and "\'F\'", or before and after the '
- 'decimal point\n'
- 'for a floating point value formatted with "\'g\'" or '
- '"\'G\'". For non-\n'
- 'number types the field indicates the maximum field size - '
- 'in other\n'
- 'words, how many characters will be used from the field '
- 'content. The\n'
- '*precision* is not allowed for integer values.\n'
- '\n'
- 'Finally, the *type* determines how the data should be '
- 'presented.\n'
- '\n'
- 'The available string presentation types are:\n'
- '\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | Type | '
- 'Meaning '
- '|\n'
- ' '
- '+===========+============================================================+\n'
- ' | "\'s\'" | String format. This is the default type '
- 'for strings and |\n'
- ' | | may be '
- 'omitted. |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | None | The same as '
- '"\'s\'". |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- '\n'
- 'The available integer presentation types are:\n'
- '\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | Type | '
- 'Meaning '
- '|\n'
- ' '
- '+===========+============================================================+\n'
- ' | "\'b\'" | Binary format. Outputs the number in '
- 'base 2. |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | "\'c\'" | Character. Converts the integer to the '
- 'corresponding |\n'
- ' | | unicode character before '
- 'printing. |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | "\'d\'" | Decimal Integer. Outputs the number in '
- 'base 10. |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | "\'o\'" | Octal format. Outputs the number in base '
- '8. |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | "\'x\'" | Hex format. Outputs the number in base '
- '16, using lower- |\n'
- ' | | case letters for the digits above '
- '9. |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | "\'X\'" | Hex format. Outputs the number in base '
- '16, using upper- |\n'
- ' | | case letters for the digits above '
- '9. |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | "\'n\'" | Number. This is the same as "\'d\'", '
- 'except that it uses the |\n'
- ' | | current locale setting to insert the '
- 'appropriate number |\n'
- ' | | separator '
- 'characters. |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | None | The same as '
- '"\'d\'". |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- '\n'
- 'In addition to the above presentation types, integers can '
- 'be formatted\n'
- 'with the floating point presentation types listed below '
- '(except "\'n\'"\n'
- 'and None). When doing so, "float()" is used to convert the '
- 'integer to\n'
- 'a floating point number before formatting.\n'
- '\n'
- 'The available presentation types for floating point and '
- 'decimal values\n'
- 'are:\n'
- '\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | Type | '
- 'Meaning '
- '|\n'
- ' '
- '+===========+============================================================+\n'
- ' | "\'e\'" | Exponent notation. Prints the number in '
- 'scientific |\n'
- " | | notation using the letter 'e' to indicate "
- 'the exponent. |\n'
- ' | | The default precision is '
- '"6". |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | "\'E\'" | Exponent notation. Same as "\'e\'" '
- 'except it uses an upper |\n'
- " | | case 'E' as the separator "
- 'character. |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | "\'f\'" | Fixed point. Displays the number as a '
- 'fixed-point number. |\n'
- ' | | The default precision is '
- '"6". |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | "\'F\'" | Fixed point. Same as '
- '"\'f\'". |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | "\'g\'" | General format. For a given precision '
- '"p >= 1", this |\n'
- ' | | rounds the number to "p" significant '
- 'digits and then |\n'
- ' | | formats the result in either fixed-point '
- 'format or in |\n'
- ' | | scientific notation, depending on its '
- 'magnitude. The |\n'
- ' | | precise rules are as follows: suppose that '
- 'the result |\n'
- ' | | formatted with presentation type "\'e\'" '
- 'and precision "p-1" |\n'
- ' | | would have exponent "exp". Then if "-4 <= '
- 'exp < p", the |\n'
- ' | | number is formatted with presentation type '
- '"\'f\'" and |\n'
- ' | | precision "p-1-exp". Otherwise, the '
- 'number is formatted |\n'
- ' | | with presentation type "\'e\'" and '
- 'precision "p-1". In both |\n'
- ' | | cases insignificant trailing zeros are '
- 'removed from the |\n'
- ' | | significand, and the decimal point is also '
- 'removed if |\n'
- ' | | there are no remaining digits following '
- 'it. Positive and |\n'
- ' | | negative infinity, positive and negative '
- 'zero, and nans, |\n'
- ' | | are formatted as "inf", "-inf", "0", "-0" '
- 'and "nan" |\n'
- ' | | respectively, regardless of the '
- 'precision. A precision of |\n'
- ' | | "0" is treated as equivalent to a '
- 'precision of "1". The |\n'
- ' | | default precision is '
- '"6". |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | "\'G\'" | General format. Same as "\'g\'" except '
- 'switches to "\'E\'" if |\n'
- ' | | the number gets too large. The '
- 'representations of infinity |\n'
- ' | | and NaN are uppercased, '
- 'too. |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | "\'n\'" | Number. This is the same as "\'g\'", '
- 'except that it uses the |\n'
- ' | | current locale setting to insert the '
- 'appropriate number |\n'
- ' | | separator '
- 'characters. |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | "\'%\'" | Percentage. Multiplies the number by 100 '
- 'and displays in |\n'
- ' | | fixed ("\'f\'") format, followed by a '
- 'percent sign. |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- ' | None | The same as '
- '"\'g\'". |\n'
- ' '
- '+-----------+------------------------------------------------------------+\n'
- '\n'
- '\n'
- 'Format examples\n'
- '===============\n'
- '\n'
- 'This section contains examples of the "str.format()" syntax '
- 'and\n'
- 'comparison with the old "%"-formatting.\n'
- '\n'
- 'In most of the cases the syntax is similar to the old '
- '"%"-formatting,\n'
- 'with the addition of the "{}" and with ":" used instead of '
- '"%". For\n'
- 'example, "\'%03.2f\'" can be translated to "\'{:03.2f}\'".\n'
- '\n'
- 'The new format syntax also supports new and different '
- 'options, shown\n'
- 'in the follow examples.\n'
- '\n'
- 'Accessing arguments by position:\n'
- '\n'
- " >>> '{0}, {1}, {2}'.format('a', 'b', 'c')\n"
- " 'a, b, c'\n"
- " >>> '{}, {}, {}'.format('a', 'b', 'c') # 2.7+ only\n"
- " 'a, b, c'\n"
- " >>> '{2}, {1}, {0}'.format('a', 'b', 'c')\n"
- " 'c, b, a'\n"
- " >>> '{2}, {1}, {0}'.format(*'abc') # unpacking "
- 'argument sequence\n'
- " 'c, b, a'\n"
- " >>> '{0}{1}{0}'.format('abra', 'cad') # arguments' "
- 'indices can be repeated\n'
- " 'abracadabra'\n"
- '\n'
- 'Accessing arguments by name:\n'
- '\n'
- " >>> 'Coordinates: {latitude}, "
- "{longitude}'.format(latitude='37.24N', "
- "longitude='-115.81W')\n"
- " 'Coordinates: 37.24N, -115.81W'\n"
- " >>> coord = {'latitude': '37.24N', 'longitude': "
- "'-115.81W'}\n"
- " >>> 'Coordinates: {latitude}, "
- "{longitude}'.format(**coord)\n"
- " 'Coordinates: 37.24N, -115.81W'\n"
- '\n'
- "Accessing arguments' attributes:\n"
- '\n'
- ' >>> c = 3-5j\n'
- " >>> ('The complex number {0} is formed from the real "
- "part {0.real} '\n"
- " ... 'and the imaginary part {0.imag}.').format(c)\n"
- " 'The complex number (3-5j) is formed from the real part "
- "3.0 and the imaginary part -5.0.'\n"
- ' >>> class Point(object):\n'
- ' ... def __init__(self, x, y):\n'
- ' ... self.x, self.y = x, y\n'
- ' ... def __str__(self):\n'
- " ... return 'Point({self.x}, "
- "{self.y})'.format(self=self)\n"
- ' ...\n'
- ' >>> str(Point(4, 2))\n'
- " 'Point(4, 2)'\n"
- '\n'
- "Accessing arguments' items:\n"
- '\n'
- ' >>> coord = (3, 5)\n'
- " >>> 'X: {0[0]}; Y: {0[1]}'.format(coord)\n"
- " 'X: 3; Y: 5'\n"
- '\n'
- 'Replacing "%s" and "%r":\n'
- '\n'
- ' >>> "repr() shows quotes: {!r}; str() doesn\'t: '
- '{!s}".format(\'test1\', \'test2\')\n'
- ' "repr() shows quotes: \'test1\'; str() doesn\'t: test2"\n'
- '\n'
- 'Aligning the text and specifying a width:\n'
- '\n'
- " >>> '{:<30}'.format('left aligned')\n"
- " 'left aligned '\n"
- " >>> '{:>30}'.format('right aligned')\n"
- " ' right aligned'\n"
- " >>> '{:^30}'.format('centered')\n"
- " ' centered '\n"
- " >>> '{:*^30}'.format('centered') # use '*' as a fill "
- 'char\n'
- " '***********centered***********'\n"
- '\n'
- 'Replacing "%+f", "%-f", and "% f" and specifying a sign:\n'
- '\n'
- " >>> '{:+f}; {:+f}'.format(3.14, -3.14) # show it "
- 'always\n'
- " '+3.140000; -3.140000'\n"
- " >>> '{: f}; {: f}'.format(3.14, -3.14) # show a space "
- 'for positive numbers\n'
- " ' 3.140000; -3.140000'\n"
- " >>> '{:-f}; {:-f}'.format(3.14, -3.14) # show only the "
- "minus -- same as '{:f}; {:f}'\n"
- " '3.140000; -3.140000'\n"
- '\n'
- 'Replacing "%x" and "%o" and converting the value to '
- 'different bases:\n'
- '\n'
- ' >>> # format also supports binary numbers\n'
- ' >>> "int: {0:d}; hex: {0:x}; oct: {0:o}; bin: '
- '{0:b}".format(42)\n'
- " 'int: 42; hex: 2a; oct: 52; bin: 101010'\n"
- ' >>> # with 0x, 0o, or 0b as prefix:\n'
- ' >>> "int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: '
- '{0:#b}".format(42)\n'
- " 'int: 42; hex: 0x2a; oct: 0o52; bin: 0b101010'\n"
- '\n'
- 'Using the comma as a thousands separator:\n'
- '\n'
- " >>> '{:,}'.format(1234567890)\n"
- " '1,234,567,890'\n"
- '\n'
- 'Expressing a percentage:\n'
- '\n'
- ' >>> points = 19.5\n'
- ' >>> total = 22\n'
- " >>> 'Correct answers: {:.2%}'.format(points/total)\n"
- " 'Correct answers: 88.64%'\n"
- '\n'
- 'Using type-specific formatting:\n'
- '\n'
- ' >>> import datetime\n'
- ' >>> d = datetime.datetime(2010, 7, 4, 12, 15, 58)\n'
- " >>> '{:%Y-%m-%d %H:%M:%S}'.format(d)\n"
- " '2010-07-04 12:15:58'\n"
- '\n'
- 'Nesting arguments and more complex examples:\n'
- '\n'
- " >>> for align, text in zip('<^>', ['left', 'center', "
- "'right']):\n"
- " ... '{0:{fill}{align}16}'.format(text, fill=align, "
- 'align=align)\n'
- ' ...\n'
- " 'left<<<<<<<<<<<<'\n"
- " '^^^^^center^^^^^'\n"
- " '>>>>>>>>>>>right'\n"
- ' >>>\n'
- ' >>> octets = [192, 168, 0, 1]\n'
- " >>> '{:02X}{:02X}{:02X}{:02X}'.format(*octets)\n"
- " 'C0A80001'\n"
- ' >>> int(_, 16)\n'
- ' 3232235521\n'
- ' >>>\n'
- ' >>> width = 5\n'
- ' >>> for num in range(5,12):\n'
- " ... for base in 'dXob':\n"
- " ... print '{0:{width}{base}}'.format(num, "
- 'base=base, width=width),\n'
- ' ... print\n'
- ' ...\n'
- ' 5 5 5 101\n'
- ' 6 6 6 110\n'
- ' 7 7 7 111\n'
- ' 8 8 10 1000\n'
- ' 9 9 11 1001\n'
- ' 10 A 12 1010\n'
- ' 11 B 13 1011\n',
- 'function': '\n'
- 'Function definitions\n'
- '********************\n'
- '\n'
- 'A function definition defines a user-defined function object '
- '(see\n'
- 'section The standard type hierarchy):\n'
- '\n'
- ' decorated ::= decorators (classdef | funcdef)\n'
- ' decorators ::= decorator+\n'
- ' decorator ::= "@" dotted_name ["(" [argument_list [","]] '
- '")"] NEWLINE\n'
- ' funcdef ::= "def" funcname "(" [parameter_list] ")" '
- '":" suite\n'
- ' dotted_name ::= identifier ("." identifier)*\n'
- ' parameter_list ::= (defparameter ",")*\n'
- ' ( "*" identifier ["," "**" identifier]\n'
- ' | "**" identifier\n'
- ' | defparameter [","] )\n'
- ' defparameter ::= parameter ["=" expression]\n'
- ' sublist ::= parameter ("," parameter)* [","]\n'
- ' parameter ::= identifier | "(" sublist ")"\n'
- ' funcname ::= identifier\n'
- '\n'
- 'A function definition is an executable statement. Its execution '
- 'binds\n'
- 'the function name in the current local namespace to a function '
- 'object\n'
- '(a wrapper around the executable code for the function). This\n'
- 'function object contains a reference to the current global '
- 'namespace\n'
- 'as the global namespace to be used when the function is called.\n'
- '\n'
- 'The function definition does not execute the function body; this '
- 'gets\n'
- 'executed only when the function is called. [3]\n'
- '\n'
- 'A function definition may be wrapped by one or more *decorator*\n'
- 'expressions. Decorator expressions are evaluated when the '
- 'function is\n'
- 'defined, in the scope that contains the function definition. '
- 'The\n'
- 'result must be a callable, which is invoked with the function '
- 'object\n'
- 'as the only argument. The returned value is bound to the '
- 'function name\n'
- 'instead of the function object. Multiple decorators are applied '
- 'in\n'
- 'nested fashion. For example, the following code:\n'
- '\n'
- ' @f1(arg)\n'
- ' @f2\n'
- ' def func(): pass\n'
- '\n'
- 'is equivalent to:\n'
- '\n'
- ' def func(): pass\n'
- ' func = f1(arg)(f2(func))\n'
- '\n'
- 'When one or more top-level *parameters* have the form '
- '*parameter* "="\n'
- '*expression*, the function is said to have "default parameter '
- 'values."\n'
- 'For a parameter with a default value, the corresponding '
- '*argument* may\n'
- "be omitted from a call, in which case the parameter's default "
- 'value is\n'
- 'substituted. If a parameter has a default value, all following\n'
- 'parameters must also have a default value --- this is a '
- 'syntactic\n'
- 'restriction that is not expressed by the grammar.\n'
- '\n'
- '**Default parameter values are evaluated when the function '
- 'definition\n'
- 'is executed.** This means that the expression is evaluated '
- 'once, when\n'
- 'the function is defined, and that the same "pre-computed" value '
- 'is\n'
- 'used for each call. This is especially important to understand '
- 'when a\n'
- 'default parameter is a mutable object, such as a list or a '
- 'dictionary:\n'
- 'if the function modifies the object (e.g. by appending an item '
- 'to a\n'
- 'list), the default value is in effect modified. This is '
- 'generally not\n'
- 'what was intended. A way around this is to use "None" as the\n'
- 'default, and explicitly test for it in the body of the function, '
- 'e.g.:\n'
- '\n'
- ' def whats_on_the_telly(penguin=None):\n'
- ' if penguin is None:\n'
- ' penguin = []\n'
- ' penguin.append("property of the zoo")\n'
- ' return penguin\n'
- '\n'
- 'Function call semantics are described in more detail in section '
- 'Calls.\n'
- 'A function call always assigns values to all parameters '
- 'mentioned in\n'
- 'the parameter list, either from position arguments, from '
- 'keyword\n'
- 'arguments, or from default values. If the form ""*identifier"" '
- 'is\n'
- 'present, it is initialized to a tuple receiving any excess '
- 'positional\n'
- 'parameters, defaulting to the empty tuple. If the form\n'
- '""**identifier"" is present, it is initialized to a new '
- 'dictionary\n'
- 'receiving any excess keyword arguments, defaulting to a new '
- 'empty\n'
- 'dictionary.\n'
- '\n'
- 'It is also possible to create anonymous functions (functions not '
- 'bound\n'
- 'to a name), for immediate use in expressions. This uses lambda\n'
- 'expressions, described in section Lambdas. Note that the '
- 'lambda\n'
- 'expression is merely a shorthand for a simplified function '
- 'definition;\n'
- 'a function defined in a ""def"" statement can be passed around '
- 'or\n'
- 'assigned to another name just like a function defined by a '
- 'lambda\n'
- 'expression. The ""def"" form is actually more powerful since '
- 'it\n'
- 'allows the execution of multiple statements.\n'
- '\n'
- "**Programmer's note:** Functions are first-class objects. A "
- '""def""\n'
- 'form executed inside a function definition defines a local '
- 'function\n'
- 'that can be returned or passed around. Free variables used in '
- 'the\n'
- 'nested function can access the local variables of the function\n'
- 'containing the def. See section Naming and binding for '
- 'details.\n',
- 'global': '\n'
- 'The "global" statement\n'
- '**********************\n'
- '\n'
- ' global_stmt ::= "global" identifier ("," identifier)*\n'
- '\n'
- 'The "global" statement is a declaration which holds for the '
- 'entire\n'
- 'current code block. It means that the listed identifiers are to '
- 'be\n'
- 'interpreted as globals. It would be impossible to assign to a '
- 'global\n'
- 'variable without "global", although free variables may refer to\n'
- 'globals without being declared global.\n'
- '\n'
- 'Names listed in a "global" statement must not be used in the same '
- 'code\n'
- 'block textually preceding that "global" statement.\n'
- '\n'
- 'Names listed in a "global" statement must not be defined as '
- 'formal\n'
- 'parameters or in a "for" loop control target, "class" definition,\n'
- 'function definition, or "import" statement.\n'
- '\n'
- '**CPython implementation detail:** The current implementation does '
- 'not\n'
- 'enforce the latter two restrictions, but programs should not '
- 'abuse\n'
- 'this freedom, as future implementations may enforce them or '
- 'silently\n'
- 'change the meaning of the program.\n'
- '\n'
- '**Programmer\'s note:** the "global" is a directive to the '
- 'parser. It\n'
- 'applies only to code parsed at the same time as the "global"\n'
- 'statement. In particular, a "global" statement contained in an '
- '"exec"\n'
- 'statement does not affect the code block *containing* the "exec"\n'
- 'statement, and code contained in an "exec" statement is unaffected '
- 'by\n'
- '"global" statements in the code containing the "exec" statement. '
- 'The\n'
- 'same applies to the "eval()", "execfile()" and "compile()" '
- 'functions.\n',
- 'id-classes': '\n'
- 'Reserved classes of identifiers\n'
- '*******************************\n'
- '\n'
- 'Certain classes of identifiers (besides keywords) have '
- 'special\n'
- 'meanings. These classes are identified by the patterns of '
- 'leading and\n'
- 'trailing underscore characters:\n'
- '\n'
- '"_*"\n'
- ' Not imported by "from module import *". The special '
- 'identifier "_"\n'
- ' is used in the interactive interpreter to store the result '
- 'of the\n'
- ' last evaluation; it is stored in the "__builtin__" module. '
- 'When\n'
- ' not in interactive mode, "_" has no special meaning and is '
- 'not\n'
- ' defined. See section The import statement.\n'
- '\n'
- ' Note: The name "_" is often used in conjunction with\n'
- ' internationalization; refer to the documentation for the\n'
- ' "gettext" module for more information on this '
- 'convention.\n'
- '\n'
- '"__*__"\n'
- ' System-defined names. These names are defined by the '
- 'interpreter\n'
- ' and its implementation (including the standard library). '
- 'Current\n'
- ' system names are discussed in the Special method names '
- 'section and\n'
- ' elsewhere. More will likely be defined in future versions '
- 'of\n'
- ' Python. *Any* use of "__*__" names, in any context, that '
- 'does not\n'
- ' follow explicitly documented use, is subject to breakage '
- 'without\n'
- ' warning.\n'
- '\n'
- '"__*"\n'
- ' Class-private names. Names in this category, when used '
- 'within the\n'
- ' context of a class definition, are re-written to use a '
- 'mangled form\n'
- ' to help avoid name clashes between "private" attributes of '
- 'base and\n'
- ' derived classes. See section Identifiers (Names).\n',
- 'identifiers': '\n'
- 'Identifiers and keywords\n'
- '************************\n'
- '\n'
- 'Identifiers (also referred to as *names*) are described by '
- 'the\n'
- 'following lexical definitions:\n'
- '\n'
- ' identifier ::= (letter|"_") (letter | digit | "_")*\n'
- ' letter ::= lowercase | uppercase\n'
- ' lowercase ::= "a"..."z"\n'
- ' uppercase ::= "A"..."Z"\n'
- ' digit ::= "0"..."9"\n'
- '\n'
- 'Identifiers are unlimited in length. Case is significant.\n'
- '\n'
- '\n'
- 'Keywords\n'
- '========\n'
- '\n'
- 'The following identifiers are used as reserved words, or '
- '*keywords* of\n'
- 'the language, and cannot be used as ordinary identifiers. '
- 'They must\n'
- 'be spelled exactly as written here:\n'
- '\n'
- ' and del from not while\n'
- ' as elif global or with\n'
- ' assert else if pass yield\n'
- ' break except import print\n'
- ' class exec in raise\n'
- ' continue finally is return\n'
- ' def for lambda try\n'
- '\n'
- 'Changed in version 2.4: "None" became a constant and is now '
- 'recognized\n'
- 'by the compiler as a name for the built-in object "None". '
- 'Although it\n'
- 'is not a keyword, you cannot assign a different object to '
- 'it.\n'
- '\n'
- 'Changed in version 2.5: Using "as" and "with" as identifiers '
- 'triggers\n'
- 'a warning. To use them as keywords, enable the '
- '"with_statement"\n'
- 'future feature .\n'
- '\n'
- 'Changed in version 2.6: "as" and "with" are full keywords.\n'
- '\n'
- '\n'
- 'Reserved classes of identifiers\n'
- '===============================\n'
- '\n'
- 'Certain classes of identifiers (besides keywords) have '
- 'special\n'
- 'meanings. These classes are identified by the patterns of '
- 'leading and\n'
- 'trailing underscore characters:\n'
- '\n'
- '"_*"\n'
- ' Not imported by "from module import *". The special '
- 'identifier "_"\n'
- ' is used in the interactive interpreter to store the result '
- 'of the\n'
- ' last evaluation; it is stored in the "__builtin__" '
- 'module. When\n'
- ' not in interactive mode, "_" has no special meaning and is '
- 'not\n'
- ' defined. See section The import statement.\n'
- '\n'
- ' Note: The name "_" is often used in conjunction with\n'
- ' internationalization; refer to the documentation for '
- 'the\n'
- ' "gettext" module for more information on this '
- 'convention.\n'
- '\n'
- '"__*__"\n'
- ' System-defined names. These names are defined by the '
- 'interpreter\n'
- ' and its implementation (including the standard library). '
- 'Current\n'
- ' system names are discussed in the Special method names '
- 'section and\n'
- ' elsewhere. More will likely be defined in future versions '
- 'of\n'
- ' Python. *Any* use of "__*__" names, in any context, that '
- 'does not\n'
- ' follow explicitly documented use, is subject to breakage '
- 'without\n'
- ' warning.\n'
- '\n'
- '"__*"\n'
- ' Class-private names. Names in this category, when used '
- 'within the\n'
- ' context of a class definition, are re-written to use a '
- 'mangled form\n'
- ' to help avoid name clashes between "private" attributes of '
- 'base and\n'
- ' derived classes. See section Identifiers (Names).\n',
- 'if': '\n'
- 'The "if" statement\n'
- '******************\n'
- '\n'
- 'The "if" statement is used for conditional execution:\n'
- '\n'
- ' if_stmt ::= "if" expression ":" suite\n'
- ' ( "elif" expression ":" suite )*\n'
- ' ["else" ":" suite]\n'
- '\n'
- 'It selects exactly one of the suites by evaluating the expressions '
- 'one\n'
- 'by one until one is found to be true (see section Boolean operations\n'
- 'for the definition of true and false); then that suite is executed\n'
- '(and no other part of the "if" statement is executed or evaluated).\n'
- 'If all expressions are false, the suite of the "else" clause, if\n'
- 'present, is executed.\n',
- 'imaginary': '\n'
- 'Imaginary literals\n'
- '******************\n'
- '\n'
- 'Imaginary literals are described by the following lexical '
- 'definitions:\n'
- '\n'
- ' imagnumber ::= (floatnumber | intpart) ("j" | "J")\n'
- '\n'
- 'An imaginary literal yields a complex number with a real part '
- 'of 0.0.\n'
- 'Complex numbers are represented as a pair of floating point '
- 'numbers\n'
- 'and have the same restrictions on their range. To create a '
- 'complex\n'
- 'number with a nonzero real part, add a floating point number to '
- 'it,\n'
- 'e.g., "(3+4j)". Some examples of imaginary literals:\n'
- '\n'
- ' 3.14j 10.j 10j .001j 1e100j 3.14e-10j\n',
- 'import': '\n'
- 'The "import" statement\n'
- '**********************\n'
- '\n'
- ' import_stmt ::= "import" module ["as" name] ( "," module '
- '["as" name] )*\n'
- ' | "from" relative_module "import" identifier '
- '["as" name]\n'
- ' ( "," identifier ["as" name] )*\n'
- ' | "from" relative_module "import" "(" '
- 'identifier ["as" name]\n'
- ' ( "," identifier ["as" name] )* [","] ")"\n'
- ' | "from" module "import" "*"\n'
- ' module ::= (identifier ".")* identifier\n'
- ' relative_module ::= "."* module | "."+\n'
- ' name ::= identifier\n'
- '\n'
- 'Import statements are executed in two steps: (1) find a module, '
- 'and\n'
- 'initialize it if necessary; (2) define a name or names in the '
- 'local\n'
- 'namespace (of the scope where the "import" statement occurs). The\n'
- 'statement comes in two forms differing on whether it uses the '
- '"from"\n'
- 'keyword. The first form (without "from") repeats these steps for '
- 'each\n'
- 'identifier in the list. The form with "from" performs step (1) '
- 'once,\n'
- 'and then performs step (2) repeatedly.\n'
- '\n'
- 'To understand how step (1) occurs, one must first understand how\n'
- 'Python handles hierarchical naming of modules. To help organize\n'
- 'modules and provide a hierarchy in naming, Python has a concept '
- 'of\n'
- 'packages. A package can contain other packages and modules while\n'
- 'modules cannot contain other modules or packages. From a file '
- 'system\n'
- 'perspective, packages are directories and modules are files.\n'
- '\n'
- 'Once the name of the module is known (unless otherwise specified, '
- 'the\n'
- 'term "module" will refer to both packages and modules), searching '
- 'for\n'
- 'the module or package can begin. The first place checked is\n'
- '"sys.modules", the cache of all modules that have been imported\n'
- 'previously. If the module is found there then it is used in step '
- '(2)\n'
- 'of import.\n'
- '\n'
- 'If the module is not found in the cache, then "sys.meta_path" is\n'
- 'searched (the specification for "sys.meta_path" can be found in '
- '**PEP\n'
- '302**). The object is a list of *finder* objects which are queried '
- 'in\n'
- 'order as to whether they know how to load the module by calling '
- 'their\n'
- '"find_module()" method with the name of the module. If the module\n'
- 'happens to be contained within a package (as denoted by the '
- 'existence\n'
- 'of a dot in the name), then a second argument to "find_module()" '
- 'is\n'
- 'given as the value of the "__path__" attribute from the parent '
- 'package\n'
- '(everything up to the last dot in the name of the module being\n'
- 'imported). If a finder can find the module it returns a *loader*\n'
- '(discussed later) or returns "None".\n'
- '\n'
- 'If none of the finders on "sys.meta_path" are able to find the '
- 'module\n'
- 'then some implicitly defined finders are queried. Implementations '
- 'of\n'
- 'Python vary in what implicit meta path finders are defined. The '
- 'one\n'
- 'they all do define, though, is one that handles "sys.path_hooks",\n'
- '"sys.path_importer_cache", and "sys.path".\n'
- '\n'
- 'The implicit finder searches for the requested module in the '
- '"paths"\n'
- 'specified in one of two places ("paths" do not have to be file '
- 'system\n'
- 'paths). If the module being imported is supposed to be contained\n'
- 'within a package then the second argument passed to '
- '"find_module()",\n'
- '"__path__" on the parent package, is used as the source of paths. '
- 'If\n'
- 'the module is not contained in a package then "sys.path" is used '
- 'as\n'
- 'the source of paths.\n'
- '\n'
- 'Once the source of paths is chosen it is iterated over to find a\n'
- 'finder that can handle that path. The dict at\n'
- '"sys.path_importer_cache" caches finders for paths and is checked '
- 'for\n'
- 'a finder. If the path does not have a finder cached then\n'
- '"sys.path_hooks" is searched by calling each object in the list '
- 'with a\n'
- 'single argument of the path, returning a finder or raises\n'
- '"ImportError". If a finder is returned then it is cached in\n'
- '"sys.path_importer_cache" and then used for that path entry. If '
- 'no\n'
- 'finder can be found but the path exists then a value of "None" is\n'
- 'stored in "sys.path_importer_cache" to signify that an implicit, '
- 'file-\n'
- 'based finder that handles modules stored as individual files '
- 'should be\n'
- 'used for that path. If the path does not exist then a finder '
- 'which\n'
- 'always returns "None" is placed in the cache for the path.\n'
- '\n'
- 'If no finder can find the module then "ImportError" is raised.\n'
- 'Otherwise some finder returned a loader whose "load_module()" '
- 'method\n'
- 'is called with the name of the module to load (see **PEP 302** for '
- 'the\n'
- 'original definition of loaders). A loader has several '
- 'responsibilities\n'
- 'to perform on a module it loads. First, if the module already '
- 'exists\n'
- 'in "sys.modules" (a possibility if the loader is called outside of '
- 'the\n'
- 'import machinery) then it is to use that module for initialization '
- 'and\n'
- 'not a new module. But if the module does not exist in '
- '"sys.modules"\n'
- 'then it is to be added to that dict before initialization begins. '
- 'If\n'
- 'an error occurs during loading of the module and it was added to\n'
- '"sys.modules" it is to be removed from the dict. If an error '
- 'occurs\n'
- 'but the module was already in "sys.modules" it is left in the '
- 'dict.\n'
- '\n'
- 'The loader must set several attributes on the module. "__name__" '
- 'is to\n'
- 'be set to the name of the module. "__file__" is to be the "path" '
- 'to\n'
- 'the file unless the module is built-in (and thus listed in\n'
- '"sys.builtin_module_names") in which case the attribute is not '
- 'set. If\n'
- 'what is being imported is a package then "__path__" is to be set '
- 'to a\n'
- 'list of paths to be searched when looking for modules and '
- 'packages\n'
- 'contained within the package being imported. "__package__" is '
- 'optional\n'
- 'but should be set to the name of package that contains the module '
- 'or\n'
- 'package (the empty string is used for module not contained in a\n'
- 'package). "__loader__" is also optional but should be set to the\n'
- 'loader object that is loading the module.\n'
- '\n'
- 'If an error occurs during loading then the loader raises '
- '"ImportError"\n'
- 'if some other exception is not already being propagated. Otherwise '
- 'the\n'
- 'loader returns the module that was loaded and initialized.\n'
- '\n'
- 'When step (1) finishes without raising an exception, step (2) can\n'
- 'begin.\n'
- '\n'
- 'The first form of "import" statement binds the module name in the\n'
- 'local namespace to the module object, and then goes on to import '
- 'the\n'
- 'next identifier, if any. If the module name is followed by "as", '
- 'the\n'
- 'name following "as" is used as the local name for the module.\n'
- '\n'
- 'The "from" form does not bind the module name: it goes through '
- 'the\n'
- 'list of identifiers, looks each one of them up in the module found '
- 'in\n'
- 'step (1), and binds the name in the local namespace to the object '
- 'thus\n'
- 'found. As with the first form of "import", an alternate local '
- 'name\n'
- 'can be supplied by specifying ""as" localname". If a name is not\n'
- 'found, "ImportError" is raised. If the list of identifiers is\n'
- 'replaced by a star ("\'*\'"), all public names defined in the '
- 'module are\n'
- 'bound in the local namespace of the "import" statement..\n'
- '\n'
- 'The *public names* defined by a module are determined by checking '
- 'the\n'
- 'module\'s namespace for a variable named "__all__"; if defined, it '
- 'must\n'
- 'be a sequence of strings which are names defined or imported by '
- 'that\n'
- 'module. The names given in "__all__" are all considered public '
- 'and\n'
- 'are required to exist. If "__all__" is not defined, the set of '
- 'public\n'
- "names includes all names found in the module's namespace which do "
- 'not\n'
- 'begin with an underscore character ("\'_\'"). "__all__" should '
- 'contain\n'
- 'the entire public API. It is intended to avoid accidentally '
- 'exporting\n'
- 'items that are not part of the API (such as library modules which '
- 'were\n'
- 'imported and used within the module).\n'
- '\n'
- 'The "from" form with "*" may only occur in a module scope. If '
- 'the\n'
- 'wild card form of import --- "import *" --- is used in a function '
- 'and\n'
- 'the function contains or is a nested block with free variables, '
- 'the\n'
- 'compiler will raise a "SyntaxError".\n'
- '\n'
- 'When specifying what module to import you do not have to specify '
- 'the\n'
- 'absolute name of the module. When a module or package is '
- 'contained\n'
- 'within another package it is possible to make a relative import '
- 'within\n'
- 'the same top package without having to mention the package name. '
- 'By\n'
- 'using leading dots in the specified module or package after "from" '
- 'you\n'
- 'can specify how high to traverse up the current package hierarchy\n'
- 'without specifying exact names. One leading dot means the current\n'
- 'package where the module making the import exists. Two dots means '
- 'up\n'
- 'one package level. Three dots is up two levels, etc. So if you '
- 'execute\n'
- '"from . import mod" from a module in the "pkg" package then you '
- 'will\n'
- 'end up importing "pkg.mod". If you execute "from ..subpkg2 import '
- 'mod"\n'
- 'from within "pkg.subpkg1" you will import "pkg.subpkg2.mod". The\n'
- 'specification for relative imports is contained within **PEP '
- '328**.\n'
- '\n'
- '"importlib.import_module()" is provided to support applications '
- 'that\n'
- 'determine which modules need to be loaded dynamically.\n'
- '\n'
- '\n'
- 'Future statements\n'
- '=================\n'
- '\n'
- 'A *future statement* is a directive to the compiler that a '
- 'particular\n'
- 'module should be compiled using syntax or semantics that will be\n'
- 'available in a specified future release of Python. The future\n'
- 'statement is intended to ease migration to future versions of '
- 'Python\n'
- 'that introduce incompatible changes to the language. It allows '
- 'use of\n'
- 'the new features on a per-module basis before the release in which '
- 'the\n'
- 'feature becomes standard.\n'
- '\n'
- ' future_statement ::= "from" "__future__" "import" feature ["as" '
- 'name]\n'
- ' ("," feature ["as" name])*\n'
- ' | "from" "__future__" "import" "(" feature '
- '["as" name]\n'
- ' ("," feature ["as" name])* [","] ")"\n'
- ' feature ::= identifier\n'
- ' name ::= identifier\n'
- '\n'
- 'A future statement must appear near the top of the module. The '
- 'only\n'
- 'lines that can appear before a future statement are:\n'
- '\n'
- '* the module docstring (if any),\n'
- '\n'
- '* comments,\n'
- '\n'
- '* blank lines, and\n'
- '\n'
- '* other future statements.\n'
- '\n'
- 'The features recognized by Python 2.6 are "unicode_literals",\n'
- '"print_function", "absolute_import", "division", "generators",\n'
- '"nested_scopes" and "with_statement". "generators", '
- '"with_statement",\n'
- '"nested_scopes" are redundant in Python version 2.6 and above '
- 'because\n'
- 'they are always enabled.\n'
- '\n'
- 'A future statement is recognized and treated specially at compile\n'
- 'time: Changes to the semantics of core constructs are often\n'
- 'implemented by generating different code. It may even be the '
- 'case\n'
- 'that a new feature introduces new incompatible syntax (such as a '
- 'new\n'
- 'reserved word), in which case the compiler may need to parse the\n'
- 'module differently. Such decisions cannot be pushed off until\n'
- 'runtime.\n'
- '\n'
- 'For any given release, the compiler knows which feature names '
- 'have\n'
- 'been defined, and raises a compile-time error if a future '
- 'statement\n'
- 'contains a feature not known to it.\n'
- '\n'
- 'The direct runtime semantics are the same as for any import '
- 'statement:\n'
- 'there is a standard module "__future__", described later, and it '
- 'will\n'
- 'be imported in the usual way at the time the future statement is\n'
- 'executed.\n'
- '\n'
- 'The interesting runtime semantics depend on the specific feature\n'
- 'enabled by the future statement.\n'
- '\n'
- 'Note that there is nothing special about the statement:\n'
- '\n'
- ' import __future__ [as name]\n'
- '\n'
- "That is not a future statement; it's an ordinary import statement "
- 'with\n'
- 'no special semantics or syntax restrictions.\n'
- '\n'
- 'Code compiled by an "exec" statement or calls to the built-in\n'
- 'functions "compile()" and "execfile()" that occur in a module "M"\n'
- 'containing a future statement will, by default, use the new '
- 'syntax or\n'
- 'semantics associated with the future statement. This can, '
- 'starting\n'
- 'with Python 2.2 be controlled by optional arguments to "compile()" '
- '---\n'
- 'see the documentation of that function for details.\n'
- '\n'
- 'A future statement typed at an interactive interpreter prompt '
- 'will\n'
- 'take effect for the rest of the interpreter session. If an\n'
- 'interpreter is started with the "-i" option, is passed a script '
- 'name\n'
- 'to execute, and the script includes a future statement, it will be '
- 'in\n'
- 'effect in the interactive session started after the script is\n'
- 'executed.\n'
- '\n'
- 'See also:\n'
- '\n'
- ' **PEP 236** - Back to the __future__\n'
- ' The original proposal for the __future__ mechanism.\n',
- 'in': '\n'
- 'Comparisons\n'
- '***********\n'
- '\n'
- 'Unlike C, all comparison operations in Python have the same priority,\n'
- 'which is lower than that of any arithmetic, shifting or bitwise\n'
- 'operation. Also unlike C, expressions like "a < b < c" have the\n'
- 'interpretation that is conventional in mathematics:\n'
- '\n'
- ' comparison ::= or_expr ( comp_operator or_expr )*\n'
- ' comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "<>" | "!="\n'
- ' | "is" ["not"] | ["not"] "in"\n'
- '\n'
- 'Comparisons yield boolean values: "True" or "False".\n'
- '\n'
- 'Comparisons can be chained arbitrarily, e.g., "x < y <= z" is\n'
- 'equivalent to "x < y and y <= z", except that "y" is evaluated only\n'
- 'once (but in both cases "z" is not evaluated at all when "x < y" is\n'
- 'found to be false).\n'
- '\n'
- 'Formally, if *a*, *b*, *c*, ..., *y*, *z* are expressions and *op1*,\n'
- '*op2*, ..., *opN* are comparison operators, then "a op1 b op2 c ... y\n'
- 'opN z" is equivalent to "a op1 b and b op2 c and ... y opN z", except\n'
- 'that each expression is evaluated at most once.\n'
- '\n'
- 'Note that "a op1 b op2 c" doesn\'t imply any kind of comparison '
- 'between\n'
- '*a* and *c*, so that, e.g., "x < y > z" is perfectly legal (though\n'
- 'perhaps not pretty).\n'
- '\n'
- 'The forms "<>" and "!=" are equivalent; for consistency with C, "!="\n'
- 'is preferred; where "!=" is mentioned below "<>" is also accepted.\n'
- 'The "<>" spelling is considered obsolescent.\n'
- '\n'
- 'The operators "<", ">", "==", ">=", "<=", and "!=" compare the values\n'
- 'of two objects. The objects need not have the same type. If both are\n'
- 'numbers, they are converted to a common type. Otherwise, objects of\n'
- 'different types *always* compare unequal, and are ordered '
- 'consistently\n'
- 'but arbitrarily. You can control comparison behavior of objects of\n'
- 'non-built-in types by defining a "__cmp__" method or rich comparison\n'
- 'methods like "__gt__", described in section Special method names.\n'
- '\n'
- '(This unusual definition of comparison was used to simplify the\n'
- 'definition of operations like sorting and the "in" and "not in"\n'
- 'operators. In the future, the comparison rules for objects of\n'
- 'different types are likely to change.)\n'
- '\n'
- 'Comparison of objects of the same type depends on the type:\n'
- '\n'
- '* Numbers are compared arithmetically.\n'
- '\n'
- '* Strings are compared lexicographically using the numeric\n'
- ' equivalents (the result of the built-in function "ord()") of their\n'
- ' characters. Unicode and 8-bit strings are fully interoperable in\n'
- ' this behavior. [4]\n'
- '\n'
- '* Tuples and lists are compared lexicographically using comparison\n'
- ' of corresponding elements. This means that to compare equal, each\n'
- ' element must compare equal and the two sequences must be of the '
- 'same\n'
- ' type and have the same length.\n'
- '\n'
- ' If not equal, the sequences are ordered the same as their first\n'
- ' differing elements. For example, "cmp([1,2,x], [1,2,y])" returns\n'
- ' the same as "cmp(x,y)". If the corresponding element does not\n'
- ' exist, the shorter sequence is ordered first (for example, "[1,2] <\n'
- ' [1,2,3]").\n'
- '\n'
- '* Mappings (dictionaries) compare equal if and only if their sorted\n'
- ' (key, value) lists compare equal. [5] Outcomes other than equality\n'
- ' are resolved consistently, but are not otherwise defined. [6]\n'
- '\n'
- '* Most other objects of built-in types compare unequal unless they\n'
- ' are the same object; the choice whether one object is considered\n'
- ' smaller or larger than another one is made arbitrarily but\n'
- ' consistently within one execution of a program.\n'
- '\n'
- 'The operators "in" and "not in" test for collection membership. "x '
- 'in\n'
- 's" evaluates to true if *x* is a member of the collection *s*, and\n'
- 'false otherwise. "x not in s" returns the negation of "x in s". The\n'
- 'collection membership test has traditionally been bound to sequences;\n'
- 'an object is a member of a collection if the collection is a sequence\n'
- 'and contains an element equal to that object. However, it make sense\n'
- 'for many other object types to support membership tests without being\n'
- 'a sequence. In particular, dictionaries (for keys) and sets support\n'
- 'membership testing.\n'
- '\n'
- 'For the list and tuple types, "x in y" is true if and only if there\n'
- 'exists an index *i* such that either "x is y[i]" or "x == y[i]" is\n'
- 'true.\n'
- '\n'
- 'For the Unicode and string types, "x in y" is true if and only if *x*\n'
- 'is a substring of *y*. An equivalent test is "y.find(x) != -1".\n'
- 'Note, *x* and *y* need not be the same type; consequently, "u\'ab\' '
- 'in\n'
- '\'abc\'" will return "True". Empty strings are always considered to be '
- 'a\n'
- 'substring of any other string, so """ in "abc"" will return "True".\n'
- '\n'
- 'Changed in version 2.3: Previously, *x* was required to be a string '
- 'of\n'
- 'length "1".\n'
- '\n'
- 'For user-defined classes which define the "__contains__()" method, "x\n'
- 'in y" is true if and only if "y.__contains__(x)" is true.\n'
- '\n'
- 'For user-defined classes which do not define "__contains__()" but do\n'
- 'define "__iter__()", "x in y" is true if some value "z" with "x == z"\n'
- 'is produced while iterating over "y". If an exception is raised\n'
- 'during the iteration, it is as if "in" raised that exception.\n'
- '\n'
- 'Lastly, the old-style iteration protocol is tried: if a class defines\n'
- '"__getitem__()", "x in y" is true if and only if there is a non-\n'
- 'negative integer index *i* such that "x == y[i]", and all lower\n'
- 'integer indices do not raise "IndexError" exception. (If any other\n'
- 'exception is raised, it is as if "in" raised that exception).\n'
- '\n'
- 'The operator "not in" is defined to have the inverse true value of\n'
- '"in".\n'
- '\n'
- 'The operators "is" and "is not" test for object identity: "x is y" is\n'
- 'true if and only if *x* and *y* are the same object. "x is not y"\n'
- 'yields the inverse truth value. [7]\n',
- 'integers': '\n'
- 'Integer and long integer literals\n'
- '*********************************\n'
- '\n'
- 'Integer and long integer literals are described by the '
- 'following\n'
- 'lexical definitions:\n'
- '\n'
- ' longinteger ::= integer ("l" | "L")\n'
- ' integer ::= decimalinteger | octinteger | hexinteger | '
- 'bininteger\n'
- ' decimalinteger ::= nonzerodigit digit* | "0"\n'
- ' octinteger ::= "0" ("o" | "O") octdigit+ | "0" octdigit+\n'
- ' hexinteger ::= "0" ("x" | "X") hexdigit+\n'
- ' bininteger ::= "0" ("b" | "B") bindigit+\n'
- ' nonzerodigit ::= "1"..."9"\n'
- ' octdigit ::= "0"..."7"\n'
- ' bindigit ::= "0" | "1"\n'
- ' hexdigit ::= digit | "a"..."f" | "A"..."F"\n'
- '\n'
- 'Although both lower case "\'l\'" and upper case "\'L\'" are '
- 'allowed as\n'
- 'suffix for long integers, it is strongly recommended to always '
- 'use\n'
- '"\'L\'", since the letter "\'l\'" looks too much like the digit '
- '"\'1\'".\n'
- '\n'
- 'Plain integer literals that are above the largest representable '
- 'plain\n'
- 'integer (e.g., 2147483647 when using 32-bit arithmetic) are '
- 'accepted\n'
- 'as if they were long integers instead. [1] There is no limit '
- 'for long\n'
- 'integer literals apart from what can be stored in available '
- 'memory.\n'
- '\n'
- 'Some examples of plain integer literals (first row) and long '
- 'integer\n'
- 'literals (second and third rows):\n'
- '\n'
- ' 7 2147483647 0177\n'
- ' 3L 79228162514264337593543950336L 0377L 0x100000000L\n'
- ' 79228162514264337593543950336 0xdeadbeef\n',
- 'lambda': '\n'
- 'Lambdas\n'
- '*******\n'
- '\n'
- ' lambda_expr ::= "lambda" [parameter_list]: expression\n'
- ' old_lambda_expr ::= "lambda" [parameter_list]: old_expression\n'
- '\n'
- 'Lambda expressions (sometimes called lambda forms) have the same\n'
- 'syntactic position as expressions. They are a shorthand to '
- 'create\n'
- 'anonymous functions; the expression "lambda arguments: '
- 'expression"\n'
- 'yields a function object. The unnamed object behaves like a '
- 'function\n'
- 'object defined with\n'
- '\n'
- ' def name(arguments):\n'
- ' return expression\n'
- '\n'
- 'See section Function definitions for the syntax of parameter '
- 'lists.\n'
- 'Note that functions created with lambda expressions cannot '
- 'contain\n'
- 'statements.\n',
- 'lists': '\n'
- 'List displays\n'
- '*************\n'
- '\n'
- 'A list display is a possibly empty series of expressions enclosed '
- 'in\n'
- 'square brackets:\n'
- '\n'
- ' list_display ::= "[" [expression_list | '
- 'list_comprehension] "]"\n'
- ' list_comprehension ::= expression list_for\n'
- ' list_for ::= "for" target_list "in" '
- 'old_expression_list [list_iter]\n'
- ' old_expression_list ::= old_expression [("," old_expression)+ '
- '[","]]\n'
- ' old_expression ::= or_test | old_lambda_expr\n'
- ' list_iter ::= list_for | list_if\n'
- ' list_if ::= "if" old_expression [list_iter]\n'
- '\n'
- 'A list display yields a new list object. Its contents are '
- 'specified\n'
- 'by providing either a list of expressions or a list comprehension.\n'
- 'When a comma-separated list of expressions is supplied, its '
- 'elements\n'
- 'are evaluated from left to right and placed into the list object '
- 'in\n'
- 'that order. When a list comprehension is supplied, it consists of '
- 'a\n'
- 'single expression followed by at least one "for" clause and zero '
- 'or\n'
- 'more "for" or "if" clauses. In this case, the elements of the new\n'
- 'list are those that would be produced by considering each of the '
- '"for"\n'
- 'or "if" clauses a block, nesting from left to right, and '
- 'evaluating\n'
- 'the expression to produce a list element each time the innermost '
- 'block\n'
- 'is reached [1].\n',
- 'naming': '\n'
- 'Naming and binding\n'
- '******************\n'
- '\n'
- '*Names* refer to objects. Names are introduced by name binding\n'
- 'operations. Each occurrence of a name in the program text refers '
- 'to\n'
- 'the *binding* of that name established in the innermost function '
- 'block\n'
- 'containing the use.\n'
- '\n'
- 'A *block* is a piece of Python program text that is executed as a\n'
- 'unit. The following are blocks: a module, a function body, and a '
- 'class\n'
- 'definition. Each command typed interactively is a block. A '
- 'script\n'
- 'file (a file given as standard input to the interpreter or '
- 'specified\n'
- 'on the interpreter command line the first argument) is a code '
- 'block.\n'
- 'A script command (a command specified on the interpreter command '
- 'line\n'
- "with the '**-c**' option) is a code block. The file read by the\n"
- 'built-in function "execfile()" is a code block. The string '
- 'argument\n'
- 'passed to the built-in function "eval()" and to the "exec" '
- 'statement\n'
- 'is a code block. The expression read and evaluated by the '
- 'built-in\n'
- 'function "input()" is a code block.\n'
- '\n'
- 'A code block is executed in an *execution frame*. A frame '
- 'contains\n'
- 'some administrative information (used for debugging) and '
- 'determines\n'
- "where and how execution continues after the code block's execution "
- 'has\n'
- 'completed.\n'
- '\n'
- 'A *scope* defines the visibility of a name within a block. If a '
- 'local\n'
- 'variable is defined in a block, its scope includes that block. If '
- 'the\n'
- 'definition occurs in a function block, the scope extends to any '
- 'blocks\n'
- 'contained within the defining one, unless a contained block '
- 'introduces\n'
- 'a different binding for the name. The scope of names defined in '
- 'a\n'
- 'class block is limited to the class block; it does not extend to '
- 'the\n'
- 'code blocks of methods -- this includes generator expressions '
- 'since\n'
- 'they are implemented using a function scope. This means that the\n'
- 'following will fail:\n'
- '\n'
- ' class A:\n'
- ' a = 42\n'
- ' b = list(a + i for i in range(10))\n'
- '\n'
- 'When a name is used in a code block, it is resolved using the '
- 'nearest\n'
- 'enclosing scope. The set of all such scopes visible to a code '
- 'block\n'
- "is called the block's *environment*.\n"
- '\n'
- 'If a name is bound in a block, it is a local variable of that '
- 'block.\n'
- 'If a name is bound at the module level, it is a global variable. '
- '(The\n'
- 'variables of the module code block are local and global.) If a\n'
- 'variable is used in a code block but not defined there, it is a '
- '*free\n'
- 'variable*.\n'
- '\n'
- 'When a name is not found at all, a "NameError" exception is '
- 'raised.\n'
- 'If the name refers to a local variable that has not been bound, a\n'
- '"UnboundLocalError" exception is raised. "UnboundLocalError" is '
- 'a\n'
- 'subclass of "NameError".\n'
- '\n'
- 'The following constructs bind names: formal parameters to '
- 'functions,\n'
- '"import" statements, class and function definitions (these bind '
- 'the\n'
- 'class or function name in the defining block), and targets that '
- 'are\n'
- 'identifiers if occurring in an assignment, "for" loop header, in '
- 'the\n'
- 'second position of an "except" clause header or after "as" in a '
- '"with"\n'
- 'statement. The "import" statement of the form "from ... import '
- '*"\n'
- 'binds all names defined in the imported module, except those '
- 'beginning\n'
- 'with an underscore. This form may only be used at the module '
- 'level.\n'
- '\n'
- 'A target occurring in a "del" statement is also considered bound '
- 'for\n'
- 'this purpose (though the actual semantics are to unbind the '
- 'name). It\n'
- 'is illegal to unbind a name that is referenced by an enclosing '
- 'scope;\n'
- 'the compiler will report a "SyntaxError".\n'
- '\n'
- 'Each assignment or import statement occurs within a block defined '
- 'by a\n'
- 'class or function definition or at the module level (the '
- 'top-level\n'
- 'code block).\n'
- '\n'
- 'If a name binding operation occurs anywhere within a code block, '
- 'all\n'
- 'uses of the name within the block are treated as references to '
- 'the\n'
- 'current block. This can lead to errors when a name is used within '
- 'a\n'
- 'block before it is bound. This rule is subtle. Python lacks\n'
- 'declarations and allows name binding operations to occur anywhere\n'
- 'within a code block. The local variables of a code block can be\n'
- 'determined by scanning the entire text of the block for name '
- 'binding\n'
- 'operations.\n'
- '\n'
- 'If the global statement occurs within a block, all uses of the '
- 'name\n'
- 'specified in the statement refer to the binding of that name in '
- 'the\n'
- 'top-level namespace. Names are resolved in the top-level namespace '
- 'by\n'
- 'searching the global namespace, i.e. the namespace of the module\n'
- 'containing the code block, and the builtins namespace, the '
- 'namespace\n'
- 'of the module "__builtin__". The global namespace is searched '
- 'first.\n'
- 'If the name is not found there, the builtins namespace is '
- 'searched.\n'
- 'The global statement must precede all uses of the name.\n'
- '\n'
- 'The builtins namespace associated with the execution of a code '
- 'block\n'
- 'is actually found by looking up the name "__builtins__" in its '
- 'global\n'
- 'namespace; this should be a dictionary or a module (in the latter '
- 'case\n'
- "the module's dictionary is used). By default, when in the "
- '"__main__"\n'
- 'module, "__builtins__" is the built-in module "__builtin__" (note: '
- 'no\n'
- '\'s\'); when in any other module, "__builtins__" is an alias for '
- 'the\n'
- 'dictionary of the "__builtin__" module itself. "__builtins__" can '
- 'be\n'
- 'set to a user-created dictionary to create a weak form of '
- 'restricted\n'
- 'execution.\n'
- '\n'
- '**CPython implementation detail:** Users should not touch\n'
- '"__builtins__"; it is strictly an implementation detail. Users\n'
- 'wanting to override values in the builtins namespace should '
- '"import"\n'
- 'the "__builtin__" (no \'s\') module and modify its attributes\n'
- 'appropriately.\n'
- '\n'
- 'The namespace for a module is automatically created the first time '
- 'a\n'
- 'module is imported. The main module for a script is always '
- 'called\n'
- '"__main__".\n'
- '\n'
- 'The "global" statement has the same scope as a name binding '
- 'operation\n'
- 'in the same block. If the nearest enclosing scope for a free '
- 'variable\n'
- 'contains a global statement, the free variable is treated as a '
- 'global.\n'
- '\n'
- 'A class definition is an executable statement that may use and '
- 'define\n'
- 'names. These references follow the normal rules for name '
- 'resolution.\n'
- 'The namespace of the class definition becomes the attribute '
- 'dictionary\n'
- 'of the class. Names defined at the class scope are not visible '
- 'in\n'
- 'methods.\n'
- '\n'
- '\n'
- 'Interaction with dynamic features\n'
- '=================================\n'
- '\n'
- 'There are several cases where Python statements are illegal when '
- 'used\n'
- 'in conjunction with nested scopes that contain free variables.\n'
- '\n'
- 'If a variable is referenced in an enclosing scope, it is illegal '
- 'to\n'
- 'delete the name. An error will be reported at compile time.\n'
- '\n'
- 'If the wild card form of import --- "import *" --- is used in a\n'
- 'function and the function contains or is a nested block with free\n'
- 'variables, the compiler will raise a "SyntaxError".\n'
- '\n'
- 'If "exec" is used in a function and the function contains or is a\n'
- 'nested block with free variables, the compiler will raise a\n'
- '"SyntaxError" unless the exec explicitly specifies the local '
- 'namespace\n'
- 'for the "exec". (In other words, "exec obj" would be illegal, '
- 'but\n'
- '"exec obj in ns" would be legal.)\n'
- '\n'
- 'The "eval()", "execfile()", and "input()" functions and the '
- '"exec"\n'
- 'statement do not have access to the full environment for '
- 'resolving\n'
- 'names. Names may be resolved in the local and global namespaces '
- 'of\n'
- 'the caller. Free variables are not resolved in the nearest '
- 'enclosing\n'
- 'namespace, but in the global namespace. [1] The "exec" statement '
- 'and\n'
- 'the "eval()" and "execfile()" functions have optional arguments '
- 'to\n'
- 'override the global and local namespace. If only one namespace '
- 'is\n'
- 'specified, it is used for both.\n',
- 'numbers': '\n'
- 'Numeric literals\n'
- '****************\n'
- '\n'
- 'There are four types of numeric literals: plain integers, long\n'
- 'integers, floating point numbers, and imaginary numbers. There '
- 'are no\n'
- 'complex literals (complex numbers can be formed by adding a real\n'
- 'number and an imaginary number).\n'
- '\n'
- 'Note that numeric literals do not include a sign; a phrase like '
- '"-1"\n'
- 'is actually an expression composed of the unary operator \'"-"\' '
- 'and the\n'
- 'literal "1".\n',
- 'numeric-types': '\n'
- 'Emulating numeric types\n'
- '***********************\n'
- '\n'
- 'The following methods can be defined to emulate numeric '
- 'objects.\n'
- 'Methods corresponding to operations that are not supported '
- 'by the\n'
- 'particular kind of number implemented (e.g., bitwise '
- 'operations for\n'
- 'non-integral numbers) should be left undefined.\n'
- '\n'
- 'object.__add__(self, other)\n'
- 'object.__sub__(self, other)\n'
- 'object.__mul__(self, other)\n'
- 'object.__floordiv__(self, other)\n'
- 'object.__mod__(self, other)\n'
- 'object.__divmod__(self, other)\n'
- 'object.__pow__(self, other[, modulo])\n'
- 'object.__lshift__(self, other)\n'
- 'object.__rshift__(self, other)\n'
- 'object.__and__(self, other)\n'
- 'object.__xor__(self, other)\n'
- 'object.__or__(self, other)\n'
- '\n'
- ' These methods are called to implement the binary '
- 'arithmetic\n'
- ' operations ("+", "-", "*", "//", "%", "divmod()", '
- '"pow()", "**",\n'
- ' "<<", ">>", "&", "^", "|"). For instance, to evaluate '
- 'the\n'
- ' expression "x + y", where *x* is an instance of a class '
- 'that has an\n'
- ' "__add__()" method, "x.__add__(y)" is called. The '
- '"__divmod__()"\n'
- ' method should be the equivalent to using '
- '"__floordiv__()" and\n'
- ' "__mod__()"; it should not be related to "__truediv__()" '
- '(described\n'
- ' below). Note that "__pow__()" should be defined to '
- 'accept an\n'
- ' optional third argument if the ternary version of the '
- 'built-in\n'
- ' "pow()" function is to be supported.\n'
- '\n'
- ' If one of those methods does not support the operation '
- 'with the\n'
- ' supplied arguments, it should return "NotImplemented".\n'
- '\n'
- 'object.__div__(self, other)\n'
- 'object.__truediv__(self, other)\n'
- '\n'
- ' The division operator ("/") is implemented by these '
- 'methods. The\n'
- ' "__truediv__()" method is used when '
- '"__future__.division" is in\n'
- ' effect, otherwise "__div__()" is used. If only one of '
- 'these two\n'
- ' methods is defined, the object will not support division '
- 'in the\n'
- ' alternate context; "TypeError" will be raised instead.\n'
- '\n'
- 'object.__radd__(self, other)\n'
- 'object.__rsub__(self, other)\n'
- 'object.__rmul__(self, other)\n'
- 'object.__rdiv__(self, other)\n'
- 'object.__rtruediv__(self, other)\n'
- 'object.__rfloordiv__(self, other)\n'
- 'object.__rmod__(self, other)\n'
- 'object.__rdivmod__(self, other)\n'
- 'object.__rpow__(self, other)\n'
- 'object.__rlshift__(self, other)\n'
- 'object.__rrshift__(self, other)\n'
- 'object.__rand__(self, other)\n'
- 'object.__rxor__(self, other)\n'
- 'object.__ror__(self, other)\n'
- '\n'
- ' These methods are called to implement the binary '
- 'arithmetic\n'
- ' operations ("+", "-", "*", "/", "%", "divmod()", '
- '"pow()", "**",\n'
- ' "<<", ">>", "&", "^", "|") with reflected (swapped) '
- 'operands.\n'
- ' These functions are only called if the left operand does '
- 'not\n'
- ' support the corresponding operation and the operands are '
- 'of\n'
- ' different types. [2] For instance, to evaluate the '
- 'expression "x -\n'
- ' y", where *y* is an instance of a class that has an '
- '"__rsub__()"\n'
- ' method, "y.__rsub__(x)" is called if "x.__sub__(y)" '
- 'returns\n'
- ' *NotImplemented*.\n'
- '\n'
- ' Note that ternary "pow()" will not try calling '
- '"__rpow__()" (the\n'
- ' coercion rules would become too complicated).\n'
- '\n'
- " Note: If the right operand's type is a subclass of the "
- 'left\n'
- " operand's type and that subclass provides the "
- 'reflected method\n'
- ' for the operation, this method will be called before '
- 'the left\n'
- " operand's non-reflected method. This behavior allows "
- 'subclasses\n'
- " to override their ancestors' operations.\n"
- '\n'
- 'object.__iadd__(self, other)\n'
- 'object.__isub__(self, other)\n'
- 'object.__imul__(self, other)\n'
- 'object.__idiv__(self, other)\n'
- 'object.__itruediv__(self, other)\n'
- 'object.__ifloordiv__(self, other)\n'
- 'object.__imod__(self, other)\n'
- 'object.__ipow__(self, other[, modulo])\n'
- 'object.__ilshift__(self, other)\n'
- 'object.__irshift__(self, other)\n'
- 'object.__iand__(self, other)\n'
- 'object.__ixor__(self, other)\n'
- 'object.__ior__(self, other)\n'
- '\n'
- ' These methods are called to implement the augmented '
- 'arithmetic\n'
- ' assignments ("+=", "-=", "*=", "/=", "//=", "%=", "**=", '
- '"<<=",\n'
- ' ">>=", "&=", "^=", "|="). These methods should attempt '
- 'to do the\n'
- ' operation in-place (modifying *self*) and return the '
- 'result (which\n'
- ' could be, but does not have to be, *self*). If a '
- 'specific method\n'
- ' is not defined, the augmented assignment falls back to '
- 'the normal\n'
- ' methods. For instance, to execute the statement "x += '
- 'y", where\n'
- ' *x* is an instance of a class that has an "__iadd__()" '
- 'method,\n'
- ' "x.__iadd__(y)" is called. If *x* is an instance of a '
- 'class that\n'
- ' does not define a "__iadd__()" method, "x.__add__(y)" '
- 'and\n'
- ' "y.__radd__(x)" are considered, as with the evaluation '
- 'of "x + y".\n'
- '\n'
- 'object.__neg__(self)\n'
- 'object.__pos__(self)\n'
- 'object.__abs__(self)\n'
- 'object.__invert__(self)\n'
- '\n'
- ' Called to implement the unary arithmetic operations '
- '("-", "+",\n'
- ' "abs()" and "~").\n'
- '\n'
- 'object.__complex__(self)\n'
- 'object.__int__(self)\n'
- 'object.__long__(self)\n'
- 'object.__float__(self)\n'
- '\n'
- ' Called to implement the built-in functions "complex()", '
- '"int()",\n'
- ' "long()", and "float()". Should return a value of the '
- 'appropriate\n'
- ' type.\n'
- '\n'
- 'object.__oct__(self)\n'
- 'object.__hex__(self)\n'
- '\n'
- ' Called to implement the built-in functions "oct()" and '
- '"hex()".\n'
- ' Should return a string value.\n'
- '\n'
- 'object.__index__(self)\n'
- '\n'
- ' Called to implement "operator.index()". Also called '
- 'whenever\n'
- ' Python needs an integer object (such as in slicing). '
- 'Must return\n'
- ' an integer (int or long).\n'
- '\n'
- ' New in version 2.5.\n'
- '\n'
- 'object.__coerce__(self, other)\n'
- '\n'
- ' Called to implement "mixed-mode" numeric arithmetic. '
- 'Should either\n'
- ' return a 2-tuple containing *self* and *other* converted '
- 'to a\n'
- ' common numeric type, or "None" if conversion is '
- 'impossible. When\n'
- ' the common type would be the type of "other", it is '
- 'sufficient to\n'
- ' return "None", since the interpreter will also ask the '
- 'other object\n'
- ' to attempt a coercion (but sometimes, if the '
- 'implementation of the\n'
- ' other type cannot be changed, it is useful to do the '
- 'conversion to\n'
- ' the other type here). A return value of '
- '"NotImplemented" is\n'
- ' equivalent to returning "None".\n',
- 'objects': '\n'
- 'Objects, values and types\n'
- '*************************\n'
- '\n'
- "*Objects* are Python's abstraction for data. All data in a "
- 'Python\n'
- 'program is represented by objects or by relations between '
- 'objects. (In\n'
- 'a sense, and in conformance to Von Neumann\'s model of a "stored\n'
- 'program computer," code is also represented by objects.)\n'
- '\n'
- "Every object has an identity, a type and a value. An object's\n"
- '*identity* never changes once it has been created; you may think '
- 'of it\n'
- 'as the object\'s address in memory. The \'"is"\' operator '
- 'compares the\n'
- 'identity of two objects; the "id()" function returns an integer\n'
- 'representing its identity (currently implemented as its address). '
- 'An\n'
- "object's *type* is also unchangeable. [1] An object's type "
- 'determines\n'
- 'the operations that the object supports (e.g., "does it have a\n'
- 'length?") and also defines the possible values for objects of '
- 'that\n'
- 'type. The "type()" function returns an object\'s type (which is '
- 'an\n'
- 'object itself). The *value* of some objects can change. '
- 'Objects\n'
- 'whose value can change are said to be *mutable*; objects whose '
- 'value\n'
- 'is unchangeable once they are created are called *immutable*. '
- '(The\n'
- 'value of an immutable container object that contains a reference '
- 'to a\n'
- "mutable object can change when the latter's value is changed; "
- 'however\n'
- 'the container is still considered immutable, because the '
- 'collection of\n'
- 'objects it contains cannot be changed. So, immutability is not\n'
- 'strictly the same as having an unchangeable value, it is more '
- 'subtle.)\n'
- "An object's mutability is determined by its type; for instance,\n"
- 'numbers, strings and tuples are immutable, while dictionaries '
- 'and\n'
- 'lists are mutable.\n'
- '\n'
- 'Objects are never explicitly destroyed; however, when they '
- 'become\n'
- 'unreachable they may be garbage-collected. An implementation is\n'
- 'allowed to postpone garbage collection or omit it altogether --- '
- 'it is\n'
- 'a matter of implementation quality how garbage collection is\n'
- 'implemented, as long as no objects are collected that are still\n'
- 'reachable.\n'
- '\n'
- '**CPython implementation detail:** CPython currently uses a '
- 'reference-\n'
- 'counting scheme with (optional) delayed detection of cyclically '
- 'linked\n'
- 'garbage, which collects most objects as soon as they become\n'
- 'unreachable, but is not guaranteed to collect garbage containing\n'
- 'circular references. See the documentation of the "gc" module '
- 'for\n'
- 'information on controlling the collection of cyclic garbage. '
- 'Other\n'
- 'implementations act differently and CPython may change. Do not '
- 'depend\n'
- 'on immediate finalization of objects when they become unreachable '
- '(ex:\n'
- 'always close files).\n'
- '\n'
- "Note that the use of the implementation's tracing or debugging\n"
- 'facilities may keep objects alive that would normally be '
- 'collectable.\n'
- 'Also note that catching an exception with a \'"try"..."except"\'\n'
- 'statement may keep objects alive.\n'
- '\n'
- 'Some objects contain references to "external" resources such as '
- 'open\n'
- 'files or windows. It is understood that these resources are '
- 'freed\n'
- 'when the object is garbage-collected, but since garbage '
- 'collection is\n'
- 'not guaranteed to happen, such objects also provide an explicit '
- 'way to\n'
- 'release the external resource, usually a "close()" method. '
- 'Programs\n'
- 'are strongly recommended to explicitly close such objects. The\n'
- '\'"try"..."finally"\' statement provides a convenient way to do '
- 'this.\n'
- '\n'
- 'Some objects contain references to other objects; these are '
- 'called\n'
- '*containers*. Examples of containers are tuples, lists and\n'
- "dictionaries. The references are part of a container's value. "
- 'In\n'
- 'most cases, when we talk about the value of a container, we imply '
- 'the\n'
- 'values, not the identities of the contained objects; however, '
- 'when we\n'
- 'talk about the mutability of a container, only the identities of '
- 'the\n'
- 'immediately contained objects are implied. So, if an immutable\n'
- 'container (like a tuple) contains a reference to a mutable '
- 'object, its\n'
- 'value changes if that mutable object is changed.\n'
- '\n'
- 'Types affect almost all aspects of object behavior. Even the\n'
- 'importance of object identity is affected in some sense: for '
- 'immutable\n'
- 'types, operations that compute new values may actually return a\n'
- 'reference to any existing object with the same type and value, '
- 'while\n'
- 'for mutable objects this is not allowed. E.g., after "a = 1; b = '
- '1",\n'
- '"a" and "b" may or may not refer to the same object with the '
- 'value\n'
- 'one, depending on the implementation, but after "c = []; d = []", '
- '"c"\n'
- 'and "d" are guaranteed to refer to two different, unique, newly\n'
- 'created empty lists. (Note that "c = d = []" assigns the same '
- 'object\n'
- 'to both "c" and "d".)\n',
- 'operator-summary': '\n'
- 'Operator precedence\n'
- '*******************\n'
- '\n'
- 'The following table summarizes the operator precedences '
- 'in Python,\n'
- 'from lowest precedence (least binding) to highest '
- 'precedence (most\n'
- 'binding). Operators in the same box have the same '
- 'precedence. Unless\n'
- 'the syntax is explicitly given, operators are binary. '
- 'Operators in\n'
- 'the same box group left to right (except for '
- 'comparisons, including\n'
- 'tests, which all have the same precedence and chain from '
- 'left to right\n'
- '--- see section Comparisons --- and exponentiation, '
- 'which groups from\n'
- 'right to left).\n'
- '\n'
- '+-------------------------------------------------+---------------------------------------+\n'
- '| Operator | '
- 'Description |\n'
- '+=================================================+=======================================+\n'
- '| "lambda" | '
- 'Lambda expression |\n'
- '+-------------------------------------------------+---------------------------------------+\n'
- '| "if" -- "else" | '
- 'Conditional expression |\n'
- '+-------------------------------------------------+---------------------------------------+\n'
- '| "or" | '
- 'Boolean OR |\n'
- '+-------------------------------------------------+---------------------------------------+\n'
- '| "and" | '
- 'Boolean AND |\n'
- '+-------------------------------------------------+---------------------------------------+\n'
- '| "not" "x" | '
- 'Boolean NOT |\n'
- '+-------------------------------------------------+---------------------------------------+\n'
- '| "in", "not in", "is", "is not", "<", "<=", ">", | '
- 'Comparisons, including membership |\n'
- '| ">=", "<>", "!=", "==" | '
- 'tests and identity tests |\n'
- '+-------------------------------------------------+---------------------------------------+\n'
- '| "|" | '
- 'Bitwise OR |\n'
- '+-------------------------------------------------+---------------------------------------+\n'
- '| "^" | '
- 'Bitwise XOR |\n'
- '+-------------------------------------------------+---------------------------------------+\n'
- '| "&" | '
- 'Bitwise AND |\n'
- '+-------------------------------------------------+---------------------------------------+\n'
- '| "<<", ">>" | '
- 'Shifts |\n'
- '+-------------------------------------------------+---------------------------------------+\n'
- '| "+", "-" | '
- 'Addition and subtraction |\n'
- '+-------------------------------------------------+---------------------------------------+\n'
- '| "*", "/", "//", "%" | '
- 'Multiplication, division, remainder |\n'
- '| | '
- '[8] |\n'
- '+-------------------------------------------------+---------------------------------------+\n'
- '| "+x", "-x", "~x" | '
- 'Positive, negative, bitwise NOT |\n'
- '+-------------------------------------------------+---------------------------------------+\n'
- '| "**" | '
- 'Exponentiation [9] |\n'
- '+-------------------------------------------------+---------------------------------------+\n'
- '| "x[index]", "x[index:index]", | '
- 'Subscription, slicing, call, |\n'
- '| "x(arguments...)", "x.attribute" | '
- 'attribute reference |\n'
- '+-------------------------------------------------+---------------------------------------+\n'
- '| "(expressions...)", "[expressions...]", "{key: | '
- 'Binding or tuple display, list |\n'
- '| value...}", "`expressions...`" | '
- 'display, dictionary display, string |\n'
- '| | '
- 'conversion |\n'
- '+-------------------------------------------------+---------------------------------------+\n'
- '\n'
- '-[ Footnotes ]-\n'
- '\n'
- '[1] In Python 2.3 and later releases, a list '
- 'comprehension "leaks"\n'
- ' the control variables of each "for" it contains into '
- 'the\n'
- ' containing scope. However, this behavior is '
- 'deprecated, and\n'
- ' relying on it will not work in Python 3.\n'
- '\n'
- '[2] While "abs(x%y) < abs(y)" is true mathematically, '
- 'for floats\n'
- ' it may not be true numerically due to roundoff. For '
- 'example, and\n'
- ' assuming a platform on which a Python float is an '
- 'IEEE 754 double-\n'
- ' precision number, in order that "-1e-100 % 1e100" '
- 'have the same\n'
- ' sign as "1e100", the computed result is "-1e-100 + '
- '1e100", which\n'
- ' is numerically exactly equal to "1e100". The '
- 'function\n'
- ' "math.fmod()" returns a result whose sign matches '
- 'the sign of the\n'
- ' first argument instead, and so returns "-1e-100" in '
- 'this case.\n'
- ' Which approach is more appropriate depends on the '
- 'application.\n'
- '\n'
- '[3] If x is very close to an exact integer multiple of '
- "y, it's\n"
- ' possible for "floor(x/y)" to be one larger than '
- '"(x-x%y)/y" due to\n'
- ' rounding. In such cases, Python returns the latter '
- 'result, in\n'
- ' order to preserve that "divmod(x,y)[0] * y + x % y" '
- 'be very close\n'
- ' to "x".\n'
- '\n'
- '[4] While comparisons between unicode strings make sense '
- 'at the\n'
- ' byte level, they may be counter-intuitive to users. '
- 'For example,\n'
- ' the strings "u"\\u00C7"" and "u"\\u0043\\u0327"" '
- 'compare differently,\n'
- ' even though they both represent the same unicode '
- 'character (LATIN\n'
- ' CAPITAL LETTER C WITH CEDILLA). To compare strings '
- 'in a human\n'
- ' recognizable way, compare using '
- '"unicodedata.normalize()".\n'
- '\n'
- '[5] The implementation computes this efficiently, '
- 'without\n'
- ' constructing lists or sorting.\n'
- '\n'
- '[6] Earlier versions of Python used lexicographic '
- 'comparison of\n'
- ' the sorted (key, value) lists, but this was very '
- 'expensive for the\n'
- ' common case of comparing for equality. An even '
- 'earlier version of\n'
- ' Python compared dictionaries by identity only, but '
- 'this caused\n'
- ' surprises because people expected to be able to test '
- 'a dictionary\n'
- ' for emptiness by comparing it to "{}".\n'
- '\n'
- '[7] Due to automatic garbage-collection, free lists, and '
- 'the\n'
- ' dynamic nature of descriptors, you may notice '
- 'seemingly unusual\n'
- ' behaviour in certain uses of the "is" operator, like '
- 'those\n'
- ' involving comparisons between instance methods, or '
- 'constants.\n'
- ' Check their documentation for more info.\n'
- '\n'
- '[8] The "%" operator is also used for string formatting; '
- 'the same\n'
- ' precedence applies.\n'
- '\n'
- '[9] The power operator "**" binds less tightly than an '
- 'arithmetic\n'
- ' or bitwise unary operator on its right, that is, '
- '"2**-1" is "0.5".\n',
- 'pass': '\n'
- 'The "pass" statement\n'
- '********************\n'
- '\n'
- ' pass_stmt ::= "pass"\n'
- '\n'
- '"pass" is a null operation --- when it is executed, nothing '
- 'happens.\n'
- 'It is useful as a placeholder when a statement is required\n'
- 'syntactically, but no code needs to be executed, for example:\n'
- '\n'
- ' def f(arg): pass # a function that does nothing (yet)\n'
- '\n'
- ' class C: pass # a class with no methods (yet)\n',
- 'power': '\n'
- 'The power operator\n'
- '******************\n'
- '\n'
- 'The power operator binds more tightly than unary operators on its\n'
- 'left; it binds less tightly than unary operators on its right. '
- 'The\n'
- 'syntax is:\n'
- '\n'
- ' power ::= primary ["**" u_expr]\n'
- '\n'
- 'Thus, in an unparenthesized sequence of power and unary operators, '
- 'the\n'
- 'operators are evaluated from right to left (this does not '
- 'constrain\n'
- 'the evaluation order for the operands): "-1**2" results in "-1".\n'
- '\n'
- 'The power operator has the same semantics as the built-in "pow()"\n'
- 'function, when called with two arguments: it yields its left '
- 'argument\n'
- 'raised to the power of its right argument. The numeric arguments '
- 'are\n'
- 'first converted to a common type. The result type is that of the\n'
- 'arguments after coercion.\n'
- '\n'
- 'With mixed operand types, the coercion rules for binary arithmetic\n'
- 'operators apply. For int and long int operands, the result has the\n'
- 'same type as the operands (after coercion) unless the second '
- 'argument\n'
- 'is negative; in that case, all arguments are converted to float and '
- 'a\n'
- 'float result is delivered. For example, "10**2" returns "100", but\n'
- '"10**-2" returns "0.01". (This last feature was added in Python '
- '2.2.\n'
- 'In Python 2.1 and before, if both arguments were of integer types '
- 'and\n'
- 'the second argument was negative, an exception was raised).\n'
- '\n'
- 'Raising "0.0" to a negative power results in a '
- '"ZeroDivisionError".\n'
- 'Raising a negative number to a fractional power results in a\n'
- '"ValueError".\n',
- 'print': '\n'
- 'The "print" statement\n'
- '*********************\n'
- '\n'
- ' print_stmt ::= "print" ([expression ("," expression)* [","]]\n'
- ' | ">>" expression [("," expression)+ [","]])\n'
- '\n'
- '"print" evaluates each expression in turn and writes the resulting\n'
- 'object to standard output (see below). If an object is not a '
- 'string,\n'
- 'it is first converted to a string using the rules for string\n'
- 'conversions. The (resulting or original) string is then written. '
- 'A\n'
- 'space is written before each object is (converted and) written, '
- 'unless\n'
- 'the output system believes it is positioned at the beginning of a\n'
- 'line. This is the case (1) when no characters have yet been '
- 'written\n'
- 'to standard output, (2) when the last character written to '
- 'standard\n'
- 'output is a whitespace character except "\' \'", or (3) when the '
- 'last\n'
- 'write operation on standard output was not a "print" statement. '
- '(In\n'
- 'some cases it may be functional to write an empty string to '
- 'standard\n'
- 'output for this reason.)\n'
- '\n'
- 'Note: Objects which act like file objects but which are not the\n'
- ' built-in file objects often do not properly emulate this aspect '
- 'of\n'
- " the file object's behavior, so it is best not to rely on this.\n"
- '\n'
- 'A "\'\\n\'" character is written at the end, unless the "print" '
- 'statement\n'
- 'ends with a comma. This is the only action if the statement '
- 'contains\n'
- 'just the keyword "print".\n'
- '\n'
- 'Standard output is defined as the file object named "stdout" in '
- 'the\n'
- 'built-in module "sys". If no such object exists, or if it does '
- 'not\n'
- 'have a "write()" method, a "RuntimeError" exception is raised.\n'
- '\n'
- '"print" also has an extended form, defined by the second portion '
- 'of\n'
- 'the syntax described above. This form is sometimes referred to as\n'
- '""print" chevron." In this form, the first expression after the '
- '">>"\n'
- 'must evaluate to a "file-like" object, specifically an object that '
- 'has\n'
- 'a "write()" method as described above. With this extended form, '
- 'the\n'
- 'subsequent expressions are printed to this file object. If the '
- 'first\n'
- 'expression evaluates to "None", then "sys.stdout" is used as the '
- 'file\n'
- 'for output.\n',
- 'raise': '\n'
- 'The "raise" statement\n'
- '*********************\n'
- '\n'
- ' raise_stmt ::= "raise" [expression ["," expression ["," '
- 'expression]]]\n'
- '\n'
- 'If no expressions are present, "raise" re-raises the last '
- 'exception\n'
- 'that was active in the current scope. If no exception is active '
- 'in\n'
- 'the current scope, a "TypeError" exception is raised indicating '
- 'that\n'
- 'this is an error (if running under IDLE, a "Queue.Empty" exception '
- 'is\n'
- 'raised instead).\n'
- '\n'
- 'Otherwise, "raise" evaluates the expressions to get three objects,\n'
- 'using "None" as the value of omitted expressions. The first two\n'
- 'objects are used to determine the *type* and *value* of the '
- 'exception.\n'
- '\n'
- 'If the first object is an instance, the type of the exception is '
- 'the\n'
- 'class of the instance, the instance itself is the value, and the\n'
- 'second object must be "None".\n'
- '\n'
- 'If the first object is a class, it becomes the type of the '
- 'exception.\n'
- 'The second object is used to determine the exception value: If it '
- 'is\n'
- 'an instance of the class, the instance becomes the exception value. '
- 'If\n'
- 'the second object is a tuple, it is used as the argument list for '
- 'the\n'
- 'class constructor; if it is "None", an empty argument list is '
- 'used,\n'
- 'and any other object is treated as a single argument to the\n'
- 'constructor. The instance so created by calling the constructor '
- 'is\n'
- 'used as the exception value.\n'
- '\n'
- 'If a third object is present and not "None", it must be a '
- 'traceback\n'
- 'object (see section The standard type hierarchy), and it is\n'
- 'substituted instead of the current location as the place where the\n'
- 'exception occurred. If the third object is present and not a\n'
- 'traceback object or "None", a "TypeError" exception is raised. '
- 'The\n'
- 'three-expression form of "raise" is useful to re-raise an '
- 'exception\n'
- 'transparently in an except clause, but "raise" with no expressions\n'
- 'should be preferred if the exception to be re-raised was the most\n'
- 'recently active exception in the current scope.\n'
- '\n'
- 'Additional information on exceptions can be found in section\n'
- 'Exceptions, and information about handling exceptions is in '
- 'section\n'
- 'The try statement.\n',
- 'return': '\n'
- 'The "return" statement\n'
- '**********************\n'
- '\n'
- ' return_stmt ::= "return" [expression_list]\n'
- '\n'
- '"return" may only occur syntactically nested in a function '
- 'definition,\n'
- 'not within a nested class definition.\n'
- '\n'
- 'If an expression list is present, it is evaluated, else "None" is\n'
- 'substituted.\n'
- '\n'
- '"return" leaves the current function call with the expression list '
- '(or\n'
- '"None") as return value.\n'
- '\n'
- 'When "return" passes control out of a "try" statement with a '
- '"finally"\n'
- 'clause, that "finally" clause is executed before really leaving '
- 'the\n'
- 'function.\n'
- '\n'
- 'In a generator function, the "return" statement is not allowed to\n'
- 'include an "expression_list". In that context, a bare "return"\n'
- 'indicates that the generator is done and will cause '
- '"StopIteration" to\n'
- 'be raised.\n',
- 'sequence-types': '\n'
- 'Emulating container types\n'
- '*************************\n'
- '\n'
- 'The following methods can be defined to implement '
- 'container objects.\n'
- 'Containers usually are sequences (such as lists or tuples) '
- 'or mappings\n'
- '(like dictionaries), but can represent other containers as '
- 'well. The\n'
- 'first set of methods is used either to emulate a sequence '
- 'or to\n'
- 'emulate a mapping; the difference is that for a sequence, '
- 'the\n'
- 'allowable keys should be the integers *k* for which "0 <= '
- 'k < N" where\n'
- '*N* is the length of the sequence, or slice objects, which '
- 'define a\n'
- 'range of items. (For backwards compatibility, the method\n'
- '"__getslice__()" (see below) can also be defined to handle '
- 'simple, but\n'
- 'not extended slices.) It is also recommended that mappings '
- 'provide the\n'
- 'methods "keys()", "values()", "items()", "has_key()", '
- '"get()",\n'
- '"clear()", "setdefault()", "iterkeys()", "itervalues()",\n'
- '"iteritems()", "pop()", "popitem()", "copy()", and '
- '"update()" behaving\n'
- "similar to those for Python's standard dictionary "
- 'objects. The\n'
- '"UserDict" module provides a "DictMixin" class to help '
- 'create those\n'
- 'methods from a base set of "__getitem__()", '
- '"__setitem__()",\n'
- '"__delitem__()", and "keys()". Mutable sequences should '
- 'provide\n'
- 'methods "append()", "count()", "index()", "extend()", '
- '"insert()",\n'
- '"pop()", "remove()", "reverse()" and "sort()", like Python '
- 'standard\n'
- 'list objects. Finally, sequence types should implement '
- 'addition\n'
- '(meaning concatenation) and multiplication (meaning '
- 'repetition) by\n'
- 'defining the methods "__add__()", "__radd__()", '
- '"__iadd__()",\n'
- '"__mul__()", "__rmul__()" and "__imul__()" described '
- 'below; they\n'
- 'should not define "__coerce__()" or other numerical '
- 'operators. It is\n'
- 'recommended that both mappings and sequences implement '
- 'the\n'
- '"__contains__()" method to allow efficient use of the "in" '
- 'operator;\n'
- 'for mappings, "in" should be equivalent of "has_key()"; '
- 'for sequences,\n'
- 'it should search through the values. It is further '
- 'recommended that\n'
- 'both mappings and sequences implement the "__iter__()" '
- 'method to allow\n'
- 'efficient iteration through the container; for mappings, '
- '"__iter__()"\n'
- 'should be the same as "iterkeys()"; for sequences, it '
- 'should iterate\n'
- 'through the values.\n'
- '\n'
- 'object.__len__(self)\n'
- '\n'
- ' Called to implement the built-in function "len()". '
- 'Should return\n'
- ' the length of the object, an integer ">=" 0. Also, an '
- 'object that\n'
- ' doesn\'t define a "__nonzero__()" method and whose '
- '"__len__()"\n'
- ' method returns zero is considered to be false in a '
- 'Boolean context.\n'
- '\n'
- 'object.__getitem__(self, key)\n'
- '\n'
- ' Called to implement evaluation of "self[key]". For '
- 'sequence types,\n'
- ' the accepted keys should be integers and slice '
- 'objects. Note that\n'
- ' the special interpretation of negative indexes (if the '
- 'class wishes\n'
- ' to emulate a sequence type) is up to the '
- '"__getitem__()" method. If\n'
- ' *key* is of an inappropriate type, "TypeError" may be '
- 'raised; if of\n'
- ' a value outside the set of indexes for the sequence '
- '(after any\n'
- ' special interpretation of negative values), '
- '"IndexError" should be\n'
- ' raised. For mapping types, if *key* is missing (not in '
- 'the\n'
- ' container), "KeyError" should be raised.\n'
- '\n'
- ' Note: "for" loops expect that an "IndexError" will be '
- 'raised for\n'
- ' illegal indexes to allow proper detection of the end '
- 'of the\n'
- ' sequence.\n'
- '\n'
- 'object.__missing__(self, key)\n'
- '\n'
- ' Called by "dict"."__getitem__()" to implement '
- '"self[key]" for dict\n'
- ' subclasses when key is not in the dictionary.\n'
- '\n'
- 'object.__setitem__(self, key, value)\n'
- '\n'
- ' Called to implement assignment to "self[key]". Same '
- 'note as for\n'
- ' "__getitem__()". This should only be implemented for '
- 'mappings if\n'
- ' the objects support changes to the values for keys, or '
- 'if new keys\n'
- ' can be added, or for sequences if elements can be '
- 'replaced. The\n'
- ' same exceptions should be raised for improper *key* '
- 'values as for\n'
- ' the "__getitem__()" method.\n'
- '\n'
- 'object.__delitem__(self, key)\n'
- '\n'
- ' Called to implement deletion of "self[key]". Same note '
- 'as for\n'
- ' "__getitem__()". This should only be implemented for '
- 'mappings if\n'
- ' the objects support removal of keys, or for sequences '
- 'if elements\n'
- ' can be removed from the sequence. The same exceptions '
- 'should be\n'
- ' raised for improper *key* values as for the '
- '"__getitem__()" method.\n'
- '\n'
- 'object.__iter__(self)\n'
- '\n'
- ' This method is called when an iterator is required for '
- 'a container.\n'
- ' This method should return a new iterator object that '
- 'can iterate\n'
- ' over all the objects in the container. For mappings, '
- 'it should\n'
- ' iterate over the keys of the container, and should also '
- 'be made\n'
- ' available as the method "iterkeys()".\n'
- '\n'
- ' Iterator objects also need to implement this method; '
- 'they are\n'
- ' required to return themselves. For more information on '
- 'iterator\n'
- ' objects, see Iterator Types.\n'
- '\n'
- 'object.__reversed__(self)\n'
- '\n'
- ' Called (if present) by the "reversed()" built-in to '
- 'implement\n'
- ' reverse iteration. It should return a new iterator '
- 'object that\n'
- ' iterates over all the objects in the container in '
- 'reverse order.\n'
- '\n'
- ' If the "__reversed__()" method is not provided, the '
- '"reversed()"\n'
- ' built-in will fall back to using the sequence protocol '
- '("__len__()"\n'
- ' and "__getitem__()"). Objects that support the '
- 'sequence protocol\n'
- ' should only provide "__reversed__()" if they can '
- 'provide an\n'
- ' implementation that is more efficient than the one '
- 'provided by\n'
- ' "reversed()".\n'
- '\n'
- ' New in version 2.6.\n'
- '\n'
- 'The membership test operators ("in" and "not in") are '
- 'normally\n'
- 'implemented as an iteration through a sequence. However, '
- 'container\n'
- 'objects can supply the following special method with a '
- 'more efficient\n'
- 'implementation, which also does not require the object be '
- 'a sequence.\n'
- '\n'
- 'object.__contains__(self, item)\n'
- '\n'
- ' Called to implement membership test operators. Should '
- 'return true\n'
- ' if *item* is in *self*, false otherwise. For mapping '
- 'objects, this\n'
- ' should consider the keys of the mapping rather than the '
- 'values or\n'
- ' the key-item pairs.\n'
- '\n'
- ' For objects that don\'t define "__contains__()", the '
- 'membership test\n'
- ' first tries iteration via "__iter__()", then the old '
- 'sequence\n'
- ' iteration protocol via "__getitem__()", see this '
- 'section in the\n'
- ' language reference.\n',
- 'shifting': '\n'
- 'Shifting operations\n'
- '*******************\n'
- '\n'
- 'The shifting operations have lower priority than the arithmetic\n'
- 'operations:\n'
- '\n'
- ' shift_expr ::= a_expr | shift_expr ( "<<" | ">>" ) a_expr\n'
- '\n'
- 'These operators accept plain or long integers as arguments. '
- 'The\n'
- 'arguments are converted to a common type. They shift the first\n'
- 'argument to the left or right by the number of bits given by '
- 'the\n'
- 'second argument.\n'
- '\n'
- 'A right shift by *n* bits is defined as division by "pow(2, '
- 'n)". A\n'
- 'left shift by *n* bits is defined as multiplication with "pow(2, '
- 'n)".\n'
- 'Negative shift counts raise a "ValueError" exception.\n'
- '\n'
- 'Note: In the current implementation, the right-hand operand is\n'
- ' required to be at most "sys.maxsize". If the right-hand '
- 'operand is\n'
- ' larger than "sys.maxsize" an "OverflowError" exception is '
- 'raised.\n',
- 'slicings': '\n'
- 'Slicings\n'
- '********\n'
- '\n'
- 'A slicing selects a range of items in a sequence object (e.g., '
- 'a\n'
- 'string, tuple or list). Slicings may be used as expressions or '
- 'as\n'
- 'targets in assignment or "del" statements. The syntax for a '
- 'slicing:\n'
- '\n'
- ' slicing ::= simple_slicing | extended_slicing\n'
- ' simple_slicing ::= primary "[" short_slice "]"\n'
- ' extended_slicing ::= primary "[" slice_list "]"\n'
- ' slice_list ::= slice_item ("," slice_item)* [","]\n'
- ' slice_item ::= expression | proper_slice | ellipsis\n'
- ' proper_slice ::= short_slice | long_slice\n'
- ' short_slice ::= [lower_bound] ":" [upper_bound]\n'
- ' long_slice ::= short_slice ":" [stride]\n'
- ' lower_bound ::= expression\n'
- ' upper_bound ::= expression\n'
- ' stride ::= expression\n'
- ' ellipsis ::= "..."\n'
- '\n'
- 'There is ambiguity in the formal syntax here: anything that '
- 'looks like\n'
- 'an expression list also looks like a slice list, so any '
- 'subscription\n'
- 'can be interpreted as a slicing. Rather than further '
- 'complicating the\n'
- 'syntax, this is disambiguated by defining that in this case the\n'
- 'interpretation as a subscription takes priority over the\n'
- 'interpretation as a slicing (this is the case if the slice list\n'
- 'contains no proper slice nor ellipses). Similarly, when the '
- 'slice\n'
- 'list has exactly one short slice and no trailing comma, the\n'
- 'interpretation as a simple slicing takes priority over that as '
- 'an\n'
- 'extended slicing.\n'
- '\n'
- 'The semantics for a simple slicing are as follows. The primary '
- 'must\n'
- 'evaluate to a sequence object. The lower and upper bound '
- 'expressions,\n'
- 'if present, must evaluate to plain integers; defaults are zero '
- 'and the\n'
- '"sys.maxint", respectively. If either bound is negative, the\n'
- "sequence's length is added to it. The slicing now selects all "
- 'items\n'
- 'with index *k* such that "i <= k < j" where *i* and *j* are the\n'
- 'specified lower and upper bounds. This may be an empty '
- 'sequence. It\n'
- 'is not an error if *i* or *j* lie outside the range of valid '
- 'indexes\n'
- "(such items don't exist so they aren't selected).\n"
- '\n'
- 'The semantics for an extended slicing are as follows. The '
- 'primary\n'
- 'must evaluate to a mapping object, and it is indexed with a key '
- 'that\n'
- 'is constructed from the slice list, as follows. If the slice '
- 'list\n'
- 'contains at least one comma, the key is a tuple containing the\n'
- 'conversion of the slice items; otherwise, the conversion of the '
- 'lone\n'
- 'slice item is the key. The conversion of a slice item that is '
- 'an\n'
- 'expression is that expression. The conversion of an ellipsis '
- 'slice\n'
- 'item is the built-in "Ellipsis" object. The conversion of a '
- 'proper\n'
- 'slice is a slice object (see section The standard type '
- 'hierarchy)\n'
- 'whose "start", "stop" and "step" attributes are the values of '
- 'the\n'
- 'expressions given as lower bound, upper bound and stride,\n'
- 'respectively, substituting "None" for missing expressions.\n',
- 'specialattrs': '\n'
- 'Special Attributes\n'
- '******************\n'
- '\n'
- 'The implementation adds a few special read-only attributes '
- 'to several\n'
- 'object types, where they are relevant. Some of these are '
- 'not reported\n'
- 'by the "dir()" built-in function.\n'
- '\n'
- 'object.__dict__\n'
- '\n'
- ' A dictionary or other mapping object used to store an '
- "object's\n"
- ' (writable) attributes.\n'
- '\n'
- 'object.__methods__\n'
- '\n'
- ' Deprecated since version 2.2: Use the built-in function '
- '"dir()" to\n'
- " get a list of an object's attributes. This attribute is "
- 'no longer\n'
- ' available.\n'
- '\n'
- 'object.__members__\n'
- '\n'
- ' Deprecated since version 2.2: Use the built-in function '
- '"dir()" to\n'
- " get a list of an object's attributes. This attribute is "
- 'no longer\n'
- ' available.\n'
- '\n'
- 'instance.__class__\n'
- '\n'
- ' The class to which a class instance belongs.\n'
- '\n'
- 'class.__bases__\n'
- '\n'
- ' The tuple of base classes of a class object.\n'
- '\n'
- 'class.__name__\n'
- '\n'
- ' The name of the class or type.\n'
- '\n'
- 'The following attributes are only supported by *new-style '
- 'class*es.\n'
- '\n'
- 'class.__mro__\n'
- '\n'
- ' This attribute is a tuple of classes that are considered '
- 'when\n'
- ' looking for base classes during method resolution.\n'
- '\n'
- 'class.mro()\n'
- '\n'
- ' This method can be overridden by a metaclass to customize '
- 'the\n'
- ' method resolution order for its instances. It is called '
- 'at class\n'
- ' instantiation, and its result is stored in "__mro__".\n'
- '\n'
- 'class.__subclasses__()\n'
- '\n'
- ' Each new-style class keeps a list of weak references to '
- 'its\n'
- ' immediate subclasses. This method returns a list of all '
- 'those\n'
- ' references still alive. Example:\n'
- '\n'
- ' >>> int.__subclasses__()\n'
- " [<type 'bool'>]\n"
- '\n'
- '-[ Footnotes ]-\n'
- '\n'
- '[1] Additional information on these special methods may be '
- 'found\n'
- ' in the Python Reference Manual (Basic customization).\n'
- '\n'
- '[2] As a consequence, the list "[1, 2]" is considered equal '
- 'to\n'
- ' "[1.0, 2.0]", and similarly for tuples.\n'
- '\n'
- "[3] They must have since the parser can't tell the type of "
- 'the\n'
- ' operands.\n'
- '\n'
- '[4] Cased characters are those with general category '
- 'property\n'
- ' being one of "Lu" (Letter, uppercase), "Ll" (Letter, '
- 'lowercase),\n'
- ' or "Lt" (Letter, titlecase).\n'
- '\n'
- '[5] To format only a tuple you should therefore provide a\n'
- ' singleton tuple whose only element is the tuple to be '
- 'formatted.\n'
- '\n'
- '[6] The advantage of leaving the newline on is that '
- 'returning an\n'
- ' empty string is then an unambiguous EOF indication. It '
- 'is also\n'
- ' possible (in cases where it might matter, for example, '
- 'if you want\n'
- ' to make an exact copy of a file while scanning its '
- 'lines) to tell\n'
- ' whether the last line of a file ended in a newline or '
- 'not (yes\n'
- ' this happens!).\n',
- 'specialnames': '\n'
- 'Special method names\n'
- '********************\n'
- '\n'
- 'A class can implement certain operations that are invoked by '
- 'special\n'
- 'syntax (such as arithmetic operations or subscripting and '
- 'slicing) by\n'
- "defining methods with special names. This is Python's "
- 'approach to\n'
- '*operator overloading*, allowing classes to define their own '
- 'behavior\n'
- 'with respect to language operators. For instance, if a '
- 'class defines\n'
- 'a method named "__getitem__()", and "x" is an instance of '
- 'this class,\n'
- 'then "x[i]" is roughly equivalent to "x.__getitem__(i)" for '
- 'old-style\n'
- 'classes and "type(x).__getitem__(x, i)" for new-style '
- 'classes. Except\n'
- 'where mentioned, attempts to execute an operation raise an '
- 'exception\n'
- 'when no appropriate method is defined (typically '
- '"AttributeError" or\n'
- '"TypeError").\n'
- '\n'
- 'When implementing a class that emulates any built-in type, '
- 'it is\n'
- 'important that the emulation only be implemented to the '
- 'degree that it\n'
- 'makes sense for the object being modelled. For example, '
- 'some\n'
- 'sequences may work well with retrieval of individual '
- 'elements, but\n'
- 'extracting a slice may not make sense. (One example of this '
- 'is the\n'
- '"NodeList" interface in the W3C\'s Document Object Model.)\n'
- '\n'
- '\n'
- 'Basic customization\n'
- '===================\n'
- '\n'
- 'object.__new__(cls[, ...])\n'
- '\n'
- ' Called to create a new instance of class *cls*. '
- '"__new__()" is a\n'
- ' static method (special-cased so you need not declare it '
- 'as such)\n'
- ' that takes the class of which an instance was requested '
- 'as its\n'
- ' first argument. The remaining arguments are those passed '
- 'to the\n'
- ' object constructor expression (the call to the class). '
- 'The return\n'
- ' value of "__new__()" should be the new object instance '
- '(usually an\n'
- ' instance of *cls*).\n'
- '\n'
- ' Typical implementations create a new instance of the '
- 'class by\n'
- ' invoking the superclass\'s "__new__()" method using\n'
- ' "super(currentclass, cls).__new__(cls[, ...])" with '
- 'appropriate\n'
- ' arguments and then modifying the newly-created instance '
- 'as\n'
- ' necessary before returning it.\n'
- '\n'
- ' If "__new__()" returns an instance of *cls*, then the '
- 'new\n'
- ' instance\'s "__init__()" method will be invoked like\n'
- ' "__init__(self[, ...])", where *self* is the new instance '
- 'and the\n'
- ' remaining arguments are the same as were passed to '
- '"__new__()".\n'
- '\n'
- ' If "__new__()" does not return an instance of *cls*, then '
- 'the new\n'
- ' instance\'s "__init__()" method will not be invoked.\n'
- '\n'
- ' "__new__()" is intended mainly to allow subclasses of '
- 'immutable\n'
- ' types (like int, str, or tuple) to customize instance '
- 'creation. It\n'
- ' is also commonly overridden in custom metaclasses in '
- 'order to\n'
- ' customize class creation.\n'
- '\n'
- 'object.__init__(self[, ...])\n'
- '\n'
- ' Called after the instance has been created (by '
- '"__new__()"), but\n'
- ' before it is returned to the caller. The arguments are '
- 'those\n'
- ' passed to the class constructor expression. If a base '
- 'class has an\n'
- ' "__init__()" method, the derived class\'s "__init__()" '
- 'method, if\n'
- ' any, must explicitly call it to ensure proper '
- 'initialization of the\n'
- ' base class part of the instance; for example:\n'
- ' "BaseClass.__init__(self, [args...])".\n'
- '\n'
- ' Because "__new__()" and "__init__()" work together in '
- 'constructing\n'
- ' objects ("__new__()" to create it, and "__init__()" to '
- 'customise\n'
- ' it), no non-"None" value may be returned by "__init__()"; '
- 'doing so\n'
- ' will cause a "TypeError" to be raised at runtime.\n'
- '\n'
- 'object.__del__(self)\n'
- '\n'
- ' Called when the instance is about to be destroyed. This '
- 'is also\n'
- ' called a destructor. If a base class has a "__del__()" '
- 'method, the\n'
- ' derived class\'s "__del__()" method, if any, must '
- 'explicitly call it\n'
- ' to ensure proper deletion of the base class part of the '
- 'instance.\n'
- ' Note that it is possible (though not recommended!) for '
- 'the\n'
- ' "__del__()" method to postpone destruction of the '
- 'instance by\n'
- ' creating a new reference to it. It may then be called at '
- 'a later\n'
- ' time when this new reference is deleted. It is not '
- 'guaranteed that\n'
- ' "__del__()" methods are called for objects that still '
- 'exist when\n'
- ' the interpreter exits.\n'
- '\n'
- ' Note: "del x" doesn\'t directly call "x.__del__()" --- '
- 'the former\n'
- ' decrements the reference count for "x" by one, and the '
- 'latter is\n'
- ' only called when "x"\'s reference count reaches zero. '
- 'Some common\n'
- ' situations that may prevent the reference count of an '
- 'object from\n'
- ' going to zero include: circular references between '
- 'objects (e.g.,\n'
- ' a doubly-linked list or a tree data structure with '
- 'parent and\n'
- ' child pointers); a reference to the object on the stack '
- 'frame of\n'
- ' a function that caught an exception (the traceback '
- 'stored in\n'
- ' "sys.exc_traceback" keeps the stack frame alive); or a '
- 'reference\n'
- ' to the object on the stack frame that raised an '
- 'unhandled\n'
- ' exception in interactive mode (the traceback stored in\n'
- ' "sys.last_traceback" keeps the stack frame alive). The '
- 'first\n'
- ' situation can only be remedied by explicitly breaking '
- 'the cycles;\n'
- ' the latter two situations can be resolved by storing '
- '"None" in\n'
- ' "sys.exc_traceback" or "sys.last_traceback". Circular '
- 'references\n'
- ' which are garbage are detected when the option cycle '
- 'detector is\n'
- " enabled (it's on by default), but can only be cleaned "
- 'up if there\n'
- ' are no Python-level "__del__()" methods involved. Refer '
- 'to the\n'
- ' documentation for the "gc" module for more information '
- 'about how\n'
- ' "__del__()" methods are handled by the cycle detector,\n'
- ' particularly the description of the "garbage" value.\n'
- '\n'
- ' Warning: Due to the precarious circumstances under which\n'
- ' "__del__()" methods are invoked, exceptions that occur '
- 'during\n'
- ' their execution are ignored, and a warning is printed '
- 'to\n'
- ' "sys.stderr" instead. Also, when "__del__()" is invoked '
- 'in\n'
- ' response to a module being deleted (e.g., when '
- 'execution of the\n'
- ' program is done), other globals referenced by the '
- '"__del__()"\n'
- ' method may already have been deleted or in the process '
- 'of being\n'
- ' torn down (e.g. the import machinery shutting down). '
- 'For this\n'
- ' reason, "__del__()" methods should do the absolute '
- 'minimum needed\n'
- ' to maintain external invariants. Starting with version '
- '1.5,\n'
- ' Python guarantees that globals whose name begins with a '
- 'single\n'
- ' underscore are deleted from their module before other '
- 'globals are\n'
- ' deleted; if no other references to such globals exist, '
- 'this may\n'
- ' help in assuring that imported modules are still '
- 'available at the\n'
- ' time when the "__del__()" method is called.\n'
- '\n'
- ' See also the "-R" command-line option.\n'
- '\n'
- 'object.__repr__(self)\n'
- '\n'
- ' Called by the "repr()" built-in function and by string '
- 'conversions\n'
- ' (reverse quotes) to compute the "official" string '
- 'representation of\n'
- ' an object. If at all possible, this should look like a '
- 'valid\n'
- ' Python expression that could be used to recreate an '
- 'object with the\n'
- ' same value (given an appropriate environment). If this '
- 'is not\n'
- ' possible, a string of the form "<...some useful '
- 'description...>"\n'
- ' should be returned. The return value must be a string '
- 'object. If a\n'
- ' class defines "__repr__()" but not "__str__()", then '
- '"__repr__()"\n'
- ' is also used when an "informal" string representation of '
- 'instances\n'
- ' of that class is required.\n'
- '\n'
- ' This is typically used for debugging, so it is important '
- 'that the\n'
- ' representation is information-rich and unambiguous.\n'
- '\n'
- 'object.__str__(self)\n'
- '\n'
- ' Called by the "str()" built-in function and by the '
- '"print"\n'
- ' statement to compute the "informal" string representation '
- 'of an\n'
- ' object. This differs from "__repr__()" in that it does '
- 'not have to\n'
- ' be a valid Python expression: a more convenient or '
- 'concise\n'
- ' representation may be used instead. The return value must '
- 'be a\n'
- ' string object.\n'
- '\n'
- 'object.__lt__(self, other)\n'
- 'object.__le__(self, other)\n'
- 'object.__eq__(self, other)\n'
- 'object.__ne__(self, other)\n'
- 'object.__gt__(self, other)\n'
- 'object.__ge__(self, other)\n'
- '\n'
- ' New in version 2.1.\n'
- '\n'
- ' These are the so-called "rich comparison" methods, and '
- 'are called\n'
- ' for comparison operators in preference to "__cmp__()" '
- 'below. The\n'
- ' correspondence between operator symbols and method names '
- 'is as\n'
- ' follows: "x<y" calls "x.__lt__(y)", "x<=y" calls '
- '"x.__le__(y)",\n'
- ' "x==y" calls "x.__eq__(y)", "x!=y" and "x<>y" call '
- '"x.__ne__(y)",\n'
- ' "x>y" calls "x.__gt__(y)", and "x>=y" calls '
- '"x.__ge__(y)".\n'
- '\n'
- ' A rich comparison method may return the singleton '
- '"NotImplemented"\n'
- ' if it does not implement the operation for a given pair '
- 'of\n'
- ' arguments. By convention, "False" and "True" are returned '
- 'for a\n'
- ' successful comparison. However, these methods can return '
- 'any value,\n'
- ' so if the comparison operator is used in a Boolean '
- 'context (e.g.,\n'
- ' in the condition of an "if" statement), Python will call '
- '"bool()"\n'
- ' on the value to determine if the result is true or '
- 'false.\n'
- '\n'
- ' There are no implied relationships among the comparison '
- 'operators.\n'
- ' The truth of "x==y" does not imply that "x!=y" is false.\n'
- ' Accordingly, when defining "__eq__()", one should also '
- 'define\n'
- ' "__ne__()" so that the operators will behave as '
- 'expected. See the\n'
- ' paragraph on "__hash__()" for some important notes on '
- 'creating\n'
- ' *hashable* objects which support custom comparison '
- 'operations and\n'
- ' are usable as dictionary keys.\n'
- '\n'
- ' There are no swapped-argument versions of these methods '
- '(to be used\n'
- ' when the left argument does not support the operation but '
- 'the right\n'
- ' argument does); rather, "__lt__()" and "__gt__()" are '
- "each other's\n"
- ' reflection, "__le__()" and "__ge__()" are each other\'s '
- 'reflection,\n'
- ' and "__eq__()" and "__ne__()" are their own reflection.\n'
- '\n'
- ' Arguments to rich comparison methods are never coerced.\n'
- '\n'
- ' To automatically generate ordering operations from a '
- 'single root\n'
- ' operation, see "functools.total_ordering()".\n'
- '\n'
- 'object.__cmp__(self, other)\n'
- '\n'
- ' Called by comparison operations if rich comparison (see '
- 'above) is\n'
- ' not defined. Should return a negative integer if "self < '
- 'other",\n'
- ' zero if "self == other", a positive integer if "self > '
- 'other". If\n'
- ' no "__cmp__()", "__eq__()" or "__ne__()" operation is '
- 'defined,\n'
- ' class instances are compared by object identity '
- '("address"). See\n'
- ' also the description of "__hash__()" for some important '
- 'notes on\n'
- ' creating *hashable* objects which support custom '
- 'comparison\n'
- ' operations and are usable as dictionary keys. (Note: the\n'
- ' restriction that exceptions are not propagated by '
- '"__cmp__()" has\n'
- ' been removed since Python 1.5.)\n'
- '\n'
- 'object.__rcmp__(self, other)\n'
- '\n'
- ' Changed in version 2.1: No longer supported.\n'
- '\n'
- 'object.__hash__(self)\n'
- '\n'
- ' Called by built-in function "hash()" and for operations '
- 'on members\n'
- ' of hashed collections including "set", "frozenset", and '
- '"dict".\n'
- ' "__hash__()" should return an integer. The only required '
- 'property\n'
- ' is that objects which compare equal have the same hash '
- 'value; it is\n'
- ' advised to somehow mix together (e.g. using exclusive or) '
- 'the hash\n'
- ' values for the components of the object that also play a '
- 'part in\n'
- ' comparison of objects.\n'
- '\n'
- ' If a class does not define a "__cmp__()" or "__eq__()" '
- 'method it\n'
- ' should not define a "__hash__()" operation either; if it '
- 'defines\n'
- ' "__cmp__()" or "__eq__()" but not "__hash__()", its '
- 'instances will\n'
- ' not be usable in hashed collections. If a class defines '
- 'mutable\n'
- ' objects and implements a "__cmp__()" or "__eq__()" '
- 'method, it\n'
- ' should not implement "__hash__()", since hashable '
- 'collection\n'
- " implementations require that a object's hash value is "
- 'immutable (if\n'
- " the object's hash value changes, it will be in the wrong "
- 'hash\n'
- ' bucket).\n'
- '\n'
- ' User-defined classes have "__cmp__()" and "__hash__()" '
- 'methods by\n'
- ' default; with them, all objects compare unequal (except '
- 'with\n'
- ' themselves) and "x.__hash__()" returns a result derived '
- 'from\n'
- ' "id(x)".\n'
- '\n'
- ' Classes which inherit a "__hash__()" method from a parent '
- 'class but\n'
- ' change the meaning of "__cmp__()" or "__eq__()" such that '
- 'the hash\n'
- ' value returned is no longer appropriate (e.g. by '
- 'switching to a\n'
- ' value-based concept of equality instead of the default '
- 'identity\n'
- ' based equality) can explicitly flag themselves as being '
- 'unhashable\n'
- ' by setting "__hash__ = None" in the class definition. '
- 'Doing so\n'
- ' means that not only will instances of the class raise an\n'
- ' appropriate "TypeError" when a program attempts to '
- 'retrieve their\n'
- ' hash value, but they will also be correctly identified '
- 'as\n'
- ' unhashable when checking "isinstance(obj, '
- 'collections.Hashable)"\n'
- ' (unlike classes which define their own "__hash__()" to '
- 'explicitly\n'
- ' raise "TypeError").\n'
- '\n'
- ' Changed in version 2.5: "__hash__()" may now also return '
- 'a long\n'
- ' integer object; the 32-bit integer is then derived from '
- 'the hash of\n'
- ' that object.\n'
- '\n'
- ' Changed in version 2.6: "__hash__" may now be set to '
- '"None" to\n'
- ' explicitly flag instances of a class as unhashable.\n'
- '\n'
- 'object.__nonzero__(self)\n'
- '\n'
- ' Called to implement truth value testing and the built-in '
- 'operation\n'
- ' "bool()"; should return "False" or "True", or their '
- 'integer\n'
- ' equivalents "0" or "1". When this method is not '
- 'defined,\n'
- ' "__len__()" is called, if it is defined, and the object '
- 'is\n'
- ' considered true if its result is nonzero. If a class '
- 'defines\n'
- ' neither "__len__()" nor "__nonzero__()", all its '
- 'instances are\n'
- ' considered true.\n'
- '\n'
- 'object.__unicode__(self)\n'
- '\n'
- ' Called to implement "unicode()" built-in; should return a '
- 'Unicode\n'
- ' object. When this method is not defined, string '
- 'conversion is\n'
- ' attempted, and the result of string conversion is '
- 'converted to\n'
- ' Unicode using the system default encoding.\n'
- '\n'
- '\n'
- 'Customizing attribute access\n'
- '============================\n'
- '\n'
- 'The following methods can be defined to customize the '
- 'meaning of\n'
- 'attribute access (use of, assignment to, or deletion of '
- '"x.name") for\n'
- 'class instances.\n'
- '\n'
- 'object.__getattr__(self, name)\n'
- '\n'
- ' Called when an attribute lookup has not found the '
- 'attribute in the\n'
- ' usual places (i.e. it is not an instance attribute nor is '
- 'it found\n'
- ' in the class tree for "self"). "name" is the attribute '
- 'name. This\n'
- ' method should return the (computed) attribute value or '
- 'raise an\n'
- ' "AttributeError" exception.\n'
- '\n'
- ' Note that if the attribute is found through the normal '
- 'mechanism,\n'
- ' "__getattr__()" is not called. (This is an intentional '
- 'asymmetry\n'
- ' between "__getattr__()" and "__setattr__()".) This is '
- 'done both for\n'
- ' efficiency reasons and because otherwise "__getattr__()" '
- 'would have\n'
- ' no way to access other attributes of the instance. Note '
- 'that at\n'
- ' least for instance variables, you can fake total control '
- 'by not\n'
- ' inserting any values in the instance attribute dictionary '
- '(but\n'
- ' instead inserting them in another object). See the\n'
- ' "__getattribute__()" method below for a way to actually '
- 'get total\n'
- ' control in new-style classes.\n'
- '\n'
- 'object.__setattr__(self, name, value)\n'
- '\n'
- ' Called when an attribute assignment is attempted. This '
- 'is called\n'
- ' instead of the normal mechanism (i.e. store the value in '
- 'the\n'
- ' instance dictionary). *name* is the attribute name, '
- '*value* is the\n'
- ' value to be assigned to it.\n'
- '\n'
- ' If "__setattr__()" wants to assign to an instance '
- 'attribute, it\n'
- ' should not simply execute "self.name = value" --- this '
- 'would cause\n'
- ' a recursive call to itself. Instead, it should insert '
- 'the value in\n'
- ' the dictionary of instance attributes, e.g., '
- '"self.__dict__[name] =\n'
- ' value". For new-style classes, rather than accessing the '
- 'instance\n'
- ' dictionary, it should call the base class method with the '
- 'same\n'
- ' name, for example, "object.__setattr__(self, name, '
- 'value)".\n'
- '\n'
- 'object.__delattr__(self, name)\n'
- '\n'
- ' Like "__setattr__()" but for attribute deletion instead '
- 'of\n'
- ' assignment. This should only be implemented if "del '
- 'obj.name" is\n'
- ' meaningful for the object.\n'
- '\n'
- '\n'
- 'More attribute access for new-style classes\n'
- '-------------------------------------------\n'
- '\n'
- 'The following methods only apply to new-style classes.\n'
- '\n'
- 'object.__getattribute__(self, name)\n'
- '\n'
- ' Called unconditionally to implement attribute accesses '
- 'for\n'
- ' instances of the class. If the class also defines '
- '"__getattr__()",\n'
- ' the latter will not be called unless "__getattribute__()" '
- 'either\n'
- ' calls it explicitly or raises an "AttributeError". This '
- 'method\n'
- ' should return the (computed) attribute value or raise an\n'
- ' "AttributeError" exception. In order to avoid infinite '
- 'recursion in\n'
- ' this method, its implementation should always call the '
- 'base class\n'
- ' method with the same name to access any attributes it '
- 'needs, for\n'
- ' example, "object.__getattribute__(self, name)".\n'
- '\n'
- ' Note: This method may still be bypassed when looking up '
- 'special\n'
- ' methods as the result of implicit invocation via '
- 'language syntax\n'
- ' or built-in functions. See Special method lookup for '
- 'new-style\n'
- ' classes.\n'
- '\n'
- '\n'
- 'Implementing Descriptors\n'
- '------------------------\n'
- '\n'
- 'The following methods only apply when an instance of the '
- 'class\n'
- 'containing the method (a so-called *descriptor* class) '
- 'appears in an\n'
- "*owner* class (the descriptor must be in either the owner's "
- 'class\n'
- 'dictionary or in the class dictionary for one of its '
- 'parents). In the\n'
- 'examples below, "the attribute" refers to the attribute '
- 'whose name is\n'
- 'the key of the property in the owner class\' "__dict__".\n'
- '\n'
- 'object.__get__(self, instance, owner)\n'
- '\n'
- ' Called to get the attribute of the owner class (class '
- 'attribute\n'
- ' access) or of an instance of that class (instance '
- 'attribute\n'
- ' access). *owner* is always the owner class, while '
- '*instance* is the\n'
- ' instance that the attribute was accessed through, or '
- '"None" when\n'
- ' the attribute is accessed through the *owner*. This '
- 'method should\n'
- ' return the (computed) attribute value or raise an '
- '"AttributeError"\n'
- ' exception.\n'
- '\n'
- 'object.__set__(self, instance, value)\n'
- '\n'
- ' Called to set the attribute on an instance *instance* of '
- 'the owner\n'
- ' class to a new value, *value*.\n'
- '\n'
- 'object.__delete__(self, instance)\n'
- '\n'
- ' Called to delete the attribute on an instance *instance* '
- 'of the\n'
- ' owner class.\n'
- '\n'
- '\n'
- 'Invoking Descriptors\n'
- '--------------------\n'
- '\n'
- 'In general, a descriptor is an object attribute with '
- '"binding\n'
- 'behavior", one whose attribute access has been overridden by '
- 'methods\n'
- 'in the descriptor protocol: "__get__()", "__set__()", and\n'
- '"__delete__()". If any of those methods are defined for an '
- 'object, it\n'
- 'is said to be a descriptor.\n'
- '\n'
- 'The default behavior for attribute access is to get, set, or '
- 'delete\n'
- "the attribute from an object's dictionary. For instance, "
- '"a.x" has a\n'
- 'lookup chain starting with "a.__dict__[\'x\']", then\n'
- '"type(a).__dict__[\'x\']", and continuing through the base '
- 'classes of\n'
- '"type(a)" excluding metaclasses.\n'
- '\n'
- 'However, if the looked-up value is an object defining one of '
- 'the\n'
- 'descriptor methods, then Python may override the default '
- 'behavior and\n'
- 'invoke the descriptor method instead. Where this occurs in '
- 'the\n'
- 'precedence chain depends on which descriptor methods were '
- 'defined and\n'
- 'how they were called. Note that descriptors are only '
- 'invoked for new\n'
- 'style objects or classes (ones that subclass "object()" or '
- '"type()").\n'
- '\n'
- 'The starting point for descriptor invocation is a binding, '
- '"a.x". How\n'
- 'the arguments are assembled depends on "a":\n'
- '\n'
- 'Direct Call\n'
- ' The simplest and least common call is when user code '
- 'directly\n'
- ' invokes a descriptor method: "x.__get__(a)".\n'
- '\n'
- 'Instance Binding\n'
- ' If binding to a new-style object instance, "a.x" is '
- 'transformed\n'
- ' into the call: "type(a).__dict__[\'x\'].__get__(a, '
- 'type(a))".\n'
- '\n'
- 'Class Binding\n'
- ' If binding to a new-style class, "A.x" is transformed '
- 'into the\n'
- ' call: "A.__dict__[\'x\'].__get__(None, A)".\n'
- '\n'
- 'Super Binding\n'
- ' If "a" is an instance of "super", then the binding '
- '"super(B,\n'
- ' obj).m()" searches "obj.__class__.__mro__" for the base '
- 'class "A"\n'
- ' immediately preceding "B" and then invokes the descriptor '
- 'with the\n'
- ' call: "A.__dict__[\'m\'].__get__(obj, obj.__class__)".\n'
- '\n'
- 'For instance bindings, the precedence of descriptor '
- 'invocation depends\n'
- 'on the which descriptor methods are defined. A descriptor '
- 'can define\n'
- 'any combination of "__get__()", "__set__()" and '
- '"__delete__()". If it\n'
- 'does not define "__get__()", then accessing the attribute '
- 'will return\n'
- 'the descriptor object itself unless there is a value in the '
- "object's\n"
- 'instance dictionary. If the descriptor defines "__set__()" '
- 'and/or\n'
- '"__delete__()", it is a data descriptor; if it defines '
- 'neither, it is\n'
- 'a non-data descriptor. Normally, data descriptors define '
- 'both\n'
- '"__get__()" and "__set__()", while non-data descriptors have '
- 'just the\n'
- '"__get__()" method. Data descriptors with "__set__()" and '
- '"__get__()"\n'
- 'defined always override a redefinition in an instance '
- 'dictionary. In\n'
- 'contrast, non-data descriptors can be overridden by '
- 'instances.\n'
- '\n'
- 'Python methods (including "staticmethod()" and '
- '"classmethod()") are\n'
- 'implemented as non-data descriptors. Accordingly, instances '
- 'can\n'
- 'redefine and override methods. This allows individual '
- 'instances to\n'
- 'acquire behaviors that differ from other instances of the '
- 'same class.\n'
- '\n'
- 'The "property()" function is implemented as a data '
- 'descriptor.\n'
- 'Accordingly, instances cannot override the behavior of a '
- 'property.\n'
- '\n'
- '\n'
- '__slots__\n'
- '---------\n'
- '\n'
- 'By default, instances of both old and new-style classes have '
- 'a\n'
- 'dictionary for attribute storage. This wastes space for '
- 'objects\n'
- 'having very few instance variables. The space consumption '
- 'can become\n'
- 'acute when creating large numbers of instances.\n'
- '\n'
- 'The default can be overridden by defining *__slots__* in a '
- 'new-style\n'
- 'class definition. The *__slots__* declaration takes a '
- 'sequence of\n'
- 'instance variables and reserves just enough space in each '
- 'instance to\n'
- 'hold a value for each variable. Space is saved because '
- '*__dict__* is\n'
- 'not created for each instance.\n'
- '\n'
- '__slots__\n'
- '\n'
- ' This class variable can be assigned a string, iterable, '
- 'or sequence\n'
- ' of strings with variable names used by instances. If '
- 'defined in a\n'
- ' new-style class, *__slots__* reserves space for the '
- 'declared\n'
- ' variables and prevents the automatic creation of '
- '*__dict__* and\n'
- ' *__weakref__* for each instance.\n'
- '\n'
- ' New in version 2.2.\n'
- '\n'
- 'Notes on using *__slots__*\n'
- '\n'
- '* When inheriting from a class without *__slots__*, the '
- '*__dict__*\n'
- ' attribute of that class will always be accessible, so a '
- '*__slots__*\n'
- ' definition in the subclass is meaningless.\n'
- '\n'
- '* Without a *__dict__* variable, instances cannot be '
- 'assigned new\n'
- ' variables not listed in the *__slots__* definition. '
- 'Attempts to\n'
- ' assign to an unlisted variable name raises '
- '"AttributeError". If\n'
- ' dynamic assignment of new variables is desired, then add\n'
- ' "\'__dict__\'" to the sequence of strings in the '
- '*__slots__*\n'
- ' declaration.\n'
- '\n'
- ' Changed in version 2.3: Previously, adding "\'__dict__\'" '
- 'to the\n'
- ' *__slots__* declaration would not enable the assignment of '
- 'new\n'
- ' attributes not specifically listed in the sequence of '
- 'instance\n'
- ' variable names.\n'
- '\n'
- '* Without a *__weakref__* variable for each instance, '
- 'classes\n'
- ' defining *__slots__* do not support weak references to '
- 'its\n'
- ' instances. If weak reference support is needed, then add\n'
- ' "\'__weakref__\'" to the sequence of strings in the '
- '*__slots__*\n'
- ' declaration.\n'
- '\n'
- ' Changed in version 2.3: Previously, adding '
- '"\'__weakref__\'" to the\n'
- ' *__slots__* declaration would not enable support for weak\n'
- ' references.\n'
- '\n'
- '* *__slots__* are implemented at the class level by '
- 'creating\n'
- ' descriptors (Implementing Descriptors) for each variable '
- 'name. As a\n'
- ' result, class attributes cannot be used to set default '
- 'values for\n'
- ' instance variables defined by *__slots__*; otherwise, the '
- 'class\n'
- ' attribute would overwrite the descriptor assignment.\n'
- '\n'
- '* The action of a *__slots__* declaration is limited to the '
- 'class\n'
- ' where it is defined. As a result, subclasses will have a '
- '*__dict__*\n'
- ' unless they also define *__slots__* (which must only '
- 'contain names\n'
- ' of any *additional* slots).\n'
- '\n'
- '* If a class defines a slot also defined in a base class, '
- 'the\n'
- ' instance variable defined by the base class slot is '
- 'inaccessible\n'
- ' (except by retrieving its descriptor directly from the '
- 'base class).\n'
- ' This renders the meaning of the program undefined. In the '
- 'future, a\n'
- ' check may be added to prevent this.\n'
- '\n'
- '* Nonempty *__slots__* does not work for classes derived '
- 'from\n'
- ' "variable-length" built-in types such as "long", "str" and '
- '"tuple".\n'
- '\n'
- '* Any non-string iterable may be assigned to *__slots__*. '
- 'Mappings\n'
- ' may also be used; however, in the future, special meaning '
- 'may be\n'
- ' assigned to the values corresponding to each key.\n'
- '\n'
- '* *__class__* assignment works only if both classes have the '
- 'same\n'
- ' *__slots__*.\n'
- '\n'
- ' Changed in version 2.6: Previously, *__class__* assignment '
- 'raised an\n'
- ' error if either new or old class had *__slots__*.\n'
- '\n'
- '\n'
- 'Customizing class creation\n'
- '==========================\n'
- '\n'
- 'By default, new-style classes are constructed using '
- '"type()". A class\n'
- 'definition is read into a separate namespace and the value '
- 'of class\n'
- 'name is bound to the result of "type(name, bases, dict)".\n'
- '\n'
- 'When the class definition is read, if *__metaclass__* is '
- 'defined then\n'
- 'the callable assigned to it will be called instead of '
- '"type()". This\n'
- 'allows classes or functions to be written which monitor or '
- 'alter the\n'
- 'class creation process:\n'
- '\n'
- '* Modifying the class dictionary prior to the class being '
- 'created.\n'
- '\n'
- '* Returning an instance of another class -- essentially '
- 'performing\n'
- ' the role of a factory function.\n'
- '\n'
- "These steps will have to be performed in the metaclass's "
- '"__new__()"\n'
- 'method -- "type.__new__()" can then be called from this '
- 'method to\n'
- 'create a class with different properties. This example adds '
- 'a new\n'
- 'element to the class dictionary before creating the class:\n'
- '\n'
- ' class metacls(type):\n'
- ' def __new__(mcs, name, bases, dict):\n'
- " dict['foo'] = 'metacls was here'\n"
- ' return type.__new__(mcs, name, bases, dict)\n'
- '\n'
- 'You can of course also override other class methods (or add '
- 'new\n'
- 'methods); for example defining a custom "__call__()" method '
- 'in the\n'
- 'metaclass allows custom behavior when the class is called, '
- 'e.g. not\n'
- 'always creating a new instance.\n'
- '\n'
- '__metaclass__\n'
- '\n'
- ' This variable can be any callable accepting arguments for '
- '"name",\n'
- ' "bases", and "dict". Upon class creation, the callable '
- 'is used\n'
- ' instead of the built-in "type()".\n'
- '\n'
- ' New in version 2.2.\n'
- '\n'
- 'The appropriate metaclass is determined by the following '
- 'precedence\n'
- 'rules:\n'
- '\n'
- '* If "dict[\'__metaclass__\']" exists, it is used.\n'
- '\n'
- '* Otherwise, if there is at least one base class, its '
- 'metaclass is\n'
- ' used (this looks for a *__class__* attribute first and if '
- 'not found,\n'
- ' uses its type).\n'
- '\n'
- '* Otherwise, if a global variable named __metaclass__ '
- 'exists, it is\n'
- ' used.\n'
- '\n'
- '* Otherwise, the old-style, classic metaclass '
- '(types.ClassType) is\n'
- ' used.\n'
- '\n'
- 'The potential uses for metaclasses are boundless. Some ideas '
- 'that have\n'
- 'been explored including logging, interface checking, '
- 'automatic\n'
- 'delegation, automatic property creation, proxies, '
- 'frameworks, and\n'
- 'automatic resource locking/synchronization.\n'
- '\n'
- '\n'
- 'Customizing instance and subclass checks\n'
- '========================================\n'
- '\n'
- 'New in version 2.6.\n'
- '\n'
- 'The following methods are used to override the default '
- 'behavior of the\n'
- '"isinstance()" and "issubclass()" built-in functions.\n'
- '\n'
- 'In particular, the metaclass "abc.ABCMeta" implements these '
- 'methods in\n'
- 'order to allow the addition of Abstract Base Classes (ABCs) '
- 'as\n'
- '"virtual base classes" to any class or type (including '
- 'built-in\n'
- 'types), including other ABCs.\n'
- '\n'
- 'class.__instancecheck__(self, instance)\n'
- '\n'
- ' Return true if *instance* should be considered a (direct '
- 'or\n'
- ' indirect) instance of *class*. If defined, called to '
- 'implement\n'
- ' "isinstance(instance, class)".\n'
- '\n'
- 'class.__subclasscheck__(self, subclass)\n'
- '\n'
- ' Return true if *subclass* should be considered a (direct '
- 'or\n'
- ' indirect) subclass of *class*. If defined, called to '
- 'implement\n'
- ' "issubclass(subclass, class)".\n'
- '\n'
- 'Note that these methods are looked up on the type '
- '(metaclass) of a\n'
- 'class. They cannot be defined as class methods in the '
- 'actual class.\n'
- 'This is consistent with the lookup of special methods that '
- 'are called\n'
- 'on instances, only in this case the instance is itself a '
- 'class.\n'
- '\n'
- 'See also:\n'
- '\n'
- ' **PEP 3119** - Introducing Abstract Base Classes\n'
- ' Includes the specification for customizing '
- '"isinstance()" and\n'
- ' "issubclass()" behavior through "__instancecheck__()" '
- 'and\n'
- ' "__subclasscheck__()", with motivation for this '
- 'functionality in\n'
- ' the context of adding Abstract Base Classes (see the '
- '"abc"\n'
- ' module) to the language.\n'
- '\n'
- '\n'
- 'Emulating callable objects\n'
- '==========================\n'
- '\n'
- 'object.__call__(self[, args...])\n'
- '\n'
- ' Called when the instance is "called" as a function; if '
- 'this method\n'
- ' is defined, "x(arg1, arg2, ...)" is a shorthand for\n'
- ' "x.__call__(arg1, arg2, ...)".\n'
- '\n'
- '\n'
- 'Emulating container types\n'
- '=========================\n'
- '\n'
- 'The following methods can be defined to implement container '
- 'objects.\n'
- 'Containers usually are sequences (such as lists or tuples) '
- 'or mappings\n'
- '(like dictionaries), but can represent other containers as '
- 'well. The\n'
- 'first set of methods is used either to emulate a sequence or '
- 'to\n'
- 'emulate a mapping; the difference is that for a sequence, '
- 'the\n'
- 'allowable keys should be the integers *k* for which "0 <= k '
- '< N" where\n'
- '*N* is the length of the sequence, or slice objects, which '
- 'define a\n'
- 'range of items. (For backwards compatibility, the method\n'
- '"__getslice__()" (see below) can also be defined to handle '
- 'simple, but\n'
- 'not extended slices.) It is also recommended that mappings '
- 'provide the\n'
- 'methods "keys()", "values()", "items()", "has_key()", '
- '"get()",\n'
- '"clear()", "setdefault()", "iterkeys()", "itervalues()",\n'
- '"iteritems()", "pop()", "popitem()", "copy()", and '
- '"update()" behaving\n'
- "similar to those for Python's standard dictionary objects. "
- 'The\n'
- '"UserDict" module provides a "DictMixin" class to help '
- 'create those\n'
- 'methods from a base set of "__getitem__()", '
- '"__setitem__()",\n'
- '"__delitem__()", and "keys()". Mutable sequences should '
- 'provide\n'
- 'methods "append()", "count()", "index()", "extend()", '
- '"insert()",\n'
- '"pop()", "remove()", "reverse()" and "sort()", like Python '
- 'standard\n'
- 'list objects. Finally, sequence types should implement '
- 'addition\n'
- '(meaning concatenation) and multiplication (meaning '
- 'repetition) by\n'
- 'defining the methods "__add__()", "__radd__()", '
- '"__iadd__()",\n'
- '"__mul__()", "__rmul__()" and "__imul__()" described below; '
- 'they\n'
- 'should not define "__coerce__()" or other numerical '
- 'operators. It is\n'
- 'recommended that both mappings and sequences implement the\n'
- '"__contains__()" method to allow efficient use of the "in" '
- 'operator;\n'
- 'for mappings, "in" should be equivalent of "has_key()"; for '
- 'sequences,\n'
- 'it should search through the values. It is further '
- 'recommended that\n'
- 'both mappings and sequences implement the "__iter__()" '
- 'method to allow\n'
- 'efficient iteration through the container; for mappings, '
- '"__iter__()"\n'
- 'should be the same as "iterkeys()"; for sequences, it should '
- 'iterate\n'
- 'through the values.\n'
- '\n'
- 'object.__len__(self)\n'
- '\n'
- ' Called to implement the built-in function "len()". '
- 'Should return\n'
- ' the length of the object, an integer ">=" 0. Also, an '
- 'object that\n'
- ' doesn\'t define a "__nonzero__()" method and whose '
- '"__len__()"\n'
- ' method returns zero is considered to be false in a '
- 'Boolean context.\n'
- '\n'
- 'object.__getitem__(self, key)\n'
- '\n'
- ' Called to implement evaluation of "self[key]". For '
- 'sequence types,\n'
- ' the accepted keys should be integers and slice objects. '
- 'Note that\n'
- ' the special interpretation of negative indexes (if the '
- 'class wishes\n'
- ' to emulate a sequence type) is up to the "__getitem__()" '
- 'method. If\n'
- ' *key* is of an inappropriate type, "TypeError" may be '
- 'raised; if of\n'
- ' a value outside the set of indexes for the sequence '
- '(after any\n'
- ' special interpretation of negative values), "IndexError" '
- 'should be\n'
- ' raised. For mapping types, if *key* is missing (not in '
- 'the\n'
- ' container), "KeyError" should be raised.\n'
- '\n'
- ' Note: "for" loops expect that an "IndexError" will be '
- 'raised for\n'
- ' illegal indexes to allow proper detection of the end of '
- 'the\n'
- ' sequence.\n'
- '\n'
- 'object.__missing__(self, key)\n'
- '\n'
- ' Called by "dict"."__getitem__()" to implement "self[key]" '
- 'for dict\n'
- ' subclasses when key is not in the dictionary.\n'
- '\n'
- 'object.__setitem__(self, key, value)\n'
- '\n'
- ' Called to implement assignment to "self[key]". Same note '
- 'as for\n'
- ' "__getitem__()". This should only be implemented for '
- 'mappings if\n'
- ' the objects support changes to the values for keys, or if '
- 'new keys\n'
- ' can be added, or for sequences if elements can be '
- 'replaced. The\n'
- ' same exceptions should be raised for improper *key* '
- 'values as for\n'
- ' the "__getitem__()" method.\n'
- '\n'
- 'object.__delitem__(self, key)\n'
- '\n'
- ' Called to implement deletion of "self[key]". Same note '
- 'as for\n'
- ' "__getitem__()". This should only be implemented for '
- 'mappings if\n'
- ' the objects support removal of keys, or for sequences if '
- 'elements\n'
- ' can be removed from the sequence. The same exceptions '
- 'should be\n'
- ' raised for improper *key* values as for the '
- '"__getitem__()" method.\n'
- '\n'
- 'object.__iter__(self)\n'
- '\n'
- ' This method is called when an iterator is required for a '
- 'container.\n'
- ' This method should return a new iterator object that can '
- 'iterate\n'
- ' over all the objects in the container. For mappings, it '
- 'should\n'
- ' iterate over the keys of the container, and should also '
- 'be made\n'
- ' available as the method "iterkeys()".\n'
- '\n'
- ' Iterator objects also need to implement this method; they '
- 'are\n'
- ' required to return themselves. For more information on '
- 'iterator\n'
- ' objects, see Iterator Types.\n'
- '\n'
- 'object.__reversed__(self)\n'
- '\n'
- ' Called (if present) by the "reversed()" built-in to '
- 'implement\n'
- ' reverse iteration. It should return a new iterator '
- 'object that\n'
- ' iterates over all the objects in the container in reverse '
- 'order.\n'
- '\n'
- ' If the "__reversed__()" method is not provided, the '
- '"reversed()"\n'
- ' built-in will fall back to using the sequence protocol '
- '("__len__()"\n'
- ' and "__getitem__()"). Objects that support the sequence '
- 'protocol\n'
- ' should only provide "__reversed__()" if they can provide '
- 'an\n'
- ' implementation that is more efficient than the one '
- 'provided by\n'
- ' "reversed()".\n'
- '\n'
- ' New in version 2.6.\n'
- '\n'
- 'The membership test operators ("in" and "not in") are '
- 'normally\n'
- 'implemented as an iteration through a sequence. However, '
- 'container\n'
- 'objects can supply the following special method with a more '
- 'efficient\n'
- 'implementation, which also does not require the object be a '
- 'sequence.\n'
- '\n'
- 'object.__contains__(self, item)\n'
- '\n'
- ' Called to implement membership test operators. Should '
- 'return true\n'
- ' if *item* is in *self*, false otherwise. For mapping '
- 'objects, this\n'
- ' should consider the keys of the mapping rather than the '
- 'values or\n'
- ' the key-item pairs.\n'
- '\n'
- ' For objects that don\'t define "__contains__()", the '
- 'membership test\n'
- ' first tries iteration via "__iter__()", then the old '
- 'sequence\n'
- ' iteration protocol via "__getitem__()", see this section '
- 'in the\n'
- ' language reference.\n'
- '\n'
- '\n'
- 'Additional methods for emulation of sequence types\n'
- '==================================================\n'
- '\n'
- 'The following optional methods can be defined to further '
- 'emulate\n'
- 'sequence objects. Immutable sequences methods should at '
- 'most only\n'
- 'define "__getslice__()"; mutable sequences might define all '
- 'three\n'
- 'methods.\n'
- '\n'
- 'object.__getslice__(self, i, j)\n'
- '\n'
- ' Deprecated since version 2.0: Support slice objects as '
- 'parameters\n'
- ' to the "__getitem__()" method. (However, built-in types '
- 'in CPython\n'
- ' currently still implement "__getslice__()". Therefore, '
- 'you have to\n'
- ' override it in derived classes when implementing '
- 'slicing.)\n'
- '\n'
- ' Called to implement evaluation of "self[i:j]". The '
- 'returned object\n'
- ' should be of the same type as *self*. Note that missing '
- '*i* or *j*\n'
- ' in the slice expression are replaced by zero or '
- '"sys.maxsize",\n'
- ' respectively. If negative indexes are used in the slice, '
- 'the\n'
- ' length of the sequence is added to that index. If the '
- 'instance does\n'
- ' not implement the "__len__()" method, an "AttributeError" '
- 'is\n'
- ' raised. No guarantee is made that indexes adjusted this '
- 'way are not\n'
- ' still negative. Indexes which are greater than the '
- 'length of the\n'
- ' sequence are not modified. If no "__getslice__()" is '
- 'found, a slice\n'
- ' object is created instead, and passed to "__getitem__()" '
- 'instead.\n'
- '\n'
- 'object.__setslice__(self, i, j, sequence)\n'
- '\n'
- ' Called to implement assignment to "self[i:j]". Same notes '
- 'for *i*\n'
- ' and *j* as for "__getslice__()".\n'
- '\n'
- ' This method is deprecated. If no "__setslice__()" is '
- 'found, or for\n'
- ' extended slicing of the form "self[i:j:k]", a slice '
- 'object is\n'
- ' created, and passed to "__setitem__()", instead of '
- '"__setslice__()"\n'
- ' being called.\n'
- '\n'
- 'object.__delslice__(self, i, j)\n'
- '\n'
- ' Called to implement deletion of "self[i:j]". Same notes '
- 'for *i* and\n'
- ' *j* as for "__getslice__()". This method is deprecated. '
- 'If no\n'
- ' "__delslice__()" is found, or for extended slicing of the '
- 'form\n'
- ' "self[i:j:k]", a slice object is created, and passed to\n'
- ' "__delitem__()", instead of "__delslice__()" being '
- 'called.\n'
- '\n'
- 'Notice that these methods are only invoked when a single '
- 'slice with a\n'
- 'single colon is used, and the slice method is available. '
- 'For slice\n'
- 'operations involving extended slice notation, or in absence '
- 'of the\n'
- 'slice methods, "__getitem__()", "__setitem__()" or '
- '"__delitem__()" is\n'
- 'called with a slice object as argument.\n'
- '\n'
- 'The following example demonstrate how to make your program '
- 'or module\n'
- 'compatible with earlier versions of Python (assuming that '
- 'methods\n'
- '"__getitem__()", "__setitem__()" and "__delitem__()" support '
- 'slice\n'
- 'objects as arguments):\n'
- '\n'
- ' class MyClass:\n'
- ' ...\n'
- ' def __getitem__(self, index):\n'
- ' ...\n'
- ' def __setitem__(self, index, value):\n'
- ' ...\n'
- ' def __delitem__(self, index):\n'
- ' ...\n'
- '\n'
- ' if sys.version_info < (2, 0):\n'
- " # They won't be defined if version is at least "
- '2.0 final\n'
- '\n'
- ' def __getslice__(self, i, j):\n'
- ' return self[max(0, i):max(0, j):]\n'
- ' def __setslice__(self, i, j, seq):\n'
- ' self[max(0, i):max(0, j):] = seq\n'
- ' def __delslice__(self, i, j):\n'
- ' del self[max(0, i):max(0, j):]\n'
- ' ...\n'
- '\n'
- 'Note the calls to "max()"; these are necessary because of '
- 'the handling\n'
- 'of negative indices before the "__*slice__()" methods are '
- 'called.\n'
- 'When negative indexes are used, the "__*item__()" methods '
- 'receive them\n'
- 'as provided, but the "__*slice__()" methods get a "cooked" '
- 'form of the\n'
- 'index values. For each negative index value, the length of '
- 'the\n'
- 'sequence is added to the index before calling the method '
- '(which may\n'
- 'still result in a negative index); this is the customary '
- 'handling of\n'
- 'negative indexes by the built-in sequence types, and the '
- '"__*item__()"\n'
- 'methods are expected to do this as well. However, since '
- 'they should\n'
- 'already be doing that, negative indexes cannot be passed in; '
- 'they must\n'
- 'be constrained to the bounds of the sequence before being '
- 'passed to\n'
- 'the "__*item__()" methods. Calling "max(0, i)" conveniently '
- 'returns\n'
- 'the proper value.\n'
- '\n'
- '\n'
- 'Emulating numeric types\n'
- '=======================\n'
- '\n'
- 'The following methods can be defined to emulate numeric '
- 'objects.\n'
- 'Methods corresponding to operations that are not supported '
- 'by the\n'
- 'particular kind of number implemented (e.g., bitwise '
- 'operations for\n'
- 'non-integral numbers) should be left undefined.\n'
- '\n'
- 'object.__add__(self, other)\n'
- 'object.__sub__(self, other)\n'
- 'object.__mul__(self, other)\n'
- 'object.__floordiv__(self, other)\n'
- 'object.__mod__(self, other)\n'
- 'object.__divmod__(self, other)\n'
- 'object.__pow__(self, other[, modulo])\n'
- 'object.__lshift__(self, other)\n'
- 'object.__rshift__(self, other)\n'
- 'object.__and__(self, other)\n'
- 'object.__xor__(self, other)\n'
- 'object.__or__(self, other)\n'
- '\n'
- ' These methods are called to implement the binary '
- 'arithmetic\n'
- ' operations ("+", "-", "*", "//", "%", "divmod()", '
- '"pow()", "**",\n'
- ' "<<", ">>", "&", "^", "|"). For instance, to evaluate '
- 'the\n'
- ' expression "x + y", where *x* is an instance of a class '
- 'that has an\n'
- ' "__add__()" method, "x.__add__(y)" is called. The '
- '"__divmod__()"\n'
- ' method should be the equivalent to using "__floordiv__()" '
- 'and\n'
- ' "__mod__()"; it should not be related to "__truediv__()" '
- '(described\n'
- ' below). Note that "__pow__()" should be defined to '
- 'accept an\n'
- ' optional third argument if the ternary version of the '
- 'built-in\n'
- ' "pow()" function is to be supported.\n'
- '\n'
- ' If one of those methods does not support the operation '
- 'with the\n'
- ' supplied arguments, it should return "NotImplemented".\n'
- '\n'
- 'object.__div__(self, other)\n'
- 'object.__truediv__(self, other)\n'
- '\n'
- ' The division operator ("/") is implemented by these '
- 'methods. The\n'
- ' "__truediv__()" method is used when "__future__.division" '
- 'is in\n'
- ' effect, otherwise "__div__()" is used. If only one of '
- 'these two\n'
- ' methods is defined, the object will not support division '
- 'in the\n'
- ' alternate context; "TypeError" will be raised instead.\n'
- '\n'
- 'object.__radd__(self, other)\n'
- 'object.__rsub__(self, other)\n'
- 'object.__rmul__(self, other)\n'
- 'object.__rdiv__(self, other)\n'
- 'object.__rtruediv__(self, other)\n'
- 'object.__rfloordiv__(self, other)\n'
- 'object.__rmod__(self, other)\n'
- 'object.__rdivmod__(self, other)\n'
- 'object.__rpow__(self, other)\n'
- 'object.__rlshift__(self, other)\n'
- 'object.__rrshift__(self, other)\n'
- 'object.__rand__(self, other)\n'
- 'object.__rxor__(self, other)\n'
- 'object.__ror__(self, other)\n'
- '\n'
- ' These methods are called to implement the binary '
- 'arithmetic\n'
- ' operations ("+", "-", "*", "/", "%", "divmod()", "pow()", '
- '"**",\n'
- ' "<<", ">>", "&", "^", "|") with reflected (swapped) '
- 'operands.\n'
- ' These functions are only called if the left operand does '
- 'not\n'
- ' support the corresponding operation and the operands are '
- 'of\n'
- ' different types. [2] For instance, to evaluate the '
- 'expression "x -\n'
- ' y", where *y* is an instance of a class that has an '
- '"__rsub__()"\n'
- ' method, "y.__rsub__(x)" is called if "x.__sub__(y)" '
- 'returns\n'
- ' *NotImplemented*.\n'
- '\n'
- ' Note that ternary "pow()" will not try calling '
- '"__rpow__()" (the\n'
- ' coercion rules would become too complicated).\n'
- '\n'
- " Note: If the right operand's type is a subclass of the "
- 'left\n'
- " operand's type and that subclass provides the reflected "
- 'method\n'
- ' for the operation, this method will be called before '
- 'the left\n'
- " operand's non-reflected method. This behavior allows "
- 'subclasses\n'
- " to override their ancestors' operations.\n"
- '\n'
- 'object.__iadd__(self, other)\n'
- 'object.__isub__(self, other)\n'
- 'object.__imul__(self, other)\n'
- 'object.__idiv__(self, other)\n'
- 'object.__itruediv__(self, other)\n'
- 'object.__ifloordiv__(self, other)\n'
- 'object.__imod__(self, other)\n'
- 'object.__ipow__(self, other[, modulo])\n'
- 'object.__ilshift__(self, other)\n'
- 'object.__irshift__(self, other)\n'
- 'object.__iand__(self, other)\n'
- 'object.__ixor__(self, other)\n'
- 'object.__ior__(self, other)\n'
- '\n'
- ' These methods are called to implement the augmented '
- 'arithmetic\n'
- ' assignments ("+=", "-=", "*=", "/=", "//=", "%=", "**=", '
- '"<<=",\n'
- ' ">>=", "&=", "^=", "|="). These methods should attempt '
- 'to do the\n'
- ' operation in-place (modifying *self*) and return the '
- 'result (which\n'
- ' could be, but does not have to be, *self*). If a '
- 'specific method\n'
- ' is not defined, the augmented assignment falls back to '
- 'the normal\n'
- ' methods. For instance, to execute the statement "x += '
- 'y", where\n'
- ' *x* is an instance of a class that has an "__iadd__()" '
- 'method,\n'
- ' "x.__iadd__(y)" is called. If *x* is an instance of a '
- 'class that\n'
- ' does not define a "__iadd__()" method, "x.__add__(y)" '
- 'and\n'
- ' "y.__radd__(x)" are considered, as with the evaluation of '
- '"x + y".\n'
- '\n'
- 'object.__neg__(self)\n'
- 'object.__pos__(self)\n'
- 'object.__abs__(self)\n'
- 'object.__invert__(self)\n'
- '\n'
- ' Called to implement the unary arithmetic operations ("-", '
- '"+",\n'
- ' "abs()" and "~").\n'
- '\n'
- 'object.__complex__(self)\n'
- 'object.__int__(self)\n'
- 'object.__long__(self)\n'
- 'object.__float__(self)\n'
- '\n'
- ' Called to implement the built-in functions "complex()", '
- '"int()",\n'
- ' "long()", and "float()". Should return a value of the '
- 'appropriate\n'
- ' type.\n'
- '\n'
- 'object.__oct__(self)\n'
- 'object.__hex__(self)\n'
- '\n'
- ' Called to implement the built-in functions "oct()" and '
- '"hex()".\n'
- ' Should return a string value.\n'
- '\n'
- 'object.__index__(self)\n'
- '\n'
- ' Called to implement "operator.index()". Also called '
- 'whenever\n'
- ' Python needs an integer object (such as in slicing). '
- 'Must return\n'
- ' an integer (int or long).\n'
- '\n'
- ' New in version 2.5.\n'
- '\n'
- 'object.__coerce__(self, other)\n'
- '\n'
- ' Called to implement "mixed-mode" numeric arithmetic. '
- 'Should either\n'
- ' return a 2-tuple containing *self* and *other* converted '
- 'to a\n'
- ' common numeric type, or "None" if conversion is '
- 'impossible. When\n'
- ' the common type would be the type of "other", it is '
- 'sufficient to\n'
- ' return "None", since the interpreter will also ask the '
- 'other object\n'
- ' to attempt a coercion (but sometimes, if the '
- 'implementation of the\n'
- ' other type cannot be changed, it is useful to do the '
- 'conversion to\n'
- ' the other type here). A return value of "NotImplemented" '
- 'is\n'
- ' equivalent to returning "None".\n'
- '\n'
- '\n'
- 'Coercion rules\n'
- '==============\n'
- '\n'
- 'This section used to document the rules for coercion. As '
- 'the language\n'
- 'has evolved, the coercion rules have become hard to '
- 'document\n'
- 'precisely; documenting what one version of one particular\n'
- 'implementation does is undesirable. Instead, here are some '
- 'informal\n'
- 'guidelines regarding coercion. In Python 3, coercion will '
- 'not be\n'
- 'supported.\n'
- '\n'
- '* If the left operand of a % operator is a string or Unicode '
- 'object,\n'
- ' no coercion takes place and the string formatting '
- 'operation is\n'
- ' invoked instead.\n'
- '\n'
- '* It is no longer recommended to define a coercion '
- 'operation. Mixed-\n'
- " mode operations on types that don't define coercion pass "
- 'the\n'
- ' original arguments to the operation.\n'
- '\n'
- '* New-style classes (those derived from "object") never '
- 'invoke the\n'
- ' "__coerce__()" method in response to a binary operator; '
- 'the only\n'
- ' time "__coerce__()" is invoked is when the built-in '
- 'function\n'
- ' "coerce()" is called.\n'
- '\n'
- '* For most intents and purposes, an operator that returns\n'
- ' "NotImplemented" is treated the same as one that is not '
- 'implemented\n'
- ' at all.\n'
- '\n'
- '* Below, "__op__()" and "__rop__()" are used to signify the '
- 'generic\n'
- ' method names corresponding to an operator; "__iop__()" is '
- 'used for\n'
- ' the corresponding in-place operator. For example, for the '
- 'operator\n'
- ' \'"+"\', "__add__()" and "__radd__()" are used for the '
- 'left and right\n'
- ' variant of the binary operator, and "__iadd__()" for the '
- 'in-place\n'
- ' variant.\n'
- '\n'
- '* For objects *x* and *y*, first "x.__op__(y)" is tried. If '
- 'this is\n'
- ' not implemented or returns "NotImplemented", '
- '"y.__rop__(x)" is\n'
- ' tried. If this is also not implemented or returns '
- '"NotImplemented",\n'
- ' a "TypeError" exception is raised. But see the following '
- 'exception:\n'
- '\n'
- '* Exception to the previous item: if the left operand is an '
- 'instance\n'
- ' of a built-in type or a new-style class, and the right '
- 'operand is an\n'
- ' instance of a proper subclass of that type or class and '
- 'overrides\n'
- ' the base\'s "__rop__()" method, the right operand\'s '
- '"__rop__()"\n'
- ' method is tried *before* the left operand\'s "__op__()" '
- 'method.\n'
- '\n'
- ' This is done so that a subclass can completely override '
- 'binary\n'
- ' operators. Otherwise, the left operand\'s "__op__()" '
- 'method would\n'
- ' always accept the right operand: when an instance of a '
- 'given class\n'
- ' is expected, an instance of a subclass of that class is '
- 'always\n'
- ' acceptable.\n'
- '\n'
- '* When either operand type defines a coercion, this coercion '
- 'is\n'
- ' called before that type\'s "__op__()" or "__rop__()" '
- 'method is\n'
- ' called, but no sooner. If the coercion returns an object '
- 'of a\n'
- ' different type for the operand whose coercion is invoked, '
- 'part of\n'
- ' the process is redone using the new object.\n'
- '\n'
- '* When an in-place operator (like \'"+="\') is used, if the '
- 'left\n'
- ' operand implements "__iop__()", it is invoked without any '
- 'coercion.\n'
- ' When the operation falls back to "__op__()" and/or '
- '"__rop__()", the\n'
- ' normal coercion rules apply.\n'
- '\n'
- '* In "x + y", if *x* is a sequence that implements sequence\n'
- ' concatenation, sequence concatenation is invoked.\n'
- '\n'
- '* In "x * y", if one operand is a sequence that implements '
- 'sequence\n'
- ' repetition, and the other is an integer ("int" or "long"), '
- 'sequence\n'
- ' repetition is invoked.\n'
- '\n'
- '* Rich comparisons (implemented by methods "__eq__()" and so '
- 'on)\n'
- ' never use coercion. Three-way comparison (implemented by\n'
- ' "__cmp__()") does use coercion under the same conditions '
- 'as other\n'
- ' binary operations use it.\n'
- '\n'
- '* In the current implementation, the built-in numeric types '
- '"int",\n'
- ' "long", "float", and "complex" do not use coercion. All '
- 'these types\n'
- ' implement a "__coerce__()" method, for use by the '
- 'built-in\n'
- ' "coerce()" function.\n'
- '\n'
- ' Changed in version 2.7: The complex type no longer makes '
- 'implicit\n'
- ' calls to the "__coerce__()" method for mixed-type binary '
- 'arithmetic\n'
- ' operations.\n'
- '\n'
- '\n'
- 'With Statement Context Managers\n'
- '===============================\n'
- '\n'
- 'New in version 2.5.\n'
- '\n'
- 'A *context manager* is an object that defines the runtime '
- 'context to\n'
- 'be established when executing a "with" statement. The '
- 'context manager\n'
- 'handles the entry into, and the exit from, the desired '
- 'runtime context\n'
- 'for the execution of the block of code. Context managers '
- 'are normally\n'
- 'invoked using the "with" statement (described in section The '
- 'with\n'
- 'statement), but can also be used by directly invoking their '
- 'methods.\n'
- '\n'
- 'Typical uses of context managers include saving and '
- 'restoring various\n'
- 'kinds of global state, locking and unlocking resources, '
- 'closing opened\n'
- 'files, etc.\n'
- '\n'
- 'For more information on context managers, see Context '
- 'Manager Types.\n'
- '\n'
- 'object.__enter__(self)\n'
- '\n'
- ' Enter the runtime context related to this object. The '
- '"with"\n'
- " statement will bind this method's return value to the "
- 'target(s)\n'
- ' specified in the "as" clause of the statement, if any.\n'
- '\n'
- 'object.__exit__(self, exc_type, exc_value, traceback)\n'
- '\n'
- ' Exit the runtime context related to this object. The '
- 'parameters\n'
- ' describe the exception that caused the context to be '
- 'exited. If the\n'
- ' context was exited without an exception, all three '
- 'arguments will\n'
- ' be "None".\n'
- '\n'
- ' If an exception is supplied, and the method wishes to '
- 'suppress the\n'
- ' exception (i.e., prevent it from being propagated), it '
- 'should\n'
- ' return a true value. Otherwise, the exception will be '
- 'processed\n'
- ' normally upon exit from this method.\n'
- '\n'
- ' Note that "__exit__()" methods should not reraise the '
- 'passed-in\n'
- " exception; this is the caller's responsibility.\n"
- '\n'
- 'See also:\n'
- '\n'
- ' **PEP 343** - The "with" statement\n'
- ' The specification, background, and examples for the '
- 'Python "with"\n'
- ' statement.\n'
- '\n'
- '\n'
- 'Special method lookup for old-style classes\n'
- '===========================================\n'
- '\n'
- 'For old-style classes, special methods are always looked up '
- 'in exactly\n'
- 'the same way as any other method or attribute. This is the '
- 'case\n'
- 'regardless of whether the method is being looked up '
- 'explicitly as in\n'
- '"x.__getitem__(i)" or implicitly as in "x[i]".\n'
- '\n'
- 'This behaviour means that special methods may exhibit '
- 'different\n'
- 'behaviour for different instances of a single old-style '
- 'class if the\n'
- 'appropriate special attributes are set differently:\n'
- '\n'
- ' >>> class C:\n'
- ' ... pass\n'
- ' ...\n'
- ' >>> c1 = C()\n'
- ' >>> c2 = C()\n'
- ' >>> c1.__len__ = lambda: 5\n'
- ' >>> c2.__len__ = lambda: 9\n'
- ' >>> len(c1)\n'
- ' 5\n'
- ' >>> len(c2)\n'
- ' 9\n'
- '\n'
- '\n'
- 'Special method lookup for new-style classes\n'
- '===========================================\n'
- '\n'
- 'For new-style classes, implicit invocations of special '
- 'methods are\n'
- "only guaranteed to work correctly if defined on an object's "
- 'type, not\n'
- "in the object's instance dictionary. That behaviour is the "
- 'reason why\n'
- 'the following code raises an exception (unlike the '
- 'equivalent example\n'
- 'with old-style classes):\n'
- '\n'
- ' >>> class C(object):\n'
- ' ... pass\n'
- ' ...\n'
- ' >>> c = C()\n'
- ' >>> c.__len__ = lambda: 5\n'
- ' >>> len(c)\n'
- ' Traceback (most recent call last):\n'
- ' File "<stdin>", line 1, in <module>\n'
- " TypeError: object of type 'C' has no len()\n"
- '\n'
- 'The rationale behind this behaviour lies with a number of '
- 'special\n'
- 'methods such as "__hash__()" and "__repr__()" that are '
- 'implemented by\n'
- 'all objects, including type objects. If the implicit lookup '
- 'of these\n'
- 'methods used the conventional lookup process, they would '
- 'fail when\n'
- 'invoked on the type object itself:\n'
- '\n'
- ' >>> 1 .__hash__() == hash(1)\n'
- ' True\n'
- ' >>> int.__hash__() == hash(int)\n'
- ' Traceback (most recent call last):\n'
- ' File "<stdin>", line 1, in <module>\n'
- " TypeError: descriptor '__hash__' of 'int' object needs an "
- 'argument\n'
- '\n'
- 'Incorrectly attempting to invoke an unbound method of a '
- 'class in this\n'
- "way is sometimes referred to as 'metaclass confusion', and "
- 'is avoided\n'
- 'by bypassing the instance when looking up special methods:\n'
- '\n'
- ' >>> type(1).__hash__(1) == hash(1)\n'
- ' True\n'
- ' >>> type(int).__hash__(int) == hash(int)\n'
- ' True\n'
- '\n'
- 'In addition to bypassing any instance attributes in the '
- 'interest of\n'
- 'correctness, implicit special method lookup generally also '
- 'bypasses\n'
- 'the "__getattribute__()" method even of the object\'s '
- 'metaclass:\n'
- '\n'
- ' >>> class Meta(type):\n'
- ' ... def __getattribute__(*args):\n'
- ' ... print "Metaclass getattribute invoked"\n'
- ' ... return type.__getattribute__(*args)\n'
- ' ...\n'
- ' >>> class C(object):\n'
- ' ... __metaclass__ = Meta\n'
- ' ... def __len__(self):\n'
- ' ... return 10\n'
- ' ... def __getattribute__(*args):\n'
- ' ... print "Class getattribute invoked"\n'
- ' ... return object.__getattribute__(*args)\n'
- ' ...\n'
- ' >>> c = C()\n'
- ' >>> c.__len__() # Explicit lookup via '
- 'instance\n'
- ' Class getattribute invoked\n'
- ' 10\n'
- ' >>> type(c).__len__(c) # Explicit lookup via '
- 'type\n'
- ' Metaclass getattribute invoked\n'
- ' 10\n'
- ' >>> len(c) # Implicit lookup\n'
- ' 10\n'
- '\n'
- 'Bypassing the "__getattribute__()" machinery in this fashion '
- 'provides\n'
- 'significant scope for speed optimisations within the '
- 'interpreter, at\n'
- 'the cost of some flexibility in the handling of special '
- 'methods (the\n'
- 'special method *must* be set on the class object itself in '
- 'order to be\n'
- 'consistently invoked by the interpreter).\n'
- '\n'
- '-[ Footnotes ]-\n'
- '\n'
- "[1] It *is* possible in some cases to change an object's "
- 'type,\n'
- " under certain controlled conditions. It generally isn't "
- 'a good\n'
- ' idea though, since it can lead to some very strange '
- 'behaviour if\n'
- ' it is handled incorrectly.\n'
- '\n'
- '[2] For operands of the same type, it is assumed that if the '
- 'non-\n'
- ' reflected method (such as "__add__()") fails the '
- 'operation is not\n'
- ' supported, which is why the reflected method is not '
- 'called.\n',
- 'string-methods': '\n'
- 'String Methods\n'
- '**************\n'
- '\n'
- 'Below are listed the string methods which both 8-bit '
- 'strings and\n'
- 'Unicode objects support. Some of them are also available '
- 'on\n'
- '"bytearray" objects.\n'
- '\n'
- "In addition, Python's strings support the sequence type "
- 'methods\n'
- 'described in the Sequence Types --- str, unicode, list, '
- 'tuple,\n'
- 'bytearray, buffer, xrange section. To output formatted '
- 'strings use\n'
- 'template strings or the "%" operator described in the '
- 'String\n'
- 'Formatting Operations section. Also, see the "re" module '
- 'for string\n'
- 'functions based on regular expressions.\n'
- '\n'
- 'str.capitalize()\n'
- '\n'
- ' Return a copy of the string with its first character '
- 'capitalized\n'
- ' and the rest lowercased.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.center(width[, fillchar])\n'
- '\n'
- ' Return centered in a string of length *width*. Padding '
- 'is done\n'
- ' using the specified *fillchar* (default is a space).\n'
- '\n'
- ' Changed in version 2.4: Support for the *fillchar* '
- 'argument.\n'
- '\n'
- 'str.count(sub[, start[, end]])\n'
- '\n'
- ' Return the number of non-overlapping occurrences of '
- 'substring *sub*\n'
- ' in the range [*start*, *end*]. Optional arguments '
- '*start* and\n'
- ' *end* are interpreted as in slice notation.\n'
- '\n'
- 'str.decode([encoding[, errors]])\n'
- '\n'
- ' Decodes the string using the codec registered for '
- '*encoding*.\n'
- ' *encoding* defaults to the default string encoding. '
- '*errors* may\n'
- ' be given to set a different error handling scheme. The '
- 'default is\n'
- ' "\'strict\'", meaning that encoding errors raise '
- '"UnicodeError".\n'
- ' Other possible values are "\'ignore\'", "\'replace\'" '
- 'and any other\n'
- ' name registered via "codecs.register_error()", see '
- 'section Codec\n'
- ' Base Classes.\n'
- '\n'
- ' New in version 2.2.\n'
- '\n'
- ' Changed in version 2.3: Support for other error '
- 'handling schemes\n'
- ' added.\n'
- '\n'
- ' Changed in version 2.7: Support for keyword arguments '
- 'added.\n'
- '\n'
- 'str.encode([encoding[, errors]])\n'
- '\n'
- ' Return an encoded version of the string. Default '
- 'encoding is the\n'
- ' current default string encoding. *errors* may be given '
- 'to set a\n'
- ' different error handling scheme. The default for '
- '*errors* is\n'
- ' "\'strict\'", meaning that encoding errors raise a '
- '"UnicodeError".\n'
- ' Other possible values are "\'ignore\'", "\'replace\'",\n'
- ' "\'xmlcharrefreplace\'", "\'backslashreplace\'" and any '
- 'other name\n'
- ' registered via "codecs.register_error()", see section '
- 'Codec Base\n'
- ' Classes. For a list of possible encodings, see section '
- 'Standard\n'
- ' Encodings.\n'
- '\n'
- ' New in version 2.0.\n'
- '\n'
- ' Changed in version 2.3: Support for '
- '"\'xmlcharrefreplace\'" and\n'
- ' "\'backslashreplace\'" and other error handling schemes '
- 'added.\n'
- '\n'
- ' Changed in version 2.7: Support for keyword arguments '
- 'added.\n'
- '\n'
- 'str.endswith(suffix[, start[, end]])\n'
- '\n'
- ' Return "True" if the string ends with the specified '
- '*suffix*,\n'
- ' otherwise return "False". *suffix* can also be a tuple '
- 'of suffixes\n'
- ' to look for. With optional *start*, test beginning at '
- 'that\n'
- ' position. With optional *end*, stop comparing at that '
- 'position.\n'
- '\n'
- ' Changed in version 2.5: Accept tuples as *suffix*.\n'
- '\n'
- 'str.expandtabs([tabsize])\n'
- '\n'
- ' Return a copy of the string where all tab characters '
- 'are replaced\n'
- ' by one or more spaces, depending on the current column '
- 'and the\n'
- ' given tab size. Tab positions occur every *tabsize* '
- 'characters\n'
- ' (default is 8, giving tab positions at columns 0, 8, 16 '
- 'and so on).\n'
- ' To expand the string, the current column is set to zero '
- 'and the\n'
- ' string is examined character by character. If the '
- 'character is a\n'
- ' tab ("\\t"), one or more space characters are inserted '
- 'in the result\n'
- ' until the current column is equal to the next tab '
- 'position. (The\n'
- ' tab character itself is not copied.) If the character '
- 'is a newline\n'
- ' ("\\n") or return ("\\r"), it is copied and the current '
- 'column is\n'
- ' reset to zero. Any other character is copied unchanged '
- 'and the\n'
- ' current column is incremented by one regardless of how '
- 'the\n'
- ' character is represented when printed.\n'
- '\n'
- " >>> '01\\t012\\t0123\\t01234'.expandtabs()\n"
- " '01 012 0123 01234'\n"
- " >>> '01\\t012\\t0123\\t01234'.expandtabs(4)\n"
- " '01 012 0123 01234'\n"
- '\n'
- 'str.find(sub[, start[, end]])\n'
- '\n'
- ' Return the lowest index in the string where substring '
- '*sub* is\n'
- ' found within the slice "s[start:end]". Optional '
- 'arguments *start*\n'
- ' and *end* are interpreted as in slice notation. Return '
- '"-1" if\n'
- ' *sub* is not found.\n'
- '\n'
- ' Note: The "find()" method should be used only if you '
- 'need to know\n'
- ' the position of *sub*. To check if *sub* is a '
- 'substring or not,\n'
- ' use the "in" operator:\n'
- '\n'
- " >>> 'Py' in 'Python'\n"
- ' True\n'
- '\n'
- 'str.format(*args, **kwargs)\n'
- '\n'
- ' Perform a string formatting operation. The string on '
- 'which this\n'
- ' method is called can contain literal text or '
- 'replacement fields\n'
- ' delimited by braces "{}". Each replacement field '
- 'contains either\n'
- ' the numeric index of a positional argument, or the name '
- 'of a\n'
- ' keyword argument. Returns a copy of the string where '
- 'each\n'
- ' replacement field is replaced with the string value of '
- 'the\n'
- ' corresponding argument.\n'
- '\n'
- ' >>> "The sum of 1 + 2 is {0}".format(1+2)\n'
- " 'The sum of 1 + 2 is 3'\n"
- '\n'
- ' See Format String Syntax for a description of the '
- 'various\n'
- ' formatting options that can be specified in format '
- 'strings.\n'
- '\n'
- ' This method of string formatting is the new standard in '
- 'Python 3,\n'
- ' and should be preferred to the "%" formatting described '
- 'in String\n'
- ' Formatting Operations in new code.\n'
- '\n'
- ' New in version 2.6.\n'
- '\n'
- 'str.index(sub[, start[, end]])\n'
- '\n'
- ' Like "find()", but raise "ValueError" when the '
- 'substring is not\n'
- ' found.\n'
- '\n'
- 'str.isalnum()\n'
- '\n'
- ' Return true if all characters in the string are '
- 'alphanumeric and\n'
- ' there is at least one character, false otherwise.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.isalpha()\n'
- '\n'
- ' Return true if all characters in the string are '
- 'alphabetic and\n'
- ' there is at least one character, false otherwise.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.isdigit()\n'
- '\n'
- ' Return true if all characters in the string are digits '
- 'and there is\n'
- ' at least one character, false otherwise.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.islower()\n'
- '\n'
- ' Return true if all cased characters [4] in the string '
- 'are lowercase\n'
- ' and there is at least one cased character, false '
- 'otherwise.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.isspace()\n'
- '\n'
- ' Return true if there are only whitespace characters in '
- 'the string\n'
- ' and there is at least one character, false otherwise.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.istitle()\n'
- '\n'
- ' Return true if the string is a titlecased string and '
- 'there is at\n'
- ' least one character, for example uppercase characters '
- 'may only\n'
- ' follow uncased characters and lowercase characters only '
- 'cased ones.\n'
- ' Return false otherwise.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.isupper()\n'
- '\n'
- ' Return true if all cased characters [4] in the string '
- 'are uppercase\n'
- ' and there is at least one cased character, false '
- 'otherwise.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.join(iterable)\n'
- '\n'
- ' Return a string which is the concatenation of the '
- 'strings in the\n'
- ' *iterable* *iterable*. The separator between elements '
- 'is the\n'
- ' string providing this method.\n'
- '\n'
- 'str.ljust(width[, fillchar])\n'
- '\n'
- ' Return the string left justified in a string of length '
- '*width*.\n'
- ' Padding is done using the specified *fillchar* (default '
- 'is a\n'
- ' space). The original string is returned if *width* is '
- 'less than or\n'
- ' equal to "len(s)".\n'
- '\n'
- ' Changed in version 2.4: Support for the *fillchar* '
- 'argument.\n'
- '\n'
- 'str.lower()\n'
- '\n'
- ' Return a copy of the string with all the cased '
- 'characters [4]\n'
- ' converted to lowercase.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.lstrip([chars])\n'
- '\n'
- ' Return a copy of the string with leading characters '
- 'removed. The\n'
- ' *chars* argument is a string specifying the set of '
- 'characters to be\n'
- ' removed. If omitted or "None", the *chars* argument '
- 'defaults to\n'
- ' removing whitespace. The *chars* argument is not a '
- 'prefix; rather,\n'
- ' all combinations of its values are stripped:\n'
- '\n'
- " >>> ' spacious '.lstrip()\n"
- " 'spacious '\n"
- " >>> 'www.example.com'.lstrip('cmowz.')\n"
- " 'example.com'\n"
- '\n'
- ' Changed in version 2.2.2: Support for the *chars* '
- 'argument.\n'
- '\n'
- 'str.partition(sep)\n'
- '\n'
- ' Split the string at the first occurrence of *sep*, and '
- 'return a\n'
- ' 3-tuple containing the part before the separator, the '
- 'separator\n'
- ' itself, and the part after the separator. If the '
- 'separator is not\n'
- ' found, return a 3-tuple containing the string itself, '
- 'followed by\n'
- ' two empty strings.\n'
- '\n'
- ' New in version 2.5.\n'
- '\n'
- 'str.replace(old, new[, count])\n'
- '\n'
- ' Return a copy of the string with all occurrences of '
- 'substring *old*\n'
- ' replaced by *new*. If the optional argument *count* is '
- 'given, only\n'
- ' the first *count* occurrences are replaced.\n'
- '\n'
- 'str.rfind(sub[, start[, end]])\n'
- '\n'
- ' Return the highest index in the string where substring '
- '*sub* is\n'
- ' found, such that *sub* is contained within '
- '"s[start:end]".\n'
- ' Optional arguments *start* and *end* are interpreted as '
- 'in slice\n'
- ' notation. Return "-1" on failure.\n'
- '\n'
- 'str.rindex(sub[, start[, end]])\n'
- '\n'
- ' Like "rfind()" but raises "ValueError" when the '
- 'substring *sub* is\n'
- ' not found.\n'
- '\n'
- 'str.rjust(width[, fillchar])\n'
- '\n'
- ' Return the string right justified in a string of length '
- '*width*.\n'
- ' Padding is done using the specified *fillchar* (default '
- 'is a\n'
- ' space). The original string is returned if *width* is '
- 'less than or\n'
- ' equal to "len(s)".\n'
- '\n'
- ' Changed in version 2.4: Support for the *fillchar* '
- 'argument.\n'
- '\n'
- 'str.rpartition(sep)\n'
- '\n'
- ' Split the string at the last occurrence of *sep*, and '
- 'return a\n'
- ' 3-tuple containing the part before the separator, the '
- 'separator\n'
- ' itself, and the part after the separator. If the '
- 'separator is not\n'
- ' found, return a 3-tuple containing two empty strings, '
- 'followed by\n'
- ' the string itself.\n'
- '\n'
- ' New in version 2.5.\n'
- '\n'
- 'str.rsplit([sep[, maxsplit]])\n'
- '\n'
- ' Return a list of the words in the string, using *sep* '
- 'as the\n'
- ' delimiter string. If *maxsplit* is given, at most '
- '*maxsplit* splits\n'
- ' are done, the *rightmost* ones. If *sep* is not '
- 'specified or\n'
- ' "None", any whitespace string is a separator. Except '
- 'for splitting\n'
- ' from the right, "rsplit()" behaves like "split()" which '
- 'is\n'
- ' described in detail below.\n'
- '\n'
- ' New in version 2.4.\n'
- '\n'
- 'str.rstrip([chars])\n'
- '\n'
- ' Return a copy of the string with trailing characters '
- 'removed. The\n'
- ' *chars* argument is a string specifying the set of '
- 'characters to be\n'
- ' removed. If omitted or "None", the *chars* argument '
- 'defaults to\n'
- ' removing whitespace. The *chars* argument is not a '
- 'suffix; rather,\n'
- ' all combinations of its values are stripped:\n'
- '\n'
- " >>> ' spacious '.rstrip()\n"
- " ' spacious'\n"
- " >>> 'mississippi'.rstrip('ipz')\n"
- " 'mississ'\n"
- '\n'
- ' Changed in version 2.2.2: Support for the *chars* '
- 'argument.\n'
- '\n'
- 'str.split([sep[, maxsplit]])\n'
- '\n'
- ' Return a list of the words in the string, using *sep* '
- 'as the\n'
- ' delimiter string. If *maxsplit* is given, at most '
- '*maxsplit*\n'
- ' splits are done (thus, the list will have at most '
- '"maxsplit+1"\n'
- ' elements). If *maxsplit* is not specified or "-1", '
- 'then there is\n'
- ' no limit on the number of splits (all possible splits '
- 'are made).\n'
- '\n'
- ' If *sep* is given, consecutive delimiters are not '
- 'grouped together\n'
- ' and are deemed to delimit empty strings (for example,\n'
- ' "\'1,,2\'.split(\',\')" returns "[\'1\', \'\', '
- '\'2\']"). The *sep* argument\n'
- ' may consist of multiple characters (for example,\n'
- ' "\'1<>2<>3\'.split(\'<>\')" returns "[\'1\', \'2\', '
- '\'3\']"). Splitting an\n'
- ' empty string with a specified separator returns '
- '"[\'\']".\n'
- '\n'
- ' If *sep* is not specified or is "None", a different '
- 'splitting\n'
- ' algorithm is applied: runs of consecutive whitespace '
- 'are regarded\n'
- ' as a single separator, and the result will contain no '
- 'empty strings\n'
- ' at the start or end if the string has leading or '
- 'trailing\n'
- ' whitespace. Consequently, splitting an empty string or '
- 'a string\n'
- ' consisting of just whitespace with a "None" separator '
- 'returns "[]".\n'
- '\n'
- ' For example, "\' 1 2 3 \'.split()" returns "[\'1\', '
- '\'2\', \'3\']", and\n'
- ' "\' 1 2 3 \'.split(None, 1)" returns "[\'1\', '
- '\'2 3 \']".\n'
- '\n'
- 'str.splitlines([keepends])\n'
- '\n'
- ' Return a list of the lines in the string, breaking at '
- 'line\n'
- ' boundaries. This method uses the *universal newlines* '
- 'approach to\n'
- ' splitting lines. Line breaks are not included in the '
- 'resulting list\n'
- ' unless *keepends* is given and true.\n'
- '\n'
- ' For example, "\'ab c\\n\\nde '
- 'fg\\rkl\\r\\n\'.splitlines()" returns "[\'ab\n'
- ' c\', \'\', \'de fg\', \'kl\']", while the same call '
- 'with\n'
- ' "splitlines(True)" returns "[\'ab c\\n\', \'\\n\', \'de '
- 'fg\\r\', \'kl\\r\\n\']".\n'
- '\n'
- ' Unlike "split()" when a delimiter string *sep* is '
- 'given, this\n'
- ' method returns an empty list for the empty string, and '
- 'a terminal\n'
- ' line break does not result in an extra line.\n'
- '\n'
- 'str.startswith(prefix[, start[, end]])\n'
- '\n'
- ' Return "True" if string starts with the *prefix*, '
- 'otherwise return\n'
- ' "False". *prefix* can also be a tuple of prefixes to '
- 'look for.\n'
- ' With optional *start*, test string beginning at that '
- 'position.\n'
- ' With optional *end*, stop comparing string at that '
- 'position.\n'
- '\n'
- ' Changed in version 2.5: Accept tuples as *prefix*.\n'
- '\n'
- 'str.strip([chars])\n'
- '\n'
- ' Return a copy of the string with the leading and '
- 'trailing\n'
- ' characters removed. The *chars* argument is a string '
- 'specifying the\n'
- ' set of characters to be removed. If omitted or "None", '
- 'the *chars*\n'
- ' argument defaults to removing whitespace. The *chars* '
- 'argument is\n'
- ' not a prefix or suffix; rather, all combinations of its '
- 'values are\n'
- ' stripped:\n'
- '\n'
- " >>> ' spacious '.strip()\n"
- " 'spacious'\n"
- " >>> 'www.example.com'.strip('cmowz.')\n"
- " 'example'\n"
- '\n'
- ' Changed in version 2.2.2: Support for the *chars* '
- 'argument.\n'
- '\n'
- 'str.swapcase()\n'
- '\n'
- ' Return a copy of the string with uppercase characters '
- 'converted to\n'
- ' lowercase and vice versa.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.title()\n'
- '\n'
- ' Return a titlecased version of the string where words '
- 'start with an\n'
- ' uppercase character and the remaining characters are '
- 'lowercase.\n'
- '\n'
- ' The algorithm uses a simple language-independent '
- 'definition of a\n'
- ' word as groups of consecutive letters. The definition '
- 'works in\n'
- ' many contexts but it means that apostrophes in '
- 'contractions and\n'
- ' possessives form word boundaries, which may not be the '
- 'desired\n'
- ' result:\n'
- '\n'
- ' >>> "they\'re bill\'s friends from the UK".title()\n'
- ' "They\'Re Bill\'S Friends From The Uk"\n'
- '\n'
- ' A workaround for apostrophes can be constructed using '
- 'regular\n'
- ' expressions:\n'
- '\n'
- ' >>> import re\n'
- ' >>> def titlecase(s):\n'
- ' ... return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n'
- ' ... lambda mo: '
- 'mo.group(0)[0].upper() +\n'
- ' ... '
- 'mo.group(0)[1:].lower(),\n'
- ' ... s)\n'
- ' ...\n'
- ' >>> titlecase("they\'re bill\'s friends.")\n'
- ' "They\'re Bill\'s Friends."\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.translate(table[, deletechars])\n'
- '\n'
- ' Return a copy of the string where all characters '
- 'occurring in the\n'
- ' optional argument *deletechars* are removed, and the '
- 'remaining\n'
- ' characters have been mapped through the given '
- 'translation table,\n'
- ' which must be a string of length 256.\n'
- '\n'
- ' You can use the "maketrans()" helper function in the '
- '"string"\n'
- ' module to create a translation table. For string '
- 'objects, set the\n'
- ' *table* argument to "None" for translations that only '
- 'delete\n'
- ' characters:\n'
- '\n'
- " >>> 'read this short text'.translate(None, 'aeiou')\n"
- " 'rd ths shrt txt'\n"
- '\n'
- ' New in version 2.6: Support for a "None" *table* '
- 'argument.\n'
- '\n'
- ' For Unicode objects, the "translate()" method does not '
- 'accept the\n'
- ' optional *deletechars* argument. Instead, it returns a '
- 'copy of the\n'
- ' *s* where all characters have been mapped through the '
- 'given\n'
- ' translation table which must be a mapping of Unicode '
- 'ordinals to\n'
- ' Unicode ordinals, Unicode strings or "None". Unmapped '
- 'characters\n'
- ' are left untouched. Characters mapped to "None" are '
- 'deleted. Note,\n'
- ' a more flexible approach is to create a custom '
- 'character mapping\n'
- ' codec using the "codecs" module (see "encodings.cp1251" '
- 'for an\n'
- ' example).\n'
- '\n'
- 'str.upper()\n'
- '\n'
- ' Return a copy of the string with all the cased '
- 'characters [4]\n'
- ' converted to uppercase. Note that '
- '"str.upper().isupper()" might be\n'
- ' "False" if "s" contains uncased characters or if the '
- 'Unicode\n'
- ' category of the resulting character(s) is not "Lu" '
- '(Letter,\n'
- ' uppercase), but e.g. "Lt" (Letter, titlecase).\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.zfill(width)\n'
- '\n'
- ' Return the numeric string left filled with zeros in a '
- 'string of\n'
- ' length *width*. A sign prefix is handled correctly. '
- 'The original\n'
- ' string is returned if *width* is less than or equal to '
- '"len(s)".\n'
- '\n'
- ' New in version 2.2.2.\n'
- '\n'
- 'The following methods are present only on unicode '
- 'objects:\n'
- '\n'
- 'unicode.isnumeric()\n'
- '\n'
- ' Return "True" if there are only numeric characters in '
- 'S, "False"\n'
- ' otherwise. Numeric characters include digit characters, '
- 'and all\n'
- ' characters that have the Unicode numeric value '
- 'property, e.g.\n'
- ' U+2155, VULGAR FRACTION ONE FIFTH.\n'
- '\n'
- 'unicode.isdecimal()\n'
- '\n'
- ' Return "True" if there are only decimal characters in '
- 'S, "False"\n'
- ' otherwise. Decimal characters include digit characters, '
- 'and all\n'
- ' characters that can be used to form decimal-radix '
- 'numbers, e.g.\n'
- ' U+0660, ARABIC-INDIC DIGIT ZERO.\n',
- 'strings': '\n'
- 'String literals\n'
- '***************\n'
- '\n'
- 'String literals are described by the following lexical '
- 'definitions:\n'
- '\n'
- ' stringliteral ::= [stringprefix](shortstring | longstring)\n'
- ' stringprefix ::= "r" | "u" | "ur" | "R" | "U" | "UR" | "Ur" '
- '| "uR"\n'
- ' | "b" | "B" | "br" | "Br" | "bR" | "BR"\n'
- ' shortstring ::= "\'" shortstringitem* "\'" | \'"\' '
- 'shortstringitem* \'"\'\n'
- ' longstring ::= "\'\'\'" longstringitem* "\'\'\'"\n'
- ' | \'"""\' longstringitem* \'"""\'\n'
- ' shortstringitem ::= shortstringchar | escapeseq\n'
- ' longstringitem ::= longstringchar | escapeseq\n'
- ' shortstringchar ::= <any source character except "\\" or '
- 'newline or the quote>\n'
- ' longstringchar ::= <any source character except "\\">\n'
- ' escapeseq ::= "\\" <any ASCII character>\n'
- '\n'
- 'One syntactic restriction not indicated by these productions is '
- 'that\n'
- 'whitespace is not allowed between the "stringprefix" and the rest '
- 'of\n'
- 'the string literal. The source character set is defined by the\n'
- 'encoding declaration; it is ASCII if no encoding declaration is '
- 'given\n'
- 'in the source file; see section Encoding declarations.\n'
- '\n'
- 'In plain English: String literals can be enclosed in matching '
- 'single\n'
- 'quotes ("\'") or double quotes ("""). They can also be enclosed '
- 'in\n'
- 'matching groups of three single or double quotes (these are '
- 'generally\n'
- 'referred to as *triple-quoted strings*). The backslash ("\\")\n'
- 'character is used to escape characters that otherwise have a '
- 'special\n'
- 'meaning, such as newline, backslash itself, or the quote '
- 'character.\n'
- 'String literals may optionally be prefixed with a letter "\'r\'" '
- 'or\n'
- '"\'R\'"; such strings are called *raw strings* and use different '
- 'rules\n'
- 'for interpreting backslash escape sequences. A prefix of "\'u\'" '
- 'or\n'
- '"\'U\'" makes the string a Unicode string. Unicode strings use '
- 'the\n'
- 'Unicode character set as defined by the Unicode Consortium and '
- 'ISO\n'
- '10646. Some additional escape sequences, described below, are\n'
- 'available in Unicode strings. A prefix of "\'b\'" or "\'B\'" is '
- 'ignored in\n'
- 'Python 2; it indicates that the literal should become a bytes '
- 'literal\n'
- 'in Python 3 (e.g. when code is automatically converted with '
- '2to3). A\n'
- '"\'u\'" or "\'b\'" prefix may be followed by an "\'r\'" prefix.\n'
- '\n'
- 'In triple-quoted strings, unescaped newlines and quotes are '
- 'allowed\n'
- '(and are retained), except that three unescaped quotes in a row\n'
- 'terminate the string. (A "quote" is the character used to open '
- 'the\n'
- 'string, i.e. either "\'" or """.)\n'
- '\n'
- 'Unless an "\'r\'" or "\'R\'" prefix is present, escape sequences '
- 'in\n'
- 'strings are interpreted according to rules similar to those used '
- 'by\n'
- 'Standard C. The recognized escape sequences are:\n'
- '\n'
- '+-------------------+-----------------------------------+---------+\n'
- '| Escape Sequence | Meaning | Notes '
- '|\n'
- '+===================+===================================+=========+\n'
- '| "\\newline" | Ignored '
- '| |\n'
- '+-------------------+-----------------------------------+---------+\n'
- '| "\\\\" | Backslash ("\\") '
- '| |\n'
- '+-------------------+-----------------------------------+---------+\n'
- '| "\\\'" | Single quote ("\'") '
- '| |\n'
- '+-------------------+-----------------------------------+---------+\n'
- '| "\\"" | Double quote (""") '
- '| |\n'
- '+-------------------+-----------------------------------+---------+\n'
- '| "\\a" | ASCII Bell (BEL) '
- '| |\n'
- '+-------------------+-----------------------------------+---------+\n'
- '| "\\b" | ASCII Backspace (BS) '
- '| |\n'
- '+-------------------+-----------------------------------+---------+\n'
- '| "\\f" | ASCII Formfeed (FF) '
- '| |\n'
- '+-------------------+-----------------------------------+---------+\n'
- '| "\\n" | ASCII Linefeed (LF) '
- '| |\n'
- '+-------------------+-----------------------------------+---------+\n'
- '| "\\N{name}" | Character named *name* in the '
- '| |\n'
- '| | Unicode database (Unicode only) | '
- '|\n'
- '+-------------------+-----------------------------------+---------+\n'
- '| "\\r" | ASCII Carriage Return (CR) '
- '| |\n'
- '+-------------------+-----------------------------------+---------+\n'
- '| "\\t" | ASCII Horizontal Tab (TAB) '
- '| |\n'
- '+-------------------+-----------------------------------+---------+\n'
- '| "\\uxxxx" | Character with 16-bit hex value | '
- '(1) |\n'
- '| | *xxxx* (Unicode only) | '
- '|\n'
- '+-------------------+-----------------------------------+---------+\n'
- '| "\\Uxxxxxxxx" | Character with 32-bit hex value | '
- '(2) |\n'
- '| | *xxxxxxxx* (Unicode only) | '
- '|\n'
- '+-------------------+-----------------------------------+---------+\n'
- '| "\\v" | ASCII Vertical Tab (VT) '
- '| |\n'
- '+-------------------+-----------------------------------+---------+\n'
- '| "\\ooo" | Character with octal value *ooo* | '
- '(3,5) |\n'
- '+-------------------+-----------------------------------+---------+\n'
- '| "\\xhh" | Character with hex value *hh* | '
- '(4,5) |\n'
- '+-------------------+-----------------------------------+---------+\n'
- '\n'
- 'Notes:\n'
- '\n'
- '1. Individual code units which form parts of a surrogate pair '
- 'can\n'
- ' be encoded using this escape sequence.\n'
- '\n'
- '2. Any Unicode character can be encoded this way, but characters\n'
- ' outside the Basic Multilingual Plane (BMP) will be encoded '
- 'using a\n'
- ' surrogate pair if Python is compiled to use 16-bit code units '
- '(the\n'
- ' default).\n'
- '\n'
- '3. As in Standard C, up to three octal digits are accepted.\n'
- '\n'
- '4. Unlike in Standard C, exactly two hex digits are required.\n'
- '\n'
- '5. In a string literal, hexadecimal and octal escapes denote the\n'
- ' byte with the given value; it is not necessary that the byte\n'
- ' encodes a character in the source character set. In a Unicode\n'
- ' literal, these escapes denote a Unicode character with the '
- 'given\n'
- ' value.\n'
- '\n'
- 'Unlike Standard C, all unrecognized escape sequences are left in '
- 'the\n'
- 'string unchanged, i.e., *the backslash is left in the string*. '
- '(This\n'
- 'behavior is useful when debugging: if an escape sequence is '
- 'mistyped,\n'
- 'the resulting output is more easily recognized as broken.) It is '
- 'also\n'
- 'important to note that the escape sequences marked as "(Unicode '
- 'only)"\n'
- 'in the table above fall into the category of unrecognized escapes '
- 'for\n'
- 'non-Unicode string literals.\n'
- '\n'
- 'When an "\'r\'" or "\'R\'" prefix is present, a character '
- 'following a\n'
- 'backslash is included in the string without change, and *all\n'
- 'backslashes are left in the string*. For example, the string '
- 'literal\n'
- '"r"\\n"" consists of two characters: a backslash and a lowercase '
- '"\'n\'".\n'
- 'String quotes can be escaped with a backslash, but the backslash\n'
- 'remains in the string; for example, "r"\\""" is a valid string '
- 'literal\n'
- 'consisting of two characters: a backslash and a double quote; '
- '"r"\\""\n'
- 'is not a valid string literal (even a raw string cannot end in an '
- 'odd\n'
- 'number of backslashes). Specifically, *a raw string cannot end '
- 'in a\n'
- 'single backslash* (since the backslash would escape the '
- 'following\n'
- 'quote character). Note also that a single backslash followed by '
- 'a\n'
- 'newline is interpreted as those two characters as part of the '
- 'string,\n'
- '*not* as a line continuation.\n'
- '\n'
- 'When an "\'r\'" or "\'R\'" prefix is used in conjunction with a '
- '"\'u\'" or\n'
- '"\'U\'" prefix, then the "\\uXXXX" and "\\UXXXXXXXX" escape '
- 'sequences are\n'
- 'processed while *all other backslashes are left in the string*. '
- 'For\n'
- 'example, the string literal "ur"\\u0062\\n"" consists of three '
- 'Unicode\n'
- "characters: 'LATIN SMALL LETTER B', 'REVERSE SOLIDUS', and "
- "'LATIN\n"
- "SMALL LETTER N'. Backslashes can be escaped with a preceding\n"
- 'backslash; however, both remain in the string. As a result, '
- '"\\uXXXX"\n'
- 'escape sequences are only recognized when there are an odd number '
- 'of\n'
- 'backslashes.\n',
- 'subscriptions': '\n'
- 'Subscriptions\n'
- '*************\n'
- '\n'
- 'A subscription selects an item of a sequence (string, tuple '
- 'or list)\n'
- 'or mapping (dictionary) object:\n'
- '\n'
- ' subscription ::= primary "[" expression_list "]"\n'
- '\n'
- 'The primary must evaluate to an object of a sequence or '
- 'mapping type.\n'
- '\n'
- 'If the primary is a mapping, the expression list must '
- 'evaluate to an\n'
- 'object whose value is one of the keys of the mapping, and '
- 'the\n'
- 'subscription selects the value in the mapping that '
- 'corresponds to that\n'
- 'key. (The expression list is a tuple except if it has '
- 'exactly one\n'
- 'item.)\n'
- '\n'
- 'If the primary is a sequence, the expression (list) must '
- 'evaluate to a\n'
- 'plain integer. If this value is negative, the length of '
- 'the sequence\n'
- 'is added to it (so that, e.g., "x[-1]" selects the last '
- 'item of "x".)\n'
- 'The resulting value must be a nonnegative integer less than '
- 'the number\n'
- 'of items in the sequence, and the subscription selects the '
- 'item whose\n'
- 'index is that value (counting from zero).\n'
- '\n'
- "A string's items are characters. A character is not a "
- 'separate data\n'
- 'type but a string of exactly one character.\n',
- 'truth': '\n'
- 'Truth Value Testing\n'
- '*******************\n'
- '\n'
- 'Any object can be tested for truth value, for use in an "if" or\n'
- '"while" condition or as operand of the Boolean operations below. '
- 'The\n'
- 'following values are considered false:\n'
- '\n'
- '* "None"\n'
- '\n'
- '* "False"\n'
- '\n'
- '* zero of any numeric type, for example, "0", "0L", "0.0", "0j".\n'
- '\n'
- '* any empty sequence, for example, "\'\'", "()", "[]".\n'
- '\n'
- '* any empty mapping, for example, "{}".\n'
- '\n'
- '* instances of user-defined classes, if the class defines a\n'
- ' "__nonzero__()" or "__len__()" method, when that method returns '
- 'the\n'
- ' integer zero or "bool" value "False". [1]\n'
- '\n'
- 'All other values are considered true --- so objects of many types '
- 'are\n'
- 'always true.\n'
- '\n'
- 'Operations and built-in functions that have a Boolean result '
- 'always\n'
- 'return "0" or "False" for false and "1" or "True" for true, unless\n'
- 'otherwise stated. (Important exception: the Boolean operations '
- '"or"\n'
- 'and "and" always return one of their operands.)\n',
- 'try': '\n'
- 'The "try" statement\n'
- '*******************\n'
- '\n'
- 'The "try" statement specifies exception handlers and/or cleanup code\n'
- 'for a group of statements:\n'
- '\n'
- ' try_stmt ::= try1_stmt | try2_stmt\n'
- ' try1_stmt ::= "try" ":" suite\n'
- ' ("except" [expression [("as" | ",") identifier]] ":" '
- 'suite)+\n'
- ' ["else" ":" suite]\n'
- ' ["finally" ":" suite]\n'
- ' try2_stmt ::= "try" ":" suite\n'
- ' "finally" ":" suite\n'
- '\n'
- 'Changed in version 2.5: In previous versions of Python,\n'
- '"try"..."except"..."finally" did not work. "try"..."except" had to '
- 'be\n'
- 'nested in "try"..."finally".\n'
- '\n'
- 'The "except" clause(s) specify one or more exception handlers. When '
- 'no\n'
- 'exception occurs in the "try" clause, no exception handler is\n'
- 'executed. When an exception occurs in the "try" suite, a search for '
- 'an\n'
- 'exception handler is started. This search inspects the except '
- 'clauses\n'
- 'in turn until one is found that matches the exception. An '
- 'expression-\n'
- 'less except clause, if present, must be last; it matches any\n'
- 'exception. For an except clause with an expression, that expression\n'
- 'is evaluated, and the clause matches the exception if the resulting\n'
- 'object is "compatible" with the exception. An object is compatible\n'
- 'with an exception if it is the class or a base class of the '
- 'exception\n'
- 'object, or a tuple containing an item compatible with the exception.\n'
- '\n'
- 'If no except clause matches the exception, the search for an '
- 'exception\n'
- 'handler continues in the surrounding code and on the invocation '
- 'stack.\n'
- '[1]\n'
- '\n'
- 'If the evaluation of an expression in the header of an except clause\n'
- 'raises an exception, the original search for a handler is canceled '
- 'and\n'
- 'a search starts for the new exception in the surrounding code and on\n'
- 'the call stack (it is treated as if the entire "try" statement '
- 'raised\n'
- 'the exception).\n'
- '\n'
- 'When a matching except clause is found, the exception is assigned to\n'
- 'the target specified in that except clause, if present, and the '
- 'except\n'
- "clause's suite is executed. All except clauses must have an\n"
- 'executable block. When the end of this block is reached, execution\n'
- 'continues normally after the entire try statement. (This means that\n'
- 'if two nested handlers exist for the same exception, and the '
- 'exception\n'
- 'occurs in the try clause of the inner handler, the outer handler '
- 'will\n'
- 'not handle the exception.)\n'
- '\n'
- "Before an except clause's suite is executed, details about the\n"
- 'exception are assigned to three variables in the "sys" module:\n'
- '"sys.exc_type" receives the object identifying the exception;\n'
- '"sys.exc_value" receives the exception\'s parameter;\n'
- '"sys.exc_traceback" receives a traceback object (see section The\n'
- 'standard type hierarchy) identifying the point in the program where\n'
- 'the exception occurred. These details are also available through the\n'
- '"sys.exc_info()" function, which returns a tuple "(exc_type,\n'
- 'exc_value, exc_traceback)". Use of the corresponding variables is\n'
- 'deprecated in favor of this function, since their use is unsafe in a\n'
- 'threaded program. As of Python 1.5, the variables are restored to\n'
- 'their previous values (before the call) when returning from a '
- 'function\n'
- 'that handled an exception.\n'
- '\n'
- 'The optional "else" clause is executed if and when control flows off\n'
- 'the end of the "try" clause. [2] Exceptions in the "else" clause are\n'
- 'not handled by the preceding "except" clauses.\n'
- '\n'
- 'If "finally" is present, it specifies a \'cleanup\' handler. The '
- '"try"\n'
- 'clause is executed, including any "except" and "else" clauses. If '
- 'an\n'
- 'exception occurs in any of the clauses and is not handled, the\n'
- 'exception is temporarily saved. The "finally" clause is executed. '
- 'If\n'
- 'there is a saved exception, it is re-raised at the end of the\n'
- '"finally" clause. If the "finally" clause raises another exception '
- 'or\n'
- 'executes a "return" or "break" statement, the saved exception is\n'
- 'discarded:\n'
- '\n'
- ' >>> def f():\n'
- ' ... try:\n'
- ' ... 1/0\n'
- ' ... finally:\n'
- ' ... return 42\n'
- ' ...\n'
- ' >>> f()\n'
- ' 42\n'
- '\n'
- 'The exception information is not available to the program during\n'
- 'execution of the "finally" clause.\n'
- '\n'
- 'When a "return", "break" or "continue" statement is executed in the\n'
- '"try" suite of a "try"..."finally" statement, the "finally" clause '
- 'is\n'
- 'also executed \'on the way out.\' A "continue" statement is illegal '
- 'in\n'
- 'the "finally" clause. (The reason is a problem with the current\n'
- 'implementation --- this restriction may be lifted in the future).\n'
- '\n'
- 'The return value of a function is determined by the last "return"\n'
- 'statement executed. Since the "finally" clause always executes, a\n'
- '"return" statement executed in the "finally" clause will always be '
- 'the\n'
- 'last one executed:\n'
- '\n'
- ' >>> def foo():\n'
- ' ... try:\n'
- " ... return 'try'\n"
- ' ... finally:\n'
- " ... return 'finally'\n"
- ' ...\n'
- ' >>> foo()\n'
- " 'finally'\n"
- '\n'
- 'Additional information on exceptions can be found in section\n'
- 'Exceptions, and information on using the "raise" statement to '
- 'generate\n'
- 'exceptions may be found in section The raise statement.\n',
- 'types': '\n'
- 'The standard type hierarchy\n'
- '***************************\n'
- '\n'
- 'Below is a list of the types that are built into Python. '
- 'Extension\n'
- 'modules (written in C, Java, or other languages, depending on the\n'
- 'implementation) can define additional types. Future versions of\n'
- 'Python may add types to the type hierarchy (e.g., rational '
- 'numbers,\n'
- 'efficiently stored arrays of integers, etc.).\n'
- '\n'
- 'Some of the type descriptions below contain a paragraph listing\n'
- "'special attributes.' These are attributes that provide access to "
- 'the\n'
- 'implementation and are not intended for general use. Their '
- 'definition\n'
- 'may change in the future.\n'
- '\n'
- 'None\n'
- ' This type has a single value. There is a single object with '
- 'this\n'
- ' value. This object is accessed through the built-in name "None". '
- 'It\n'
- ' is used to signify the absence of a value in many situations, '
- 'e.g.,\n'
- " it is returned from functions that don't explicitly return\n"
- ' anything. Its truth value is false.\n'
- '\n'
- 'NotImplemented\n'
- ' This type has a single value. There is a single object with '
- 'this\n'
- ' value. This object is accessed through the built-in name\n'
- ' "NotImplemented". Numeric methods and rich comparison methods '
- 'may\n'
- ' return this value if they do not implement the operation for '
- 'the\n'
- ' operands provided. (The interpreter will then try the '
- 'reflected\n'
- ' operation, or some other fallback, depending on the operator.) '
- 'Its\n'
- ' truth value is true.\n'
- '\n'
- 'Ellipsis\n'
- ' This type has a single value. There is a single object with '
- 'this\n'
- ' value. This object is accessed through the built-in name\n'
- ' "Ellipsis". It is used to indicate the presence of the "..." '
- 'syntax\n'
- ' in a slice. Its truth value is true.\n'
- '\n'
- '"numbers.Number"\n'
- ' These are created by numeric literals and returned as results '
- 'by\n'
- ' arithmetic operators and arithmetic built-in functions. '
- 'Numeric\n'
- ' objects are immutable; once created their value never changes.\n'
- ' Python numbers are of course strongly related to mathematical\n'
- ' numbers, but subject to the limitations of numerical '
- 'representation\n'
- ' in computers.\n'
- '\n'
- ' Python distinguishes between integers, floating point numbers, '
- 'and\n'
- ' complex numbers:\n'
- '\n'
- ' "numbers.Integral"\n'
- ' These represent elements from the mathematical set of '
- 'integers\n'
- ' (positive and negative).\n'
- '\n'
- ' There are three types of integers:\n'
- '\n'
- ' Plain integers\n'
- ' These represent numbers in the range -2147483648 through\n'
- ' 2147483647. (The range may be larger on machines with a\n'
- ' larger natural word size, but not smaller.) When the '
- 'result\n'
- ' of an operation would fall outside this range, the result '
- 'is\n'
- ' normally returned as a long integer (in some cases, the\n'
- ' exception "OverflowError" is raised instead). For the\n'
- ' purpose of shift and mask operations, integers are assumed '
- 'to\n'
- " have a binary, 2's complement notation using 32 or more "
- 'bits,\n'
- ' and hiding no bits from the user (i.e., all 4294967296\n'
- ' different bit patterns correspond to different values).\n'
- '\n'
- ' Long integers\n'
- ' These represent numbers in an unlimited range, subject to\n'
- ' available (virtual) memory only. For the purpose of '
- 'shift\n'
- ' and mask operations, a binary representation is assumed, '
- 'and\n'
- " negative numbers are represented in a variant of 2's\n"
- ' complement which gives the illusion of an infinite string '
- 'of\n'
- ' sign bits extending to the left.\n'
- '\n'
- ' Booleans\n'
- ' These represent the truth values False and True. The two\n'
- ' objects representing the values "False" and "True" are '
- 'the\n'
- ' only Boolean objects. The Boolean type is a subtype of '
- 'plain\n'
- ' integers, and Boolean values behave like the values 0 and '
- '1,\n'
- ' respectively, in almost all contexts, the exception being\n'
- ' that when converted to a string, the strings ""False"" or\n'
- ' ""True"" are returned, respectively.\n'
- '\n'
- ' The rules for integer representation are intended to give '
- 'the\n'
- ' most meaningful interpretation of shift and mask operations\n'
- ' involving negative integers and the least surprises when\n'
- ' switching between the plain and long integer domains. Any\n'
- ' operation, if it yields a result in the plain integer '
- 'domain,\n'
- ' will yield the same result in the long integer domain or '
- 'when\n'
- ' using mixed operands. The switch between domains is '
- 'transparent\n'
- ' to the programmer.\n'
- '\n'
- ' "numbers.Real" ("float")\n'
- ' These represent machine-level double precision floating '
- 'point\n'
- ' numbers. You are at the mercy of the underlying machine\n'
- ' architecture (and C or Java implementation) for the accepted\n'
- ' range and handling of overflow. Python does not support '
- 'single-\n'
- ' precision floating point numbers; the savings in processor '
- 'and\n'
- ' memory usage that are usually the reason for using these are\n'
- ' dwarfed by the overhead of using objects in Python, so there '
- 'is\n'
- ' no reason to complicate the language with two kinds of '
- 'floating\n'
- ' point numbers.\n'
- '\n'
- ' "numbers.Complex"\n'
- ' These represent complex numbers as a pair of machine-level\n'
- ' double precision floating point numbers. The same caveats '
- 'apply\n'
- ' as for floating point numbers. The real and imaginary parts '
- 'of a\n'
- ' complex number "z" can be retrieved through the read-only\n'
- ' attributes "z.real" and "z.imag".\n'
- '\n'
- 'Sequences\n'
- ' These represent finite ordered sets indexed by non-negative\n'
- ' numbers. The built-in function "len()" returns the number of '
- 'items\n'
- ' of a sequence. When the length of a sequence is *n*, the index '
- 'set\n'
- ' contains the numbers 0, 1, ..., *n*-1. Item *i* of sequence *a* '
- 'is\n'
- ' selected by "a[i]".\n'
- '\n'
- ' Sequences also support slicing: "a[i:j]" selects all items with\n'
- ' index *k* such that *i* "<=" *k* "<" *j*. When used as an\n'
- ' expression, a slice is a sequence of the same type. This '
- 'implies\n'
- ' that the index set is renumbered so that it starts at 0.\n'
- '\n'
- ' Some sequences also support "extended slicing" with a third '
- '"step"\n'
- ' parameter: "a[i:j:k]" selects all items of *a* with index *x* '
- 'where\n'
- ' "x = i + n*k", *n* ">=" "0" and *i* "<=" *x* "<" *j*.\n'
- '\n'
- ' Sequences are distinguished according to their mutability:\n'
- '\n'
- ' Immutable sequences\n'
- ' An object of an immutable sequence type cannot change once it '
- 'is\n'
- ' created. (If the object contains references to other '
- 'objects,\n'
- ' these other objects may be mutable and may be changed; '
- 'however,\n'
- ' the collection of objects directly referenced by an '
- 'immutable\n'
- ' object cannot change.)\n'
- '\n'
- ' The following types are immutable sequences:\n'
- '\n'
- ' Strings\n'
- ' The items of a string are characters. There is no '
- 'separate\n'
- ' character type; a character is represented by a string of '
- 'one\n'
- ' item. Characters represent (at least) 8-bit bytes. The\n'
- ' built-in functions "chr()" and "ord()" convert between\n'
- ' characters and nonnegative integers representing the byte\n'
- ' values. Bytes with the values 0-127 usually represent '
- 'the\n'
- ' corresponding ASCII values, but the interpretation of '
- 'values\n'
- ' is up to the program. The string data type is also used '
- 'to\n'
- ' represent arrays of bytes, e.g., to hold data read from a\n'
- ' file.\n'
- '\n'
- ' (On systems whose native character set is not ASCII, '
- 'strings\n'
- ' may use EBCDIC in their internal representation, provided '
- 'the\n'
- ' functions "chr()" and "ord()" implement a mapping between\n'
- ' ASCII and EBCDIC, and string comparison preserves the '
- 'ASCII\n'
- ' order. Or perhaps someone can propose a better rule?)\n'
- '\n'
- ' Unicode\n'
- ' The items of a Unicode object are Unicode code units. A\n'
- ' Unicode code unit is represented by a Unicode object of '
- 'one\n'
- ' item and can hold either a 16-bit or 32-bit value\n'
- ' representing a Unicode ordinal (the maximum value for the\n'
- ' ordinal is given in "sys.maxunicode", and depends on how\n'
- ' Python is configured at compile time). Surrogate pairs '
- 'may\n'
- ' be present in the Unicode object, and will be reported as '
- 'two\n'
- ' separate items. The built-in functions "unichr()" and\n'
- ' "ord()" convert between code units and nonnegative '
- 'integers\n'
- ' representing the Unicode ordinals as defined in the '
- 'Unicode\n'
- ' Standard 3.0. Conversion from and to other encodings are\n'
- ' possible through the Unicode method "encode()" and the '
- 'built-\n'
- ' in function "unicode()".\n'
- '\n'
- ' Tuples\n'
- ' The items of a tuple are arbitrary Python objects. Tuples '
- 'of\n'
- ' two or more items are formed by comma-separated lists of\n'
- " expressions. A tuple of one item (a 'singleton') can be\n"
- ' formed by affixing a comma to an expression (an expression '
- 'by\n'
- ' itself does not create a tuple, since parentheses must be\n'
- ' usable for grouping of expressions). An empty tuple can '
- 'be\n'
- ' formed by an empty pair of parentheses.\n'
- '\n'
- ' Mutable sequences\n'
- ' Mutable sequences can be changed after they are created. '
- 'The\n'
- ' subscription and slicing notations can be used as the target '
- 'of\n'
- ' assignment and "del" (delete) statements.\n'
- '\n'
- ' There are currently two intrinsic mutable sequence types:\n'
- '\n'
- ' Lists\n'
- ' The items of a list are arbitrary Python objects. Lists '
- 'are\n'
- ' formed by placing a comma-separated list of expressions '
- 'in\n'
- ' square brackets. (Note that there are no special cases '
- 'needed\n'
- ' to form lists of length 0 or 1.)\n'
- '\n'
- ' Byte Arrays\n'
- ' A bytearray object is a mutable array. They are created '
- 'by\n'
- ' the built-in "bytearray()" constructor. Aside from being\n'
- ' mutable (and hence unhashable), byte arrays otherwise '
- 'provide\n'
- ' the same interface and functionality as immutable bytes\n'
- ' objects.\n'
- '\n'
- ' The extension module "array" provides an additional example '
- 'of a\n'
- ' mutable sequence type.\n'
- '\n'
- 'Set types\n'
- ' These represent unordered, finite sets of unique, immutable\n'
- ' objects. As such, they cannot be indexed by any subscript. '
- 'However,\n'
- ' they can be iterated over, and the built-in function "len()"\n'
- ' returns the number of items in a set. Common uses for sets are '
- 'fast\n'
- ' membership testing, removing duplicates from a sequence, and\n'
- ' computing mathematical operations such as intersection, union,\n'
- ' difference, and symmetric difference.\n'
- '\n'
- ' For set elements, the same immutability rules apply as for\n'
- ' dictionary keys. Note that numeric types obey the normal rules '
- 'for\n'
- ' numeric comparison: if two numbers compare equal (e.g., "1" and\n'
- ' "1.0"), only one of them can be contained in a set.\n'
- '\n'
- ' There are currently two intrinsic set types:\n'
- '\n'
- ' Sets\n'
- ' These represent a mutable set. They are created by the '
- 'built-in\n'
- ' "set()" constructor and can be modified afterwards by '
- 'several\n'
- ' methods, such as "add()".\n'
- '\n'
- ' Frozen sets\n'
- ' These represent an immutable set. They are created by the\n'
- ' built-in "frozenset()" constructor. As a frozenset is '
- 'immutable\n'
- ' and *hashable*, it can be used again as an element of '
- 'another\n'
- ' set, or as a dictionary key.\n'
- '\n'
- 'Mappings\n'
- ' These represent finite sets of objects indexed by arbitrary '
- 'index\n'
- ' sets. The subscript notation "a[k]" selects the item indexed by '
- '"k"\n'
- ' from the mapping "a"; this can be used in expressions and as '
- 'the\n'
- ' target of assignments or "del" statements. The built-in '
- 'function\n'
- ' "len()" returns the number of items in a mapping.\n'
- '\n'
- ' There is currently a single intrinsic mapping type:\n'
- '\n'
- ' Dictionaries\n'
- ' These represent finite sets of objects indexed by nearly\n'
- ' arbitrary values. The only types of values not acceptable '
- 'as\n'
- ' keys are values containing lists or dictionaries or other\n'
- ' mutable types that are compared by value rather than by '
- 'object\n'
- ' identity, the reason being that the efficient implementation '
- 'of\n'
- " dictionaries requires a key's hash value to remain constant.\n"
- ' Numeric types used for keys obey the normal rules for '
- 'numeric\n'
- ' comparison: if two numbers compare equal (e.g., "1" and '
- '"1.0")\n'
- ' then they can be used interchangeably to index the same\n'
- ' dictionary entry.\n'
- '\n'
- ' Dictionaries are mutable; they can be created by the "{...}"\n'
- ' notation (see section Dictionary displays).\n'
- '\n'
- ' The extension modules "dbm", "gdbm", and "bsddb" provide\n'
- ' additional examples of mapping types.\n'
- '\n'
- 'Callable types\n'
- ' These are the types to which the function call operation (see\n'
- ' section Calls) can be applied:\n'
- '\n'
- ' User-defined functions\n'
- ' A user-defined function object is created by a function\n'
- ' definition (see section Function definitions). It should be\n'
- ' called with an argument list containing the same number of '
- 'items\n'
- " as the function's formal parameter list.\n"
- '\n'
- ' Special attributes:\n'
- '\n'
- ' '
- '+-------------------------+---------------------------------+-------------+\n'
- ' | Attribute | Meaning '
- '| |\n'
- ' '
- '+=========================+=================================+=============+\n'
- ' | "__doc__" "func_doc" | The function\'s documentation '
- '| Writable |\n'
- ' | | string, or "None" if '
- '| |\n'
- ' | | unavailable. '
- '| |\n'
- ' '
- '+-------------------------+---------------------------------+-------------+\n'
- ' | "__name__" "func_name" | The function\'s name. '
- '| Writable |\n'
- ' '
- '+-------------------------+---------------------------------+-------------+\n'
- ' | "__module__" | The name of the module the | '
- 'Writable |\n'
- ' | | function was defined in, or '
- '| |\n'
- ' | | "None" if unavailable. '
- '| |\n'
- ' '
- '+-------------------------+---------------------------------+-------------+\n'
- ' | "__defaults__" | A tuple containing default | '
- 'Writable |\n'
- ' | "func_defaults" | argument values for those '
- '| |\n'
- ' | | arguments that have defaults, '
- '| |\n'
- ' | | or "None" if no arguments have '
- '| |\n'
- ' | | a default value. '
- '| |\n'
- ' '
- '+-------------------------+---------------------------------+-------------+\n'
- ' | "__code__" "func_code" | The code object representing | '
- 'Writable |\n'
- ' | | the compiled function body. '
- '| |\n'
- ' '
- '+-------------------------+---------------------------------+-------------+\n'
- ' | "__globals__" | A reference to the dictionary | '
- 'Read-only |\n'
- ' | "func_globals" | that holds the function\'s '
- '| |\n'
- ' | | global variables --- the global '
- '| |\n'
- ' | | namespace of the module in '
- '| |\n'
- ' | | which the function was defined. '
- '| |\n'
- ' '
- '+-------------------------+---------------------------------+-------------+\n'
- ' | "__dict__" "func_dict" | The namespace supporting | '
- 'Writable |\n'
- ' | | arbitrary function attributes. '
- '| |\n'
- ' '
- '+-------------------------+---------------------------------+-------------+\n'
- ' | "__closure__" | "None" or a tuple of cells that | '
- 'Read-only |\n'
- ' | "func_closure" | contain bindings for the '
- '| |\n'
- " | | function's free variables. "
- '| |\n'
- ' '
- '+-------------------------+---------------------------------+-------------+\n'
- '\n'
- ' Most of the attributes labelled "Writable" check the type of '
- 'the\n'
- ' assigned value.\n'
- '\n'
- ' Changed in version 2.4: "func_name" is now writable.\n'
- '\n'
- ' Changed in version 2.6: The double-underscore attributes\n'
- ' "__closure__", "__code__", "__defaults__", and "__globals__"\n'
- ' were introduced as aliases for the corresponding "func_*"\n'
- ' attributes for forwards compatibility with Python 3.\n'
- '\n'
- ' Function objects also support getting and setting arbitrary\n'
- ' attributes, which can be used, for example, to attach '
- 'metadata\n'
- ' to functions. Regular attribute dot-notation is used to get '
- 'and\n'
- ' set such attributes. *Note that the current implementation '
- 'only\n'
- ' supports function attributes on user-defined functions. '
- 'Function\n'
- ' attributes on built-in functions may be supported in the\n'
- ' future.*\n'
- '\n'
- " Additional information about a function's definition can be\n"
- ' retrieved from its code object; see the description of '
- 'internal\n'
- ' types below.\n'
- '\n'
- ' User-defined methods\n'
- ' A user-defined method object combines a class, a class '
- 'instance\n'
- ' (or "None") and any callable object (normally a user-defined\n'
- ' function).\n'
- '\n'
- ' Special read-only attributes: "im_self" is the class '
- 'instance\n'
- ' object, "im_func" is the function object; "im_class" is the\n'
- ' class of "im_self" for bound methods or the class that asked '
- 'for\n'
- ' the method for unbound methods; "__doc__" is the method\'s\n'
- ' documentation (same as "im_func.__doc__"); "__name__" is the\n'
- ' method name (same as "im_func.__name__"); "__module__" is '
- 'the\n'
- ' name of the module the method was defined in, or "None" if\n'
- ' unavailable.\n'
- '\n'
- ' Changed in version 2.2: "im_self" used to refer to the class\n'
- ' that defined the method.\n'
- '\n'
- ' Changed in version 2.6: For Python 3 forward-compatibility,\n'
- ' "im_func" is also available as "__func__", and "im_self" as\n'
- ' "__self__".\n'
- '\n'
- ' Methods also support accessing (but not setting) the '
- 'arbitrary\n'
- ' function attributes on the underlying function object.\n'
- '\n'
- ' User-defined method objects may be created when getting an\n'
- ' attribute of a class (perhaps via an instance of that class), '
- 'if\n'
- ' that attribute is a user-defined function object, an unbound\n'
- ' user-defined method object, or a class method object. When '
- 'the\n'
- ' attribute is a user-defined method object, a new method '
- 'object\n'
- ' is only created if the class from which it is being retrieved '
- 'is\n'
- ' the same as, or a derived class of, the class stored in the\n'
- ' original method object; otherwise, the original method object '
- 'is\n'
- ' used as it is.\n'
- '\n'
- ' When a user-defined method object is created by retrieving a\n'
- ' user-defined function object from a class, its "im_self"\n'
- ' attribute is "None" and the method object is said to be '
- 'unbound.\n'
- ' When one is created by retrieving a user-defined function '
- 'object\n'
- ' from a class via one of its instances, its "im_self" '
- 'attribute\n'
- ' is the instance, and the method object is said to be bound. '
- 'In\n'
- ' either case, the new method\'s "im_class" attribute is the '
- 'class\n'
- ' from which the retrieval takes place, and its "im_func"\n'
- ' attribute is the original function object.\n'
- '\n'
- ' When a user-defined method object is created by retrieving\n'
- ' another method object from a class or instance, the behaviour '
- 'is\n'
- ' the same as for a function object, except that the "im_func"\n'
- ' attribute of the new instance is not the original method '
- 'object\n'
- ' but its "im_func" attribute.\n'
- '\n'
- ' When a user-defined method object is created by retrieving a\n'
- ' class method object from a class or instance, its "im_self"\n'
- ' attribute is the class itself, and its "im_func" attribute '
- 'is\n'
- ' the function object underlying the class method.\n'
- '\n'
- ' When an unbound user-defined method object is called, the\n'
- ' underlying function ("im_func") is called, with the '
- 'restriction\n'
- ' that the first argument must be an instance of the proper '
- 'class\n'
- ' ("im_class") or of a derived class thereof.\n'
- '\n'
- ' When a bound user-defined method object is called, the\n'
- ' underlying function ("im_func") is called, inserting the '
- 'class\n'
- ' instance ("im_self") in front of the argument list. For\n'
- ' instance, when "C" is a class which contains a definition for '
- 'a\n'
- ' function "f()", and "x" is an instance of "C", calling '
- '"x.f(1)"\n'
- ' is equivalent to calling "C.f(x, 1)".\n'
- '\n'
- ' When a user-defined method object is derived from a class '
- 'method\n'
- ' object, the "class instance" stored in "im_self" will '
- 'actually\n'
- ' be the class itself, so that calling either "x.f(1)" or '
- '"C.f(1)"\n'
- ' is equivalent to calling "f(C,1)" where "f" is the '
- 'underlying\n'
- ' function.\n'
- '\n'
- ' Note that the transformation from function object to (unbound '
- 'or\n'
- ' bound) method object happens each time the attribute is\n'
- ' retrieved from the class or instance. In some cases, a '
- 'fruitful\n'
- ' optimization is to assign the attribute to a local variable '
- 'and\n'
- ' call that local variable. Also notice that this '
- 'transformation\n'
- ' only happens for user-defined functions; other callable '
- 'objects\n'
- ' (and all non-callable objects) are retrieved without\n'
- ' transformation. It is also important to note that '
- 'user-defined\n'
- ' functions which are attributes of a class instance are not\n'
- ' converted to bound methods; this *only* happens when the\n'
- ' function is an attribute of the class.\n'
- '\n'
- ' Generator functions\n'
- ' A function or method which uses the "yield" statement (see\n'
- ' section The yield statement) is called a *generator '
- 'function*.\n'
- ' Such a function, when called, always returns an iterator '
- 'object\n'
- ' which can be used to execute the body of the function: '
- 'calling\n'
- ' the iterator\'s "next()" method will cause the function to\n'
- ' execute until it provides a value using the "yield" '
- 'statement.\n'
- ' When the function executes a "return" statement or falls off '
- 'the\n'
- ' end, a "StopIteration" exception is raised and the iterator '
- 'will\n'
- ' have reached the end of the set of values to be returned.\n'
- '\n'
- ' Built-in functions\n'
- ' A built-in function object is a wrapper around a C function.\n'
- ' Examples of built-in functions are "len()" and "math.sin()"\n'
- ' ("math" is a standard built-in module). The number and type '
- 'of\n'
- ' the arguments are determined by the C function. Special '
- 'read-\n'
- ' only attributes: "__doc__" is the function\'s documentation\n'
- ' string, or "None" if unavailable; "__name__" is the '
- "function's\n"
- ' name; "__self__" is set to "None" (but see the next item);\n'
- ' "__module__" is the name of the module the function was '
- 'defined\n'
- ' in or "None" if unavailable.\n'
- '\n'
- ' Built-in methods\n'
- ' This is really a different disguise of a built-in function, '
- 'this\n'
- ' time containing an object passed to the C function as an\n'
- ' implicit extra argument. An example of a built-in method is\n'
- ' "alist.append()", assuming *alist* is a list object. In this\n'
- ' case, the special read-only attribute "__self__" is set to '
- 'the\n'
- ' object denoted by *alist*.\n'
- '\n'
- ' Class Types\n'
- ' Class types, or "new-style classes," are callable. These\n'
- ' objects normally act as factories for new instances of\n'
- ' themselves, but variations are possible for class types that\n'
- ' override "__new__()". The arguments of the call are passed '
- 'to\n'
- ' "__new__()" and, in the typical case, to "__init__()" to\n'
- ' initialize the new instance.\n'
- '\n'
- ' Classic Classes\n'
- ' Class objects are described below. When a class object is\n'
- ' called, a new class instance (also described below) is '
- 'created\n'
- " and returned. This implies a call to the class's "
- '"__init__()"\n'
- ' method if it has one. Any arguments are passed on to the\n'
- ' "__init__()" method. If there is no "__init__()" method, '
- 'the\n'
- ' class must be called without arguments.\n'
- '\n'
- ' Class instances\n'
- ' Class instances are described below. Class instances are\n'
- ' callable only when the class has a "__call__()" method;\n'
- ' "x(arguments)" is a shorthand for "x.__call__(arguments)".\n'
- '\n'
- 'Modules\n'
- ' Modules are imported by the "import" statement (see section The\n'
- ' import statement). A module object has a namespace implemented '
- 'by a\n'
- ' dictionary object (this is the dictionary referenced by the\n'
- ' func_globals attribute of functions defined in the module).\n'
- ' Attribute references are translated to lookups in this '
- 'dictionary,\n'
- ' e.g., "m.x" is equivalent to "m.__dict__["x"]". A module object\n'
- ' does not contain the code object used to initialize the module\n'
- " (since it isn't needed once the initialization is done).\n"
- '\n'
- " Attribute assignment updates the module's namespace dictionary,\n"
- ' e.g., "m.x = 1" is equivalent to "m.__dict__["x"] = 1".\n'
- '\n'
- ' Special read-only attribute: "__dict__" is the module\'s '
- 'namespace\n'
- ' as a dictionary object.\n'
- '\n'
- ' **CPython implementation detail:** Because of the way CPython\n'
- ' clears module dictionaries, the module dictionary will be '
- 'cleared\n'
- ' when the module falls out of scope even if the dictionary still '
- 'has\n'
- ' live references. To avoid this, copy the dictionary or keep '
- 'the\n'
- ' module around while using its dictionary directly.\n'
- '\n'
- ' Predefined (writable) attributes: "__name__" is the module\'s '
- 'name;\n'
- ' "__doc__" is the module\'s documentation string, or "None" if\n'
- ' unavailable; "__file__" is the pathname of the file from which '
- 'the\n'
- ' module was loaded, if it was loaded from a file. The "__file__"\n'
- ' attribute is not present for C modules that are statically '
- 'linked\n'
- ' into the interpreter; for extension modules loaded dynamically '
- 'from\n'
- ' a shared library, it is the pathname of the shared library '
- 'file.\n'
- '\n'
- 'Classes\n'
- ' Both class types (new-style classes) and class objects (old-\n'
- ' style/classic classes) are typically created by class '
- 'definitions\n'
- ' (see section Class definitions). A class has a namespace\n'
- ' implemented by a dictionary object. Class attribute references '
- 'are\n'
- ' translated to lookups in this dictionary, e.g., "C.x" is '
- 'translated\n'
- ' to "C.__dict__["x"]" (although for new-style classes in '
- 'particular\n'
- ' there are a number of hooks which allow for other means of '
- 'locating\n'
- ' attributes). When the attribute name is not found there, the\n'
- ' attribute search continues in the base classes. For old-style\n'
- ' classes, the search is depth-first, left-to-right in the order '
- 'of\n'
- ' occurrence in the base class list. New-style classes use the '
- 'more\n'
- ' complex C3 method resolution order which behaves correctly even '
- 'in\n'
- " the presence of 'diamond' inheritance structures where there "
- 'are\n'
- ' multiple inheritance paths leading back to a common ancestor.\n'
- ' Additional details on the C3 MRO used by new-style classes can '
- 'be\n'
- ' found in the documentation accompanying the 2.3 release at\n'
- ' https://www.python.org/download/releases/2.3/mro/.\n'
- '\n'
- ' When a class attribute reference (for class "C", say) would '
- 'yield a\n'
- ' user-defined function object or an unbound user-defined method\n'
- ' object whose associated class is either "C" or one of its base\n'
- ' classes, it is transformed into an unbound user-defined method\n'
- ' object whose "im_class" attribute is "C". When it would yield a\n'
- ' class method object, it is transformed into a bound '
- 'user-defined\n'
- ' method object whose "im_self" attribute is "C". When it would\n'
- ' yield a static method object, it is transformed into the object\n'
- ' wrapped by the static method object. See section Implementing\n'
- ' Descriptors for another way in which attributes retrieved from '
- 'a\n'
- ' class may differ from those actually contained in its '
- '"__dict__"\n'
- ' (note that only new-style classes support descriptors).\n'
- '\n'
- " Class attribute assignments update the class's dictionary, "
- 'never\n'
- ' the dictionary of a base class.\n'
- '\n'
- ' A class object can be called (see above) to yield a class '
- 'instance\n'
- ' (see below).\n'
- '\n'
- ' Special attributes: "__name__" is the class name; "__module__" '
- 'is\n'
- ' the module name in which the class was defined; "__dict__" is '
- 'the\n'
- ' dictionary containing the class\'s namespace; "__bases__" is a '
- 'tuple\n'
- ' (possibly empty or a singleton) containing the base classes, in '
- 'the\n'
- ' order of their occurrence in the base class list; "__doc__" is '
- 'the\n'
- " class's documentation string, or None if undefined.\n"
- '\n'
- 'Class instances\n'
- ' A class instance is created by calling a class object (see '
- 'above).\n'
- ' A class instance has a namespace implemented as a dictionary '
- 'which\n'
- ' is the first place in which attribute references are searched.\n'
- " When an attribute is not found there, and the instance's class "
- 'has\n'
- ' an attribute by that name, the search continues with the class\n'
- ' attributes. If a class attribute is found that is a '
- 'user-defined\n'
- ' function object or an unbound user-defined method object whose\n'
- ' associated class is the class (call it "C") of the instance for\n'
- ' which the attribute reference was initiated or one of its bases, '
- 'it\n'
- ' is transformed into a bound user-defined method object whose\n'
- ' "im_class" attribute is "C" and whose "im_self" attribute is '
- 'the\n'
- ' instance. Static method and class method objects are also\n'
- ' transformed, as if they had been retrieved from class "C"; see\n'
- ' above under "Classes". See section Implementing Descriptors for\n'
- ' another way in which attributes of a class retrieved via its\n'
- ' instances may differ from the objects actually stored in the\n'
- ' class\'s "__dict__". If no class attribute is found, and the\n'
- ' object\'s class has a "__getattr__()" method, that is called to\n'
- ' satisfy the lookup.\n'
- '\n'
- " Attribute assignments and deletions update the instance's\n"
- " dictionary, never a class's dictionary. If the class has a\n"
- ' "__setattr__()" or "__delattr__()" method, this is called '
- 'instead\n'
- ' of updating the instance dictionary directly.\n'
- '\n'
- ' Class instances can pretend to be numbers, sequences, or '
- 'mappings\n'
- ' if they have methods with certain special names. See section\n'
- ' Special method names.\n'
- '\n'
- ' Special attributes: "__dict__" is the attribute dictionary;\n'
- ' "__class__" is the instance\'s class.\n'
- '\n'
- 'Files\n'
- ' A file object represents an open file. File objects are created '
- 'by\n'
- ' the "open()" built-in function, and also by "os.popen()",\n'
- ' "os.fdopen()", and the "makefile()" method of socket objects '
- '(and\n'
- ' perhaps by other functions or methods provided by extension\n'
- ' modules). The objects "sys.stdin", "sys.stdout" and '
- '"sys.stderr"\n'
- ' are initialized to file objects corresponding to the '
- "interpreter's\n"
- ' standard input, output and error streams. See File Objects for\n'
- ' complete documentation of file objects.\n'
- '\n'
- 'Internal types\n'
- ' A few types used internally by the interpreter are exposed to '
- 'the\n'
- ' user. Their definitions may change with future versions of the\n'
- ' interpreter, but they are mentioned here for completeness.\n'
- '\n'
- ' Code objects\n'
- ' Code objects represent *byte-compiled* executable Python '
- 'code,\n'
- ' or *bytecode*. The difference between a code object and a\n'
- ' function object is that the function object contains an '
- 'explicit\n'
- " reference to the function's globals (the module in which it "
- 'was\n'
- ' defined), while a code object contains no context; also the\n'
- ' default argument values are stored in the function object, '
- 'not\n'
- ' in the code object (because they represent values calculated '
- 'at\n'
- ' run-time). Unlike function objects, code objects are '
- 'immutable\n'
- ' and contain no references (directly or indirectly) to '
- 'mutable\n'
- ' objects.\n'
- '\n'
- ' Special read-only attributes: "co_name" gives the function '
- 'name;\n'
- ' "co_argcount" is the number of positional arguments '
- '(including\n'
- ' arguments with default values); "co_nlocals" is the number '
- 'of\n'
- ' local variables used by the function (including arguments);\n'
- ' "co_varnames" is a tuple containing the names of the local\n'
- ' variables (starting with the argument names); "co_cellvars" '
- 'is a\n'
- ' tuple containing the names of local variables that are\n'
- ' referenced by nested functions; "co_freevars" is a tuple\n'
- ' containing the names of free variables; "co_code" is a '
- 'string\n'
- ' representing the sequence of bytecode instructions; '
- '"co_consts"\n'
- ' is a tuple containing the literals used by the bytecode;\n'
- ' "co_names" is a tuple containing the names used by the '
- 'bytecode;\n'
- ' "co_filename" is the filename from which the code was '
- 'compiled;\n'
- ' "co_firstlineno" is the first line number of the function;\n'
- ' "co_lnotab" is a string encoding the mapping from bytecode\n'
- ' offsets to line numbers (for details see the source code of '
- 'the\n'
- ' interpreter); "co_stacksize" is the required stack size\n'
- ' (including local variables); "co_flags" is an integer '
- 'encoding a\n'
- ' number of flags for the interpreter.\n'
- '\n'
- ' The following flag bits are defined for "co_flags": bit '
- '"0x04"\n'
- ' is set if the function uses the "*arguments" syntax to accept '
- 'an\n'
- ' arbitrary number of positional arguments; bit "0x08" is set '
- 'if\n'
- ' the function uses the "**keywords" syntax to accept '
- 'arbitrary\n'
- ' keyword arguments; bit "0x20" is set if the function is a\n'
- ' generator.\n'
- '\n'
- ' Future feature declarations ("from __future__ import '
- 'division")\n'
- ' also use bits in "co_flags" to indicate whether a code '
- 'object\n'
- ' was compiled with a particular feature enabled: bit "0x2000" '
- 'is\n'
- ' set if the function was compiled with future division '
- 'enabled;\n'
- ' bits "0x10" and "0x1000" were used in earlier versions of\n'
- ' Python.\n'
- '\n'
- ' Other bits in "co_flags" are reserved for internal use.\n'
- '\n'
- ' If a code object represents a function, the first item in\n'
- ' "co_consts" is the documentation string of the function, or\n'
- ' "None" if undefined.\n'
- '\n'
- ' Frame objects\n'
- ' Frame objects represent execution frames. They may occur in\n'
- ' traceback objects (see below).\n'
- '\n'
- ' Special read-only attributes: "f_back" is to the previous '
- 'stack\n'
- ' frame (towards the caller), or "None" if this is the bottom\n'
- ' stack frame; "f_code" is the code object being executed in '
- 'this\n'
- ' frame; "f_locals" is the dictionary used to look up local\n'
- ' variables; "f_globals" is used for global variables;\n'
- ' "f_builtins" is used for built-in (intrinsic) names;\n'
- ' "f_restricted" is a flag indicating whether the function is\n'
- ' executing in restricted execution mode; "f_lasti" gives the\n'
- ' precise instruction (this is an index into the bytecode '
- 'string\n'
- ' of the code object).\n'
- '\n'
- ' Special writable attributes: "f_trace", if not "None", is a\n'
- ' function called at the start of each source code line (this '
- 'is\n'
- ' used by the debugger); "f_exc_type", "f_exc_value",\n'
- ' "f_exc_traceback" represent the last exception raised in the\n'
- ' parent frame provided another exception was ever raised in '
- 'the\n'
- ' current frame (in all other cases they are None); "f_lineno" '
- 'is\n'
- ' the current line number of the frame --- writing to this '
- 'from\n'
- ' within a trace function jumps to the given line (only for '
- 'the\n'
- ' bottom-most frame). A debugger can implement a Jump command\n'
- ' (aka Set Next Statement) by writing to f_lineno.\n'
- '\n'
- ' Traceback objects\n'
- ' Traceback objects represent a stack trace of an exception. '
- 'A\n'
- ' traceback object is created when an exception occurs. When '
- 'the\n'
- ' search for an exception handler unwinds the execution stack, '
- 'at\n'
- ' each unwound level a traceback object is inserted in front '
- 'of\n'
- ' the current traceback. When an exception handler is '
- 'entered,\n'
- ' the stack trace is made available to the program. (See '
- 'section\n'
- ' The try statement.) It is accessible as "sys.exc_traceback", '
- 'and\n'
- ' also as the third item of the tuple returned by\n'
- ' "sys.exc_info()". The latter is the preferred interface, '
- 'since\n'
- ' it works correctly when the program is using multiple '
- 'threads.\n'
- ' When the program contains no suitable handler, the stack '
- 'trace\n'
- ' is written (nicely formatted) to the standard error stream; '
- 'if\n'
- ' the interpreter is interactive, it is also made available to '
- 'the\n'
- ' user as "sys.last_traceback".\n'
- '\n'
- ' Special read-only attributes: "tb_next" is the next level in '
- 'the\n'
- ' stack trace (towards the frame where the exception occurred), '
- 'or\n'
- ' "None" if there is no next level; "tb_frame" points to the\n'
- ' execution frame of the current level; "tb_lineno" gives the '
- 'line\n'
- ' number where the exception occurred; "tb_lasti" indicates '
- 'the\n'
- ' precise instruction. The line number and last instruction '
- 'in\n'
- ' the traceback may differ from the line number of its frame\n'
- ' object if the exception occurred in a "try" statement with '
- 'no\n'
- ' matching except clause or with a finally clause.\n'
- '\n'
- ' Slice objects\n'
- ' Slice objects are used to represent slices when *extended '
- 'slice\n'
- ' syntax* is used. This is a slice using two colons, or '
- 'multiple\n'
- ' slices or ellipses separated by commas, e.g., "a[i:j:step]",\n'
- ' "a[i:j, k:l]", or "a[..., i:j]". They are also created by '
- 'the\n'
- ' built-in "slice()" function.\n'
- '\n'
- ' Special read-only attributes: "start" is the lower bound; '
- '"stop"\n'
- ' is the upper bound; "step" is the step value; each is "None" '
- 'if\n'
- ' omitted. These attributes can have any type.\n'
- '\n'
- ' Slice objects support one method:\n'
- '\n'
- ' slice.indices(self, length)\n'
- '\n'
- ' This method takes a single integer argument *length* and\n'
- ' computes information about the extended slice that the '
- 'slice\n'
- ' object would describe if applied to a sequence of '
- '*length*\n'
- ' items. It returns a tuple of three integers; '
- 'respectively\n'
- ' these are the *start* and *stop* indices and the *step* '
- 'or\n'
- ' stride length of the slice. Missing or out-of-bounds '
- 'indices\n'
- ' are handled in a manner consistent with regular slices.\n'
- '\n'
- ' New in version 2.3.\n'
- '\n'
- ' Static method objects\n'
- ' Static method objects provide a way of defeating the\n'
- ' transformation of function objects to method objects '
- 'described\n'
- ' above. A static method object is a wrapper around any other\n'
- ' object, usually a user-defined method object. When a static\n'
- ' method object is retrieved from a class or a class instance, '
- 'the\n'
- ' object actually returned is the wrapped object, which is not\n'
- ' subject to any further transformation. Static method objects '
- 'are\n'
- ' not themselves callable, although the objects they wrap '
- 'usually\n'
- ' are. Static method objects are created by the built-in\n'
- ' "staticmethod()" constructor.\n'
- '\n'
- ' Class method objects\n'
- ' A class method object, like a static method object, is a '
- 'wrapper\n'
- ' around another object that alters the way in which that '
- 'object\n'
- ' is retrieved from classes and class instances. The behaviour '
- 'of\n'
- ' class method objects upon such retrieval is described above,\n'
- ' under "User-defined methods". Class method objects are '
- 'created\n'
- ' by the built-in "classmethod()" constructor.\n',
- 'typesfunctions': '\n'
- 'Functions\n'
- '*********\n'
- '\n'
- 'Function objects are created by function definitions. The '
- 'only\n'
- 'operation on a function object is to call it: '
- '"func(argument-list)".\n'
- '\n'
- 'There are really two flavors of function objects: built-in '
- 'functions\n'
- 'and user-defined functions. Both support the same '
- 'operation (to call\n'
- 'the function), but the implementation is different, hence '
- 'the\n'
- 'different object types.\n'
- '\n'
- 'See Function definitions for more information.\n',
- 'typesmapping': '\n'
- 'Mapping Types --- "dict"\n'
- '************************\n'
- '\n'
- 'A *mapping* object maps *hashable* values to arbitrary '
- 'objects.\n'
- 'Mappings are mutable objects. There is currently only one '
- 'standard\n'
- 'mapping type, the *dictionary*. (For other containers see '
- 'the built\n'
- 'in "list", "set", and "tuple" classes, and the "collections" '
- 'module.)\n'
- '\n'
- "A dictionary's keys are *almost* arbitrary values. Values "
- 'that are\n'
- 'not *hashable*, that is, values containing lists, '
- 'dictionaries or\n'
- 'other mutable types (that are compared by value rather than '
- 'by object\n'
- 'identity) may not be used as keys. Numeric types used for '
- 'keys obey\n'
- 'the normal rules for numeric comparison: if two numbers '
- 'compare equal\n'
- '(such as "1" and "1.0") then they can be used '
- 'interchangeably to index\n'
- 'the same dictionary entry. (Note however, that since '
- 'computers store\n'
- 'floating-point numbers as approximations it is usually '
- 'unwise to use\n'
- 'them as dictionary keys.)\n'
- '\n'
- 'Dictionaries can be created by placing a comma-separated '
- 'list of "key:\n'
- 'value" pairs within braces, for example: "{\'jack\': 4098, '
- "'sjoerd':\n"
- '4127}" or "{4098: \'jack\', 4127: \'sjoerd\'}", or by the '
- '"dict"\n'
- 'constructor.\n'
- '\n'
- 'class dict(**kwarg)\n'
- 'class dict(mapping, **kwarg)\n'
- 'class dict(iterable, **kwarg)\n'
- '\n'
- ' Return a new dictionary initialized from an optional '
- 'positional\n'
- ' argument and a possibly empty set of keyword arguments.\n'
- '\n'
- ' If no positional argument is given, an empty dictionary '
- 'is created.\n'
- ' If a positional argument is given and it is a mapping '
- 'object, a\n'
- ' dictionary is created with the same key-value pairs as '
- 'the mapping\n'
- ' object. Otherwise, the positional argument must be an '
- '*iterable*\n'
- ' object. Each item in the iterable must itself be an '
- 'iterable with\n'
- ' exactly two objects. The first object of each item '
- 'becomes a key\n'
- ' in the new dictionary, and the second object the '
- 'corresponding\n'
- ' value. If a key occurs more than once, the last value '
- 'for that key\n'
- ' becomes the corresponding value in the new dictionary.\n'
- '\n'
- ' If keyword arguments are given, the keyword arguments and '
- 'their\n'
- ' values are added to the dictionary created from the '
- 'positional\n'
- ' argument. If a key being added is already present, the '
- 'value from\n'
- ' the keyword argument replaces the value from the '
- 'positional\n'
- ' argument.\n'
- '\n'
- ' To illustrate, the following examples all return a '
- 'dictionary equal\n'
- ' to "{"one": 1, "two": 2, "three": 3}":\n'
- '\n'
- ' >>> a = dict(one=1, two=2, three=3)\n'
- " >>> b = {'one': 1, 'two': 2, 'three': 3}\n"
- " >>> c = dict(zip(['one', 'two', 'three'], [1, 2, 3]))\n"
- " >>> d = dict([('two', 2), ('one', 1), ('three', 3)])\n"
- " >>> e = dict({'three': 3, 'one': 1, 'two': 2})\n"
- ' >>> a == b == c == d == e\n'
- ' True\n'
- '\n'
- ' Providing keyword arguments as in the first example only '
- 'works for\n'
- ' keys that are valid Python identifiers. Otherwise, any '
- 'valid keys\n'
- ' can be used.\n'
- '\n'
- ' New in version 2.2.\n'
- '\n'
- ' Changed in version 2.3: Support for building a dictionary '
- 'from\n'
- ' keyword arguments added.\n'
- '\n'
- ' These are the operations that dictionaries support (and '
- 'therefore,\n'
- ' custom mapping types should support too):\n'
- '\n'
- ' len(d)\n'
- '\n'
- ' Return the number of items in the dictionary *d*.\n'
- '\n'
- ' d[key]\n'
- '\n'
- ' Return the item of *d* with key *key*. Raises a '
- '"KeyError" if\n'
- ' *key* is not in the map.\n'
- '\n'
- ' If a subclass of dict defines a method "__missing__()" '
- 'and *key*\n'
- ' is not present, the "d[key]" operation calls that '
- 'method with\n'
- ' the key *key* as argument. The "d[key]" operation '
- 'then returns\n'
- ' or raises whatever is returned or raised by the\n'
- ' "__missing__(key)" call. No other operations or '
- 'methods invoke\n'
- ' "__missing__()". If "__missing__()" is not defined, '
- '"KeyError"\n'
- ' is raised. "__missing__()" must be a method; it cannot '
- 'be an\n'
- ' instance variable:\n'
- '\n'
- ' >>> class Counter(dict):\n'
- ' ... def __missing__(self, key):\n'
- ' ... return 0\n'
- ' >>> c = Counter()\n'
- " >>> c['red']\n"
- ' 0\n'
- " >>> c['red'] += 1\n"
- " >>> c['red']\n"
- ' 1\n'
- '\n'
- ' The example above shows part of the implementation of\n'
- ' "collections.Counter". A different "__missing__" '
- 'method is used\n'
- ' by "collections.defaultdict".\n'
- '\n'
- ' New in version 2.5: Recognition of __missing__ methods '
- 'of dict\n'
- ' subclasses.\n'
- '\n'
- ' d[key] = value\n'
- '\n'
- ' Set "d[key]" to *value*.\n'
- '\n'
- ' del d[key]\n'
- '\n'
- ' Remove "d[key]" from *d*. Raises a "KeyError" if '
- '*key* is not\n'
- ' in the map.\n'
- '\n'
- ' key in d\n'
- '\n'
- ' Return "True" if *d* has a key *key*, else "False".\n'
- '\n'
- ' New in version 2.2.\n'
- '\n'
- ' key not in d\n'
- '\n'
- ' Equivalent to "not key in d".\n'
- '\n'
- ' New in version 2.2.\n'
- '\n'
- ' iter(d)\n'
- '\n'
- ' Return an iterator over the keys of the dictionary. '
- 'This is a\n'
- ' shortcut for "iterkeys()".\n'
- '\n'
- ' clear()\n'
- '\n'
- ' Remove all items from the dictionary.\n'
- '\n'
- ' copy()\n'
- '\n'
- ' Return a shallow copy of the dictionary.\n'
- '\n'
- ' fromkeys(seq[, value])\n'
- '\n'
- ' Create a new dictionary with keys from *seq* and '
- 'values set to\n'
- ' *value*.\n'
- '\n'
- ' "fromkeys()" is a class method that returns a new '
- 'dictionary.\n'
- ' *value* defaults to "None".\n'
- '\n'
- ' New in version 2.3.\n'
- '\n'
- ' get(key[, default])\n'
- '\n'
- ' Return the value for *key* if *key* is in the '
- 'dictionary, else\n'
- ' *default*. If *default* is not given, it defaults to '
- '"None", so\n'
- ' that this method never raises a "KeyError".\n'
- '\n'
- ' has_key(key)\n'
- '\n'
- ' Test for the presence of *key* in the dictionary. '
- '"has_key()"\n'
- ' is deprecated in favor of "key in d".\n'
- '\n'
- ' items()\n'
- '\n'
- ' Return a copy of the dictionary\'s list of "(key, '
- 'value)" pairs.\n'
- '\n'
- ' **CPython implementation detail:** Keys and values are '
- 'listed in\n'
- ' an arbitrary order which is non-random, varies across '
- 'Python\n'
- " implementations, and depends on the dictionary's "
- 'history of\n'
- ' insertions and deletions.\n'
- '\n'
- ' If "items()", "keys()", "values()", "iteritems()", '
- '"iterkeys()",\n'
- ' and "itervalues()" are called with no intervening '
- 'modifications\n'
- ' to the dictionary, the lists will directly '
- 'correspond. This\n'
- ' allows the creation of "(value, key)" pairs using '
- '"zip()":\n'
- ' "pairs = zip(d.values(), d.keys())". The same '
- 'relationship\n'
- ' holds for the "iterkeys()" and "itervalues()" methods: '
- '"pairs =\n'
- ' zip(d.itervalues(), d.iterkeys())" provides the same '
- 'value for\n'
- ' "pairs". Another way to create the same list is "pairs '
- '= [(v, k)\n'
- ' for (k, v) in d.iteritems()]".\n'
- '\n'
- ' iteritems()\n'
- '\n'
- ' Return an iterator over the dictionary\'s "(key, '
- 'value)" pairs.\n'
- ' See the note for "dict.items()".\n'
- '\n'
- ' Using "iteritems()" while adding or deleting entries '
- 'in the\n'
- ' dictionary may raise a "RuntimeError" or fail to '
- 'iterate over\n'
- ' all entries.\n'
- '\n'
- ' New in version 2.2.\n'
- '\n'
- ' iterkeys()\n'
- '\n'
- " Return an iterator over the dictionary's keys. See "
- 'the note for\n'
- ' "dict.items()".\n'
- '\n'
- ' Using "iterkeys()" while adding or deleting entries in '
- 'the\n'
- ' dictionary may raise a "RuntimeError" or fail to '
- 'iterate over\n'
- ' all entries.\n'
- '\n'
- ' New in version 2.2.\n'
- '\n'
- ' itervalues()\n'
- '\n'
- " Return an iterator over the dictionary's values. See "
- 'the note\n'
- ' for "dict.items()".\n'
- '\n'
- ' Using "itervalues()" while adding or deleting entries '
- 'in the\n'
- ' dictionary may raise a "RuntimeError" or fail to '
- 'iterate over\n'
- ' all entries.\n'
- '\n'
- ' New in version 2.2.\n'
- '\n'
- ' keys()\n'
- '\n'
- " Return a copy of the dictionary's list of keys. See "
- 'the note\n'
- ' for "dict.items()".\n'
- '\n'
- ' pop(key[, default])\n'
- '\n'
- ' If *key* is in the dictionary, remove it and return '
- 'its value,\n'
- ' else return *default*. If *default* is not given and '
- '*key* is\n'
- ' not in the dictionary, a "KeyError" is raised.\n'
- '\n'
- ' New in version 2.3.\n'
- '\n'
- ' popitem()\n'
- '\n'
- ' Remove and return an arbitrary "(key, value)" pair '
- 'from the\n'
- ' dictionary.\n'
- '\n'
- ' "popitem()" is useful to destructively iterate over a\n'
- ' dictionary, as often used in set algorithms. If the '
- 'dictionary\n'
- ' is empty, calling "popitem()" raises a "KeyError".\n'
- '\n'
- ' setdefault(key[, default])\n'
- '\n'
- ' If *key* is in the dictionary, return its value. If '
- 'not, insert\n'
- ' *key* with a value of *default* and return *default*. '
- '*default*\n'
- ' defaults to "None".\n'
- '\n'
- ' update([other])\n'
- '\n'
- ' Update the dictionary with the key/value pairs from '
- '*other*,\n'
- ' overwriting existing keys. Return "None".\n'
- '\n'
- ' "update()" accepts either another dictionary object or '
- 'an\n'
- ' iterable of key/value pairs (as tuples or other '
- 'iterables of\n'
- ' length two). If keyword arguments are specified, the '
- 'dictionary\n'
- ' is then updated with those key/value pairs: '
- '"d.update(red=1,\n'
- ' blue=2)".\n'
- '\n'
- ' Changed in version 2.4: Allowed the argument to be an '
- 'iterable\n'
- ' of key/value pairs and allowed keyword arguments.\n'
- '\n'
- ' values()\n'
- '\n'
- " Return a copy of the dictionary's list of values. See "
- 'the note\n'
- ' for "dict.items()".\n'
- '\n'
- ' viewitems()\n'
- '\n'
- ' Return a new view of the dictionary\'s items ("(key, '
- 'value)"\n'
- ' pairs). See below for documentation of view objects.\n'
- '\n'
- ' New in version 2.7.\n'
- '\n'
- ' viewkeys()\n'
- '\n'
- " Return a new view of the dictionary's keys. See below "
- 'for\n'
- ' documentation of view objects.\n'
- '\n'
- ' New in version 2.7.\n'
- '\n'
- ' viewvalues()\n'
- '\n'
- " Return a new view of the dictionary's values. See "
- 'below for\n'
- ' documentation of view objects.\n'
- '\n'
- ' New in version 2.7.\n'
- '\n'
- ' Dictionaries compare equal if and only if they have the '
- 'same "(key,\n'
- ' value)" pairs.\n'
- '\n'
- '\n'
- 'Dictionary view objects\n'
- '=======================\n'
- '\n'
- 'The objects returned by "dict.viewkeys()", '
- '"dict.viewvalues()" and\n'
- '"dict.viewitems()" are *view objects*. They provide a '
- 'dynamic view on\n'
- "the dictionary's entries, which means that when the "
- 'dictionary\n'
- 'changes, the view reflects these changes.\n'
- '\n'
- 'Dictionary views can be iterated over to yield their '
- 'respective data,\n'
- 'and support membership tests:\n'
- '\n'
- 'len(dictview)\n'
- '\n'
- ' Return the number of entries in the dictionary.\n'
- '\n'
- 'iter(dictview)\n'
- '\n'
- ' Return an iterator over the keys, values or items '
- '(represented as\n'
- ' tuples of "(key, value)") in the dictionary.\n'
- '\n'
- ' Keys and values are iterated over in an arbitrary order '
- 'which is\n'
- ' non-random, varies across Python implementations, and '
- 'depends on\n'
- " the dictionary's history of insertions and deletions. If "
- 'keys,\n'
- ' values and items views are iterated over with no '
- 'intervening\n'
- ' modifications to the dictionary, the order of items will '
- 'directly\n'
- ' correspond. This allows the creation of "(value, key)" '
- 'pairs using\n'
- ' "zip()": "pairs = zip(d.values(), d.keys())". Another '
- 'way to\n'
- ' create the same list is "pairs = [(v, k) for (k, v) in '
- 'd.items()]".\n'
- '\n'
- ' Iterating views while adding or deleting entries in the '
- 'dictionary\n'
- ' may raise a "RuntimeError" or fail to iterate over all '
- 'entries.\n'
- '\n'
- 'x in dictview\n'
- '\n'
- ' Return "True" if *x* is in the underlying dictionary\'s '
- 'keys, values\n'
- ' or items (in the latter case, *x* should be a "(key, '
- 'value)"\n'
- ' tuple).\n'
- '\n'
- 'Keys views are set-like since their entries are unique and '
- 'hashable.\n'
- 'If all values are hashable, so that (key, value) pairs are '
- 'unique and\n'
- 'hashable, then the items view is also set-like. (Values '
- 'views are not\n'
- 'treated as set-like since the entries are generally not '
- 'unique.) Then\n'
- 'these set operations are available ("other" refers either to '
- 'another\n'
- 'view or a set):\n'
- '\n'
- 'dictview & other\n'
- '\n'
- ' Return the intersection of the dictview and the other '
- 'object as a\n'
- ' new set.\n'
- '\n'
- 'dictview | other\n'
- '\n'
- ' Return the union of the dictview and the other object as '
- 'a new set.\n'
- '\n'
- 'dictview - other\n'
- '\n'
- ' Return the difference between the dictview and the other '
- 'object\n'
- " (all elements in *dictview* that aren't in *other*) as a "
- 'new set.\n'
- '\n'
- 'dictview ^ other\n'
- '\n'
- ' Return the symmetric difference (all elements either in '
- '*dictview*\n'
- ' or *other*, but not in both) of the dictview and the '
- 'other object\n'
- ' as a new set.\n'
- '\n'
- 'An example of dictionary view usage:\n'
- '\n'
- " >>> dishes = {'eggs': 2, 'sausage': 1, 'bacon': 1, "
- "'spam': 500}\n"
- ' >>> keys = dishes.viewkeys()\n'
- ' >>> values = dishes.viewvalues()\n'
- '\n'
- ' >>> # iteration\n'
- ' >>> n = 0\n'
- ' >>> for val in values:\n'
- ' ... n += val\n'
- ' >>> print(n)\n'
- ' 504\n'
- '\n'
- ' >>> # keys and values are iterated over in the same '
- 'order\n'
- ' >>> list(keys)\n'
- " ['eggs', 'bacon', 'sausage', 'spam']\n"
- ' >>> list(values)\n'
- ' [2, 1, 1, 500]\n'
- '\n'
- ' >>> # view objects are dynamic and reflect dict changes\n'
- " >>> del dishes['eggs']\n"
- " >>> del dishes['sausage']\n"
- ' >>> list(keys)\n'
- " ['spam', 'bacon']\n"
- '\n'
- ' >>> # set operations\n'
- " >>> keys & {'eggs', 'bacon', 'salad'}\n"
- " {'bacon'}\n",
- 'typesmethods': '\n'
- 'Methods\n'
- '*******\n'
- '\n'
- 'Methods are functions that are called using the attribute '
- 'notation.\n'
- 'There are two flavors: built-in methods (such as "append()" '
- 'on lists)\n'
- 'and class instance methods. Built-in methods are described '
- 'with the\n'
- 'types that support them.\n'
- '\n'
- 'The implementation adds two special read-only attributes to '
- 'class\n'
- 'instance methods: "m.im_self" is the object on which the '
- 'method\n'
- 'operates, and "m.im_func" is the function implementing the '
- 'method.\n'
- 'Calling "m(arg-1, arg-2, ..., arg-n)" is completely '
- 'equivalent to\n'
- 'calling "m.im_func(m.im_self, arg-1, arg-2, ..., arg-n)".\n'
- '\n'
- 'Class instance methods are either *bound* or *unbound*, '
- 'referring to\n'
- 'whether the method was accessed through an instance or a '
- 'class,\n'
- 'respectively. When a method is unbound, its "im_self" '
- 'attribute will\n'
- 'be "None" and if called, an explicit "self" object must be '
- 'passed as\n'
- 'the first argument. In this case, "self" must be an '
- 'instance of the\n'
- "unbound method's class (or a subclass of that class), "
- 'otherwise a\n'
- '"TypeError" is raised.\n'
- '\n'
- 'Like function objects, methods objects support getting '
- 'arbitrary\n'
- 'attributes. However, since method attributes are actually '
- 'stored on\n'
- 'the underlying function object ("meth.im_func"), setting '
- 'method\n'
- 'attributes on either bound or unbound methods is '
- 'disallowed.\n'
- 'Attempting to set an attribute on a method results in an\n'
- '"AttributeError" being raised. In order to set a method '
- 'attribute,\n'
- 'you need to explicitly set it on the underlying function '
- 'object:\n'
- '\n'
- ' >>> class C:\n'
- ' ... def method(self):\n'
- ' ... pass\n'
- ' ...\n'
- ' >>> c = C()\n'
- " >>> c.method.whoami = 'my name is method' # can't set on "
- 'the method\n'
- ' Traceback (most recent call last):\n'
- ' File "<stdin>", line 1, in <module>\n'
- " AttributeError: 'instancemethod' object has no attribute "
- "'whoami'\n"
- " >>> c.method.im_func.whoami = 'my name is method'\n"
- ' >>> c.method.whoami\n'
- " 'my name is method'\n"
- '\n'
- 'See The standard type hierarchy for more information.\n',
- 'typesmodules': '\n'
- 'Modules\n'
- '*******\n'
- '\n'
- 'The only special operation on a module is attribute access: '
- '"m.name",\n'
- 'where *m* is a module and *name* accesses a name defined in '
- "*m*'s\n"
- 'symbol table. Module attributes can be assigned to. (Note '
- 'that the\n'
- '"import" statement is not, strictly speaking, an operation '
- 'on a module\n'
- 'object; "import foo" does not require a module object named '
- '*foo* to\n'
- 'exist, rather it requires an (external) *definition* for a '
- 'module\n'
- 'named *foo* somewhere.)\n'
- '\n'
- 'A special attribute of every module is "__dict__". This is '
- 'the\n'
- "dictionary containing the module's symbol table. Modifying "
- 'this\n'
- "dictionary will actually change the module's symbol table, "
- 'but direct\n'
- 'assignment to the "__dict__" attribute is not possible (you '
- 'can write\n'
- '"m.__dict__[\'a\'] = 1", which defines "m.a" to be "1", but '
- "you can't\n"
- 'write "m.__dict__ = {}"). Modifying "__dict__" directly is '
- 'not\n'
- 'recommended.\n'
- '\n'
- 'Modules built into the interpreter are written like this: '
- '"<module\n'
- '\'sys\' (built-in)>". If loaded from a file, they are '
- 'written as\n'
- '"<module \'os\' from '
- '\'/usr/local/lib/pythonX.Y/os.pyc\'>".\n',
- 'typesseq': '\n'
- 'Sequence Types --- "str", "unicode", "list", "tuple", '
- '"bytearray", "buffer", "xrange"\n'
- '*************************************************************************************\n'
- '\n'
- 'There are seven sequence types: strings, Unicode strings, '
- 'lists,\n'
- 'tuples, bytearrays, buffers, and xrange objects.\n'
- '\n'
- 'For other containers see the built in "dict" and "set" classes, '
- 'and\n'
- 'the "collections" module.\n'
- '\n'
- 'String literals are written in single or double quotes: '
- '"\'xyzzy\'",\n'
- '""frobozz"". See String literals for more about string '
- 'literals.\n'
- 'Unicode strings are much like strings, but are specified in the '
- 'syntax\n'
- 'using a preceding "\'u\'" character: "u\'abc\'", "u"def"". In '
- 'addition to\n'
- 'the functionality described here, there are also '
- 'string-specific\n'
- 'methods described in the String Methods section. Lists are '
- 'constructed\n'
- 'with square brackets, separating items with commas: "[a, b, '
- 'c]".\n'
- 'Tuples are constructed by the comma operator (not within square\n'
- 'brackets), with or without enclosing parentheses, but an empty '
- 'tuple\n'
- 'must have the enclosing parentheses, such as "a, b, c" or "()". '
- 'A\n'
- 'single item tuple must have a trailing comma, such as "(d,)".\n'
- '\n'
- 'Bytearray objects are created with the built-in function\n'
- '"bytearray()".\n'
- '\n'
- 'Buffer objects are not directly supported by Python syntax, but '
- 'can be\n'
- 'created by calling the built-in function "buffer()". They '
- "don't\n"
- 'support concatenation or repetition.\n'
- '\n'
- 'Objects of type xrange are similar to buffers in that there is '
- 'no\n'
- 'specific syntax to create them, but they are created using the\n'
- '"xrange()" function. They don\'t support slicing, concatenation '
- 'or\n'
- 'repetition, and using "in", "not in", "min()" or "max()" on them '
- 'is\n'
- 'inefficient.\n'
- '\n'
- 'Most sequence types support the following operations. The "in" '
- 'and\n'
- '"not in" operations have the same priorities as the comparison\n'
- 'operations. The "+" and "*" operations have the same priority '
- 'as the\n'
- 'corresponding numeric operations. [3] Additional methods are '
- 'provided\n'
- 'for Mutable Sequence Types.\n'
- '\n'
- 'This table lists the sequence operations sorted in ascending '
- 'priority.\n'
- 'In the table, *s* and *t* are sequences of the same type; *n*, '
- '*i* and\n'
- '*j* are integers:\n'
- '\n'
- '+--------------------+----------------------------------+------------+\n'
- '| Operation | Result | '
- 'Notes |\n'
- '+====================+==================================+============+\n'
- '| "x in s" | "True" if an item of *s* is | '
- '(1) |\n'
- '| | equal to *x*, else "False" '
- '| |\n'
- '+--------------------+----------------------------------+------------+\n'
- '| "x not in s" | "False" if an item of *s* is | '
- '(1) |\n'
- '| | equal to *x*, else "True" '
- '| |\n'
- '+--------------------+----------------------------------+------------+\n'
- '| "s + t" | the concatenation of *s* and *t* | '
- '(6) |\n'
- '+--------------------+----------------------------------+------------+\n'
- '| "s * n, n * s" | equivalent to adding *s* to | '
- '(2) |\n'
- '| | itself *n* times '
- '| |\n'
- '+--------------------+----------------------------------+------------+\n'
- '| "s[i]" | *i*th item of *s*, origin 0 | '
- '(3) |\n'
- '+--------------------+----------------------------------+------------+\n'
- '| "s[i:j]" | slice of *s* from *i* to *j* | '
- '(3)(4) |\n'
- '+--------------------+----------------------------------+------------+\n'
- '| "s[i:j:k]" | slice of *s* from *i* to *j* | '
- '(3)(5) |\n'
- '| | with step *k* '
- '| |\n'
- '+--------------------+----------------------------------+------------+\n'
- '| "len(s)" | length of *s* '
- '| |\n'
- '+--------------------+----------------------------------+------------+\n'
- '| "min(s)" | smallest item of *s* '
- '| |\n'
- '+--------------------+----------------------------------+------------+\n'
- '| "max(s)" | largest item of *s* '
- '| |\n'
- '+--------------------+----------------------------------+------------+\n'
- '| "s.index(x)" | index of the first occurrence of '
- '| |\n'
- '| | *x* in *s* '
- '| |\n'
- '+--------------------+----------------------------------+------------+\n'
- '| "s.count(x)" | total number of occurrences of '
- '| |\n'
- '| | *x* in *s* '
- '| |\n'
- '+--------------------+----------------------------------+------------+\n'
- '\n'
- 'Sequence types also support comparisons. In particular, tuples '
- 'and\n'
- 'lists are compared lexicographically by comparing corresponding\n'
- 'elements. This means that to compare equal, every element must '
- 'compare\n'
- 'equal and the two sequences must be of the same type and have '
- 'the same\n'
- 'length. (For full details see Comparisons in the language '
- 'reference.)\n'
- '\n'
- 'Notes:\n'
- '\n'
- '1. When *s* is a string or Unicode string object the "in" and '
- '"not\n'
- ' in" operations act like a substring test. In Python '
- 'versions\n'
- ' before 2.3, *x* had to be a string of length 1. In Python 2.3 '
- 'and\n'
- ' beyond, *x* may be a string of any length.\n'
- '\n'
- '2. Values of *n* less than "0" are treated as "0" (which yields '
- 'an\n'
- ' empty sequence of the same type as *s*). Note that items in '
- 'the\n'
- ' sequence *s* are not copied; they are referenced multiple '
- 'times.\n'
- ' This often haunts new Python programmers; consider:\n'
- '\n'
- ' >>> lists = [[]] * 3\n'
- ' >>> lists\n'
- ' [[], [], []]\n'
- ' >>> lists[0].append(3)\n'
- ' >>> lists\n'
- ' [[3], [3], [3]]\n'
- '\n'
- ' What has happened is that "[[]]" is a one-element list '
- 'containing\n'
- ' an empty list, so all three elements of "[[]] * 3" are '
- 'references\n'
- ' to this single empty list. Modifying any of the elements of\n'
- ' "lists" modifies this single list. You can create a list of\n'
- ' different lists this way:\n'
- '\n'
- ' >>> lists = [[] for i in range(3)]\n'
- ' >>> lists[0].append(3)\n'
- ' >>> lists[1].append(5)\n'
- ' >>> lists[2].append(7)\n'
- ' >>> lists\n'
- ' [[3], [5], [7]]\n'
- '\n'
- ' Further explanation is available in the FAQ entry How do I '
- 'create a\n'
- ' multidimensional list?.\n'
- '\n'
- '3. If *i* or *j* is negative, the index is relative to the end '
- 'of\n'
- ' the string: "len(s) + i" or "len(s) + j" is substituted. But '
- 'note\n'
- ' that "-0" is still "0".\n'
- '\n'
- '4. The slice of *s* from *i* to *j* is defined as the sequence '
- 'of\n'
- ' items with index *k* such that "i <= k < j". If *i* or *j* '
- 'is\n'
- ' greater than "len(s)", use "len(s)". If *i* is omitted or '
- '"None",\n'
- ' use "0". If *j* is omitted or "None", use "len(s)". If *i* '
- 'is\n'
- ' greater than or equal to *j*, the slice is empty.\n'
- '\n'
- '5. The slice of *s* from *i* to *j* with step *k* is defined as '
- 'the\n'
- ' sequence of items with index "x = i + n*k" such that "0 <= n '
- '<\n'
- ' (j-i)/k". In other words, the indices are "i", "i+k", '
- '"i+2*k",\n'
- ' "i+3*k" and so on, stopping when *j* is reached (but never\n'
- ' including *j*). If *i* or *j* is greater than "len(s)", use\n'
- ' "len(s)". If *i* or *j* are omitted or "None", they become '
- '"end"\n'
- ' values (which end depends on the sign of *k*). Note, *k* '
- 'cannot be\n'
- ' zero. If *k* is "None", it is treated like "1".\n'
- '\n'
- '6. **CPython implementation detail:** If *s* and *t* are both\n'
- ' strings, some Python implementations such as CPython can '
- 'usually\n'
- ' perform an in-place optimization for assignments of the form '
- '"s = s\n'
- ' + t" or "s += t". When applicable, this optimization makes\n'
- ' quadratic run-time much less likely. This optimization is '
- 'both\n'
- ' version and implementation dependent. For performance '
- 'sensitive\n'
- ' code, it is preferable to use the "str.join()" method which '
- 'assures\n'
- ' consistent linear concatenation performance across versions '
- 'and\n'
- ' implementations.\n'
- '\n'
- ' Changed in version 2.4: Formerly, string concatenation never\n'
- ' occurred in-place.\n'
- '\n'
- '\n'
- 'String Methods\n'
- '==============\n'
- '\n'
- 'Below are listed the string methods which both 8-bit strings '
- 'and\n'
- 'Unicode objects support. Some of them are also available on\n'
- '"bytearray" objects.\n'
- '\n'
- "In addition, Python's strings support the sequence type methods\n"
- 'described in the Sequence Types --- str, unicode, list, tuple,\n'
- 'bytearray, buffer, xrange section. To output formatted strings '
- 'use\n'
- 'template strings or the "%" operator described in the String\n'
- 'Formatting Operations section. Also, see the "re" module for '
- 'string\n'
- 'functions based on regular expressions.\n'
- '\n'
- 'str.capitalize()\n'
- '\n'
- ' Return a copy of the string with its first character '
- 'capitalized\n'
- ' and the rest lowercased.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.center(width[, fillchar])\n'
- '\n'
- ' Return centered in a string of length *width*. Padding is '
- 'done\n'
- ' using the specified *fillchar* (default is a space).\n'
- '\n'
- ' Changed in version 2.4: Support for the *fillchar* argument.\n'
- '\n'
- 'str.count(sub[, start[, end]])\n'
- '\n'
- ' Return the number of non-overlapping occurrences of substring '
- '*sub*\n'
- ' in the range [*start*, *end*]. Optional arguments *start* '
- 'and\n'
- ' *end* are interpreted as in slice notation.\n'
- '\n'
- 'str.decode([encoding[, errors]])\n'
- '\n'
- ' Decodes the string using the codec registered for '
- '*encoding*.\n'
- ' *encoding* defaults to the default string encoding. *errors* '
- 'may\n'
- ' be given to set a different error handling scheme. The '
- 'default is\n'
- ' "\'strict\'", meaning that encoding errors raise '
- '"UnicodeError".\n'
- ' Other possible values are "\'ignore\'", "\'replace\'" and any '
- 'other\n'
- ' name registered via "codecs.register_error()", see section '
- 'Codec\n'
- ' Base Classes.\n'
- '\n'
- ' New in version 2.2.\n'
- '\n'
- ' Changed in version 2.3: Support for other error handling '
- 'schemes\n'
- ' added.\n'
- '\n'
- ' Changed in version 2.7: Support for keyword arguments added.\n'
- '\n'
- 'str.encode([encoding[, errors]])\n'
- '\n'
- ' Return an encoded version of the string. Default encoding is '
- 'the\n'
- ' current default string encoding. *errors* may be given to '
- 'set a\n'
- ' different error handling scheme. The default for *errors* '
- 'is\n'
- ' "\'strict\'", meaning that encoding errors raise a '
- '"UnicodeError".\n'
- ' Other possible values are "\'ignore\'", "\'replace\'",\n'
- ' "\'xmlcharrefreplace\'", "\'backslashreplace\'" and any other '
- 'name\n'
- ' registered via "codecs.register_error()", see section Codec '
- 'Base\n'
- ' Classes. For a list of possible encodings, see section '
- 'Standard\n'
- ' Encodings.\n'
- '\n'
- ' New in version 2.0.\n'
- '\n'
- ' Changed in version 2.3: Support for "\'xmlcharrefreplace\'" '
- 'and\n'
- ' "\'backslashreplace\'" and other error handling schemes '
- 'added.\n'
- '\n'
- ' Changed in version 2.7: Support for keyword arguments added.\n'
- '\n'
- 'str.endswith(suffix[, start[, end]])\n'
- '\n'
- ' Return "True" if the string ends with the specified '
- '*suffix*,\n'
- ' otherwise return "False". *suffix* can also be a tuple of '
- 'suffixes\n'
- ' to look for. With optional *start*, test beginning at that\n'
- ' position. With optional *end*, stop comparing at that '
- 'position.\n'
- '\n'
- ' Changed in version 2.5: Accept tuples as *suffix*.\n'
- '\n'
- 'str.expandtabs([tabsize])\n'
- '\n'
- ' Return a copy of the string where all tab characters are '
- 'replaced\n'
- ' by one or more spaces, depending on the current column and '
- 'the\n'
- ' given tab size. Tab positions occur every *tabsize* '
- 'characters\n'
- ' (default is 8, giving tab positions at columns 0, 8, 16 and '
- 'so on).\n'
- ' To expand the string, the current column is set to zero and '
- 'the\n'
- ' string is examined character by character. If the character '
- 'is a\n'
- ' tab ("\\t"), one or more space characters are inserted in the '
- 'result\n'
- ' until the current column is equal to the next tab position. '
- '(The\n'
- ' tab character itself is not copied.) If the character is a '
- 'newline\n'
- ' ("\\n") or return ("\\r"), it is copied and the current '
- 'column is\n'
- ' reset to zero. Any other character is copied unchanged and '
- 'the\n'
- ' current column is incremented by one regardless of how the\n'
- ' character is represented when printed.\n'
- '\n'
- " >>> '01\\t012\\t0123\\t01234'.expandtabs()\n"
- " '01 012 0123 01234'\n"
- " >>> '01\\t012\\t0123\\t01234'.expandtabs(4)\n"
- " '01 012 0123 01234'\n"
- '\n'
- 'str.find(sub[, start[, end]])\n'
- '\n'
- ' Return the lowest index in the string where substring *sub* '
- 'is\n'
- ' found within the slice "s[start:end]". Optional arguments '
- '*start*\n'
- ' and *end* are interpreted as in slice notation. Return "-1" '
- 'if\n'
- ' *sub* is not found.\n'
- '\n'
- ' Note: The "find()" method should be used only if you need to '
- 'know\n'
- ' the position of *sub*. To check if *sub* is a substring or '
- 'not,\n'
- ' use the "in" operator:\n'
- '\n'
- " >>> 'Py' in 'Python'\n"
- ' True\n'
- '\n'
- 'str.format(*args, **kwargs)\n'
- '\n'
- ' Perform a string formatting operation. The string on which '
- 'this\n'
- ' method is called can contain literal text or replacement '
- 'fields\n'
- ' delimited by braces "{}". Each replacement field contains '
- 'either\n'
- ' the numeric index of a positional argument, or the name of a\n'
- ' keyword argument. Returns a copy of the string where each\n'
- ' replacement field is replaced with the string value of the\n'
- ' corresponding argument.\n'
- '\n'
- ' >>> "The sum of 1 + 2 is {0}".format(1+2)\n'
- " 'The sum of 1 + 2 is 3'\n"
- '\n'
- ' See Format String Syntax for a description of the various\n'
- ' formatting options that can be specified in format strings.\n'
- '\n'
- ' This method of string formatting is the new standard in '
- 'Python 3,\n'
- ' and should be preferred to the "%" formatting described in '
- 'String\n'
- ' Formatting Operations in new code.\n'
- '\n'
- ' New in version 2.6.\n'
- '\n'
- 'str.index(sub[, start[, end]])\n'
- '\n'
- ' Like "find()", but raise "ValueError" when the substring is '
- 'not\n'
- ' found.\n'
- '\n'
- 'str.isalnum()\n'
- '\n'
- ' Return true if all characters in the string are alphanumeric '
- 'and\n'
- ' there is at least one character, false otherwise.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.isalpha()\n'
- '\n'
- ' Return true if all characters in the string are alphabetic '
- 'and\n'
- ' there is at least one character, false otherwise.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.isdigit()\n'
- '\n'
- ' Return true if all characters in the string are digits and '
- 'there is\n'
- ' at least one character, false otherwise.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.islower()\n'
- '\n'
- ' Return true if all cased characters [4] in the string are '
- 'lowercase\n'
- ' and there is at least one cased character, false otherwise.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.isspace()\n'
- '\n'
- ' Return true if there are only whitespace characters in the '
- 'string\n'
- ' and there is at least one character, false otherwise.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.istitle()\n'
- '\n'
- ' Return true if the string is a titlecased string and there is '
- 'at\n'
- ' least one character, for example uppercase characters may '
- 'only\n'
- ' follow uncased characters and lowercase characters only cased '
- 'ones.\n'
- ' Return false otherwise.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.isupper()\n'
- '\n'
- ' Return true if all cased characters [4] in the string are '
- 'uppercase\n'
- ' and there is at least one cased character, false otherwise.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.join(iterable)\n'
- '\n'
- ' Return a string which is the concatenation of the strings in '
- 'the\n'
- ' *iterable* *iterable*. The separator between elements is '
- 'the\n'
- ' string providing this method.\n'
- '\n'
- 'str.ljust(width[, fillchar])\n'
- '\n'
- ' Return the string left justified in a string of length '
- '*width*.\n'
- ' Padding is done using the specified *fillchar* (default is a\n'
- ' space). The original string is returned if *width* is less '
- 'than or\n'
- ' equal to "len(s)".\n'
- '\n'
- ' Changed in version 2.4: Support for the *fillchar* argument.\n'
- '\n'
- 'str.lower()\n'
- '\n'
- ' Return a copy of the string with all the cased characters '
- '[4]\n'
- ' converted to lowercase.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.lstrip([chars])\n'
- '\n'
- ' Return a copy of the string with leading characters removed. '
- 'The\n'
- ' *chars* argument is a string specifying the set of characters '
- 'to be\n'
- ' removed. If omitted or "None", the *chars* argument defaults '
- 'to\n'
- ' removing whitespace. The *chars* argument is not a prefix; '
- 'rather,\n'
- ' all combinations of its values are stripped:\n'
- '\n'
- " >>> ' spacious '.lstrip()\n"
- " 'spacious '\n"
- " >>> 'www.example.com'.lstrip('cmowz.')\n"
- " 'example.com'\n"
- '\n'
- ' Changed in version 2.2.2: Support for the *chars* argument.\n'
- '\n'
- 'str.partition(sep)\n'
- '\n'
- ' Split the string at the first occurrence of *sep*, and return '
- 'a\n'
- ' 3-tuple containing the part before the separator, the '
- 'separator\n'
- ' itself, and the part after the separator. If the separator '
- 'is not\n'
- ' found, return a 3-tuple containing the string itself, '
- 'followed by\n'
- ' two empty strings.\n'
- '\n'
- ' New in version 2.5.\n'
- '\n'
- 'str.replace(old, new[, count])\n'
- '\n'
- ' Return a copy of the string with all occurrences of substring '
- '*old*\n'
- ' replaced by *new*. If the optional argument *count* is '
- 'given, only\n'
- ' the first *count* occurrences are replaced.\n'
- '\n'
- 'str.rfind(sub[, start[, end]])\n'
- '\n'
- ' Return the highest index in the string where substring *sub* '
- 'is\n'
- ' found, such that *sub* is contained within "s[start:end]".\n'
- ' Optional arguments *start* and *end* are interpreted as in '
- 'slice\n'
- ' notation. Return "-1" on failure.\n'
- '\n'
- 'str.rindex(sub[, start[, end]])\n'
- '\n'
- ' Like "rfind()" but raises "ValueError" when the substring '
- '*sub* is\n'
- ' not found.\n'
- '\n'
- 'str.rjust(width[, fillchar])\n'
- '\n'
- ' Return the string right justified in a string of length '
- '*width*.\n'
- ' Padding is done using the specified *fillchar* (default is a\n'
- ' space). The original string is returned if *width* is less '
- 'than or\n'
- ' equal to "len(s)".\n'
- '\n'
- ' Changed in version 2.4: Support for the *fillchar* argument.\n'
- '\n'
- 'str.rpartition(sep)\n'
- '\n'
- ' Split the string at the last occurrence of *sep*, and return '
- 'a\n'
- ' 3-tuple containing the part before the separator, the '
- 'separator\n'
- ' itself, and the part after the separator. If the separator '
- 'is not\n'
- ' found, return a 3-tuple containing two empty strings, '
- 'followed by\n'
- ' the string itself.\n'
- '\n'
- ' New in version 2.5.\n'
- '\n'
- 'str.rsplit([sep[, maxsplit]])\n'
- '\n'
- ' Return a list of the words in the string, using *sep* as the\n'
- ' delimiter string. If *maxsplit* is given, at most *maxsplit* '
- 'splits\n'
- ' are done, the *rightmost* ones. If *sep* is not specified '
- 'or\n'
- ' "None", any whitespace string is a separator. Except for '
- 'splitting\n'
- ' from the right, "rsplit()" behaves like "split()" which is\n'
- ' described in detail below.\n'
- '\n'
- ' New in version 2.4.\n'
- '\n'
- 'str.rstrip([chars])\n'
- '\n'
- ' Return a copy of the string with trailing characters '
- 'removed. The\n'
- ' *chars* argument is a string specifying the set of characters '
- 'to be\n'
- ' removed. If omitted or "None", the *chars* argument defaults '
- 'to\n'
- ' removing whitespace. The *chars* argument is not a suffix; '
- 'rather,\n'
- ' all combinations of its values are stripped:\n'
- '\n'
- " >>> ' spacious '.rstrip()\n"
- " ' spacious'\n"
- " >>> 'mississippi'.rstrip('ipz')\n"
- " 'mississ'\n"
- '\n'
- ' Changed in version 2.2.2: Support for the *chars* argument.\n'
- '\n'
- 'str.split([sep[, maxsplit]])\n'
- '\n'
- ' Return a list of the words in the string, using *sep* as the\n'
- ' delimiter string. If *maxsplit* is given, at most '
- '*maxsplit*\n'
- ' splits are done (thus, the list will have at most '
- '"maxsplit+1"\n'
- ' elements). If *maxsplit* is not specified or "-1", then '
- 'there is\n'
- ' no limit on the number of splits (all possible splits are '
- 'made).\n'
- '\n'
- ' If *sep* is given, consecutive delimiters are not grouped '
- 'together\n'
- ' and are deemed to delimit empty strings (for example,\n'
- ' "\'1,,2\'.split(\',\')" returns "[\'1\', \'\', \'2\']"). The '
- '*sep* argument\n'
- ' may consist of multiple characters (for example,\n'
- ' "\'1<>2<>3\'.split(\'<>\')" returns "[\'1\', \'2\', \'3\']"). '
- 'Splitting an\n'
- ' empty string with a specified separator returns "[\'\']".\n'
- '\n'
- ' If *sep* is not specified or is "None", a different '
- 'splitting\n'
- ' algorithm is applied: runs of consecutive whitespace are '
- 'regarded\n'
- ' as a single separator, and the result will contain no empty '
- 'strings\n'
- ' at the start or end if the string has leading or trailing\n'
- ' whitespace. Consequently, splitting an empty string or a '
- 'string\n'
- ' consisting of just whitespace with a "None" separator returns '
- '"[]".\n'
- '\n'
- ' For example, "\' 1 2 3 \'.split()" returns "[\'1\', '
- '\'2\', \'3\']", and\n'
- ' "\' 1 2 3 \'.split(None, 1)" returns "[\'1\', \'2 3 '
- '\']".\n'
- '\n'
- 'str.splitlines([keepends])\n'
- '\n'
- ' Return a list of the lines in the string, breaking at line\n'
- ' boundaries. This method uses the *universal newlines* '
- 'approach to\n'
- ' splitting lines. Line breaks are not included in the '
- 'resulting list\n'
- ' unless *keepends* is given and true.\n'
- '\n'
- ' For example, "\'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()" '
- 'returns "[\'ab\n'
- ' c\', \'\', \'de fg\', \'kl\']", while the same call with\n'
- ' "splitlines(True)" returns "[\'ab c\\n\', \'\\n\', \'de '
- 'fg\\r\', \'kl\\r\\n\']".\n'
- '\n'
- ' Unlike "split()" when a delimiter string *sep* is given, '
- 'this\n'
- ' method returns an empty list for the empty string, and a '
- 'terminal\n'
- ' line break does not result in an extra line.\n'
- '\n'
- 'str.startswith(prefix[, start[, end]])\n'
- '\n'
- ' Return "True" if string starts with the *prefix*, otherwise '
- 'return\n'
- ' "False". *prefix* can also be a tuple of prefixes to look '
- 'for.\n'
- ' With optional *start*, test string beginning at that '
- 'position.\n'
- ' With optional *end*, stop comparing string at that position.\n'
- '\n'
- ' Changed in version 2.5: Accept tuples as *prefix*.\n'
- '\n'
- 'str.strip([chars])\n'
- '\n'
- ' Return a copy of the string with the leading and trailing\n'
- ' characters removed. The *chars* argument is a string '
- 'specifying the\n'
- ' set of characters to be removed. If omitted or "None", the '
- '*chars*\n'
- ' argument defaults to removing whitespace. The *chars* '
- 'argument is\n'
- ' not a prefix or suffix; rather, all combinations of its '
- 'values are\n'
- ' stripped:\n'
- '\n'
- " >>> ' spacious '.strip()\n"
- " 'spacious'\n"
- " >>> 'www.example.com'.strip('cmowz.')\n"
- " 'example'\n"
- '\n'
- ' Changed in version 2.2.2: Support for the *chars* argument.\n'
- '\n'
- 'str.swapcase()\n'
- '\n'
- ' Return a copy of the string with uppercase characters '
- 'converted to\n'
- ' lowercase and vice versa.\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.title()\n'
- '\n'
- ' Return a titlecased version of the string where words start '
- 'with an\n'
- ' uppercase character and the remaining characters are '
- 'lowercase.\n'
- '\n'
- ' The algorithm uses a simple language-independent definition '
- 'of a\n'
- ' word as groups of consecutive letters. The definition works '
- 'in\n'
- ' many contexts but it means that apostrophes in contractions '
- 'and\n'
- ' possessives form word boundaries, which may not be the '
- 'desired\n'
- ' result:\n'
- '\n'
- ' >>> "they\'re bill\'s friends from the UK".title()\n'
- ' "They\'Re Bill\'S Friends From The Uk"\n'
- '\n'
- ' A workaround for apostrophes can be constructed using '
- 'regular\n'
- ' expressions:\n'
- '\n'
- ' >>> import re\n'
- ' >>> def titlecase(s):\n'
- ' ... return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n'
- ' ... lambda mo: mo.group(0)[0].upper() +\n'
- ' ... mo.group(0)[1:].lower(),\n'
- ' ... s)\n'
- ' ...\n'
- ' >>> titlecase("they\'re bill\'s friends.")\n'
- ' "They\'re Bill\'s Friends."\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.translate(table[, deletechars])\n'
- '\n'
- ' Return a copy of the string where all characters occurring in '
- 'the\n'
- ' optional argument *deletechars* are removed, and the '
- 'remaining\n'
- ' characters have been mapped through the given translation '
- 'table,\n'
- ' which must be a string of length 256.\n'
- '\n'
- ' You can use the "maketrans()" helper function in the '
- '"string"\n'
- ' module to create a translation table. For string objects, set '
- 'the\n'
- ' *table* argument to "None" for translations that only delete\n'
- ' characters:\n'
- '\n'
- " >>> 'read this short text'.translate(None, 'aeiou')\n"
- " 'rd ths shrt txt'\n"
- '\n'
- ' New in version 2.6: Support for a "None" *table* argument.\n'
- '\n'
- ' For Unicode objects, the "translate()" method does not accept '
- 'the\n'
- ' optional *deletechars* argument. Instead, it returns a copy '
- 'of the\n'
- ' *s* where all characters have been mapped through the given\n'
- ' translation table which must be a mapping of Unicode ordinals '
- 'to\n'
- ' Unicode ordinals, Unicode strings or "None". Unmapped '
- 'characters\n'
- ' are left untouched. Characters mapped to "None" are deleted. '
- 'Note,\n'
- ' a more flexible approach is to create a custom character '
- 'mapping\n'
- ' codec using the "codecs" module (see "encodings.cp1251" for '
- 'an\n'
- ' example).\n'
- '\n'
- 'str.upper()\n'
- '\n'
- ' Return a copy of the string with all the cased characters '
- '[4]\n'
- ' converted to uppercase. Note that "str.upper().isupper()" '
- 'might be\n'
- ' "False" if "s" contains uncased characters or if the Unicode\n'
- ' category of the resulting character(s) is not "Lu" (Letter,\n'
- ' uppercase), but e.g. "Lt" (Letter, titlecase).\n'
- '\n'
- ' For 8-bit strings, this method is locale-dependent.\n'
- '\n'
- 'str.zfill(width)\n'
- '\n'
- ' Return the numeric string left filled with zeros in a string '
- 'of\n'
- ' length *width*. A sign prefix is handled correctly. The '
- 'original\n'
- ' string is returned if *width* is less than or equal to '
- '"len(s)".\n'
- '\n'
- ' New in version 2.2.2.\n'
- '\n'
- 'The following methods are present only on unicode objects:\n'
- '\n'
- 'unicode.isnumeric()\n'
- '\n'
- ' Return "True" if there are only numeric characters in S, '
- '"False"\n'
- ' otherwise. Numeric characters include digit characters, and '
- 'all\n'
- ' characters that have the Unicode numeric value property, '
- 'e.g.\n'
- ' U+2155, VULGAR FRACTION ONE FIFTH.\n'
- '\n'
- 'unicode.isdecimal()\n'
- '\n'
- ' Return "True" if there are only decimal characters in S, '
- '"False"\n'
- ' otherwise. Decimal characters include digit characters, and '
- 'all\n'
- ' characters that can be used to form decimal-radix numbers, '
- 'e.g.\n'
- ' U+0660, ARABIC-INDIC DIGIT ZERO.\n'
- '\n'
- '\n'
- 'String Formatting Operations\n'
- '============================\n'
- '\n'
- 'String and Unicode objects have one unique built-in operation: '
- 'the "%"\n'
- 'operator (modulo). This is also known as the string '
- '*formatting* or\n'
- '*interpolation* operator. Given "format % values" (where '
- '*format* is\n'
- 'a string or Unicode object), "%" conversion specifications in '
- '*format*\n'
- 'are replaced with zero or more elements of *values*. The effect '
- 'is\n'
- 'similar to the using "sprintf()" in the C language. If *format* '
- 'is a\n'
- 'Unicode object, or if any of the objects being converted using '
- 'the\n'
- '"%s" conversion are Unicode objects, the result will also be a '
- 'Unicode\n'
- 'object.\n'
- '\n'
- 'If *format* requires a single argument, *values* may be a single '
- 'non-\n'
- 'tuple object. [5] Otherwise, *values* must be a tuple with '
- 'exactly\n'
- 'the number of items specified by the format string, or a single\n'
- 'mapping object (for example, a dictionary).\n'
- '\n'
- 'A conversion specifier contains two or more characters and has '
- 'the\n'
- 'following components, which must occur in this order:\n'
- '\n'
- '1. The "\'%\'" character, which marks the start of the '
- 'specifier.\n'
- '\n'
- '2. Mapping key (optional), consisting of a parenthesised '
- 'sequence\n'
- ' of characters (for example, "(somename)").\n'
- '\n'
- '3. Conversion flags (optional), which affect the result of some\n'
- ' conversion types.\n'
- '\n'
- '4. Minimum field width (optional). If specified as an "\'*\'"\n'
- ' (asterisk), the actual width is read from the next element of '
- 'the\n'
- ' tuple in *values*, and the object to convert comes after the\n'
- ' minimum field width and optional precision.\n'
- '\n'
- '5. Precision (optional), given as a "\'.\'" (dot) followed by '
- 'the\n'
- ' precision. If specified as "\'*\'" (an asterisk), the actual '
- 'width\n'
- ' is read from the next element of the tuple in *values*, and '
- 'the\n'
- ' value to convert comes after the precision.\n'
- '\n'
- '6. Length modifier (optional).\n'
- '\n'
- '7. Conversion type.\n'
- '\n'
- 'When the right argument is a dictionary (or other mapping type), '
- 'then\n'
- 'the formats in the string *must* include a parenthesised mapping '
- 'key\n'
- 'into that dictionary inserted immediately after the "\'%\'" '
- 'character.\n'
- 'The mapping key selects the value to be formatted from the '
- 'mapping.\n'
- 'For example:\n'
- '\n'
- ">>> print '%(language)s has %(number)03d quote types.' % \\\n"
- '... {"language": "Python", "number": 2}\n'
- 'Python has 002 quote types.\n'
- '\n'
- 'In this case no "*" specifiers may occur in a format (since '
- 'they\n'
- 'require a sequential parameter list).\n'
- '\n'
- 'The conversion flag characters are:\n'
- '\n'
- '+-----------+-----------------------------------------------------------------------+\n'
- '| Flag | '
- 'Meaning '
- '|\n'
- '+===========+=======================================================================+\n'
- '| "\'#\'" | The value conversion will use the "alternate '
- 'form" (where defined |\n'
- '| | '
- 'below). '
- '|\n'
- '+-----------+-----------------------------------------------------------------------+\n'
- '| "\'0\'" | The conversion will be zero padded for numeric '
- 'values. |\n'
- '+-----------+-----------------------------------------------------------------------+\n'
- '| "\'-\'" | The converted value is left adjusted (overrides '
- 'the "\'0\'" conversion |\n'
- '| | if both are '
- 'given). |\n'
- '+-----------+-----------------------------------------------------------------------+\n'
- '| "\' \'" | (a space) A blank should be left before a '
- 'positive number (or empty |\n'
- '| | string) produced by a signed '
- 'conversion. |\n'
- '+-----------+-----------------------------------------------------------------------+\n'
- '| "\'+\'" | A sign character ("\'+\'" or "\'-\'") will '
- 'precede the conversion |\n'
- '| | (overrides a "space" '
- 'flag). |\n'
- '+-----------+-----------------------------------------------------------------------+\n'
- '\n'
- 'A length modifier ("h", "l", or "L") may be present, but is '
- 'ignored as\n'
- 'it is not necessary for Python -- so e.g. "%ld" is identical to '
- '"%d".\n'
- '\n'
- 'The conversion types are:\n'
- '\n'
- '+--------------+-------------------------------------------------------+---------+\n'
- '| Conversion | '
- 'Meaning | Notes '
- '|\n'
- '+==============+=======================================================+=========+\n'
- '| "\'d\'" | Signed integer '
- 'decimal. | |\n'
- '+--------------+-------------------------------------------------------+---------+\n'
- '| "\'i\'" | Signed integer '
- 'decimal. | |\n'
- '+--------------+-------------------------------------------------------+---------+\n'
- '| "\'o\'" | Signed octal '
- 'value. | (1) |\n'
- '+--------------+-------------------------------------------------------+---------+\n'
- '| "\'u\'" | Obsolete type -- it is identical to '
- '"\'d\'". | (7) |\n'
- '+--------------+-------------------------------------------------------+---------+\n'
- '| "\'x\'" | Signed hexadecimal '
- '(lowercase). | (2) |\n'
- '+--------------+-------------------------------------------------------+---------+\n'
- '| "\'X\'" | Signed hexadecimal '
- '(uppercase). | (2) |\n'
- '+--------------+-------------------------------------------------------+---------+\n'
- '| "\'e\'" | Floating point exponential format '
- '(lowercase). | (3) |\n'
- '+--------------+-------------------------------------------------------+---------+\n'
- '| "\'E\'" | Floating point exponential format '
- '(uppercase). | (3) |\n'
- '+--------------+-------------------------------------------------------+---------+\n'
- '| "\'f\'" | Floating point decimal '
- 'format. | (3) |\n'
- '+--------------+-------------------------------------------------------+---------+\n'
- '| "\'F\'" | Floating point decimal '
- 'format. | (3) |\n'
- '+--------------+-------------------------------------------------------+---------+\n'
- '| "\'g\'" | Floating point format. Uses lowercase '
- 'exponential | (4) |\n'
- '| | format if exponent is less than -4 or not less '
- 'than | |\n'
- '| | precision, decimal format '
- 'otherwise. | |\n'
- '+--------------+-------------------------------------------------------+---------+\n'
- '| "\'G\'" | Floating point format. Uses uppercase '
- 'exponential | (4) |\n'
- '| | format if exponent is less than -4 or not less '
- 'than | |\n'
- '| | precision, decimal format '
- 'otherwise. | |\n'
- '+--------------+-------------------------------------------------------+---------+\n'
- '| "\'c\'" | Single character (accepts integer or single '
- 'character | |\n'
- '| | '
- 'string). | '
- '|\n'
- '+--------------+-------------------------------------------------------+---------+\n'
- '| "\'r\'" | String (converts any Python object using '
- 'repr()). | (5) |\n'
- '+--------------+-------------------------------------------------------+---------+\n'
- '| "\'s\'" | String (converts any Python object using '
- '"str()"). | (6) |\n'
- '+--------------+-------------------------------------------------------+---------+\n'
- '| "\'%\'" | No argument is converted, results in a '
- '"\'%\'" | |\n'
- '| | character in the '
- 'result. | |\n'
- '+--------------+-------------------------------------------------------+---------+\n'
- '\n'
- 'Notes:\n'
- '\n'
- '1. The alternate form causes a leading zero ("\'0\'") to be '
- 'inserted\n'
- ' between left-hand padding and the formatting of the number if '
- 'the\n'
- ' leading character of the result is not already a zero.\n'
- '\n'
- '2. The alternate form causes a leading "\'0x\'" or "\'0X\'" '
- '(depending\n'
- ' on whether the "\'x\'" or "\'X\'" format was used) to be '
- 'inserted\n'
- ' between left-hand padding and the formatting of the number if '
- 'the\n'
- ' leading character of the result is not already a zero.\n'
- '\n'
- '3. The alternate form causes the result to always contain a '
- 'decimal\n'
- ' point, even if no digits follow it.\n'
- '\n'
- ' The precision determines the number of digits after the '
- 'decimal\n'
- ' point and defaults to 6.\n'
- '\n'
- '4. The alternate form causes the result to always contain a '
- 'decimal\n'
- ' point, and trailing zeroes are not removed as they would '
- 'otherwise\n'
- ' be.\n'
- '\n'
- ' The precision determines the number of significant digits '
- 'before\n'
- ' and after the decimal point and defaults to 6.\n'
- '\n'
- '5. The "%r" conversion was added in Python 2.0.\n'
- '\n'
- ' The precision determines the maximal number of characters '
- 'used.\n'
- '\n'
- '6. If the object or format provided is a "unicode" string, the\n'
- ' resulting string will also be "unicode".\n'
- '\n'
- ' The precision determines the maximal number of characters '
- 'used.\n'
- '\n'
- '7. See **PEP 237**.\n'
- '\n'
- 'Since Python strings have an explicit length, "%s" conversions '
- 'do not\n'
- 'assume that "\'\\0\'" is the end of the string.\n'
- '\n'
- 'Changed in version 2.7: "%f" conversions for numbers whose '
- 'absolute\n'
- 'value is over 1e50 are no longer replaced by "%g" conversions.\n'
- '\n'
- 'Additional string operations are defined in standard modules '
- '"string"\n'
- 'and "re".\n'
- '\n'
- '\n'
- 'XRange Type\n'
- '===========\n'
- '\n'
- 'The "xrange" type is an immutable sequence which is commonly '
- 'used for\n'
- 'looping. The advantage of the "xrange" type is that an '
- '"xrange"\n'
- 'object will always take the same amount of memory, no matter the '
- 'size\n'
- 'of the range it represents. There are no consistent '
- 'performance\n'
- 'advantages.\n'
- '\n'
- 'XRange objects have very little behavior: they only support '
- 'indexing,\n'
- 'iteration, and the "len()" function.\n'
- '\n'
- '\n'
- 'Mutable Sequence Types\n'
- '======================\n'
- '\n'
- 'List and "bytearray" objects support additional operations that '
- 'allow\n'
- 'in-place modification of the object. Other mutable sequence '
- 'types\n'
- '(when added to the language) should also support these '
- 'operations.\n'
- 'Strings and tuples are immutable sequence types: such objects '
- 'cannot\n'
- 'be modified once created. The following operations are defined '
- 'on\n'
- 'mutable sequence types (where *x* is an arbitrary object):\n'
- '\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| Operation | '
- 'Result | Notes |\n'
- '+================================+==================================+=======================+\n'
- '| "s[i] = x" | item *i* of *s* is replaced '
- 'by | |\n'
- '| | '
- '*x* | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s[i:j] = t" | slice of *s* from *i* to *j* '
- 'is | |\n'
- '| | replaced by the contents of '
- 'the | |\n'
- '| | iterable '
- '*t* | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "del s[i:j]" | same as "s[i:j] = '
- '[]" | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s[i:j:k] = t" | the elements of "s[i:j:k]" '
- 'are | (1) |\n'
- '| | replaced by those of '
- '*t* | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "del s[i:j:k]" | removes the elements '
- 'of | |\n'
- '| | "s[i:j:k]" from the '
- 'list | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.append(x)" | same as "s[len(s):len(s)] = '
- '[x]" | (2) |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.extend(x)" or "s += t" | for the most part the same '
- 'as | (3) |\n'
- '| | "s[len(s):len(s)] = '
- 'x" | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s *= n" | updates *s* with its '
- 'contents | (11) |\n'
- '| | repeated *n* '
- 'times | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.count(x)" | return number of *i*\'s for '
- 'which | |\n'
- '| | "s[i] == '
- 'x" | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.index(x[, i[, j]])" | return smallest *k* such '
- 'that | (4) |\n'
- '| | "s[k] == x" and "i <= k < '
- 'j" | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.insert(i, x)" | same as "s[i:i] = '
- '[x]" | (5) |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.pop([i])" | same as "x = s[i]; del '
- 's[i]; | (6) |\n'
- '| | return '
- 'x" | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.remove(x)" | same as "del '
- 's[s.index(x)]" | (4) |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.reverse()" | reverses the items of *s* '
- 'in | (7) |\n'
- '| | '
- 'place | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.sort([cmp[, key[, | sort the items of *s* in '
- 'place | (7)(8)(9)(10) |\n'
- '| reverse]]])" '
- '| | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '\n'
- 'Notes:\n'
- '\n'
- '1. *t* must have the same length as the slice it is replacing.\n'
- '\n'
- '2. The C implementation of Python has historically accepted\n'
- ' multiple parameters and implicitly joined them into a tuple; '
- 'this\n'
- ' no longer works in Python 2.0. Use of this misfeature has '
- 'been\n'
- ' deprecated since Python 1.4.\n'
- '\n'
- '3. *x* can be any iterable object.\n'
- '\n'
- '4. Raises "ValueError" when *x* is not found in *s*. When a\n'
- ' negative index is passed as the second or third parameter to '
- 'the\n'
- ' "index()" method, the list length is added, as for slice '
- 'indices.\n'
- ' If it is still negative, it is truncated to zero, as for '
- 'slice\n'
- ' indices.\n'
- '\n'
- ' Changed in version 2.3: Previously, "index()" didn\'t have '
- 'arguments\n'
- ' for specifying start and stop positions.\n'
- '\n'
- '5. When a negative index is passed as the first parameter to '
- 'the\n'
- ' "insert()" method, the list length is added, as for slice '
- 'indices.\n'
- ' If it is still negative, it is truncated to zero, as for '
- 'slice\n'
- ' indices.\n'
- '\n'
- ' Changed in version 2.3: Previously, all negative indices '
- 'were\n'
- ' truncated to zero.\n'
- '\n'
- '6. The "pop()" method\'s optional argument *i* defaults to "-1", '
- 'so\n'
- ' that by default the last item is removed and returned.\n'
- '\n'
- '7. The "sort()" and "reverse()" methods modify the list in '
- 'place\n'
- ' for economy of space when sorting or reversing a large list. '
- 'To\n'
- " remind you that they operate by side effect, they don't "
- 'return the\n'
- ' sorted or reversed list.\n'
- '\n'
- '8. The "sort()" method takes optional arguments for controlling '
- 'the\n'
- ' comparisons.\n'
- '\n'
- ' *cmp* specifies a custom comparison function of two arguments '
- '(list\n'
- ' items) which should return a negative, zero or positive '
- 'number\n'
- ' depending on whether the first argument is considered smaller '
- 'than,\n'
- ' equal to, or larger than the second argument: "cmp=lambda '
- 'x,y:\n'
- ' cmp(x.lower(), y.lower())". The default value is "None".\n'
- '\n'
- ' *key* specifies a function of one argument that is used to '
- 'extract\n'
- ' a comparison key from each list element: "key=str.lower". '
- 'The\n'
- ' default value is "None".\n'
- '\n'
- ' *reverse* is a boolean value. If set to "True", then the '
- 'list\n'
- ' elements are sorted as if each comparison were reversed.\n'
- '\n'
- ' In general, the *key* and *reverse* conversion processes are '
- 'much\n'
- ' faster than specifying an equivalent *cmp* function. This '
- 'is\n'
- ' because *cmp* is called multiple times for each list element '
- 'while\n'
- ' *key* and *reverse* touch each element only once. Use\n'
- ' "functools.cmp_to_key()" to convert an old-style *cmp* '
- 'function to\n'
- ' a *key* function.\n'
- '\n'
- ' Changed in version 2.3: Support for "None" as an equivalent '
- 'to\n'
- ' omitting *cmp* was added.\n'
- '\n'
- ' Changed in version 2.4: Support for *key* and *reverse* was '
- 'added.\n'
- '\n'
- '9. Starting with Python 2.3, the "sort()" method is guaranteed '
- 'to\n'
- ' be stable. A sort is stable if it guarantees not to change '
- 'the\n'
- ' relative order of elements that compare equal --- this is '
- 'helpful\n'
- ' for sorting in multiple passes (for example, sort by '
- 'department,\n'
- ' then by salary grade).\n'
- '\n'
- '10. **CPython implementation detail:** While a list is being\n'
- ' sorted, the effect of attempting to mutate, or even inspect, '
- 'the\n'
- ' list is undefined. The C implementation of Python 2.3 and '
- 'newer\n'
- ' makes the list appear empty for the duration, and raises\n'
- ' "ValueError" if it can detect that the list has been '
- 'mutated\n'
- ' during a sort.\n'
- '\n'
- '11. The value *n* is an integer, or an object implementing\n'
- ' "__index__()". Zero and negative values of *n* clear the\n'
- ' sequence. Items in the sequence are not copied; they are\n'
- ' referenced multiple times, as explained for "s * n" under '
- 'Sequence\n'
- ' Types --- str, unicode, list, tuple, bytearray, buffer, '
- 'xrange.\n',
- 'typesseq-mutable': '\n'
- 'Mutable Sequence Types\n'
- '**********************\n'
- '\n'
- 'List and "bytearray" objects support additional '
- 'operations that allow\n'
- 'in-place modification of the object. Other mutable '
- 'sequence types\n'
- '(when added to the language) should also support these '
- 'operations.\n'
- 'Strings and tuples are immutable sequence types: such '
- 'objects cannot\n'
- 'be modified once created. The following operations are '
- 'defined on\n'
- 'mutable sequence types (where *x* is an arbitrary '
- 'object):\n'
- '\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| Operation | '
- 'Result | Notes '
- '|\n'
- '+================================+==================================+=======================+\n'
- '| "s[i] = x" | item *i* of *s* is '
- 'replaced by | |\n'
- '| | '
- '*x* | '
- '|\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s[i:j] = t" | slice of *s* from *i* '
- 'to *j* is | |\n'
- '| | replaced by the '
- 'contents of the | |\n'
- '| | iterable '
- '*t* | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "del s[i:j]" | same as "s[i:j] = '
- '[]" | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s[i:j:k] = t" | the elements of '
- '"s[i:j:k]" are | (1) |\n'
- '| | replaced by those of '
- '*t* | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "del s[i:j:k]" | removes the elements '
- 'of | |\n'
- '| | "s[i:j:k]" from the '
- 'list | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.append(x)" | same as '
- '"s[len(s):len(s)] = [x]" | (2) |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.extend(x)" or "s += t" | for the most part the '
- 'same as | (3) |\n'
- '| | "s[len(s):len(s)] = '
- 'x" | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s *= n" | updates *s* with its '
- 'contents | (11) |\n'
- '| | repeated *n* '
- 'times | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.count(x)" | return number of '
- "*i*'s for which | |\n"
- '| | "s[i] == '
- 'x" | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.index(x[, i[, j]])" | return smallest *k* '
- 'such that | (4) |\n'
- '| | "s[k] == x" and "i <= '
- 'k < j" | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.insert(i, x)" | same as "s[i:i] = '
- '[x]" | (5) |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.pop([i])" | same as "x = s[i]; '
- 'del s[i]; | (6) |\n'
- '| | return '
- 'x" | |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.remove(x)" | same as "del '
- 's[s.index(x)]" | (4) |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.reverse()" | reverses the items of '
- '*s* in | (7) |\n'
- '| | '
- 'place | '
- '|\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '| "s.sort([cmp[, key[, | sort the items of *s* '
- 'in place | (7)(8)(9)(10) |\n'
- '| reverse]]])" '
- '| '
- '| |\n'
- '+--------------------------------+----------------------------------+-----------------------+\n'
- '\n'
- 'Notes:\n'
- '\n'
- '1. *t* must have the same length as the slice it is '
- 'replacing.\n'
- '\n'
- '2. The C implementation of Python has historically '
- 'accepted\n'
- ' multiple parameters and implicitly joined them into a '
- 'tuple; this\n'
- ' no longer works in Python 2.0. Use of this '
- 'misfeature has been\n'
- ' deprecated since Python 1.4.\n'
- '\n'
- '3. *x* can be any iterable object.\n'
- '\n'
- '4. Raises "ValueError" when *x* is not found in *s*. '
- 'When a\n'
- ' negative index is passed as the second or third '
- 'parameter to the\n'
- ' "index()" method, the list length is added, as for '
- 'slice indices.\n'
- ' If it is still negative, it is truncated to zero, as '
- 'for slice\n'
- ' indices.\n'
- '\n'
- ' Changed in version 2.3: Previously, "index()" didn\'t '
- 'have arguments\n'
- ' for specifying start and stop positions.\n'
- '\n'
- '5. When a negative index is passed as the first '
- 'parameter to the\n'
- ' "insert()" method, the list length is added, as for '
- 'slice indices.\n'
- ' If it is still negative, it is truncated to zero, as '
- 'for slice\n'
- ' indices.\n'
- '\n'
- ' Changed in version 2.3: Previously, all negative '
- 'indices were\n'
- ' truncated to zero.\n'
- '\n'
- '6. The "pop()" method\'s optional argument *i* defaults '
- 'to "-1", so\n'
- ' that by default the last item is removed and '
- 'returned.\n'
- '\n'
- '7. The "sort()" and "reverse()" methods modify the list '
- 'in place\n'
- ' for economy of space when sorting or reversing a '
- 'large list. To\n'
- ' remind you that they operate by side effect, they '
- "don't return the\n"
- ' sorted or reversed list.\n'
- '\n'
- '8. The "sort()" method takes optional arguments for '
- 'controlling the\n'
- ' comparisons.\n'
- '\n'
- ' *cmp* specifies a custom comparison function of two '
- 'arguments (list\n'
- ' items) which should return a negative, zero or '
- 'positive number\n'
- ' depending on whether the first argument is considered '
- 'smaller than,\n'
- ' equal to, or larger than the second argument: '
- '"cmp=lambda x,y:\n'
- ' cmp(x.lower(), y.lower())". The default value is '
- '"None".\n'
- '\n'
- ' *key* specifies a function of one argument that is '
- 'used to extract\n'
- ' a comparison key from each list element: '
- '"key=str.lower". The\n'
- ' default value is "None".\n'
- '\n'
- ' *reverse* is a boolean value. If set to "True", then '
- 'the list\n'
- ' elements are sorted as if each comparison were '
- 'reversed.\n'
- '\n'
- ' In general, the *key* and *reverse* conversion '
- 'processes are much\n'
- ' faster than specifying an equivalent *cmp* function. '
- 'This is\n'
- ' because *cmp* is called multiple times for each list '
- 'element while\n'
- ' *key* and *reverse* touch each element only once. '
- 'Use\n'
- ' "functools.cmp_to_key()" to convert an old-style '
- '*cmp* function to\n'
- ' a *key* function.\n'
- '\n'
- ' Changed in version 2.3: Support for "None" as an '
- 'equivalent to\n'
- ' omitting *cmp* was added.\n'
- '\n'
- ' Changed in version 2.4: Support for *key* and '
- '*reverse* was added.\n'
- '\n'
- '9. Starting with Python 2.3, the "sort()" method is '
- 'guaranteed to\n'
- ' be stable. A sort is stable if it guarantees not to '
- 'change the\n'
- ' relative order of elements that compare equal --- '
- 'this is helpful\n'
- ' for sorting in multiple passes (for example, sort by '
- 'department,\n'
- ' then by salary grade).\n'
- '\n'
- '10. **CPython implementation detail:** While a list is '
- 'being\n'
- ' sorted, the effect of attempting to mutate, or even '
- 'inspect, the\n'
- ' list is undefined. The C implementation of Python '
- '2.3 and newer\n'
- ' makes the list appear empty for the duration, and '
- 'raises\n'
- ' "ValueError" if it can detect that the list has been '
- 'mutated\n'
- ' during a sort.\n'
- '\n'
- '11. The value *n* is an integer, or an object '
- 'implementing\n'
- ' "__index__()". Zero and negative values of *n* '
- 'clear the\n'
- ' sequence. Items in the sequence are not copied; '
- 'they are\n'
- ' referenced multiple times, as explained for "s * n" '
- 'under Sequence\n'
- ' Types --- str, unicode, list, tuple, bytearray, '
- 'buffer, xrange.\n',
- 'unary': '\n'
- 'Unary arithmetic and bitwise operations\n'
- '***************************************\n'
- '\n'
- 'All unary arithmetic and bitwise operations have the same '
- 'priority:\n'
- '\n'
- ' u_expr ::= power | "-" u_expr | "+" u_expr | "~" u_expr\n'
- '\n'
- 'The unary "-" (minus) operator yields the negation of its numeric\n'
- 'argument.\n'
- '\n'
- 'The unary "+" (plus) operator yields its numeric argument '
- 'unchanged.\n'
- '\n'
- 'The unary "~" (invert) operator yields the bitwise inversion of '
- 'its\n'
- 'plain or long integer argument. The bitwise inversion of "x" is\n'
- 'defined as "-(x+1)". It only applies to integral numbers.\n'
- '\n'
- 'In all three cases, if the argument does not have the proper type, '
- 'a\n'
- '"TypeError" exception is raised.\n',
- 'while': '\n'
- 'The "while" statement\n'
- '*********************\n'
- '\n'
- 'The "while" statement is used for repeated execution as long as an\n'
- 'expression is true:\n'
- '\n'
- ' while_stmt ::= "while" expression ":" suite\n'
- ' ["else" ":" suite]\n'
- '\n'
- 'This repeatedly tests the expression and, if it is true, executes '
- 'the\n'
- 'first suite; if the expression is false (which may be the first '
- 'time\n'
- 'it is tested) the suite of the "else" clause, if present, is '
- 'executed\n'
- 'and the loop terminates.\n'
- '\n'
- 'A "break" statement executed in the first suite terminates the '
- 'loop\n'
- 'without executing the "else" clause\'s suite. A "continue" '
- 'statement\n'
- 'executed in the first suite skips the rest of the suite and goes '
- 'back\n'
- 'to testing the expression.\n',
- 'with': '\n'
- 'The "with" statement\n'
- '********************\n'
- '\n'
- 'New in version 2.5.\n'
- '\n'
- 'The "with" statement is used to wrap the execution of a block with\n'
- 'methods defined by a context manager (see section With Statement\n'
- 'Context Managers). This allows common "try"..."except"..."finally"\n'
- 'usage patterns to be encapsulated for convenient reuse.\n'
- '\n'
- ' with_stmt ::= "with" with_item ("," with_item)* ":" suite\n'
- ' with_item ::= expression ["as" target]\n'
- '\n'
- 'The execution of the "with" statement with one "item" proceeds as\n'
- 'follows:\n'
- '\n'
- '1. The context expression (the expression given in the "with_item")\n'
- ' is evaluated to obtain a context manager.\n'
- '\n'
- '2. The context manager\'s "__exit__()" is loaded for later use.\n'
- '\n'
- '3. The context manager\'s "__enter__()" method is invoked.\n'
- '\n'
- '4. If a target was included in the "with" statement, the return\n'
- ' value from "__enter__()" is assigned to it.\n'
- '\n'
- ' Note: The "with" statement guarantees that if the "__enter__()"\n'
- ' method returns without an error, then "__exit__()" will always '
- 'be\n'
- ' called. Thus, if an error occurs during the assignment to the\n'
- ' target list, it will be treated the same as an error occurring\n'
- ' within the suite would be. See step 6 below.\n'
- '\n'
- '5. The suite is executed.\n'
- '\n'
- '6. The context manager\'s "__exit__()" method is invoked. If an\n'
- ' exception caused the suite to be exited, its type, value, and\n'
- ' traceback are passed as arguments to "__exit__()". Otherwise, '
- 'three\n'
- ' "None" arguments are supplied.\n'
- '\n'
- ' If the suite was exited due to an exception, and the return '
- 'value\n'
- ' from the "__exit__()" method was false, the exception is '
- 'reraised.\n'
- ' If the return value was true, the exception is suppressed, and\n'
- ' execution continues with the statement following the "with"\n'
- ' statement.\n'
- '\n'
- ' If the suite was exited for any reason other than an exception, '
- 'the\n'
- ' return value from "__exit__()" is ignored, and execution '
- 'proceeds\n'
- ' at the normal location for the kind of exit that was taken.\n'
- '\n'
- 'With more than one item, the context managers are processed as if\n'
- 'multiple "with" statements were nested:\n'
- '\n'
- ' with A() as a, B() as b:\n'
- ' suite\n'
- '\n'
- 'is equivalent to\n'
- '\n'
- ' with A() as a:\n'
- ' with B() as b:\n'
- ' suite\n'
- '\n'
- 'Note: In Python 2.5, the "with" statement is only allowed when the\n'
- ' "with_statement" feature has been enabled. It is always enabled '
- 'in\n'
- ' Python 2.6.\n'
- '\n'
- 'Changed in version 2.7: Support for multiple context expressions.\n'
- '\n'
- 'See also:\n'
- '\n'
- ' **PEP 343** - The "with" statement\n'
- ' The specification, background, and examples for the Python '
- '"with"\n'
- ' statement.\n',
- 'yield': '\n'
- 'The "yield" statement\n'
- '*********************\n'
- '\n'
- ' yield_stmt ::= yield_expression\n'
- '\n'
- 'The "yield" statement is only used when defining a generator '
- 'function,\n'
- 'and is only used in the body of the generator function. Using a\n'
- '"yield" statement in a function definition is sufficient to cause '
- 'that\n'
- 'definition to create a generator function instead of a normal\n'
- 'function.\n'
- '\n'
- 'When a generator function is called, it returns an iterator known '
- 'as a\n'
- 'generator iterator, or more commonly, a generator. The body of '
- 'the\n'
- "generator function is executed by calling the generator's "
- '"next()"\n'
- 'method repeatedly until it raises an exception.\n'
- '\n'
- 'When a "yield" statement is executed, the state of the generator '
- 'is\n'
- 'frozen and the value of "expression_list" is returned to '
- '"next()"\'s\n'
- 'caller. By "frozen" we mean that all local state is retained,\n'
- 'including the current bindings of local variables, the instruction\n'
- 'pointer, and the internal evaluation stack: enough information is\n'
- 'saved so that the next time "next()" is invoked, the function can\n'
- 'proceed exactly as if the "yield" statement were just another '
- 'external\n'
- 'call.\n'
- '\n'
- 'As of Python version 2.5, the "yield" statement is now allowed in '
- 'the\n'
- '"try" clause of a "try" ... "finally" construct. If the generator '
- 'is\n'
- 'not resumed before it is finalized (by reaching a zero reference '
- 'count\n'
- "or by being garbage collected), the generator-iterator's "
- '"close()"\n'
- 'method will be called, allowing any pending "finally" clauses to\n'
- 'execute.\n'
- '\n'
- 'For full details of "yield" semantics, refer to the Yield '
- 'expressions\n'
- 'section.\n'
- '\n'
- 'Note: In Python 2.2, the "yield" statement was only allowed when '
- 'the\n'
- ' "generators" feature has been enabled. This "__future__" import\n'
- ' statement was used to enable the feature:\n'
- '\n'
- ' from __future__ import generators\n'
- '\n'
- 'See also:\n'
- '\n'
- ' **PEP 255** - Simple Generators\n'
- ' The proposal for adding generators and the "yield" statement '
- 'to\n'
- ' Python.\n'
- '\n'
- ' **PEP 342** - Coroutines via Enhanced Generators\n'
- ' The proposal that, among other generator enhancements, '
- 'proposed\n'
- ' allowing "yield" to appear inside a "try" ... "finally" '
- 'block.\n'}
+# Autogenerated by Sphinx on Sat Dec 3 12:36:20 2016
+topics = {'assert': u'\nThe "assert" statement\n**********************\n\nAssert statements are a convenient way to insert debugging assertions\ninto a program:\n\n assert_stmt ::= "assert" expression ["," expression]\n\nThe simple form, "assert expression", is equivalent to\n\n if __debug__:\n if not expression: raise AssertionError\n\nThe extended form, "assert expression1, expression2", is equivalent to\n\n if __debug__:\n if not expression1: raise AssertionError(expression2)\n\nThese equivalences assume that "__debug__" and "AssertionError" refer\nto the built-in variables with those names. In the current\nimplementation, the built-in variable "__debug__" is "True" under\nnormal circumstances, "False" when optimization is requested (command\nline option -O). The current code generator emits no code for an\nassert statement when optimization is requested at compile time. Note\nthat it is unnecessary to include the source code for the expression\nthat failed in the error message; it will be displayed as part of the\nstack trace.\n\nAssignments to "__debug__" are illegal. The value for the built-in\nvariable is determined when the interpreter starts.\n',
+ 'assignment': u'\nAssignment statements\n*********************\n\nAssignment statements are used to (re)bind names to values and to\nmodify attributes or items of mutable objects:\n\n assignment_stmt ::= (target_list "=")+ (expression_list | yield_expression)\n target_list ::= target ("," target)* [","]\n target ::= identifier\n | "(" target_list ")"\n | "[" [target_list] "]"\n | attributeref\n | subscription\n | slicing\n\n(See section Primaries for the syntax definitions for the last three\nsymbols.)\n\nAn assignment statement evaluates the expression list (remember that\nthis can be a single expression or a comma-separated list, the latter\nyielding a tuple) and assigns the single resulting object to each of\nthe target lists, from left to right.\n\nAssignment is defined recursively depending on the form of the target\n(list). When a target is part of a mutable object (an attribute\nreference, subscription or slicing), the mutable object must\nultimately perform the assignment and decide about its validity, and\nmay raise an exception if the assignment is unacceptable. The rules\nobserved by various types and the exceptions raised are given with the\ndefinition of the object types (see section The standard type\nhierarchy).\n\nAssignment of an object to a target list is recursively defined as\nfollows.\n\n* If the target list is a single target: The object is assigned to\n that target.\n\n* If the target list is a comma-separated list of targets: The\n object must be an iterable with the same number of items as there\n are targets in the target list, and the items are assigned, from\n left to right, to the corresponding targets.\n\nAssignment of an object to a single target is recursively defined as\nfollows.\n\n* If the target is an identifier (name):\n\n * If the name does not occur in a "global" statement in the\n current code block: the name is bound to the object in the current\n local namespace.\n\n * Otherwise: the name is bound to the object in the current global\n namespace.\n\n The name is rebound if it was already bound. This may cause the\n reference count for the object previously bound to the name to reach\n zero, causing the object to be deallocated and its destructor (if it\n has one) to be called.\n\n* If the target is a target list enclosed in parentheses or in\n square brackets: The object must be an iterable with the same number\n of items as there are targets in the target list, and its items are\n assigned, from left to right, to the corresponding targets.\n\n* If the target is an attribute reference: The primary expression in\n the reference is evaluated. It should yield an object with\n assignable attributes; if this is not the case, "TypeError" is\n raised. That object is then asked to assign the assigned object to\n the given attribute; if it cannot perform the assignment, it raises\n an exception (usually but not necessarily "AttributeError").\n\n Note: If the object is a class instance and the attribute reference\n occurs on both sides of the assignment operator, the RHS expression,\n "a.x" can access either an instance attribute or (if no instance\n attribute exists) a class attribute. The LHS target "a.x" is always\n set as an instance attribute, creating it if necessary. Thus, the\n two occurrences of "a.x" do not necessarily refer to the same\n attribute: if the RHS expression refers to a class attribute, the\n LHS creates a new instance attribute as the target of the\n assignment:\n\n class Cls:\n x = 3 # class variable\n inst = Cls()\n inst.x = inst.x + 1 # writes inst.x as 4 leaving Cls.x as 3\n\n This description does not necessarily apply to descriptor\n attributes, such as properties created with "property()".\n\n* If the target is a subscription: The primary expression in the\n reference is evaluated. It should yield either a mutable sequence\n object (such as a list) or a mapping object (such as a dictionary).\n Next, the subscript expression is evaluated.\n\n If the primary is a mutable sequence object (such as a list), the\n subscript must yield a plain integer. If it is negative, the\n sequence\'s length is added to it. The resulting value must be a\n nonnegative integer less than the sequence\'s length, and the\n sequence is asked to assign the assigned object to its item with\n that index. If the index is out of range, "IndexError" is raised\n (assignment to a subscripted sequence cannot add new items to a\n list).\n\n If the primary is a mapping object (such as a dictionary), the\n subscript must have a type compatible with the mapping\'s key type,\n and the mapping is then asked to create a key/datum pair which maps\n the subscript to the assigned object. This can either replace an\n existing key/value pair with the same key value, or insert a new\n key/value pair (if no key with the same value existed).\n\n* If the target is a slicing: The primary expression in the\n reference is evaluated. It should yield a mutable sequence object\n (such as a list). The assigned object should be a sequence object\n of the same type. Next, the lower and upper bound expressions are\n evaluated, insofar they are present; defaults are zero and the\n sequence\'s length. The bounds should evaluate to (small) integers.\n If either bound is negative, the sequence\'s length is added to it.\n The resulting bounds are clipped to lie between zero and the\n sequence\'s length, inclusive. Finally, the sequence object is asked\n to replace the slice with the items of the assigned sequence. The\n length of the slice may be different from the length of the assigned\n sequence, thus changing the length of the target sequence, if the\n object allows it.\n\n**CPython implementation detail:** In the current implementation, the\nsyntax for targets is taken to be the same as for expressions, and\ninvalid syntax is rejected during the code generation phase, causing\nless detailed error messages.\n\nWARNING: Although the definition of assignment implies that overlaps\nbetween the left-hand side and the right-hand side are \'safe\' (for\nexample "a, b = b, a" swaps two variables), overlaps *within* the\ncollection of assigned-to variables are not safe! For instance, the\nfollowing program prints "[0, 2]":\n\n x = [0, 1]\n i = 0\n i, x[i] = 1, 2\n print x\n\n\nAugmented assignment statements\n===============================\n\nAugmented assignment is the combination, in a single statement, of a\nbinary operation and an assignment statement:\n\n augmented_assignment_stmt ::= augtarget augop (expression_list | yield_expression)\n augtarget ::= identifier | attributeref | subscription | slicing\n augop ::= "+=" | "-=" | "*=" | "/=" | "//=" | "%=" | "**="\n | ">>=" | "<<=" | "&=" | "^=" | "|="\n\n(See section Primaries for the syntax definitions for the last three\nsymbols.)\n\nAn augmented assignment evaluates the target (which, unlike normal\nassignment statements, cannot be an unpacking) and the expression\nlist, performs the binary operation specific to the type of assignment\non the two operands, and assigns the result to the original target.\nThe target is only evaluated once.\n\nAn augmented assignment expression like "x += 1" can be rewritten as\n"x = x + 1" to achieve a similar, but not exactly equal effect. In the\naugmented version, "x" is only evaluated once. Also, when possible,\nthe actual operation is performed *in-place*, meaning that rather than\ncreating a new object and assigning that to the target, the old object\nis modified instead.\n\nWith the exception of assigning to tuples and multiple targets in a\nsingle statement, the assignment done by augmented assignment\nstatements is handled the same way as normal assignments. Similarly,\nwith the exception of the possible *in-place* behavior, the binary\noperation performed by augmented assignment is the same as the normal\nbinary operations.\n\nFor targets which are attribute references, the same caveat about\nclass and instance attributes applies as for regular assignments.\n',
+ 'atom-identifiers': u'\nIdentifiers (Names)\n*******************\n\nAn identifier occurring as an atom is a name. See section Identifiers\nand keywords for lexical definition and section Naming and binding for\ndocumentation of naming and binding.\n\nWhen the name is bound to an object, evaluation of the atom yields\nthat object. When a name is not bound, an attempt to evaluate it\nraises a "NameError" exception.\n\n**Private name mangling:** When an identifier that textually occurs in\na class definition begins with two or more underscore characters and\ndoes not end in two or more underscores, it is considered a *private\nname* of that class. Private names are transformed to a longer form\nbefore code is generated for them. The transformation inserts the\nclass name, with leading underscores removed and a single underscore\ninserted, in front of the name. For example, the identifier "__spam"\noccurring in a class named "Ham" will be transformed to "_Ham__spam".\nThis transformation is independent of the syntactical context in which\nthe identifier is used. If the transformed name is extremely long\n(longer than 255 characters), implementation defined truncation may\nhappen. If the class name consists only of underscores, no\ntransformation is done.\n',
+ 'atom-literals': u"\nLiterals\n********\n\nPython supports string literals and various numeric literals:\n\n literal ::= stringliteral | integer | longinteger\n | floatnumber | imagnumber\n\nEvaluation of a literal yields an object of the given type (string,\ninteger, long integer, floating point number, complex number) with the\ngiven value. The value may be approximated in the case of floating\npoint and imaginary (complex) literals. See section Literals for\ndetails.\n\nAll literals correspond to immutable data types, and hence the\nobject's identity is less important than its value. Multiple\nevaluations of literals with the same value (either the same\noccurrence in the program text or a different occurrence) may obtain\nthe same object or a different object with the same value.\n",
+ 'attribute-access': u'\nCustomizing attribute access\n****************************\n\nThe following methods can be defined to customize the meaning of\nattribute access (use of, assignment to, or deletion of "x.name") for\nclass instances.\n\nobject.__getattr__(self, name)\n\n Called when an attribute lookup has not found the attribute in the\n usual places (i.e. it is not an instance attribute nor is it found\n in the class tree for "self"). "name" is the attribute name. This\n method should return the (computed) attribute value or raise an\n "AttributeError" exception.\n\n Note that if the attribute is found through the normal mechanism,\n "__getattr__()" is not called. (This is an intentional asymmetry\n between "__getattr__()" and "__setattr__()".) This is done both for\n efficiency reasons and because otherwise "__getattr__()" would have\n no way to access other attributes of the instance. Note that at\n least for instance variables, you can fake total control by not\n inserting any values in the instance attribute dictionary (but\n instead inserting them in another object). See the\n "__getattribute__()" method below for a way to actually get total\n control in new-style classes.\n\nobject.__setattr__(self, name, value)\n\n Called when an attribute assignment is attempted. This is called\n instead of the normal mechanism (i.e. store the value in the\n instance dictionary). *name* is the attribute name, *value* is the\n value to be assigned to it.\n\n If "__setattr__()" wants to assign to an instance attribute, it\n should not simply execute "self.name = value" --- this would cause\n a recursive call to itself. Instead, it should insert the value in\n the dictionary of instance attributes, e.g., "self.__dict__[name] =\n value". For new-style classes, rather than accessing the instance\n dictionary, it should call the base class method with the same\n name, for example, "object.__setattr__(self, name, value)".\n\nobject.__delattr__(self, name)\n\n Like "__setattr__()" but for attribute deletion instead of\n assignment. This should only be implemented if "del obj.name" is\n meaningful for the object.\n\n\nMore attribute access for new-style classes\n===========================================\n\nThe following methods only apply to new-style classes.\n\nobject.__getattribute__(self, name)\n\n Called unconditionally to implement attribute accesses for\n instances of the class. If the class also defines "__getattr__()",\n the latter will not be called unless "__getattribute__()" either\n calls it explicitly or raises an "AttributeError". This method\n should return the (computed) attribute value or raise an\n "AttributeError" exception. In order to avoid infinite recursion in\n this method, its implementation should always call the base class\n method with the same name to access any attributes it needs, for\n example, "object.__getattribute__(self, name)".\n\n Note: This method may still be bypassed when looking up special\n methods as the result of implicit invocation via language syntax\n or built-in functions. See Special method lookup for new-style\n classes.\n\n\nImplementing Descriptors\n========================\n\nThe following methods only apply when an instance of the class\ncontaining the method (a so-called *descriptor* class) appears in an\n*owner* class (the descriptor must be in either the owner\'s class\ndictionary or in the class dictionary for one of its parents). In the\nexamples below, "the attribute" refers to the attribute whose name is\nthe key of the property in the owner class\' "__dict__".\n\nobject.__get__(self, instance, owner)\n\n Called to get the attribute of the owner class (class attribute\n access) or of an instance of that class (instance attribute\n access). *owner* is always the owner class, while *instance* is the\n instance that the attribute was accessed through, or "None" when\n the attribute is accessed through the *owner*. This method should\n return the (computed) attribute value or raise an "AttributeError"\n exception.\n\nobject.__set__(self, instance, value)\n\n Called to set the attribute on an instance *instance* of the owner\n class to a new value, *value*.\n\nobject.__delete__(self, instance)\n\n Called to delete the attribute on an instance *instance* of the\n owner class.\n\n\nInvoking Descriptors\n====================\n\nIn general, a descriptor is an object attribute with "binding\nbehavior", one whose attribute access has been overridden by methods\nin the descriptor protocol: "__get__()", "__set__()", and\n"__delete__()". If any of those methods are defined for an object, it\nis said to be a descriptor.\n\nThe default behavior for attribute access is to get, set, or delete\nthe attribute from an object\'s dictionary. For instance, "a.x" has a\nlookup chain starting with "a.__dict__[\'x\']", then\n"type(a).__dict__[\'x\']", and continuing through the base classes of\n"type(a)" excluding metaclasses.\n\nHowever, if the looked-up value is an object defining one of the\ndescriptor methods, then Python may override the default behavior and\ninvoke the descriptor method instead. Where this occurs in the\nprecedence chain depends on which descriptor methods were defined and\nhow they were called. Note that descriptors are only invoked for new\nstyle objects or classes (ones that subclass "object()" or "type()").\n\nThe starting point for descriptor invocation is a binding, "a.x". How\nthe arguments are assembled depends on "a":\n\nDirect Call\n The simplest and least common call is when user code directly\n invokes a descriptor method: "x.__get__(a)".\n\nInstance Binding\n If binding to a new-style object instance, "a.x" is transformed\n into the call: "type(a).__dict__[\'x\'].__get__(a, type(a))".\n\nClass Binding\n If binding to a new-style class, "A.x" is transformed into the\n call: "A.__dict__[\'x\'].__get__(None, A)".\n\nSuper Binding\n If "a" is an instance of "super", then the binding "super(B,\n obj).m()" searches "obj.__class__.__mro__" for the base class "A"\n immediately preceding "B" and then invokes the descriptor with the\n call: "A.__dict__[\'m\'].__get__(obj, obj.__class__)".\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. A descriptor can define\nany combination of "__get__()", "__set__()" and "__delete__()". If it\ndoes not define "__get__()", then accessing the attribute will return\nthe descriptor object itself unless there is a value in the object\'s\ninstance dictionary. If the descriptor defines "__set__()" and/or\n"__delete__()", it is a data descriptor; if it defines neither, it is\na non-data descriptor. Normally, data descriptors define both\n"__get__()" and "__set__()", while non-data descriptors have just the\n"__get__()" method. Data descriptors with "__set__()" and "__get__()"\ndefined always override a redefinition in an instance dictionary. In\ncontrast, non-data descriptors can be overridden by instances.\n\nPython methods (including "staticmethod()" and "classmethod()") are\nimplemented as non-data descriptors. Accordingly, instances can\nredefine and override methods. This allows individual instances to\nacquire behaviors that differ from other instances of the same class.\n\nThe "property()" function is implemented as a data descriptor.\nAccordingly, instances cannot override the behavior of a property.\n\n\n__slots__\n=========\n\nBy default, instances of both old and new-style classes have a\ndictionary for attribute storage. This wastes space for objects\nhaving very few instance variables. The space consumption can become\nacute when creating large numbers of instances.\n\nThe default can be overridden by defining *__slots__* in a new-style\nclass definition. The *__slots__* declaration takes a sequence of\ninstance variables and reserves just enough space in each instance to\nhold a value for each variable. Space is saved because *__dict__* is\nnot created for each instance.\n\n__slots__\n\n This class variable can be assigned a string, iterable, or sequence\n of strings with variable names used by instances. If defined in a\n new-style class, *__slots__* reserves space for the declared\n variables and prevents the automatic creation of *__dict__* and\n *__weakref__* for each instance.\n\n New in version 2.2.\n\nNotes on using *__slots__*\n\n* When inheriting from a class without *__slots__*, the *__dict__*\n attribute of that class will always be accessible, so a *__slots__*\n definition in the subclass is meaningless.\n\n* Without a *__dict__* variable, instances cannot be assigned new\n variables not listed in the *__slots__* definition. Attempts to\n assign to an unlisted variable name raises "AttributeError". If\n dynamic assignment of new variables is desired, then add\n "\'__dict__\'" to the sequence of strings in the *__slots__*\n declaration.\n\n Changed in version 2.3: Previously, adding "\'__dict__\'" to the\n *__slots__* declaration would not enable the assignment of new\n attributes not specifically listed in the sequence of instance\n variable names.\n\n* Without a *__weakref__* variable for each instance, classes\n defining *__slots__* do not support weak references to its\n instances. If weak reference support is needed, then add\n "\'__weakref__\'" to the sequence of strings in the *__slots__*\n declaration.\n\n Changed in version 2.3: Previously, adding "\'__weakref__\'" to the\n *__slots__* declaration would not enable support for weak\n references.\n\n* *__slots__* are implemented at the class level by creating\n descriptors (Implementing Descriptors) for each variable name. As a\n result, class attributes cannot be used to set default values for\n instance variables defined by *__slots__*; otherwise, the class\n attribute would overwrite the descriptor assignment.\n\n* The action of a *__slots__* declaration is limited to the class\n where it is defined. As a result, subclasses will have a *__dict__*\n unless they also define *__slots__* (which must only contain names\n of any *additional* slots).\n\n* If a class defines a slot also defined in a base class, the\n instance variable defined by the base class slot is inaccessible\n (except by retrieving its descriptor directly from the base class).\n This renders the meaning of the program undefined. In the future, a\n check may be added to prevent this.\n\n* Nonempty *__slots__* does not work for classes derived from\n "variable-length" built-in types such as "long", "str" and "tuple".\n\n* Any non-string iterable may be assigned to *__slots__*. Mappings\n may also be used; however, in the future, special meaning may be\n assigned to the values corresponding to each key.\n\n* *__class__* assignment works only if both classes have the same\n *__slots__*.\n\n Changed in version 2.6: Previously, *__class__* assignment raised an\n error if either new or old class had *__slots__*.\n',
+ 'attribute-references': u'\nAttribute references\n********************\n\nAn attribute reference is a primary followed by a period and a name:\n\n attributeref ::= primary "." identifier\n\nThe primary must evaluate to an object of a type that supports\nattribute references, e.g., a module, list, or an instance. This\nobject is then asked to produce the attribute whose name is the\nidentifier. If this attribute is not available, the exception\n"AttributeError" is raised. Otherwise, the type and value of the\nobject produced is determined by the object. Multiple evaluations of\nthe same attribute reference may yield different objects.\n',
+ 'augassign': u'\nAugmented assignment statements\n*******************************\n\nAugmented assignment is the combination, in a single statement, of a\nbinary operation and an assignment statement:\n\n augmented_assignment_stmt ::= augtarget augop (expression_list | yield_expression)\n augtarget ::= identifier | attributeref | subscription | slicing\n augop ::= "+=" | "-=" | "*=" | "/=" | "//=" | "%=" | "**="\n | ">>=" | "<<=" | "&=" | "^=" | "|="\n\n(See section Primaries for the syntax definitions for the last three\nsymbols.)\n\nAn augmented assignment evaluates the target (which, unlike normal\nassignment statements, cannot be an unpacking) and the expression\nlist, performs the binary operation specific to the type of assignment\non the two operands, and assigns the result to the original target.\nThe target is only evaluated once.\n\nAn augmented assignment expression like "x += 1" can be rewritten as\n"x = x + 1" to achieve a similar, but not exactly equal effect. In the\naugmented version, "x" is only evaluated once. Also, when possible,\nthe actual operation is performed *in-place*, meaning that rather than\ncreating a new object and assigning that to the target, the old object\nis modified instead.\n\nWith the exception of assigning to tuples and multiple targets in a\nsingle statement, the assignment done by augmented assignment\nstatements is handled the same way as normal assignments. Similarly,\nwith the exception of the possible *in-place* behavior, the binary\noperation performed by augmented assignment is the same as the normal\nbinary operations.\n\nFor targets which are attribute references, the same caveat about\nclass and instance attributes applies as for regular assignments.\n',
+ 'binary': u'\nBinary arithmetic operations\n****************************\n\nThe binary arithmetic operations have the conventional priority\nlevels. Note that some of these operations also apply to certain non-\nnumeric types. Apart from the power operator, there are only two\nlevels, one for multiplicative operators and one for additive\noperators:\n\n m_expr ::= u_expr | m_expr "*" u_expr | m_expr "//" u_expr | m_expr "/" u_expr\n | m_expr "%" u_expr\n a_expr ::= m_expr | a_expr "+" m_expr | a_expr "-" m_expr\n\nThe "*" (multiplication) operator yields the product of its arguments.\nThe arguments must either both be numbers, or one argument must be an\ninteger (plain or long) and the other must be a sequence. In the\nformer case, the numbers are converted to a common type and then\nmultiplied together. In the latter case, sequence repetition is\nperformed; a negative repetition factor yields an empty sequence.\n\nThe "/" (division) and "//" (floor division) operators yield the\nquotient of their arguments. The numeric arguments are first\nconverted to a common type. Plain or long integer division yields an\ninteger of the same type; the result is that of mathematical division\nwith the \'floor\' function applied to the result. Division by zero\nraises the "ZeroDivisionError" exception.\n\nThe "%" (modulo) operator yields the remainder from the division of\nthe first argument by the second. The numeric arguments are first\nconverted to a common type. A zero right argument raises the\n"ZeroDivisionError" exception. The arguments may be floating point\nnumbers, e.g., "3.14%0.7" equals "0.34" (since "3.14" equals "4*0.7 +\n0.34".) The modulo operator always yields a result with the same sign\nas its second operand (or zero); the absolute value of the result is\nstrictly smaller than the absolute value of the second operand [2].\n\nThe integer division and modulo operators are connected by the\nfollowing identity: "x == (x/y)*y + (x%y)". Integer division and\nmodulo are also connected with the built-in function "divmod()":\n"divmod(x, y) == (x/y, x%y)". These identities don\'t hold for\nfloating point numbers; there similar identities hold approximately\nwhere "x/y" is replaced by "floor(x/y)" or "floor(x/y) - 1" [3].\n\nIn addition to performing the modulo operation on numbers, the "%"\noperator is also overloaded by string and unicode objects to perform\nstring formatting (also known as interpolation). The syntax for string\nformatting is described in the Python Library Reference, section\nString Formatting Operations.\n\nDeprecated since version 2.3: The floor division operator, the modulo\noperator, and the "divmod()" function are no longer defined for\ncomplex numbers. Instead, convert to a floating point number using\nthe "abs()" function if appropriate.\n\nThe "+" (addition) operator yields the sum of its arguments. The\narguments must either both be numbers or both sequences of the same\ntype. In the former case, the numbers are converted to a common type\nand then added together. In the latter case, the sequences are\nconcatenated.\n\nThe "-" (subtraction) operator yields the difference of its arguments.\nThe numeric arguments are first converted to a common type.\n',
+ 'bitwise': u'\nBinary bitwise operations\n*************************\n\nEach of the three bitwise operations has a different priority level:\n\n and_expr ::= shift_expr | and_expr "&" shift_expr\n xor_expr ::= and_expr | xor_expr "^" and_expr\n or_expr ::= xor_expr | or_expr "|" xor_expr\n\nThe "&" operator yields the bitwise AND of its arguments, which must\nbe plain or long integers. The arguments are converted to a common\ntype.\n\nThe "^" operator yields the bitwise XOR (exclusive OR) of its\narguments, which must be plain or long integers. The arguments are\nconverted to a common type.\n\nThe "|" operator yields the bitwise (inclusive) OR of its arguments,\nwhich must be plain or long integers. The arguments are converted to\na common type.\n',
+ 'bltin-code-objects': u'\nCode Objects\n************\n\nCode objects are used by the implementation to represent "pseudo-\ncompiled" executable Python code such as a function body. They differ\nfrom function objects because they don\'t contain a reference to their\nglobal execution environment. Code objects are returned by the built-\nin "compile()" function and can be extracted from function objects\nthrough their "func_code" attribute. See also the "code" module.\n\nA code object can be executed or evaluated by passing it (instead of a\nsource string) to the "exec" statement or the built-in "eval()"\nfunction.\n\nSee The standard type hierarchy for more information.\n',
+ 'bltin-ellipsis-object': u'\nThe Ellipsis Object\n*******************\n\nThis object is used by extended slice notation (see Slicings). It\nsupports no special operations. There is exactly one ellipsis object,\nnamed "Ellipsis" (a built-in name).\n\nIt is written as "Ellipsis". When in a subscript, it can also be\nwritten as "...", for example "seq[...]".\n',
+ 'bltin-file-objects': u'\nFile Objects\n************\n\nFile objects are implemented using C\'s "stdio" package and can be\ncreated with the built-in "open()" function. File objects are also\nreturned by some other built-in functions and methods, such as\n"os.popen()" and "os.fdopen()" and the "makefile()" method of socket\nobjects. Temporary files can be created using the "tempfile" module,\nand high-level file operations such as copying, moving, and deleting\nfiles and directories can be achieved with the "shutil" module.\n\nWhen a file operation fails for an I/O-related reason, the exception\n"IOError" is raised. This includes situations where the operation is\nnot defined for some reason, like "seek()" on a tty device or writing\na file opened for reading.\n\nFiles have the following methods:\n\nfile.close()\n\n Close the file. A closed file cannot be read or written any more.\n Any operation which requires that the file be open will raise a\n "ValueError" after the file has been closed. Calling "close()"\n more than once is allowed.\n\n As of Python 2.5, you can avoid having to call this method\n explicitly if you use the "with" statement. For example, the\n following code will automatically close *f* when the "with" block\n is exited:\n\n from __future__ import with_statement # This isn\'t required in Python 2.6\n\n with open("hello.txt") as f:\n for line in f:\n print line,\n\n In older versions of Python, you would have needed to do this to\n get the same effect:\n\n f = open("hello.txt")\n try:\n for line in f:\n print line,\n finally:\n f.close()\n\n Note: Not all "file-like" types in Python support use as a\n context manager for the "with" statement. If your code is\n intended to work with any file-like object, you can use the\n function "contextlib.closing()" instead of using the object\n directly.\n\nfile.flush()\n\n Flush the internal buffer, like "stdio"\'s "fflush()". This may be\n a no-op on some file-like objects.\n\n Note: "flush()" does not necessarily write the file\'s data to\n disk. Use "flush()" followed by "os.fsync()" to ensure this\n behavior.\n\nfile.fileno()\n\n Return the integer "file descriptor" that is used by the underlying\n implementation to request I/O operations from the operating system.\n This can be useful for other, lower level interfaces that use file\n descriptors, such as the "fcntl" module or "os.read()" and friends.\n\n Note: File-like objects which do not have a real file descriptor\n should *not* provide this method!\n\nfile.isatty()\n\n Return "True" if the file is connected to a tty(-like) device, else\n "False".\n\n Note: If a file-like object is not associated with a real file,\n this method should *not* be implemented.\n\nfile.next()\n\n A file object is its own iterator, for example "iter(f)" returns\n *f* (unless *f* is closed). When a file is used as an iterator,\n typically in a "for" loop (for example, "for line in f: print\n line.strip()"), the "next()" method is called repeatedly. This\n method returns the next input line, or raises "StopIteration" when\n EOF is hit when the file is open for reading (behavior is undefined\n when the file is open for writing). In order to make a "for" loop\n the most efficient way of looping over the lines of a file (a very\n common operation), the "next()" method uses a hidden read-ahead\n buffer. As a consequence of using a read-ahead buffer, combining\n "next()" with other file methods (like "readline()") does not work\n right. However, using "seek()" to reposition the file to an\n absolute position will flush the read-ahead buffer.\n\n New in version 2.3.\n\nfile.read([size])\n\n Read at most *size* bytes from the file (less if the read hits EOF\n before obtaining *size* bytes). If the *size* argument is negative\n or omitted, read all data until EOF is reached. The bytes are\n returned as a string object. An empty string is returned when EOF\n is encountered immediately. (For certain files, like ttys, it\n makes sense to continue reading after an EOF is hit.) Note that\n this method may call the underlying C function "fread()" more than\n once in an effort to acquire as close to *size* bytes as possible.\n Also note that when in non-blocking mode, less data than was\n requested may be returned, even if no *size* parameter was given.\n\n Note: This function is simply a wrapper for the underlying\n "fread()" C function, and will behave the same in corner cases,\n such as whether the EOF value is cached.\n\nfile.readline([size])\n\n Read one entire line from the file. A trailing newline character\n is kept in the string (but may be absent when a file ends with an\n incomplete line). [6] If the *size* argument is present and non-\n negative, it is a maximum byte count (including the trailing\n newline) and an incomplete line may be returned. When *size* is not\n 0, an empty string is returned *only* when EOF is encountered\n immediately.\n\n Note: Unlike "stdio"\'s "fgets()", the returned string contains\n null characters ("\'\\0\'") if they occurred in the input.\n\nfile.readlines([sizehint])\n\n Read until EOF using "readline()" and return a list containing the\n lines thus read. If the optional *sizehint* argument is present,\n instead of reading up to EOF, whole lines totalling approximately\n *sizehint* bytes (possibly after rounding up to an internal buffer\n size) are read. Objects implementing a file-like interface may\n choose to ignore *sizehint* if it cannot be implemented, or cannot\n be implemented efficiently.\n\nfile.xreadlines()\n\n This method returns the same thing as "iter(f)".\n\n New in version 2.1.\n\n Deprecated since version 2.3: Use "for line in file" instead.\n\nfile.seek(offset[, whence])\n\n Set the file\'s current position, like "stdio"\'s "fseek()". The\n *whence* argument is optional and defaults to "os.SEEK_SET" or "0"\n (absolute file positioning); other values are "os.SEEK_CUR" or "1"\n (seek relative to the current position) and "os.SEEK_END" or "2"\n (seek relative to the file\'s end). There is no return value.\n\n For example, "f.seek(2, os.SEEK_CUR)" advances the position by two\n and "f.seek(-3, os.SEEK_END)" sets the position to the third to\n last.\n\n Note that if the file is opened for appending (mode "\'a\'" or\n "\'a+\'"), any "seek()" operations will be undone at the next write.\n If the file is only opened for writing in append mode (mode "\'a\'"),\n this method is essentially a no-op, but it remains useful for files\n opened in append mode with reading enabled (mode "\'a+\'"). If the\n file is opened in text mode (without "\'b\'"), only offsets returned\n by "tell()" are legal. Use of other offsets causes undefined\n behavior.\n\n Note that not all file objects are seekable.\n\n Changed in version 2.6: Passing float values as offset has been\n deprecated.\n\nfile.tell()\n\n Return the file\'s current position, like "stdio"\'s "ftell()".\n\n Note: On Windows, "tell()" can return illegal values (after an\n "fgets()") when reading files with Unix-style line-endings. Use\n binary mode ("\'rb\'") to circumvent this problem.\n\nfile.truncate([size])\n\n Truncate the file\'s size. If the optional *size* argument is\n present, the file is truncated to (at most) that size. The size\n defaults to the current position. The current file position is not\n changed. Note that if a specified size exceeds the file\'s current\n size, the result is platform-dependent: possibilities include that\n the file may remain unchanged, increase to the specified size as if\n zero-filled, or increase to the specified size with undefined new\n content. Availability: Windows, many Unix variants.\n\nfile.write(str)\n\n Write a string to the file. There is no return value. Due to\n buffering, the string may not actually show up in the file until\n the "flush()" or "close()" method is called.\n\nfile.writelines(sequence)\n\n Write a sequence of strings to the file. The sequence can be any\n iterable object producing strings, typically a list of strings.\n There is no return value. (The name is intended to match\n "readlines()"; "writelines()" does not add line separators.)\n\nFiles support the iterator protocol. Each iteration returns the same\nresult as "readline()", and iteration ends when the "readline()"\nmethod returns an empty string.\n\nFile objects also offer a number of other interesting attributes.\nThese are not required for file-like objects, but should be\nimplemented if they make sense for the particular object.\n\nfile.closed\n\n bool indicating the current state of the file object. This is a\n read-only attribute; the "close()" method changes the value. It may\n not be available on all file-like objects.\n\nfile.encoding\n\n The encoding that this file uses. When Unicode strings are written\n to a file, they will be converted to byte strings using this\n encoding. In addition, when the file is connected to a terminal,\n the attribute gives the encoding that the terminal is likely to use\n (that information might be incorrect if the user has misconfigured\n the terminal). The attribute is read-only and may not be present\n on all file-like objects. It may also be "None", in which case the\n file uses the system default encoding for converting Unicode\n strings.\n\n New in version 2.3.\n\nfile.errors\n\n The Unicode error handler used along with the encoding.\n\n New in version 2.6.\n\nfile.mode\n\n The I/O mode for the file. If the file was created using the\n "open()" built-in function, this will be the value of the *mode*\n parameter. This is a read-only attribute and may not be present on\n all file-like objects.\n\nfile.name\n\n If the file object was created using "open()", the name of the\n file. Otherwise, some string that indicates the source of the file\n object, of the form "<...>". This is a read-only attribute and may\n not be present on all file-like objects.\n\nfile.newlines\n\n If Python was built with *universal newlines* enabled (the default)\n this read-only attribute exists, and for files opened in universal\n newline read mode it keeps track of the types of newlines\n encountered while reading the file. The values it can take are\n "\'\\r\'", "\'\\n\'", "\'\\r\\n\'", "None" (unknown, no newlines read yet) or\n a tuple containing all the newline types seen, to indicate that\n multiple newline conventions were encountered. For files not opened\n in universal newlines read mode the value of this attribute will be\n "None".\n\nfile.softspace\n\n Boolean that indicates whether a space character needs to be\n printed before another value when using the "print" statement.\n Classes that are trying to simulate a file object should also have\n a writable "softspace" attribute, which should be initialized to\n zero. This will be automatic for most classes implemented in\n Python (care may be needed for objects that override attribute\n access); types implemented in C will have to provide a writable\n "softspace" attribute.\n\n Note: This attribute is not used to control the "print"\n statement, but to allow the implementation of "print" to keep\n track of its internal state.\n',
+ 'bltin-null-object': u'\nThe Null Object\n***************\n\nThis object is returned by functions that don\'t explicitly return a\nvalue. It supports no special operations. There is exactly one null\nobject, named "None" (a built-in name).\n\nIt is written as "None".\n',
+ 'bltin-type-objects': u'\nType Objects\n************\n\nType objects represent the various object types. An object\'s type is\naccessed by the built-in function "type()". There are no special\noperations on types. The standard module "types" defines names for\nall standard built-in types.\n\nTypes are written like this: "<type \'int\'>".\n',
+ 'booleans': u'\nBoolean operations\n******************\n\n or_test ::= and_test | or_test "or" and_test\n and_test ::= not_test | and_test "and" not_test\n not_test ::= comparison | "not" not_test\n\nIn the context of Boolean operations, and also when expressions are\nused by control flow statements, the following values are interpreted\nas false: "False", "None", numeric zero of all types, and empty\nstrings and containers (including strings, tuples, lists,\ndictionaries, sets and frozensets). All other values are interpreted\nas true. (See the "__nonzero__()" special method for a way to change\nthis.)\n\nThe operator "not" yields "True" if its argument is false, "False"\notherwise.\n\nThe expression "x and y" first evaluates *x*; if *x* is false, its\nvalue is returned; otherwise, *y* is evaluated and the resulting value\nis returned.\n\nThe expression "x or y" first evaluates *x*; if *x* is true, its value\nis returned; otherwise, *y* is evaluated and the resulting value is\nreturned.\n\n(Note that neither "and" nor "or" restrict the value and type they\nreturn to "False" and "True", but rather return the last evaluated\nargument. This is sometimes useful, e.g., if "s" is a string that\nshould be replaced by a default value if it is empty, the expression\n"s or \'foo\'" yields the desired value. Because "not" has to invent a\nvalue anyway, it does not bother to return a value of the same type as\nits argument, so e.g., "not \'foo\'" yields "False", not "\'\'".)\n',
+ 'break': u'\nThe "break" statement\n*********************\n\n break_stmt ::= "break"\n\n"break" may only occur syntactically nested in a "for" or "while"\nloop, but not nested in a function or class definition within that\nloop.\n\nIt terminates the nearest enclosing loop, skipping the optional "else"\nclause if the loop has one.\n\nIf a "for" loop is terminated by "break", the loop control target\nkeeps its current value.\n\nWhen "break" passes control out of a "try" statement with a "finally"\nclause, that "finally" clause is executed before really leaving the\nloop.\n',
+ 'callable-types': u'\nEmulating callable objects\n**************************\n\nobject.__call__(self[, args...])\n\n Called when the instance is "called" as a function; if this method\n is defined, "x(arg1, arg2, ...)" is a shorthand for\n "x.__call__(arg1, arg2, ...)".\n',
+ 'calls': u'\nCalls\n*****\n\nA call calls a callable object (e.g., a *function*) with a possibly\nempty series of *arguments*:\n\n call ::= primary "(" [argument_list [","]\n | expression genexpr_for] ")"\n argument_list ::= positional_arguments ["," keyword_arguments]\n ["," "*" expression] ["," keyword_arguments]\n ["," "**" expression]\n | keyword_arguments ["," "*" expression]\n ["," "**" expression]\n | "*" expression ["," keyword_arguments] ["," "**" expression]\n | "**" expression\n positional_arguments ::= expression ("," expression)*\n keyword_arguments ::= keyword_item ("," keyword_item)*\n keyword_item ::= identifier "=" expression\n\nA trailing comma may be present after the positional and keyword\narguments but does not affect the semantics.\n\nThe primary must evaluate to a callable object (user-defined\nfunctions, built-in functions, methods of built-in objects, class\nobjects, methods of class instances, and certain class instances\nthemselves are callable; extensions may define additional callable\nobject types). All argument expressions are evaluated before the call\nis attempted. Please refer to section Function definitions for the\nsyntax of formal *parameter* lists.\n\nIf keyword arguments are present, they are first converted to\npositional arguments, as follows. First, a list of unfilled slots is\ncreated for the formal parameters. If there are N positional\narguments, they are placed in the first N slots. Next, for each\nkeyword argument, the identifier is used to determine the\ncorresponding slot (if the identifier is the same as the first formal\nparameter name, the first slot is used, and so on). If the slot is\nalready filled, a "TypeError" exception is raised. Otherwise, the\nvalue of the argument is placed in the slot, filling it (even if the\nexpression is "None", it fills the slot). When all arguments have\nbeen processed, the slots that are still unfilled are filled with the\ncorresponding default value from the function definition. (Default\nvalues are calculated, once, when the function is defined; thus, a\nmutable object such as a list or dictionary used as default value will\nbe shared by all calls that don\'t specify an argument value for the\ncorresponding slot; this should usually be avoided.) If there are any\nunfilled slots for which no default value is specified, a "TypeError"\nexception is raised. Otherwise, the list of filled slots is used as\nthe argument list for the call.\n\n**CPython implementation detail:** An implementation may provide\nbuilt-in functions whose positional parameters do not have names, even\nif they are \'named\' for the purpose of documentation, and which\ntherefore cannot be supplied by keyword. In CPython, this is the case\nfor functions implemented in C that use "PyArg_ParseTuple()" to parse\ntheir arguments.\n\nIf there are more positional arguments than there are formal parameter\nslots, a "TypeError" exception is raised, unless a formal parameter\nusing the syntax "*identifier" is present; in this case, that formal\nparameter receives a tuple containing the excess positional arguments\n(or an empty tuple if there were no excess positional arguments).\n\nIf any keyword argument does not correspond to a formal parameter\nname, a "TypeError" exception is raised, unless a formal parameter\nusing the syntax "**identifier" is present; in this case, that formal\nparameter receives a dictionary containing the excess keyword\narguments (using the keywords as keys and the argument values as\ncorresponding values), or a (new) empty dictionary if there were no\nexcess keyword arguments.\n\nIf the syntax "*expression" appears in the function call, "expression"\nmust evaluate to an iterable. Elements from this iterable are treated\nas if they were additional positional arguments; if there are\npositional arguments *x1*, ..., *xN*, and "expression" evaluates to a\nsequence *y1*, ..., *yM*, this is equivalent to a call with M+N\npositional arguments *x1*, ..., *xN*, *y1*, ..., *yM*.\n\nA consequence of this is that although the "*expression" syntax may\nappear *after* some keyword arguments, it is processed *before* the\nkeyword arguments (and the "**expression" argument, if any -- see\nbelow). So:\n\n >>> def f(a, b):\n ... print a, b\n ...\n >>> f(b=1, *(2,))\n 2 1\n >>> f(a=1, *(2,))\n Traceback (most recent call last):\n File "<stdin>", line 1, in ?\n TypeError: f() got multiple values for keyword argument \'a\'\n >>> f(1, *(2,))\n 1 2\n\nIt is unusual for both keyword arguments and the "*expression" syntax\nto be used in the same call, so in practice this confusion does not\narise.\n\nIf the syntax "**expression" appears in the function call,\n"expression" must evaluate to a mapping, the contents of which are\ntreated as additional keyword arguments. In the case of a keyword\nappearing in both "expression" and as an explicit keyword argument, a\n"TypeError" exception is raised.\n\nFormal parameters using the syntax "*identifier" or "**identifier"\ncannot be used as positional argument slots or as keyword argument\nnames. Formal parameters using the syntax "(sublist)" cannot be used\nas keyword argument names; the outermost sublist corresponds to a\nsingle unnamed argument slot, and the argument value is assigned to\nthe sublist using the usual tuple assignment rules after all other\nparameter processing is done.\n\nA call always returns some value, possibly "None", unless it raises an\nexception. How this value is computed depends on the type of the\ncallable object.\n\nIf it is---\n\na user-defined function:\n The code block for the function is executed, passing it the\n argument list. The first thing the code block will do is bind the\n formal parameters to the arguments; this is described in section\n Function definitions. When the code block executes a "return"\n statement, this specifies the return value of the function call.\n\na built-in function or method:\n The result is up to the interpreter; see Built-in Functions for the\n descriptions of built-in functions and methods.\n\na class object:\n A new instance of that class is returned.\n\na class instance method:\n The corresponding user-defined function is called, with an argument\n list that is one longer than the argument list of the call: the\n instance becomes the first argument.\n\na class instance:\n The class must define a "__call__()" method; the effect is then the\n same as if that method was called.\n',
+ 'class': u'\nClass definitions\n*****************\n\nA class definition defines a class object (see section The standard\ntype hierarchy):\n\n classdef ::= "class" classname [inheritance] ":" suite\n inheritance ::= "(" [expression_list] ")"\n classname ::= identifier\n\nA class definition is an executable statement. It first evaluates the\ninheritance list, if present. Each item in the inheritance list\nshould evaluate to a class object or class type which allows\nsubclassing. The class\'s suite is then executed in a new execution\nframe (see section Naming and binding), using a newly created local\nnamespace and the original global namespace. (Usually, the suite\ncontains only function definitions.) When the class\'s suite finishes\nexecution, its execution frame is discarded but its local namespace is\nsaved. [4] A class object is then created using the inheritance list\nfor the base classes and the saved local namespace for the attribute\ndictionary. The class name is bound to this class object in the\noriginal local namespace.\n\n**Programmer\'s note:** Variables defined in the class definition are\nclass variables; they are shared by all instances. To create instance\nvariables, they can be set in a method with "self.name = value". Both\nclass and instance variables are accessible through the notation\n""self.name"", and an instance variable hides a class variable with\nthe same name when accessed in this way. Class variables can be used\nas defaults for instance variables, but using mutable values there can\nlead to unexpected results. For *new-style class*es, descriptors can\nbe used to create instance variables with different implementation\ndetails.\n\nClass definitions, like function definitions, may be wrapped by one or\nmore *decorator* expressions. The evaluation rules for the decorator\nexpressions are the same as for functions. The result must be a class\nobject, which is then bound to the class name.\n\n-[ Footnotes ]-\n\n[1] The exception is propagated to the invocation stack unless\n there is a "finally" clause which happens to raise another\n exception. That new exception causes the old one to be lost.\n\n[2] Currently, control "flows off the end" except in the case of\n an exception or the execution of a "return", "continue", or\n "break" statement.\n\n[3] A string literal appearing as the first statement in the\n function body is transformed into the function\'s "__doc__"\n attribute and therefore the function\'s *docstring*.\n\n[4] A string literal appearing as the first statement in the class\n body is transformed into the namespace\'s "__doc__" item and\n therefore the class\'s *docstring*.\n',
+ 'comparisons': u'\nComparisons\n***********\n\nUnlike C, all comparison operations in Python have the same priority,\nwhich is lower than that of any arithmetic, shifting or bitwise\noperation. Also unlike C, expressions like "a < b < c" have the\ninterpretation that is conventional in mathematics:\n\n comparison ::= or_expr ( comp_operator or_expr )*\n comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "<>" | "!="\n | "is" ["not"] | ["not"] "in"\n\nComparisons yield boolean values: "True" or "False".\n\nComparisons can be chained arbitrarily, e.g., "x < y <= z" is\nequivalent to "x < y and y <= z", except that "y" is evaluated only\nonce (but in both cases "z" is not evaluated at all when "x < y" is\nfound to be false).\n\nFormally, if *a*, *b*, *c*, ..., *y*, *z* are expressions and *op1*,\n*op2*, ..., *opN* are comparison operators, then "a op1 b op2 c ... y\nopN z" is equivalent to "a op1 b and b op2 c and ... y opN z", except\nthat each expression is evaluated at most once.\n\nNote that "a op1 b op2 c" doesn\'t imply any kind of comparison between\n*a* and *c*, so that, e.g., "x < y > z" is perfectly legal (though\nperhaps not pretty).\n\nThe forms "<>" and "!=" are equivalent; for consistency with C, "!="\nis preferred; where "!=" is mentioned below "<>" is also accepted.\nThe "<>" spelling is considered obsolescent.\n\nThe operators "<", ">", "==", ">=", "<=", and "!=" compare the values\nof two objects. The objects need not have the same type. If both are\nnumbers, they are converted to a common type. Otherwise, objects of\ndifferent types *always* compare unequal, and are ordered consistently\nbut arbitrarily. You can control comparison behavior of objects of\nnon-built-in types by defining a "__cmp__" method or rich comparison\nmethods like "__gt__", described in section Special method names.\n\n(This unusual definition of comparison was used to simplify the\ndefinition of operations like sorting and the "in" and "not in"\noperators. In the future, the comparison rules for objects of\ndifferent types are likely to change.)\n\nComparison of objects of the same type depends on the type:\n\n* Numbers are compared arithmetically.\n\n* Strings are compared lexicographically using the numeric\n equivalents (the result of the built-in function "ord()") of their\n characters. Unicode and 8-bit strings are fully interoperable in\n this behavior. [4]\n\n* Tuples and lists are compared lexicographically using comparison\n of corresponding elements. This means that to compare equal, each\n element must compare equal and the two sequences must be of the same\n type and have the same length.\n\n If not equal, the sequences are ordered the same as their first\n differing elements. For example, "cmp([1,2,x], [1,2,y])" returns\n the same as "cmp(x,y)". If the corresponding element does not\n exist, the shorter sequence is ordered first (for example, "[1,2] <\n [1,2,3]").\n\n* Mappings (dictionaries) compare equal if and only if their sorted\n (key, value) lists compare equal. [5] Outcomes other than equality\n are resolved consistently, but are not otherwise defined. [6]\n\n* Most other objects of built-in types compare unequal unless they\n are the same object; the choice whether one object is considered\n smaller or larger than another one is made arbitrarily but\n consistently within one execution of a program.\n\nThe operators "in" and "not in" test for collection membership. "x in\ns" evaluates to true if *x* is a member of the collection *s*, and\nfalse otherwise. "x not in s" returns the negation of "x in s". The\ncollection membership test has traditionally been bound to sequences;\nan object is a member of a collection if the collection is a sequence\nand contains an element equal to that object. However, it make sense\nfor many other object types to support membership tests without being\na sequence. In particular, dictionaries (for keys) and sets support\nmembership testing.\n\nFor the list and tuple types, "x in y" is true if and only if there\nexists an index *i* such that either "x is y[i]" or "x == y[i]" is\ntrue.\n\nFor the Unicode and string types, "x in y" is true if and only if *x*\nis a substring of *y*. An equivalent test is "y.find(x) != -1".\nNote, *x* and *y* need not be the same type; consequently, "u\'ab\' in\n\'abc\'" will return "True". Empty strings are always considered to be a\nsubstring of any other string, so """ in "abc"" will return "True".\n\nChanged in version 2.3: Previously, *x* was required to be a string of\nlength "1".\n\nFor user-defined classes which define the "__contains__()" method, "x\nin y" is true if and only if "y.__contains__(x)" is true.\n\nFor user-defined classes which do not define "__contains__()" but do\ndefine "__iter__()", "x in y" is true if some value "z" with "x == z"\nis produced while iterating over "y". If an exception is raised\nduring the iteration, it is as if "in" raised that exception.\n\nLastly, the old-style iteration protocol is tried: if a class defines\n"__getitem__()", "x in y" is true if and only if there is a non-\nnegative integer index *i* such that "x == y[i]", and all lower\ninteger indices do not raise "IndexError" exception. (If any other\nexception is raised, it is as if "in" raised that exception).\n\nThe operator "not in" is defined to have the inverse true value of\n"in".\n\nThe operators "is" and "is not" test for object identity: "x is y" is\ntrue if and only if *x* and *y* are the same object. "x is not y"\nyields the inverse truth value. [7]\n',
+ 'compound': u'\nCompound statements\n*******************\n\nCompound statements contain (groups of) other statements; they affect\nor control the execution of those other statements in some way. In\ngeneral, compound statements span multiple lines, although in simple\nincarnations a whole compound statement may be contained in one line.\n\nThe "if", "while" and "for" statements implement traditional control\nflow constructs. "try" specifies exception handlers and/or cleanup\ncode for a group of statements. Function and class definitions are\nalso syntactically compound statements.\n\nCompound statements consist of one or more \'clauses.\' A clause\nconsists of a header and a \'suite.\' The clause headers of a\nparticular compound statement are all at the same indentation level.\nEach clause header begins with a uniquely identifying keyword and ends\nwith a colon. A suite is a group of statements controlled by a\nclause. A suite can be one or more semicolon-separated simple\nstatements on the same line as the header, following the header\'s\ncolon, or it can be one or more indented statements on subsequent\nlines. Only the latter form of suite can contain nested compound\nstatements; the following is illegal, mostly because it wouldn\'t be\nclear to which "if" clause a following "else" clause would belong:\n\n if test1: if test2: print x\n\nAlso note that the semicolon binds tighter than the colon in this\ncontext, so that in the following example, either all or none of the\n"print" statements are executed:\n\n if x < y < z: print x; print y; print z\n\nSummarizing:\n\n compound_stmt ::= if_stmt\n | while_stmt\n | for_stmt\n | try_stmt\n | with_stmt\n | funcdef\n | classdef\n | decorated\n suite ::= stmt_list NEWLINE | NEWLINE INDENT statement+ DEDENT\n statement ::= stmt_list NEWLINE | compound_stmt\n stmt_list ::= simple_stmt (";" simple_stmt)* [";"]\n\nNote that statements always end in a "NEWLINE" possibly followed by a\n"DEDENT". Also note that optional continuation clauses always begin\nwith a keyword that cannot start a statement, thus there are no\nambiguities (the \'dangling "else"\' problem is solved in Python by\nrequiring nested "if" statements to be indented).\n\nThe formatting of the grammar rules in the following sections places\neach clause on a separate line for clarity.\n\n\nThe "if" statement\n==================\n\nThe "if" statement is used for conditional execution:\n\n if_stmt ::= "if" expression ":" suite\n ( "elif" expression ":" suite )*\n ["else" ":" suite]\n\nIt selects exactly one of the suites by evaluating the expressions one\nby one until one is found to be true (see section Boolean operations\nfor the definition of true and false); then that suite is executed\n(and no other part of the "if" statement is executed or evaluated).\nIf all expressions are false, the suite of the "else" clause, if\npresent, is executed.\n\n\nThe "while" statement\n=====================\n\nThe "while" statement is used for repeated execution as long as an\nexpression is true:\n\n while_stmt ::= "while" expression ":" suite\n ["else" ":" suite]\n\nThis repeatedly tests the expression and, if it is true, executes the\nfirst suite; if the expression is false (which may be the first time\nit is tested) the suite of the "else" clause, if present, is executed\nand the loop terminates.\n\nA "break" statement executed in the first suite terminates the loop\nwithout executing the "else" clause\'s suite. A "continue" statement\nexecuted in the first suite skips the rest of the suite and goes back\nto testing the expression.\n\n\nThe "for" statement\n===================\n\nThe "for" statement is used to iterate over the elements of a sequence\n(such as a string, tuple or list) or other iterable object:\n\n for_stmt ::= "for" target_list "in" expression_list ":" suite\n ["else" ":" suite]\n\nThe expression list is evaluated once; it should yield an iterable\nobject. An iterator is created for the result of the\n"expression_list". The suite is then executed once for each item\nprovided by the iterator, in the order of ascending indices. Each\nitem in turn is assigned to the target list using the standard rules\nfor assignments, and then the suite is executed. When the items are\nexhausted (which is immediately when the sequence is empty), the suite\nin the "else" clause, if present, is executed, and the loop\nterminates.\n\nA "break" statement executed in the first suite terminates the loop\nwithout executing the "else" clause\'s suite. A "continue" statement\nexecuted in the first suite skips the rest of the suite and continues\nwith the next item, or with the "else" clause if there was no next\nitem.\n\nThe suite may assign to the variable(s) in the target list; this does\nnot affect the next item assigned to it.\n\nThe target list is not deleted when the loop is finished, but if the\nsequence is empty, it will not have been assigned to at all by the\nloop. Hint: the built-in function "range()" returns a sequence of\nintegers suitable to emulate the effect of Pascal\'s "for i := a to b\ndo"; e.g., "range(3)" returns the list "[0, 1, 2]".\n\nNote: There is a subtlety when the sequence is being modified by the\n loop (this can only occur for mutable sequences, i.e. lists). An\n internal counter is used to keep track of which item is used next,\n and this is incremented on each iteration. When this counter has\n reached the length of the sequence the loop terminates. This means\n that if the suite deletes the current (or a previous) item from the\n sequence, the next item will be skipped (since it gets the index of\n the current item which has already been treated). Likewise, if the\n suite inserts an item in the sequence before the current item, the\n current item will be treated again the next time through the loop.\n This can lead to nasty bugs that can be avoided by making a\n temporary copy using a slice of the whole sequence, e.g.,\n\n for x in a[:]:\n if x < 0: a.remove(x)\n\n\nThe "try" statement\n===================\n\nThe "try" statement specifies exception handlers and/or cleanup code\nfor a group of statements:\n\n try_stmt ::= try1_stmt | try2_stmt\n try1_stmt ::= "try" ":" suite\n ("except" [expression [("as" | ",") identifier]] ":" suite)+\n ["else" ":" suite]\n ["finally" ":" suite]\n try2_stmt ::= "try" ":" suite\n "finally" ":" suite\n\nChanged in version 2.5: In previous versions of Python,\n"try"..."except"..."finally" did not work. "try"..."except" had to be\nnested in "try"..."finally".\n\nThe "except" clause(s) specify one or more exception handlers. When no\nexception occurs in the "try" clause, no exception handler is\nexecuted. When an exception occurs in the "try" suite, a search for an\nexception handler is started. This search inspects the except clauses\nin turn until one is found that matches the exception. An expression-\nless except clause, if present, must be last; it matches any\nexception. For an except clause with an expression, that expression\nis evaluated, and the clause matches the exception if the resulting\nobject is "compatible" with the exception. An object is compatible\nwith an exception if it is the class or a base class of the exception\nobject, or a tuple containing an item compatible with the exception.\n\nIf no except clause matches the exception, the search for an exception\nhandler continues in the surrounding code and on the invocation stack.\n[1]\n\nIf the evaluation of an expression in the header of an except clause\nraises an exception, the original search for a handler is canceled and\na search starts for the new exception in the surrounding code and on\nthe call stack (it is treated as if the entire "try" statement raised\nthe exception).\n\nWhen a matching except clause is found, the exception is assigned to\nthe target specified in that except clause, if present, and the except\nclause\'s suite is executed. All except clauses must have an\nexecutable block. When the end of this block is reached, execution\ncontinues normally after the entire try statement. (This means that\nif two nested handlers exist for the same exception, and the exception\noccurs in the try clause of the inner handler, the outer handler will\nnot handle the exception.)\n\nBefore an except clause\'s suite is executed, details about the\nexception are assigned to three variables in the "sys" module:\n"sys.exc_type" receives the object identifying the exception;\n"sys.exc_value" receives the exception\'s parameter;\n"sys.exc_traceback" receives a traceback object (see section The\nstandard type hierarchy) identifying the point in the program where\nthe exception occurred. These details are also available through the\n"sys.exc_info()" function, which returns a tuple "(exc_type,\nexc_value, exc_traceback)". Use of the corresponding variables is\ndeprecated in favor of this function, since their use is unsafe in a\nthreaded program. As of Python 1.5, the variables are restored to\ntheir previous values (before the call) when returning from a function\nthat handled an exception.\n\nThe optional "else" clause is executed if and when control flows off\nthe end of the "try" clause. [2] Exceptions in the "else" clause are\nnot handled by the preceding "except" clauses.\n\nIf "finally" is present, it specifies a \'cleanup\' handler. The "try"\nclause is executed, including any "except" and "else" clauses. If an\nexception occurs in any of the clauses and is not handled, the\nexception is temporarily saved. The "finally" clause is executed. If\nthere is a saved exception, it is re-raised at the end of the\n"finally" clause. If the "finally" clause raises another exception or\nexecutes a "return" or "break" statement, the saved exception is\ndiscarded:\n\n >>> def f():\n ... try:\n ... 1/0\n ... finally:\n ... return 42\n ...\n >>> f()\n 42\n\nThe exception information is not available to the program during\nexecution of the "finally" clause.\n\nWhen a "return", "break" or "continue" statement is executed in the\n"try" suite of a "try"..."finally" statement, the "finally" clause is\nalso executed \'on the way out.\' A "continue" statement is illegal in\nthe "finally" clause. (The reason is a problem with the current\nimplementation --- this restriction may be lifted in the future).\n\nThe return value of a function is determined by the last "return"\nstatement executed. Since the "finally" clause always executes, a\n"return" statement executed in the "finally" clause will always be the\nlast one executed:\n\n >>> def foo():\n ... try:\n ... return \'try\'\n ... finally:\n ... return \'finally\'\n ...\n >>> foo()\n \'finally\'\n\nAdditional information on exceptions can be found in section\nExceptions, and information on using the "raise" statement to generate\nexceptions may be found in section The raise statement.\n\n\nThe "with" statement\n====================\n\nNew in version 2.5.\n\nThe "with" statement is used to wrap the execution of a block with\nmethods defined by a context manager (see section With Statement\nContext Managers). This allows common "try"..."except"..."finally"\nusage patterns to be encapsulated for convenient reuse.\n\n with_stmt ::= "with" with_item ("," with_item)* ":" suite\n with_item ::= expression ["as" target]\n\nThe execution of the "with" statement with one "item" proceeds as\nfollows:\n\n1. The context expression (the expression given in the "with_item")\n is evaluated to obtain a context manager.\n\n2. The context manager\'s "__exit__()" is loaded for later use.\n\n3. The context manager\'s "__enter__()" method is invoked.\n\n4. If a target was included in the "with" statement, the return\n value from "__enter__()" is assigned to it.\n\n Note: The "with" statement guarantees that if the "__enter__()"\n method returns without an error, then "__exit__()" will always be\n called. Thus, if an error occurs during the assignment to the\n target list, it will be treated the same as an error occurring\n within the suite would be. See step 6 below.\n\n5. The suite is executed.\n\n6. The context manager\'s "__exit__()" method is invoked. If an\n exception caused the suite to be exited, its type, value, and\n traceback are passed as arguments to "__exit__()". Otherwise, three\n "None" arguments are supplied.\n\n If the suite was exited due to an exception, and the return value\n from the "__exit__()" method was false, the exception is reraised.\n If the return value was true, the exception is suppressed, and\n execution continues with the statement following the "with"\n statement.\n\n If the suite was exited for any reason other than an exception, the\n return value from "__exit__()" is ignored, and execution proceeds\n at the normal location for the kind of exit that was taken.\n\nWith more than one item, the context managers are processed as if\nmultiple "with" statements were nested:\n\n with A() as a, B() as b:\n suite\n\nis equivalent to\n\n with A() as a:\n with B() as b:\n suite\n\nNote: In Python 2.5, the "with" statement is only allowed when the\n "with_statement" feature has been enabled. It is always enabled in\n Python 2.6.\n\nChanged in version 2.7: Support for multiple context expressions.\n\nSee also:\n\n **PEP 343** - The "with" statement\n The specification, background, and examples for the Python "with"\n statement.\n\n\nFunction definitions\n====================\n\nA function definition defines a user-defined function object (see\nsection The standard type hierarchy):\n\n decorated ::= decorators (classdef | funcdef)\n decorators ::= decorator+\n decorator ::= "@" dotted_name ["(" [argument_list [","]] ")"] NEWLINE\n funcdef ::= "def" funcname "(" [parameter_list] ")" ":" suite\n dotted_name ::= identifier ("." identifier)*\n parameter_list ::= (defparameter ",")*\n ( "*" identifier ["," "**" identifier]\n | "**" identifier\n | defparameter [","] )\n defparameter ::= parameter ["=" expression]\n sublist ::= parameter ("," parameter)* [","]\n parameter ::= identifier | "(" sublist ")"\n funcname ::= identifier\n\nA function definition is an executable statement. Its execution binds\nthe function name in the current local namespace to a function object\n(a wrapper around the executable code for the function). This\nfunction object contains a reference to the current global namespace\nas the global namespace to be used when the function is called.\n\nThe function definition does not execute the function body; this gets\nexecuted only when the function is called. [3]\n\nA function definition may be wrapped by one or more *decorator*\nexpressions. Decorator expressions are evaluated when the function is\ndefined, in the scope that contains the function definition. The\nresult must be a callable, which is invoked with the function object\nas the only argument. The returned value is bound to the function name\ninstead of the function object. Multiple decorators are applied in\nnested fashion. For example, the following code:\n\n @f1(arg)\n @f2\n def func(): pass\n\nis equivalent to:\n\n def func(): pass\n func = f1(arg)(f2(func))\n\nWhen one or more top-level *parameters* have the form *parameter* "="\n*expression*, the function is said to have "default parameter values."\nFor a parameter with a default value, the corresponding *argument* may\nbe omitted from a call, in which case the parameter\'s default value is\nsubstituted. If a parameter has a default value, all following\nparameters must also have a default value --- this is a syntactic\nrestriction that is not expressed by the grammar.\n\n**Default parameter values are evaluated when the function definition\nis executed.** This means that the expression is evaluated once, when\nthe function is defined, and that the same "pre-computed" value is\nused for each call. This is especially important to understand when a\ndefault parameter is a mutable object, such as a list or a dictionary:\nif the function modifies the object (e.g. by appending an item to a\nlist), the default value is in effect modified. This is generally not\nwhat was intended. A way around this is to use "None" as the\ndefault, and explicitly test for it in the body of the function, e.g.:\n\n def whats_on_the_telly(penguin=None):\n if penguin is None:\n penguin = []\n penguin.append("property of the zoo")\n return penguin\n\nFunction call semantics are described in more detail in section Calls.\nA function call always assigns values to all parameters mentioned in\nthe parameter list, either from position arguments, from keyword\narguments, or from default values. If the form ""*identifier"" is\npresent, it is initialized to a tuple receiving any excess positional\nparameters, defaulting to the empty tuple. If the form\n""**identifier"" is present, it is initialized to a new dictionary\nreceiving any excess keyword arguments, defaulting to a new empty\ndictionary.\n\nIt is also possible to create anonymous functions (functions not bound\nto a name), for immediate use in expressions. This uses lambda\nexpressions, described in section Lambdas. Note that the lambda\nexpression is merely a shorthand for a simplified function definition;\na function defined in a ""def"" statement can be passed around or\nassigned to another name just like a function defined by a lambda\nexpression. The ""def"" form is actually more powerful since it\nallows the execution of multiple statements.\n\n**Programmer\'s note:** Functions are first-class objects. A ""def""\nform executed inside a function definition defines a local function\nthat can be returned or passed around. Free variables used in the\nnested function can access the local variables of the function\ncontaining the def. See section Naming and binding for details.\n\n\nClass definitions\n=================\n\nA class definition defines a class object (see section The standard\ntype hierarchy):\n\n classdef ::= "class" classname [inheritance] ":" suite\n inheritance ::= "(" [expression_list] ")"\n classname ::= identifier\n\nA class definition is an executable statement. It first evaluates the\ninheritance list, if present. Each item in the inheritance list\nshould evaluate to a class object or class type which allows\nsubclassing. The class\'s suite is then executed in a new execution\nframe (see section Naming and binding), using a newly created local\nnamespace and the original global namespace. (Usually, the suite\ncontains only function definitions.) When the class\'s suite finishes\nexecution, its execution frame is discarded but its local namespace is\nsaved. [4] A class object is then created using the inheritance list\nfor the base classes and the saved local namespace for the attribute\ndictionary. The class name is bound to this class object in the\noriginal local namespace.\n\n**Programmer\'s note:** Variables defined in the class definition are\nclass variables; they are shared by all instances. To create instance\nvariables, they can be set in a method with "self.name = value". Both\nclass and instance variables are accessible through the notation\n""self.name"", and an instance variable hides a class variable with\nthe same name when accessed in this way. Class variables can be used\nas defaults for instance variables, but using mutable values there can\nlead to unexpected results. For *new-style class*es, descriptors can\nbe used to create instance variables with different implementation\ndetails.\n\nClass definitions, like function definitions, may be wrapped by one or\nmore *decorator* expressions. The evaluation rules for the decorator\nexpressions are the same as for functions. The result must be a class\nobject, which is then bound to the class name.\n\n-[ Footnotes ]-\n\n[1] The exception is propagated to the invocation stack unless\n there is a "finally" clause which happens to raise another\n exception. That new exception causes the old one to be lost.\n\n[2] Currently, control "flows off the end" except in the case of\n an exception or the execution of a "return", "continue", or\n "break" statement.\n\n[3] A string literal appearing as the first statement in the\n function body is transformed into the function\'s "__doc__"\n attribute and therefore the function\'s *docstring*.\n\n[4] A string literal appearing as the first statement in the class\n body is transformed into the namespace\'s "__doc__" item and\n therefore the class\'s *docstring*.\n',
+ 'context-managers': u'\nWith Statement Context Managers\n*******************************\n\nNew in version 2.5.\n\nA *context manager* is an object that defines the runtime context to\nbe established when executing a "with" statement. The context manager\nhandles the entry into, and the exit from, the desired runtime context\nfor the execution of the block of code. Context managers are normally\ninvoked using the "with" statement (described in section The with\nstatement), but can also be used by directly invoking their methods.\n\nTypical uses of context managers include saving and restoring various\nkinds of global state, locking and unlocking resources, closing opened\nfiles, etc.\n\nFor more information on context managers, see Context Manager Types.\n\nobject.__enter__(self)\n\n Enter the runtime context related to this object. The "with"\n statement will bind this method\'s return value to the target(s)\n specified in the "as" clause of the statement, if any.\n\nobject.__exit__(self, exc_type, exc_value, traceback)\n\n Exit the runtime context related to this object. The parameters\n describe the exception that caused the context to be exited. If the\n context was exited without an exception, all three arguments will\n be "None".\n\n If an exception is supplied, and the method wishes to suppress the\n exception (i.e., prevent it from being propagated), it should\n return a true value. Otherwise, the exception will be processed\n normally upon exit from this method.\n\n Note that "__exit__()" methods should not reraise the passed-in\n exception; this is the caller\'s responsibility.\n\nSee also:\n\n **PEP 343** - The "with" statement\n The specification, background, and examples for the Python "with"\n statement.\n',
+ 'continue': u'\nThe "continue" statement\n************************\n\n continue_stmt ::= "continue"\n\n"continue" may only occur syntactically nested in a "for" or "while"\nloop, but not nested in a function or class definition or "finally"\nclause within that loop. It continues with the next cycle of the\nnearest enclosing loop.\n\nWhen "continue" passes control out of a "try" statement with a\n"finally" clause, that "finally" clause is executed before really\nstarting the next loop cycle.\n',
+ 'conversions': u'\nArithmetic conversions\n**********************\n\nWhen a description of an arithmetic operator below uses the phrase\n"the numeric arguments are converted to a common type," the arguments\nare coerced using the coercion rules listed at Coercion rules. If\nboth arguments are standard numeric types, the following coercions are\napplied:\n\n* If either argument is a complex number, the other is converted to\n complex;\n\n* otherwise, if either argument is a floating point number, the\n other is converted to floating point;\n\n* otherwise, if either argument is a long integer, the other is\n converted to long integer;\n\n* otherwise, both must be plain integers and no conversion is\n necessary.\n\nSome additional rules apply for certain operators (e.g., a string left\nargument to the \'%\' operator). Extensions can define their own\ncoercions.\n',
+ 'customization': u'\nBasic customization\n*******************\n\nobject.__new__(cls[, ...])\n\n Called to create a new instance of class *cls*. "__new__()" is a\n static method (special-cased so you need not declare it as such)\n that takes the class of which an instance was requested as its\n first argument. The remaining arguments are those passed to the\n object constructor expression (the call to the class). The return\n value of "__new__()" should be the new object instance (usually an\n instance of *cls*).\n\n Typical implementations create a new instance of the class by\n invoking the superclass\'s "__new__()" method using\n "super(currentclass, cls).__new__(cls[, ...])" with appropriate\n arguments and then modifying the newly-created instance as\n necessary before returning it.\n\n If "__new__()" returns an instance of *cls*, then the new\n instance\'s "__init__()" method will be invoked like\n "__init__(self[, ...])", where *self* is the new instance and the\n remaining arguments are the same as were passed to "__new__()".\n\n If "__new__()" does not return an instance of *cls*, then the new\n instance\'s "__init__()" method will not be invoked.\n\n "__new__()" is intended mainly to allow subclasses of immutable\n types (like int, str, or tuple) to customize instance creation. It\n is also commonly overridden in custom metaclasses in order to\n customize class creation.\n\nobject.__init__(self[, ...])\n\n Called after the instance has been created (by "__new__()"), but\n before it is returned to the caller. The arguments are those\n passed to the class constructor expression. If a base class has an\n "__init__()" method, the derived class\'s "__init__()" method, if\n any, must explicitly call it to ensure proper initialization of the\n base class part of the instance; for example:\n "BaseClass.__init__(self, [args...])".\n\n Because "__new__()" and "__init__()" work together in constructing\n objects ("__new__()" to create it, and "__init__()" to customise\n it), no non-"None" value may be returned by "__init__()"; doing so\n will cause a "TypeError" to be raised at runtime.\n\nobject.__del__(self)\n\n Called when the instance is about to be destroyed. This is also\n called a destructor. If a base class has a "__del__()" method, the\n derived class\'s "__del__()" method, if any, must explicitly call it\n to ensure proper deletion of the base class part of the instance.\n Note that it is possible (though not recommended!) for the\n "__del__()" method to postpone destruction of the instance by\n creating a new reference to it. It may then be called at a later\n time when this new reference is deleted. It is not guaranteed that\n "__del__()" methods are called for objects that still exist when\n the interpreter exits.\n\n Note: "del x" doesn\'t directly call "x.__del__()" --- the former\n decrements the reference count for "x" by one, and the latter is\n only called when "x"\'s reference count reaches zero. Some common\n situations that may prevent the reference count of an object from\n going to zero include: circular references between objects (e.g.,\n a doubly-linked list or a tree data structure with parent and\n child pointers); a reference to the object on the stack frame of\n a function that caught an exception (the traceback stored in\n "sys.exc_traceback" keeps the stack frame alive); or a reference\n to the object on the stack frame that raised an unhandled\n exception in interactive mode (the traceback stored in\n "sys.last_traceback" keeps the stack frame alive). The first\n situation can only be remedied by explicitly breaking the cycles;\n the latter two situations can be resolved by storing "None" in\n "sys.exc_traceback" or "sys.last_traceback". Circular references\n which are garbage are detected when the option cycle detector is\n enabled (it\'s on by default), but can only be cleaned up if there\n are no Python-level "__del__()" methods involved. Refer to the\n documentation for the "gc" module for more information about how\n "__del__()" methods are handled by the cycle detector,\n particularly the description of the "garbage" value.\n\n Warning: Due to the precarious circumstances under which\n "__del__()" methods are invoked, exceptions that occur during\n their execution are ignored, and a warning is printed to\n "sys.stderr" instead. Also, when "__del__()" is invoked in\n response to a module being deleted (e.g., when execution of the\n program is done), other globals referenced by the "__del__()"\n method may already have been deleted or in the process of being\n torn down (e.g. the import machinery shutting down). For this\n reason, "__del__()" methods should do the absolute minimum needed\n to maintain external invariants. Starting with version 1.5,\n Python guarantees that globals whose name begins with a single\n underscore are deleted from their module before other globals are\n deleted; if no other references to such globals exist, this may\n help in assuring that imported modules are still available at the\n time when the "__del__()" method is called.\n\n See also the "-R" command-line option.\n\nobject.__repr__(self)\n\n Called by the "repr()" built-in function and by string conversions\n (reverse quotes) to compute the "official" string representation of\n an object. If at all possible, this should look like a valid\n Python expression that could be used to recreate an object with the\n same value (given an appropriate environment). If this is not\n possible, a string of the form "<...some useful description...>"\n should be returned. The return value must be a string object. If a\n class defines "__repr__()" but not "__str__()", then "__repr__()"\n is also used when an "informal" string representation of instances\n of that class is required.\n\n This is typically used for debugging, so it is important that the\n representation is information-rich and unambiguous.\n\nobject.__str__(self)\n\n Called by the "str()" built-in function and by the "print"\n statement to compute the "informal" string representation of an\n object. This differs from "__repr__()" in that it does not have to\n be a valid Python expression: a more convenient or concise\n representation may be used instead. The return value must be a\n string object.\n\nobject.__lt__(self, other)\nobject.__le__(self, other)\nobject.__eq__(self, other)\nobject.__ne__(self, other)\nobject.__gt__(self, other)\nobject.__ge__(self, other)\n\n New in version 2.1.\n\n These are the so-called "rich comparison" methods, and are called\n for comparison operators in preference to "__cmp__()" below. The\n correspondence between operator symbols and method names is as\n follows: "x<y" calls "x.__lt__(y)", "x<=y" calls "x.__le__(y)",\n "x==y" calls "x.__eq__(y)", "x!=y" and "x<>y" call "x.__ne__(y)",\n "x>y" calls "x.__gt__(y)", and "x>=y" calls "x.__ge__(y)".\n\n A rich comparison method may return the singleton "NotImplemented"\n if it does not implement the operation for a given pair of\n arguments. By convention, "False" and "True" are returned for a\n successful comparison. However, these methods can return any value,\n so if the comparison operator is used in a Boolean context (e.g.,\n in the condition of an "if" statement), Python will call "bool()"\n on the value to determine if the result is true or false.\n\n There are no implied relationships among the comparison operators.\n The truth of "x==y" does not imply that "x!=y" is false.\n Accordingly, when defining "__eq__()", one should also define\n "__ne__()" so that the operators will behave as expected. See the\n paragraph on "__hash__()" for some important notes on creating\n *hashable* objects which support custom comparison operations and\n are usable as dictionary keys.\n\n There are no swapped-argument versions of these methods (to be used\n when the left argument does not support the operation but the right\n argument does); rather, "__lt__()" and "__gt__()" are each other\'s\n reflection, "__le__()" and "__ge__()" are each other\'s reflection,\n and "__eq__()" and "__ne__()" are their own reflection.\n\n Arguments to rich comparison methods are never coerced.\n\n To automatically generate ordering operations from a single root\n operation, see "functools.total_ordering()".\n\nobject.__cmp__(self, other)\n\n Called by comparison operations if rich comparison (see above) is\n not defined. Should return a negative integer if "self < other",\n zero if "self == other", a positive integer if "self > other". If\n no "__cmp__()", "__eq__()" or "__ne__()" operation is defined,\n class instances are compared by object identity ("address"). See\n also the description of "__hash__()" for some important notes on\n creating *hashable* objects which support custom comparison\n operations and are usable as dictionary keys. (Note: the\n restriction that exceptions are not propagated by "__cmp__()" has\n been removed since Python 1.5.)\n\nobject.__rcmp__(self, other)\n\n Changed in version 2.1: No longer supported.\n\nobject.__hash__(self)\n\n Called by built-in function "hash()" and for operations on members\n of hashed collections including "set", "frozenset", and "dict".\n "__hash__()" should return an integer. The only required property\n is that objects which compare equal have the same hash value; it is\n advised to somehow mix together (e.g. using exclusive or) the hash\n values for the components of the object that also play a part in\n comparison of objects.\n\n If a class does not define a "__cmp__()" or "__eq__()" method it\n should not define a "__hash__()" operation either; if it defines\n "__cmp__()" or "__eq__()" but not "__hash__()", its instances will\n not be usable in hashed collections. If a class defines mutable\n objects and implements a "__cmp__()" or "__eq__()" method, it\n should not implement "__hash__()", since hashable collection\n implementations require that an object\'s hash value is immutable\n (if the object\'s hash value changes, it will be in the wrong hash\n bucket).\n\n User-defined classes have "__cmp__()" and "__hash__()" methods by\n default; with them, all objects compare unequal (except with\n themselves) and "x.__hash__()" returns a result derived from\n "id(x)".\n\n Classes which inherit a "__hash__()" method from a parent class but\n change the meaning of "__cmp__()" or "__eq__()" such that the hash\n value returned is no longer appropriate (e.g. by switching to a\n value-based concept of equality instead of the default identity\n based equality) can explicitly flag themselves as being unhashable\n by setting "__hash__ = None" in the class definition. Doing so\n means that not only will instances of the class raise an\n appropriate "TypeError" when a program attempts to retrieve their\n hash value, but they will also be correctly identified as\n unhashable when checking "isinstance(obj, collections.Hashable)"\n (unlike classes which define their own "__hash__()" to explicitly\n raise "TypeError").\n\n Changed in version 2.5: "__hash__()" may now also return a long\n integer object; the 32-bit integer is then derived from the hash of\n that object.\n\n Changed in version 2.6: "__hash__" may now be set to "None" to\n explicitly flag instances of a class as unhashable.\n\nobject.__nonzero__(self)\n\n Called to implement truth value testing and the built-in operation\n "bool()"; should return "False" or "True", or their integer\n equivalents "0" or "1". When this method is not defined,\n "__len__()" is called, if it is defined, and the object is\n considered true if its result is nonzero. If a class defines\n neither "__len__()" nor "__nonzero__()", all its instances are\n considered true.\n\nobject.__unicode__(self)\n\n Called to implement "unicode()" built-in; should return a Unicode\n object. When this method is not defined, string conversion is\n attempted, and the result of string conversion is converted to\n Unicode using the system default encoding.\n',
+ 'debugger': u'\n"pdb" --- The Python Debugger\n*****************************\n\n**Source code:** Lib/pdb.py\n\n======================================================================\n\nThe module "pdb" defines an interactive source code debugger for\nPython programs. It supports setting (conditional) breakpoints and\nsingle stepping at the source line level, inspection of stack frames,\nsource code listing, and evaluation of arbitrary Python code in the\ncontext of any stack frame. It also supports post-mortem debugging\nand can be called under program control.\n\nThe debugger is extensible --- it is actually defined as the class\n"Pdb". This is currently undocumented but easily understood by reading\nthe source. The extension interface uses the modules "bdb" and "cmd".\n\nThe debugger\'s prompt is "(Pdb)". Typical usage to run a program under\ncontrol of the debugger is:\n\n >>> import pdb\n >>> import mymodule\n >>> pdb.run(\'mymodule.test()\')\n > <string>(0)?()\n (Pdb) continue\n > <string>(1)?()\n (Pdb) continue\n NameError: \'spam\'\n > <string>(1)?()\n (Pdb)\n\n"pdb.py" can also be invoked as a script to debug other scripts. For\nexample:\n\n python -m pdb myscript.py\n\nWhen invoked as a script, pdb will automatically enter post-mortem\ndebugging if the program being debugged exits abnormally. After post-\nmortem debugging (or after normal exit of the program), pdb will\nrestart the program. Automatic restarting preserves pdb\'s state (such\nas breakpoints) and in most cases is more useful than quitting the\ndebugger upon program\'s exit.\n\nNew in version 2.4: Restarting post-mortem behavior added.\n\nThe typical usage to break into the debugger from a running program is\nto insert\n\n import pdb; pdb.set_trace()\n\nat the location you want to break into the debugger. You can then\nstep through the code following this statement, and continue running\nwithout the debugger using the "c" command.\n\nThe typical usage to inspect a crashed program is:\n\n >>> import pdb\n >>> import mymodule\n >>> mymodule.test()\n Traceback (most recent call last):\n File "<stdin>", line 1, in ?\n File "./mymodule.py", line 4, in test\n test2()\n File "./mymodule.py", line 3, in test2\n print spam\n NameError: spam\n >>> pdb.pm()\n > ./mymodule.py(3)test2()\n -> print spam\n (Pdb)\n\nThe module defines the following functions; each enters the debugger\nin a slightly different way:\n\npdb.run(statement[, globals[, locals]])\n\n Execute the *statement* (given as a string) under debugger control.\n The debugger prompt appears before any code is executed; you can\n set breakpoints and type "continue", or you can step through the\n statement using "step" or "next" (all these commands are explained\n below). The optional *globals* and *locals* arguments specify the\n environment in which the code is executed; by default the\n dictionary of the module "__main__" is used. (See the explanation\n of the "exec" statement or the "eval()" built-in function.)\n\npdb.runeval(expression[, globals[, locals]])\n\n Evaluate the *expression* (given as a string) under debugger\n control. When "runeval()" returns, it returns the value of the\n expression. Otherwise this function is similar to "run()".\n\npdb.runcall(function[, argument, ...])\n\n Call the *function* (a function or method object, not a string)\n with the given arguments. When "runcall()" returns, it returns\n whatever the function call returned. The debugger prompt appears\n as soon as the function is entered.\n\npdb.set_trace()\n\n Enter the debugger at the calling stack frame. This is useful to\n hard-code a breakpoint at a given point in a program, even if the\n code is not otherwise being debugged (e.g. when an assertion\n fails).\n\npdb.post_mortem([traceback])\n\n Enter post-mortem debugging of the given *traceback* object. If no\n *traceback* is given, it uses the one of the exception that is\n currently being handled (an exception must be being handled if the\n default is to be used).\n\npdb.pm()\n\n Enter post-mortem debugging of the traceback found in\n "sys.last_traceback".\n\nThe "run*" functions and "set_trace()" are aliases for instantiating\nthe "Pdb" class and calling the method of the same name. If you want\nto access further features, you have to do this yourself:\n\nclass pdb.Pdb(completekey=\'tab\', stdin=None, stdout=None, skip=None)\n\n "Pdb" is the debugger class.\n\n The *completekey*, *stdin* and *stdout* arguments are passed to the\n underlying "cmd.Cmd" class; see the description there.\n\n The *skip* argument, if given, must be an iterable of glob-style\n module name patterns. The debugger will not step into frames that\n originate in a module that matches one of these patterns. [1]\n\n Example call to enable tracing with *skip*:\n\n import pdb; pdb.Pdb(skip=[\'django.*\']).set_trace()\n\n New in version 2.7: The *skip* argument.\n\n run(statement[, globals[, locals]])\n runeval(expression[, globals[, locals]])\n runcall(function[, argument, ...])\n set_trace()\n\n See the documentation for the functions explained above.\n',
+ 'del': u'\nThe "del" statement\n*******************\n\n del_stmt ::= "del" target_list\n\nDeletion is recursively defined very similar to the way assignment is\ndefined. Rather than spelling it out in full details, here are some\nhints.\n\nDeletion of a target list recursively deletes each target, from left\nto right.\n\nDeletion of a name removes the binding of that name from the local or\nglobal namespace, depending on whether the name occurs in a "global"\nstatement in the same code block. If the name is unbound, a\n"NameError" exception will be raised.\n\nIt is illegal to delete a name from the local namespace if it occurs\nas a free variable in a nested block.\n\nDeletion of attribute references, subscriptions and slicings is passed\nto the primary object involved; deletion of a slicing is in general\nequivalent to assignment of an empty slice of the right type (but even\nthis is determined by the sliced object).\n',
+ 'dict': u'\nDictionary displays\n*******************\n\nA dictionary display is a possibly empty series of key/datum pairs\nenclosed in curly braces:\n\n dict_display ::= "{" [key_datum_list | dict_comprehension] "}"\n key_datum_list ::= key_datum ("," key_datum)* [","]\n key_datum ::= expression ":" expression\n dict_comprehension ::= expression ":" expression comp_for\n\nA dictionary display yields a new dictionary object.\n\nIf a comma-separated sequence of key/datum pairs is given, they are\nevaluated from left to right to define the entries of the dictionary:\neach key object is used as a key into the dictionary to store the\ncorresponding datum. This means that you can specify the same key\nmultiple times in the key/datum list, and the final dictionary\'s value\nfor that key will be the last one given.\n\nA dict comprehension, in contrast to list and set comprehensions,\nneeds two expressions separated with a colon followed by the usual\n"for" and "if" clauses. When the comprehension is run, the resulting\nkey and value elements are inserted in the new dictionary in the order\nthey are produced.\n\nRestrictions on the types of the key values are listed earlier in\nsection The standard type hierarchy. (To summarize, the key type\nshould be *hashable*, which excludes all mutable objects.) Clashes\nbetween duplicate keys are not detected; the last datum (textually\nrightmost in the display) stored for a given key value prevails.\n',
+ 'dynamic-features': u'\nInteraction with dynamic features\n*********************************\n\nThere are several cases where Python statements are illegal when used\nin conjunction with nested scopes that contain free variables.\n\nIf a variable is referenced in an enclosing scope, it is illegal to\ndelete the name. An error will be reported at compile time.\n\nIf the wild card form of import --- "import *" --- is used in a\nfunction and the function contains or is a nested block with free\nvariables, the compiler will raise a "SyntaxError".\n\nIf "exec" is used in a function and the function contains or is a\nnested block with free variables, the compiler will raise a\n"SyntaxError" unless the exec explicitly specifies the local namespace\nfor the "exec". (In other words, "exec obj" would be illegal, but\n"exec obj in ns" would be legal.)\n\nThe "eval()", "execfile()", and "input()" functions and the "exec"\nstatement do not have access to the full environment for resolving\nnames. Names may be resolved in the local and global namespaces of\nthe caller. Free variables are not resolved in the nearest enclosing\nnamespace, but in the global namespace. [1] The "exec" statement and\nthe "eval()" and "execfile()" functions have optional arguments to\noverride the global and local namespace. If only one namespace is\nspecified, it is used for both.\n',
+ 'else': u'\nThe "if" statement\n******************\n\nThe "if" statement is used for conditional execution:\n\n if_stmt ::= "if" expression ":" suite\n ( "elif" expression ":" suite )*\n ["else" ":" suite]\n\nIt selects exactly one of the suites by evaluating the expressions one\nby one until one is found to be true (see section Boolean operations\nfor the definition of true and false); then that suite is executed\n(and no other part of the "if" statement is executed or evaluated).\nIf all expressions are false, the suite of the "else" clause, if\npresent, is executed.\n',
+ 'exceptions': u'\nExceptions\n**********\n\nExceptions are a means of breaking out of the normal flow of control\nof a code block in order to handle errors or other exceptional\nconditions. An exception is *raised* at the point where the error is\ndetected; it may be *handled* by the surrounding code block or by any\ncode block that directly or indirectly invoked the code block where\nthe error occurred.\n\nThe Python interpreter raises an exception when it detects a run-time\nerror (such as division by zero). A Python program can also\nexplicitly raise an exception with the "raise" statement. Exception\nhandlers are specified with the "try" ... "except" statement. The\n"finally" clause of such a statement can be used to specify cleanup\ncode which does not handle the exception, but is executed whether an\nexception occurred or not in the preceding code.\n\nPython uses the "termination" model of error handling: an exception\nhandler can find out what happened and continue execution at an outer\nlevel, but it cannot repair the cause of the error and retry the\nfailing operation (except by re-entering the offending piece of code\nfrom the top).\n\nWhen an exception is not handled at all, the interpreter terminates\nexecution of the program, or returns to its interactive main loop. In\neither case, it prints a stack backtrace, except when the exception is\n"SystemExit".\n\nExceptions are identified by class instances. The "except" clause is\nselected depending on the class of the instance: it must reference the\nclass of the instance or a base class thereof. The instance can be\nreceived by the handler and can carry additional information about the\nexceptional condition.\n\nExceptions can also be identified by strings, in which case the\n"except" clause is selected by object identity. An arbitrary value\ncan be raised along with the identifying string which can be passed to\nthe handler.\n\nNote: Messages to exceptions are not part of the Python API. Their\n contents may change from one version of Python to the next without\n warning and should not be relied on by code which will run under\n multiple versions of the interpreter.\n\nSee also the description of the "try" statement in section The try\nstatement and "raise" statement in section The raise statement.\n\n-[ Footnotes ]-\n\n[1] This limitation occurs because the code that is executed by\n these operations is not available at the time the module is\n compiled.\n',
+ 'exec': u'\nThe "exec" statement\n********************\n\n exec_stmt ::= "exec" or_expr ["in" expression ["," expression]]\n\nThis statement supports dynamic execution of Python code. The first\nexpression should evaluate to either a Unicode string, a *Latin-1*\nencoded string, an open file object, a code object, or a tuple. If it\nis a string, the string is parsed as a suite of Python statements\nwhich is then executed (unless a syntax error occurs). [1] If it is an\nopen file, the file is parsed until EOF and executed. If it is a code\nobject, it is simply executed. For the interpretation of a tuple, see\nbelow. In all cases, the code that\'s executed is expected to be valid\nas file input (see section File input). Be aware that the "return"\nand "yield" statements may not be used outside of function definitions\neven within the context of code passed to the "exec" statement.\n\nIn all cases, if the optional parts are omitted, the code is executed\nin the current scope. If only the first expression after "in" is\nspecified, it should be a dictionary, which will be used for both the\nglobal and the local variables. If two expressions are given, they\nare used for the global and local variables, respectively. If\nprovided, *locals* can be any mapping object. Remember that at module\nlevel, globals and locals are the same dictionary. If two separate\nobjects are given as *globals* and *locals*, the code will be executed\nas if it were embedded in a class definition.\n\nThe first expression may also be a tuple of length 2 or 3. In this\ncase, the optional parts must be omitted. The form "exec(expr,\nglobals)" is equivalent to "exec expr in globals", while the form\n"exec(expr, globals, locals)" is equivalent to "exec expr in globals,\nlocals". The tuple form of "exec" provides compatibility with Python\n3, where "exec" is a function rather than a statement.\n\nChanged in version 2.4: Formerly, *locals* was required to be a\ndictionary.\n\nAs a side effect, an implementation may insert additional keys into\nthe dictionaries given besides those corresponding to variable names\nset by the executed code. For example, the current implementation may\nadd a reference to the dictionary of the built-in module "__builtin__"\nunder the key "__builtins__" (!).\n\n**Programmer\'s hints:** dynamic evaluation of expressions is supported\nby the built-in function "eval()". The built-in functions "globals()"\nand "locals()" return the current global and local dictionary,\nrespectively, which may be useful to pass around for use by "exec".\n\n-[ Footnotes ]-\n\n[1] Note that the parser only accepts the Unix-style end of line\n convention. If you are reading the code from a file, make sure to\n use *universal newlines* mode to convert Windows or Mac-style\n newlines.\n',
+ 'execmodel': u'\nExecution model\n***************\n\n\nNaming and binding\n==================\n\n*Names* refer to objects. Names are introduced by name binding\noperations. Each occurrence of a name in the program text refers to\nthe *binding* of that name established in the innermost function block\ncontaining the use.\n\nA *block* is a piece of Python program text that is executed as a\nunit. The following are blocks: a module, a function body, and a class\ndefinition. Each command typed interactively is a block. A script\nfile (a file given as standard input to the interpreter or specified\non the interpreter command line the first argument) is a code block.\nA script command (a command specified on the interpreter command line\nwith the \'**-c**\' option) is a code block. The file read by the\nbuilt-in function "execfile()" is a code block. The string argument\npassed to the built-in function "eval()" and to the "exec" statement\nis a code block. The expression read and evaluated by the built-in\nfunction "input()" is a code block.\n\nA code block is executed in an *execution frame*. A frame contains\nsome administrative information (used for debugging) and determines\nwhere and how execution continues after the code block\'s execution has\ncompleted.\n\nA *scope* defines the visibility of a name within a block. If a local\nvariable is defined in a block, its scope includes that block. If the\ndefinition occurs in a function block, the scope extends to any blocks\ncontained within the defining one, unless a contained block introduces\na different binding for the name. The scope of names defined in a\nclass block is limited to the class block; it does not extend to the\ncode blocks of methods -- this includes generator expressions since\nthey are implemented using a function scope. This means that the\nfollowing will fail:\n\n class A:\n a = 42\n b = list(a + i for i in range(10))\n\nWhen a name is used in a code block, it is resolved using the nearest\nenclosing scope. The set of all such scopes visible to a code block\nis called the block\'s *environment*.\n\nIf a name is bound in a block, it is a local variable of that block.\nIf a name is bound at the module level, it is a global variable. (The\nvariables of the module code block are local and global.) If a\nvariable is used in a code block but not defined there, it is a *free\nvariable*.\n\nWhen a name is not found at all, a "NameError" exception is raised.\nIf the name refers to a local variable that has not been bound, a\n"UnboundLocalError" exception is raised. "UnboundLocalError" is a\nsubclass of "NameError".\n\nThe following constructs bind names: formal parameters to functions,\n"import" statements, class and function definitions (these bind the\nclass or function name in the defining block), and targets that are\nidentifiers if occurring in an assignment, "for" loop header, in the\nsecond position of an "except" clause header or after "as" in a "with"\nstatement. The "import" statement of the form "from ... import *"\nbinds all names defined in the imported module, except those beginning\nwith an underscore. This form may only be used at the module level.\n\nA target occurring in a "del" statement is also considered bound for\nthis purpose (though the actual semantics are to unbind the name). It\nis illegal to unbind a name that is referenced by an enclosing scope;\nthe compiler will report a "SyntaxError".\n\nEach assignment or import statement occurs within a block defined by a\nclass or function definition or at the module level (the top-level\ncode block).\n\nIf a name binding operation occurs anywhere within a code block, all\nuses of the name within the block are treated as references to the\ncurrent block. This can lead to errors when a name is used within a\nblock before it is bound. This rule is subtle. Python lacks\ndeclarations and allows name binding operations to occur anywhere\nwithin a code block. The local variables of a code block can be\ndetermined by scanning the entire text of the block for name binding\noperations.\n\nIf the global statement occurs within a block, all uses of the name\nspecified in the statement refer to the binding of that name in the\ntop-level namespace. Names are resolved in the top-level namespace by\nsearching the global namespace, i.e. the namespace of the module\ncontaining the code block, and the builtins namespace, the namespace\nof the module "__builtin__". The global namespace is searched first.\nIf the name is not found there, the builtins namespace is searched.\nThe global statement must precede all uses of the name.\n\nThe builtins namespace associated with the execution of a code block\nis actually found by looking up the name "__builtins__" in its global\nnamespace; this should be a dictionary or a module (in the latter case\nthe module\'s dictionary is used). By default, when in the "__main__"\nmodule, "__builtins__" is the built-in module "__builtin__" (note: no\n\'s\'); when in any other module, "__builtins__" is an alias for the\ndictionary of the "__builtin__" module itself. "__builtins__" can be\nset to a user-created dictionary to create a weak form of restricted\nexecution.\n\n**CPython implementation detail:** Users should not touch\n"__builtins__"; it is strictly an implementation detail. Users\nwanting to override values in the builtins namespace should "import"\nthe "__builtin__" (no \'s\') module and modify its attributes\nappropriately.\n\nThe namespace for a module is automatically created the first time a\nmodule is imported. The main module for a script is always called\n"__main__".\n\nThe "global" statement has the same scope as a name binding operation\nin the same block. If the nearest enclosing scope for a free variable\ncontains a global statement, the free variable is treated as a global.\n\nA class definition is an executable statement that may use and define\nnames. These references follow the normal rules for name resolution.\nThe namespace of the class definition becomes the attribute dictionary\nof the class. Names defined at the class scope are not visible in\nmethods.\n\n\nInteraction with dynamic features\n---------------------------------\n\nThere are several cases where Python statements are illegal when used\nin conjunction with nested scopes that contain free variables.\n\nIf a variable is referenced in an enclosing scope, it is illegal to\ndelete the name. An error will be reported at compile time.\n\nIf the wild card form of import --- "import *" --- is used in a\nfunction and the function contains or is a nested block with free\nvariables, the compiler will raise a "SyntaxError".\n\nIf "exec" is used in a function and the function contains or is a\nnested block with free variables, the compiler will raise a\n"SyntaxError" unless the exec explicitly specifies the local namespace\nfor the "exec". (In other words, "exec obj" would be illegal, but\n"exec obj in ns" would be legal.)\n\nThe "eval()", "execfile()", and "input()" functions and the "exec"\nstatement do not have access to the full environment for resolving\nnames. Names may be resolved in the local and global namespaces of\nthe caller. Free variables are not resolved in the nearest enclosing\nnamespace, but in the global namespace. [1] The "exec" statement and\nthe "eval()" and "execfile()" functions have optional arguments to\noverride the global and local namespace. If only one namespace is\nspecified, it is used for both.\n\n\nExceptions\n==========\n\nExceptions are a means of breaking out of the normal flow of control\nof a code block in order to handle errors or other exceptional\nconditions. An exception is *raised* at the point where the error is\ndetected; it may be *handled* by the surrounding code block or by any\ncode block that directly or indirectly invoked the code block where\nthe error occurred.\n\nThe Python interpreter raises an exception when it detects a run-time\nerror (such as division by zero). A Python program can also\nexplicitly raise an exception with the "raise" statement. Exception\nhandlers are specified with the "try" ... "except" statement. The\n"finally" clause of such a statement can be used to specify cleanup\ncode which does not handle the exception, but is executed whether an\nexception occurred or not in the preceding code.\n\nPython uses the "termination" model of error handling: an exception\nhandler can find out what happened and continue execution at an outer\nlevel, but it cannot repair the cause of the error and retry the\nfailing operation (except by re-entering the offending piece of code\nfrom the top).\n\nWhen an exception is not handled at all, the interpreter terminates\nexecution of the program, or returns to its interactive main loop. In\neither case, it prints a stack backtrace, except when the exception is\n"SystemExit".\n\nExceptions are identified by class instances. The "except" clause is\nselected depending on the class of the instance: it must reference the\nclass of the instance or a base class thereof. The instance can be\nreceived by the handler and can carry additional information about the\nexceptional condition.\n\nExceptions can also be identified by strings, in which case the\n"except" clause is selected by object identity. An arbitrary value\ncan be raised along with the identifying string which can be passed to\nthe handler.\n\nNote: Messages to exceptions are not part of the Python API. Their\n contents may change from one version of Python to the next without\n warning and should not be relied on by code which will run under\n multiple versions of the interpreter.\n\nSee also the description of the "try" statement in section The try\nstatement and "raise" statement in section The raise statement.\n\n-[ Footnotes ]-\n\n[1] This limitation occurs because the code that is executed by\n these operations is not available at the time the module is\n compiled.\n',
+ 'exprlists': u'\nExpression lists\n****************\n\n expression_list ::= expression ( "," expression )* [","]\n\nAn expression list containing at least one comma yields a tuple. The\nlength of the tuple is the number of expressions in the list. The\nexpressions are evaluated from left to right.\n\nThe trailing comma is required only to create a single tuple (a.k.a. a\n*singleton*); it is optional in all other cases. A single expression\nwithout a trailing comma doesn\'t create a tuple, but rather yields the\nvalue of that expression. (To create an empty tuple, use an empty pair\nof parentheses: "()".)\n',
+ 'floating': u'\nFloating point literals\n***********************\n\nFloating point literals are described by the following lexical\ndefinitions:\n\n floatnumber ::= pointfloat | exponentfloat\n pointfloat ::= [intpart] fraction | intpart "."\n exponentfloat ::= (intpart | pointfloat) exponent\n intpart ::= digit+\n fraction ::= "." digit+\n exponent ::= ("e" | "E") ["+" | "-"] digit+\n\nNote that the integer and exponent parts of floating point numbers can\nlook like octal integers, but are interpreted using radix 10. For\nexample, "077e010" is legal, and denotes the same number as "77e10".\nThe allowed range of floating point literals is implementation-\ndependent. Some examples of floating point literals:\n\n 3.14 10. .001 1e100 3.14e-10 0e0\n\nNote that numeric literals do not include a sign; a phrase like "-1"\nis actually an expression composed of the unary operator "-" and the\nliteral "1".\n',
+ 'for': u'\nThe "for" statement\n*******************\n\nThe "for" statement is used to iterate over the elements of a sequence\n(such as a string, tuple or list) or other iterable object:\n\n for_stmt ::= "for" target_list "in" expression_list ":" suite\n ["else" ":" suite]\n\nThe expression list is evaluated once; it should yield an iterable\nobject. An iterator is created for the result of the\n"expression_list". The suite is then executed once for each item\nprovided by the iterator, in the order of ascending indices. Each\nitem in turn is assigned to the target list using the standard rules\nfor assignments, and then the suite is executed. When the items are\nexhausted (which is immediately when the sequence is empty), the suite\nin the "else" clause, if present, is executed, and the loop\nterminates.\n\nA "break" statement executed in the first suite terminates the loop\nwithout executing the "else" clause\'s suite. A "continue" statement\nexecuted in the first suite skips the rest of the suite and continues\nwith the next item, or with the "else" clause if there was no next\nitem.\n\nThe suite may assign to the variable(s) in the target list; this does\nnot affect the next item assigned to it.\n\nThe target list is not deleted when the loop is finished, but if the\nsequence is empty, it will not have been assigned to at all by the\nloop. Hint: the built-in function "range()" returns a sequence of\nintegers suitable to emulate the effect of Pascal\'s "for i := a to b\ndo"; e.g., "range(3)" returns the list "[0, 1, 2]".\n\nNote: There is a subtlety when the sequence is being modified by the\n loop (this can only occur for mutable sequences, i.e. lists). An\n internal counter is used to keep track of which item is used next,\n and this is incremented on each iteration. When this counter has\n reached the length of the sequence the loop terminates. This means\n that if the suite deletes the current (or a previous) item from the\n sequence, the next item will be skipped (since it gets the index of\n the current item which has already been treated). Likewise, if the\n suite inserts an item in the sequence before the current item, the\n current item will be treated again the next time through the loop.\n This can lead to nasty bugs that can be avoided by making a\n temporary copy using a slice of the whole sequence, e.g.,\n\n for x in a[:]:\n if x < 0: a.remove(x)\n',
+ 'formatstrings': u'\nFormat String Syntax\n********************\n\nThe "str.format()" method and the "Formatter" class share the same\nsyntax for format strings (although in the case of "Formatter",\nsubclasses can define their own format string syntax).\n\nFormat strings contain "replacement fields" surrounded by curly braces\n"{}". Anything that is not contained in braces is considered literal\ntext, which is copied unchanged to the output. If you need to include\na brace character in the literal text, it can be escaped by doubling:\n"{{" and "}}".\n\nThe grammar for a replacement field is as follows:\n\n replacement_field ::= "{" [field_name] ["!" conversion] [":" format_spec] "}"\n field_name ::= arg_name ("." attribute_name | "[" element_index "]")*\n arg_name ::= [identifier | integer]\n attribute_name ::= identifier\n element_index ::= integer | index_string\n index_string ::= <any source character except "]"> +\n conversion ::= "r" | "s"\n format_spec ::= <described in the next section>\n\nIn less formal terms, the replacement field can start with a\n*field_name* that specifies the object whose value is to be formatted\nand inserted into the output instead of the replacement field. The\n*field_name* is optionally followed by a *conversion* field, which is\npreceded by an exclamation point "\'!\'", and a *format_spec*, which is\npreceded by a colon "\':\'". These specify a non-default format for the\nreplacement value.\n\nSee also the Format Specification Mini-Language section.\n\nThe *field_name* itself begins with an *arg_name* that is either a\nnumber or a keyword. If it\'s a number, it refers to a positional\nargument, and if it\'s a keyword, it refers to a named keyword\nargument. If the numerical arg_names in a format string are 0, 1, 2,\n... in sequence, they can all be omitted (not just some) and the\nnumbers 0, 1, 2, ... will be automatically inserted in that order.\nBecause *arg_name* is not quote-delimited, it is not possible to\nspecify arbitrary dictionary keys (e.g., the strings "\'10\'" or\n"\':-]\'") within a format string. The *arg_name* can be followed by any\nnumber of index or attribute expressions. An expression of the form\n"\'.name\'" selects the named attribute using "getattr()", while an\nexpression of the form "\'[index]\'" does an index lookup using\n"__getitem__()".\n\nChanged in version 2.7: The positional argument specifiers can be\nomitted, so "\'{} {}\'" is equivalent to "\'{0} {1}\'".\n\nSome simple format string examples:\n\n "First, thou shalt count to {0}" # References first positional argument\n "Bring me a {}" # Implicitly references the first positional argument\n "From {} to {}" # Same as "From {0} to {1}"\n "My quest is {name}" # References keyword argument \'name\'\n "Weight in tons {0.weight}" # \'weight\' attribute of first positional arg\n "Units destroyed: {players[0]}" # First element of keyword argument \'players\'.\n\nThe *conversion* field causes a type coercion before formatting.\nNormally, the job of formatting a value is done by the "__format__()"\nmethod of the value itself. However, in some cases it is desirable to\nforce a type to be formatted as a string, overriding its own\ndefinition of formatting. By converting the value to a string before\ncalling "__format__()", the normal formatting logic is bypassed.\n\nTwo conversion flags are currently supported: "\'!s\'" which calls\n"str()" on the value, and "\'!r\'" which calls "repr()".\n\nSome examples:\n\n "Harold\'s a clever {0!s}" # Calls str() on the argument first\n "Bring out the holy {name!r}" # Calls repr() on the argument first\n\nThe *format_spec* field contains a specification of how the value\nshould be presented, including such details as field width, alignment,\npadding, decimal precision and so on. Each value type can define its\nown "formatting mini-language" or interpretation of the *format_spec*.\n\nMost built-in types support a common formatting mini-language, which\nis described in the next section.\n\nA *format_spec* field can also include nested replacement fields\nwithin it. These nested replacement fields may contain a field name,\nconversion flag and format specification, but deeper nesting is not\nallowed. The replacement fields within the format_spec are\nsubstituted before the *format_spec* string is interpreted. This\nallows the formatting of a value to be dynamically specified.\n\nSee the Format examples section for some examples.\n\n\nFormat Specification Mini-Language\n==================================\n\n"Format specifications" are used within replacement fields contained\nwithin a format string to define how individual values are presented\n(see Format String Syntax). They can also be passed directly to the\nbuilt-in "format()" function. Each formattable type may define how\nthe format specification is to be interpreted.\n\nMost built-in types implement the following options for format\nspecifications, although some of the formatting options are only\nsupported by the numeric types.\n\nA general convention is that an empty format string ("""") produces\nthe same result as if you had called "str()" on the value. A non-empty\nformat string typically modifies the result.\n\nThe general form of a *standard format specifier* is:\n\n format_spec ::= [[fill]align][sign][#][0][width][,][.precision][type]\n fill ::= <any character>\n align ::= "<" | ">" | "=" | "^"\n sign ::= "+" | "-" | " "\n width ::= integer\n precision ::= integer\n type ::= "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"\n\nIf a valid *align* value is specified, it can be preceded by a *fill*\ncharacter that can be any character and defaults to a space if\nomitted. It is not possible to use a literal curly brace (""{"" or\n""}"") as the *fill* character when using the "str.format()" method.\nHowever, it is possible to insert a curly brace with a nested\nreplacement field. This limitation doesn\'t affect the "format()"\nfunction.\n\nThe meaning of the various alignment options is as follows:\n\n +-----------+------------------------------------------------------------+\n | Option | Meaning |\n +===========+============================================================+\n | "\'<\'" | Forces the field to be left-aligned within the available |\n | | space (this is the default for most objects). |\n +-----------+------------------------------------------------------------+\n | "\'>\'" | Forces the field to be right-aligned within the available |\n | | space (this is the default for numbers). |\n +-----------+------------------------------------------------------------+\n | "\'=\'" | Forces the padding to be placed after the sign (if any) |\n | | but before the digits. This is used for printing fields |\n | | in the form \'+000000120\'. This alignment option is only |\n | | valid for numeric types. It becomes the default when \'0\' |\n | | immediately precedes the field width. |\n +-----------+------------------------------------------------------------+\n | "\'^\'" | Forces the field to be centered within the available |\n | | space. |\n +-----------+------------------------------------------------------------+\n\nNote that unless a minimum field width is defined, the field width\nwill always be the same size as the data to fill it, so that the\nalignment option has no meaning in this case.\n\nThe *sign* option is only valid for number types, and can be one of\nthe following:\n\n +-----------+------------------------------------------------------------+\n | Option | Meaning |\n +===========+============================================================+\n | "\'+\'" | indicates that a sign should be used for both positive as |\n | | well as negative numbers. |\n +-----------+------------------------------------------------------------+\n | "\'-\'" | indicates that a sign should be used only for negative |\n | | numbers (this is the default behavior). |\n +-----------+------------------------------------------------------------+\n | space | indicates that a leading space should be used on positive |\n | | numbers, and a minus sign on negative numbers. |\n +-----------+------------------------------------------------------------+\n\nThe "\'#\'" option is only valid for integers, and only for binary,\noctal, or hexadecimal output. If present, it specifies that the\noutput will be prefixed by "\'0b\'", "\'0o\'", or "\'0x\'", respectively.\n\nThe "\',\'" option signals the use of a comma for a thousands separator.\nFor a locale aware separator, use the "\'n\'" integer presentation type\ninstead.\n\nChanged in version 2.7: Added the "\',\'" option (see also **PEP 378**).\n\n*width* is a decimal integer defining the minimum field width. If not\nspecified, then the field width will be determined by the content.\n\nWhen no explicit alignment is given, preceding the *width* field by a\nzero ("\'0\'") character enables sign-aware zero-padding for numeric\ntypes. This is equivalent to a *fill* character of "\'0\'" with an\n*alignment* type of "\'=\'".\n\nThe *precision* is a decimal number indicating how many digits should\nbe displayed after the decimal point for a floating point value\nformatted with "\'f\'" and "\'F\'", or before and after the decimal point\nfor a floating point value formatted with "\'g\'" or "\'G\'". For non-\nnumber types the field indicates the maximum field size - in other\nwords, how many characters will be used from the field content. The\n*precision* is not allowed for integer values.\n\nFinally, the *type* determines how the data should be presented.\n\nThe available string presentation types are:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | "\'s\'" | String format. This is the default type for strings and |\n | | may be omitted. |\n +-----------+------------------------------------------------------------+\n | None | The same as "\'s\'". |\n +-----------+------------------------------------------------------------+\n\nThe available integer presentation types are:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | "\'b\'" | Binary format. Outputs the number in base 2. |\n +-----------+------------------------------------------------------------+\n | "\'c\'" | Character. Converts the integer to the corresponding |\n | | unicode character before printing. |\n +-----------+------------------------------------------------------------+\n | "\'d\'" | Decimal Integer. Outputs the number in base 10. |\n +-----------+------------------------------------------------------------+\n | "\'o\'" | Octal format. Outputs the number in base 8. |\n +-----------+------------------------------------------------------------+\n | "\'x\'" | Hex format. Outputs the number in base 16, using lower- |\n | | case letters for the digits above 9. |\n +-----------+------------------------------------------------------------+\n | "\'X\'" | Hex format. Outputs the number in base 16, using upper- |\n | | case letters for the digits above 9. |\n +-----------+------------------------------------------------------------+\n | "\'n\'" | Number. This is the same as "\'d\'", except that it uses the |\n | | current locale setting to insert the appropriate number |\n | | separator characters. |\n +-----------+------------------------------------------------------------+\n | None | The same as "\'d\'". |\n +-----------+------------------------------------------------------------+\n\nIn addition to the above presentation types, integers can be formatted\nwith the floating point presentation types listed below (except "\'n\'"\nand "None"). When doing so, "float()" is used to convert the integer\nto a floating point number before formatting.\n\nThe available presentation types for floating point and decimal values\nare:\n\n +-----------+------------------------------------------------------------+\n | Type | Meaning |\n +===========+============================================================+\n | "\'e\'" | Exponent notation. Prints the number in scientific |\n | | notation using the letter \'e\' to indicate the exponent. |\n | | The default precision is "6". |\n +-----------+------------------------------------------------------------+\n | "\'E\'" | Exponent notation. Same as "\'e\'" except it uses an upper |\n | | case \'E\' as the separator character. |\n +-----------+------------------------------------------------------------+\n | "\'f\'" | Fixed point. Displays the number as a fixed-point number. |\n | | The default precision is "6". |\n +-----------+------------------------------------------------------------+\n | "\'F\'" | Fixed point. Same as "\'f\'". |\n +-----------+------------------------------------------------------------+\n | "\'g\'" | General format. For a given precision "p >= 1", this |\n | | rounds the number to "p" significant digits and then |\n | | formats the result in either fixed-point format or in |\n | | scientific notation, depending on its magnitude. The |\n | | precise rules are as follows: suppose that the result |\n | | formatted with presentation type "\'e\'" and precision "p-1" |\n | | would have exponent "exp". Then if "-4 <= exp < p", the |\n | | number is formatted with presentation type "\'f\'" and |\n | | precision "p-1-exp". Otherwise, the number is formatted |\n | | with presentation type "\'e\'" and precision "p-1". In both |\n | | cases insignificant trailing zeros are removed from the |\n | | significand, and the decimal point is also removed if |\n | | there are no remaining digits following it. Positive and |\n | | negative infinity, positive and negative zero, and nans, |\n | | are formatted as "inf", "-inf", "0", "-0" and "nan" |\n | | respectively, regardless of the precision. A precision of |\n | | "0" is treated as equivalent to a precision of "1". The |\n | | default precision is "6". |\n +-----------+------------------------------------------------------------+\n | "\'G\'" | General format. Same as "\'g\'" except switches to "\'E\'" if |\n | | the number gets too large. The representations of infinity |\n | | and NaN are uppercased, too. |\n +-----------+------------------------------------------------------------+\n | "\'n\'" | Number. This is the same as "\'g\'", except that it uses the |\n | | current locale setting to insert the appropriate number |\n | | separator characters. |\n +-----------+------------------------------------------------------------+\n | "\'%\'" | Percentage. Multiplies the number by 100 and displays in |\n | | fixed ("\'f\'") format, followed by a percent sign. |\n +-----------+------------------------------------------------------------+\n | None | The same as "\'g\'". |\n +-----------+------------------------------------------------------------+\n\n\nFormat examples\n===============\n\nThis section contains examples of the "str.format()" syntax and\ncomparison with the old "%"-formatting.\n\nIn most of the cases the syntax is similar to the old "%"-formatting,\nwith the addition of the "{}" and with ":" used instead of "%". For\nexample, "\'%03.2f\'" can be translated to "\'{:03.2f}\'".\n\nThe new format syntax also supports new and different options, shown\nin the follow examples.\n\nAccessing arguments by position:\n\n >>> \'{0}, {1}, {2}\'.format(\'a\', \'b\', \'c\')\n \'a, b, c\'\n >>> \'{}, {}, {}\'.format(\'a\', \'b\', \'c\') # 2.7+ only\n \'a, b, c\'\n >>> \'{2}, {1}, {0}\'.format(\'a\', \'b\', \'c\')\n \'c, b, a\'\n >>> \'{2}, {1}, {0}\'.format(*\'abc\') # unpacking argument sequence\n \'c, b, a\'\n >>> \'{0}{1}{0}\'.format(\'abra\', \'cad\') # arguments\' indices can be repeated\n \'abracadabra\'\n\nAccessing arguments by name:\n\n >>> \'Coordinates: {latitude}, {longitude}\'.format(latitude=\'37.24N\', longitude=\'-115.81W\')\n \'Coordinates: 37.24N, -115.81W\'\n >>> coord = {\'latitude\': \'37.24N\', \'longitude\': \'-115.81W\'}\n >>> \'Coordinates: {latitude}, {longitude}\'.format(**coord)\n \'Coordinates: 37.24N, -115.81W\'\n\nAccessing arguments\' attributes:\n\n >>> c = 3-5j\n >>> (\'The complex number {0} is formed from the real part {0.real} \'\n ... \'and the imaginary part {0.imag}.\').format(c)\n \'The complex number (3-5j) is formed from the real part 3.0 and the imaginary part -5.0.\'\n >>> class Point(object):\n ... def __init__(self, x, y):\n ... self.x, self.y = x, y\n ... def __str__(self):\n ... return \'Point({self.x}, {self.y})\'.format(self=self)\n ...\n >>> str(Point(4, 2))\n \'Point(4, 2)\'\n\nAccessing arguments\' items:\n\n >>> coord = (3, 5)\n >>> \'X: {0[0]}; Y: {0[1]}\'.format(coord)\n \'X: 3; Y: 5\'\n\nReplacing "%s" and "%r":\n\n >>> "repr() shows quotes: {!r}; str() doesn\'t: {!s}".format(\'test1\', \'test2\')\n "repr() shows quotes: \'test1\'; str() doesn\'t: test2"\n\nAligning the text and specifying a width:\n\n >>> \'{:<30}\'.format(\'left aligned\')\n \'left aligned \'\n >>> \'{:>30}\'.format(\'right aligned\')\n \' right aligned\'\n >>> \'{:^30}\'.format(\'centered\')\n \' centered \'\n >>> \'{:*^30}\'.format(\'centered\') # use \'*\' as a fill char\n \'***********centered***********\'\n\nReplacing "%+f", "%-f", and "% f" and specifying a sign:\n\n >>> \'{:+f}; {:+f}\'.format(3.14, -3.14) # show it always\n \'+3.140000; -3.140000\'\n >>> \'{: f}; {: f}\'.format(3.14, -3.14) # show a space for positive numbers\n \' 3.140000; -3.140000\'\n >>> \'{:-f}; {:-f}\'.format(3.14, -3.14) # show only the minus -- same as \'{:f}; {:f}\'\n \'3.140000; -3.140000\'\n\nReplacing "%x" and "%o" and converting the value to different bases:\n\n >>> # format also supports binary numbers\n >>> "int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}".format(42)\n \'int: 42; hex: 2a; oct: 52; bin: 101010\'\n >>> # with 0x, 0o, or 0b as prefix:\n >>> "int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}".format(42)\n \'int: 42; hex: 0x2a; oct: 0o52; bin: 0b101010\'\n\nUsing the comma as a thousands separator:\n\n >>> \'{:,}\'.format(1234567890)\n \'1,234,567,890\'\n\nExpressing a percentage:\n\n >>> points = 19.5\n >>> total = 22\n >>> \'Correct answers: {:.2%}\'.format(points/total)\n \'Correct answers: 88.64%\'\n\nUsing type-specific formatting:\n\n >>> import datetime\n >>> d = datetime.datetime(2010, 7, 4, 12, 15, 58)\n >>> \'{:%Y-%m-%d %H:%M:%S}\'.format(d)\n \'2010-07-04 12:15:58\'\n\nNesting arguments and more complex examples:\n\n >>> for align, text in zip(\'<^>\', [\'left\', \'center\', \'right\']):\n ... \'{0:{fill}{align}16}\'.format(text, fill=align, align=align)\n ...\n \'left<<<<<<<<<<<<\'\n \'^^^^^center^^^^^\'\n \'>>>>>>>>>>>right\'\n >>>\n >>> octets = [192, 168, 0, 1]\n >>> \'{:02X}{:02X}{:02X}{:02X}\'.format(*octets)\n \'C0A80001\'\n >>> int(_, 16)\n 3232235521\n >>>\n >>> width = 5\n >>> for num in range(5,12):\n ... for base in \'dXob\':\n ... print \'{0:{width}{base}}\'.format(num, base=base, width=width),\n ... print\n ...\n 5 5 5 101\n 6 6 6 110\n 7 7 7 111\n 8 8 10 1000\n 9 9 11 1001\n 10 A 12 1010\n 11 B 13 1011\n',
+ 'function': u'\nFunction definitions\n********************\n\nA function definition defines a user-defined function object (see\nsection The standard type hierarchy):\n\n decorated ::= decorators (classdef | funcdef)\n decorators ::= decorator+\n decorator ::= "@" dotted_name ["(" [argument_list [","]] ")"] NEWLINE\n funcdef ::= "def" funcname "(" [parameter_list] ")" ":" suite\n dotted_name ::= identifier ("." identifier)*\n parameter_list ::= (defparameter ",")*\n ( "*" identifier ["," "**" identifier]\n | "**" identifier\n | defparameter [","] )\n defparameter ::= parameter ["=" expression]\n sublist ::= parameter ("," parameter)* [","]\n parameter ::= identifier | "(" sublist ")"\n funcname ::= identifier\n\nA function definition is an executable statement. Its execution binds\nthe function name in the current local namespace to a function object\n(a wrapper around the executable code for the function). This\nfunction object contains a reference to the current global namespace\nas the global namespace to be used when the function is called.\n\nThe function definition does not execute the function body; this gets\nexecuted only when the function is called. [3]\n\nA function definition may be wrapped by one or more *decorator*\nexpressions. Decorator expressions are evaluated when the function is\ndefined, in the scope that contains the function definition. The\nresult must be a callable, which is invoked with the function object\nas the only argument. The returned value is bound to the function name\ninstead of the function object. Multiple decorators are applied in\nnested fashion. For example, the following code:\n\n @f1(arg)\n @f2\n def func(): pass\n\nis equivalent to:\n\n def func(): pass\n func = f1(arg)(f2(func))\n\nWhen one or more top-level *parameters* have the form *parameter* "="\n*expression*, the function is said to have "default parameter values."\nFor a parameter with a default value, the corresponding *argument* may\nbe omitted from a call, in which case the parameter\'s default value is\nsubstituted. If a parameter has a default value, all following\nparameters must also have a default value --- this is a syntactic\nrestriction that is not expressed by the grammar.\n\n**Default parameter values are evaluated when the function definition\nis executed.** This means that the expression is evaluated once, when\nthe function is defined, and that the same "pre-computed" value is\nused for each call. This is especially important to understand when a\ndefault parameter is a mutable object, such as a list or a dictionary:\nif the function modifies the object (e.g. by appending an item to a\nlist), the default value is in effect modified. This is generally not\nwhat was intended. A way around this is to use "None" as the\ndefault, and explicitly test for it in the body of the function, e.g.:\n\n def whats_on_the_telly(penguin=None):\n if penguin is None:\n penguin = []\n penguin.append("property of the zoo")\n return penguin\n\nFunction call semantics are described in more detail in section Calls.\nA function call always assigns values to all parameters mentioned in\nthe parameter list, either from position arguments, from keyword\narguments, or from default values. If the form ""*identifier"" is\npresent, it is initialized to a tuple receiving any excess positional\nparameters, defaulting to the empty tuple. If the form\n""**identifier"" is present, it is initialized to a new dictionary\nreceiving any excess keyword arguments, defaulting to a new empty\ndictionary.\n\nIt is also possible to create anonymous functions (functions not bound\nto a name), for immediate use in expressions. This uses lambda\nexpressions, described in section Lambdas. Note that the lambda\nexpression is merely a shorthand for a simplified function definition;\na function defined in a ""def"" statement can be passed around or\nassigned to another name just like a function defined by a lambda\nexpression. The ""def"" form is actually more powerful since it\nallows the execution of multiple statements.\n\n**Programmer\'s note:** Functions are first-class objects. A ""def""\nform executed inside a function definition defines a local function\nthat can be returned or passed around. Free variables used in the\nnested function can access the local variables of the function\ncontaining the def. See section Naming and binding for details.\n',
+ 'global': u'\nThe "global" statement\n**********************\n\n global_stmt ::= "global" identifier ("," identifier)*\n\nThe "global" statement is a declaration which holds for the entire\ncurrent code block. It means that the listed identifiers are to be\ninterpreted as globals. It would be impossible to assign to a global\nvariable without "global", although free variables may refer to\nglobals without being declared global.\n\nNames listed in a "global" statement must not be used in the same code\nblock textually preceding that "global" statement.\n\nNames listed in a "global" statement must not be defined as formal\nparameters or in a "for" loop control target, "class" definition,\nfunction definition, or "import" statement.\n\n**CPython implementation detail:** The current implementation does not\nenforce the latter two restrictions, but programs should not abuse\nthis freedom, as future implementations may enforce them or silently\nchange the meaning of the program.\n\n**Programmer\'s note:** the "global" is a directive to the parser. It\napplies only to code parsed at the same time as the "global"\nstatement. In particular, a "global" statement contained in an "exec"\nstatement does not affect the code block *containing* the "exec"\nstatement, and code contained in an "exec" statement is unaffected by\n"global" statements in the code containing the "exec" statement. The\nsame applies to the "eval()", "execfile()" and "compile()" functions.\n',
+ 'id-classes': u'\nReserved classes of identifiers\n*******************************\n\nCertain classes of identifiers (besides keywords) have special\nmeanings. These classes are identified by the patterns of leading and\ntrailing underscore characters:\n\n"_*"\n Not imported by "from module import *". The special identifier "_"\n is used in the interactive interpreter to store the result of the\n last evaluation; it is stored in the "__builtin__" module. When\n not in interactive mode, "_" has no special meaning and is not\n defined. See section The import statement.\n\n Note: The name "_" is often used in conjunction with\n internationalization; refer to the documentation for the\n "gettext" module for more information on this convention.\n\n"__*__"\n System-defined names. These names are defined by the interpreter\n and its implementation (including the standard library). Current\n system names are discussed in the Special method names section and\n elsewhere. More will likely be defined in future versions of\n Python. *Any* use of "__*__" names, in any context, that does not\n follow explicitly documented use, is subject to breakage without\n warning.\n\n"__*"\n Class-private names. Names in this category, when used within the\n context of a class definition, are re-written to use a mangled form\n to help avoid name clashes between "private" attributes of base and\n derived classes. See section Identifiers (Names).\n',
+ 'identifiers': u'\nIdentifiers and keywords\n************************\n\nIdentifiers (also referred to as *names*) are described by the\nfollowing lexical definitions:\n\n identifier ::= (letter|"_") (letter | digit | "_")*\n letter ::= lowercase | uppercase\n lowercase ::= "a"..."z"\n uppercase ::= "A"..."Z"\n digit ::= "0"..."9"\n\nIdentifiers are unlimited in length. Case is significant.\n\n\nKeywords\n========\n\nThe following identifiers are used as reserved words, or *keywords* of\nthe language, and cannot be used as ordinary identifiers. They must\nbe spelled exactly as written here:\n\n and del from not while\n as elif global or with\n assert else if pass yield\n break except import print\n class exec in raise\n continue finally is return\n def for lambda try\n\nChanged in version 2.4: "None" became a constant and is now recognized\nby the compiler as a name for the built-in object "None". Although it\nis not a keyword, you cannot assign a different object to it.\n\nChanged in version 2.5: Using "as" and "with" as identifiers triggers\na warning. To use them as keywords, enable the "with_statement"\nfuture feature .\n\nChanged in version 2.6: "as" and "with" are full keywords.\n\n\nReserved classes of identifiers\n===============================\n\nCertain classes of identifiers (besides keywords) have special\nmeanings. These classes are identified by the patterns of leading and\ntrailing underscore characters:\n\n"_*"\n Not imported by "from module import *". The special identifier "_"\n is used in the interactive interpreter to store the result of the\n last evaluation; it is stored in the "__builtin__" module. When\n not in interactive mode, "_" has no special meaning and is not\n defined. See section The import statement.\n\n Note: The name "_" is often used in conjunction with\n internationalization; refer to the documentation for the\n "gettext" module for more information on this convention.\n\n"__*__"\n System-defined names. These names are defined by the interpreter\n and its implementation (including the standard library). Current\n system names are discussed in the Special method names section and\n elsewhere. More will likely be defined in future versions of\n Python. *Any* use of "__*__" names, in any context, that does not\n follow explicitly documented use, is subject to breakage without\n warning.\n\n"__*"\n Class-private names. Names in this category, when used within the\n context of a class definition, are re-written to use a mangled form\n to help avoid name clashes between "private" attributes of base and\n derived classes. See section Identifiers (Names).\n',
+ 'if': u'\nThe "if" statement\n******************\n\nThe "if" statement is used for conditional execution:\n\n if_stmt ::= "if" expression ":" suite\n ( "elif" expression ":" suite )*\n ["else" ":" suite]\n\nIt selects exactly one of the suites by evaluating the expressions one\nby one until one is found to be true (see section Boolean operations\nfor the definition of true and false); then that suite is executed\n(and no other part of the "if" statement is executed or evaluated).\nIf all expressions are false, the suite of the "else" clause, if\npresent, is executed.\n',
+ 'imaginary': u'\nImaginary literals\n******************\n\nImaginary literals are described by the following lexical definitions:\n\n imagnumber ::= (floatnumber | intpart) ("j" | "J")\n\nAn imaginary literal yields a complex number with a real part of 0.0.\nComplex numbers are represented as a pair of floating point numbers\nand have the same restrictions on their range. To create a complex\nnumber with a nonzero real part, add a floating point number to it,\ne.g., "(3+4j)". Some examples of imaginary literals:\n\n 3.14j 10.j 10j .001j 1e100j 3.14e-10j\n',
+ 'import': u'\nThe "import" statement\n**********************\n\n import_stmt ::= "import" module ["as" name] ( "," module ["as" name] )*\n | "from" relative_module "import" identifier ["as" name]\n ( "," identifier ["as" name] )*\n | "from" relative_module "import" "(" identifier ["as" name]\n ( "," identifier ["as" name] )* [","] ")"\n | "from" module "import" "*"\n module ::= (identifier ".")* identifier\n relative_module ::= "."* module | "."+\n name ::= identifier\n\nImport statements are executed in two steps: (1) find a module, and\ninitialize it if necessary; (2) define a name or names in the local\nnamespace (of the scope where the "import" statement occurs). The\nstatement comes in two forms differing on whether it uses the "from"\nkeyword. The first form (without "from") repeats these steps for each\nidentifier in the list. The form with "from" performs step (1) once,\nand then performs step (2) repeatedly.\n\nTo understand how step (1) occurs, one must first understand how\nPython handles hierarchical naming of modules. To help organize\nmodules and provide a hierarchy in naming, Python has a concept of\npackages. A package can contain other packages and modules while\nmodules cannot contain other modules or packages. From a file system\nperspective, packages are directories and modules are files.\n\nOnce the name of the module is known (unless otherwise specified, the\nterm "module" will refer to both packages and modules), searching for\nthe module or package can begin. The first place checked is\n"sys.modules", the cache of all modules that have been imported\npreviously. If the module is found there then it is used in step (2)\nof import.\n\nIf the module is not found in the cache, then "sys.meta_path" is\nsearched (the specification for "sys.meta_path" can be found in **PEP\n302**). The object is a list of *finder* objects which are queried in\norder as to whether they know how to load the module by calling their\n"find_module()" method with the name of the module. If the module\nhappens to be contained within a package (as denoted by the existence\nof a dot in the name), then a second argument to "find_module()" is\ngiven as the value of the "__path__" attribute from the parent package\n(everything up to the last dot in the name of the module being\nimported). If a finder can find the module it returns a *loader*\n(discussed later) or returns "None".\n\nIf none of the finders on "sys.meta_path" are able to find the module\nthen some implicitly defined finders are queried. Implementations of\nPython vary in what implicit meta path finders are defined. The one\nthey all do define, though, is one that handles "sys.path_hooks",\n"sys.path_importer_cache", and "sys.path".\n\nThe implicit finder searches for the requested module in the "paths"\nspecified in one of two places ("paths" do not have to be file system\npaths). If the module being imported is supposed to be contained\nwithin a package then the second argument passed to "find_module()",\n"__path__" on the parent package, is used as the source of paths. If\nthe module is not contained in a package then "sys.path" is used as\nthe source of paths.\n\nOnce the source of paths is chosen it is iterated over to find a\nfinder that can handle that path. The dict at\n"sys.path_importer_cache" caches finders for paths and is checked for\na finder. If the path does not have a finder cached then\n"sys.path_hooks" is searched by calling each object in the list with a\nsingle argument of the path, returning a finder or raises\n"ImportError". If a finder is returned then it is cached in\n"sys.path_importer_cache" and then used for that path entry. If no\nfinder can be found but the path exists then a value of "None" is\nstored in "sys.path_importer_cache" to signify that an implicit, file-\nbased finder that handles modules stored as individual files should be\nused for that path. If the path does not exist then a finder which\nalways returns "None" is placed in the cache for the path.\n\nIf no finder can find the module then "ImportError" is raised.\nOtherwise some finder returned a loader whose "load_module()" method\nis called with the name of the module to load (see **PEP 302** for the\noriginal definition of loaders). A loader has several responsibilities\nto perform on a module it loads. First, if the module already exists\nin "sys.modules" (a possibility if the loader is called outside of the\nimport machinery) then it is to use that module for initialization and\nnot a new module. But if the module does not exist in "sys.modules"\nthen it is to be added to that dict before initialization begins. If\nan error occurs during loading of the module and it was added to\n"sys.modules" it is to be removed from the dict. If an error occurs\nbut the module was already in "sys.modules" it is left in the dict.\n\nThe loader must set several attributes on the module. "__name__" is to\nbe set to the name of the module. "__file__" is to be the "path" to\nthe file unless the module is built-in (and thus listed in\n"sys.builtin_module_names") in which case the attribute is not set. If\nwhat is being imported is a package then "__path__" is to be set to a\nlist of paths to be searched when looking for modules and packages\ncontained within the package being imported. "__package__" is optional\nbut should be set to the name of package that contains the module or\npackage (the empty string is used for module not contained in a\npackage). "__loader__" is also optional but should be set to the\nloader object that is loading the module.\n\nIf an error occurs during loading then the loader raises "ImportError"\nif some other exception is not already being propagated. Otherwise the\nloader returns the module that was loaded and initialized.\n\nWhen step (1) finishes without raising an exception, step (2) can\nbegin.\n\nThe first form of "import" statement binds the module name in the\nlocal namespace to the module object, and then goes on to import the\nnext identifier, if any. If the module name is followed by "as", the\nname following "as" is used as the local name for the module.\n\nThe "from" form does not bind the module name: it goes through the\nlist of identifiers, looks each one of them up in the module found in\nstep (1), and binds the name in the local namespace to the object thus\nfound. As with the first form of "import", an alternate local name\ncan be supplied by specifying ""as" localname". If a name is not\nfound, "ImportError" is raised. If the list of identifiers is\nreplaced by a star ("\'*\'"), all public names defined in the module are\nbound in the local namespace of the "import" statement..\n\nThe *public names* defined by a module are determined by checking the\nmodule\'s namespace for a variable named "__all__"; if defined, it must\nbe a sequence of strings which are names defined or imported by that\nmodule. The names given in "__all__" are all considered public and\nare required to exist. If "__all__" is not defined, the set of public\nnames includes all names found in the module\'s namespace which do not\nbegin with an underscore character ("\'_\'"). "__all__" should contain\nthe entire public API. It is intended to avoid accidentally exporting\nitems that are not part of the API (such as library modules which were\nimported and used within the module).\n\nThe "from" form with "*" may only occur in a module scope. If the\nwild card form of import --- "import *" --- is used in a function and\nthe function contains or is a nested block with free variables, the\ncompiler will raise a "SyntaxError".\n\nWhen specifying what module to import you do not have to specify the\nabsolute name of the module. When a module or package is contained\nwithin another package it is possible to make a relative import within\nthe same top package without having to mention the package name. By\nusing leading dots in the specified module or package after "from" you\ncan specify how high to traverse up the current package hierarchy\nwithout specifying exact names. One leading dot means the current\npackage where the module making the import exists. Two dots means up\none package level. Three dots is up two levels, etc. So if you execute\n"from . import mod" from a module in the "pkg" package then you will\nend up importing "pkg.mod". If you execute "from ..subpkg2 import mod"\nfrom within "pkg.subpkg1" you will import "pkg.subpkg2.mod". The\nspecification for relative imports is contained within **PEP 328**.\n\n"importlib.import_module()" is provided to support applications that\ndetermine which modules need to be loaded dynamically.\n\n\nFuture statements\n=================\n\nA *future statement* is a directive to the compiler that a particular\nmodule should be compiled using syntax or semantics that will be\navailable in a specified future release of Python. The future\nstatement is intended to ease migration to future versions of Python\nthat introduce incompatible changes to the language. It allows use of\nthe new features on a per-module basis before the release in which the\nfeature becomes standard.\n\n future_statement ::= "from" "__future__" "import" feature ["as" name]\n ("," feature ["as" name])*\n | "from" "__future__" "import" "(" feature ["as" name]\n ("," feature ["as" name])* [","] ")"\n feature ::= identifier\n name ::= identifier\n\nA future statement must appear near the top of the module. The only\nlines that can appear before a future statement are:\n\n* the module docstring (if any),\n\n* comments,\n\n* blank lines, and\n\n* other future statements.\n\nThe features recognized by Python 2.6 are "unicode_literals",\n"print_function", "absolute_import", "division", "generators",\n"nested_scopes" and "with_statement". "generators", "with_statement",\n"nested_scopes" are redundant in Python version 2.6 and above because\nthey are always enabled.\n\nA future statement is recognized and treated specially at compile\ntime: Changes to the semantics of core constructs are often\nimplemented by generating different code. It may even be the case\nthat a new feature introduces new incompatible syntax (such as a new\nreserved word), in which case the compiler may need to parse the\nmodule differently. Such decisions cannot be pushed off until\nruntime.\n\nFor any given release, the compiler knows which feature names have\nbeen defined, and raises a compile-time error if a future statement\ncontains a feature not known to it.\n\nThe direct runtime semantics are the same as for any import statement:\nthere is a standard module "__future__", described later, and it will\nbe imported in the usual way at the time the future statement is\nexecuted.\n\nThe interesting runtime semantics depend on the specific feature\nenabled by the future statement.\n\nNote that there is nothing special about the statement:\n\n import __future__ [as name]\n\nThat is not a future statement; it\'s an ordinary import statement with\nno special semantics or syntax restrictions.\n\nCode compiled by an "exec" statement or calls to the built-in\nfunctions "compile()" and "execfile()" that occur in a module "M"\ncontaining a future statement will, by default, use the new syntax or\nsemantics associated with the future statement. This can, starting\nwith Python 2.2 be controlled by optional arguments to "compile()" ---\nsee the documentation of that function for details.\n\nA future statement typed at an interactive interpreter prompt will\ntake effect for the rest of the interpreter session. If an\ninterpreter is started with the "-i" option, is passed a script name\nto execute, and the script includes a future statement, it will be in\neffect in the interactive session started after the script is\nexecuted.\n\nSee also:\n\n **PEP 236** - Back to the __future__\n The original proposal for the __future__ mechanism.\n',
+ 'in': u'\nComparisons\n***********\n\nUnlike C, all comparison operations in Python have the same priority,\nwhich is lower than that of any arithmetic, shifting or bitwise\noperation. Also unlike C, expressions like "a < b < c" have the\ninterpretation that is conventional in mathematics:\n\n comparison ::= or_expr ( comp_operator or_expr )*\n comp_operator ::= "<" | ">" | "==" | ">=" | "<=" | "<>" | "!="\n | "is" ["not"] | ["not"] "in"\n\nComparisons yield boolean values: "True" or "False".\n\nComparisons can be chained arbitrarily, e.g., "x < y <= z" is\nequivalent to "x < y and y <= z", except that "y" is evaluated only\nonce (but in both cases "z" is not evaluated at all when "x < y" is\nfound to be false).\n\nFormally, if *a*, *b*, *c*, ..., *y*, *z* are expressions and *op1*,\n*op2*, ..., *opN* are comparison operators, then "a op1 b op2 c ... y\nopN z" is equivalent to "a op1 b and b op2 c and ... y opN z", except\nthat each expression is evaluated at most once.\n\nNote that "a op1 b op2 c" doesn\'t imply any kind of comparison between\n*a* and *c*, so that, e.g., "x < y > z" is perfectly legal (though\nperhaps not pretty).\n\nThe forms "<>" and "!=" are equivalent; for consistency with C, "!="\nis preferred; where "!=" is mentioned below "<>" is also accepted.\nThe "<>" spelling is considered obsolescent.\n\nThe operators "<", ">", "==", ">=", "<=", and "!=" compare the values\nof two objects. The objects need not have the same type. If both are\nnumbers, they are converted to a common type. Otherwise, objects of\ndifferent types *always* compare unequal, and are ordered consistently\nbut arbitrarily. You can control comparison behavior of objects of\nnon-built-in types by defining a "__cmp__" method or rich comparison\nmethods like "__gt__", described in section Special method names.\n\n(This unusual definition of comparison was used to simplify the\ndefinition of operations like sorting and the "in" and "not in"\noperators. In the future, the comparison rules for objects of\ndifferent types are likely to change.)\n\nComparison of objects of the same type depends on the type:\n\n* Numbers are compared arithmetically.\n\n* Strings are compared lexicographically using the numeric\n equivalents (the result of the built-in function "ord()") of their\n characters. Unicode and 8-bit strings are fully interoperable in\n this behavior. [4]\n\n* Tuples and lists are compared lexicographically using comparison\n of corresponding elements. This means that to compare equal, each\n element must compare equal and the two sequences must be of the same\n type and have the same length.\n\n If not equal, the sequences are ordered the same as their first\n differing elements. For example, "cmp([1,2,x], [1,2,y])" returns\n the same as "cmp(x,y)". If the corresponding element does not\n exist, the shorter sequence is ordered first (for example, "[1,2] <\n [1,2,3]").\n\n* Mappings (dictionaries) compare equal if and only if their sorted\n (key, value) lists compare equal. [5] Outcomes other than equality\n are resolved consistently, but are not otherwise defined. [6]\n\n* Most other objects of built-in types compare unequal unless they\n are the same object; the choice whether one object is considered\n smaller or larger than another one is made arbitrarily but\n consistently within one execution of a program.\n\nThe operators "in" and "not in" test for collection membership. "x in\ns" evaluates to true if *x* is a member of the collection *s*, and\nfalse otherwise. "x not in s" returns the negation of "x in s". The\ncollection membership test has traditionally been bound to sequences;\nan object is a member of a collection if the collection is a sequence\nand contains an element equal to that object. However, it make sense\nfor many other object types to support membership tests without being\na sequence. In particular, dictionaries (for keys) and sets support\nmembership testing.\n\nFor the list and tuple types, "x in y" is true if and only if there\nexists an index *i* such that either "x is y[i]" or "x == y[i]" is\ntrue.\n\nFor the Unicode and string types, "x in y" is true if and only if *x*\nis a substring of *y*. An equivalent test is "y.find(x) != -1".\nNote, *x* and *y* need not be the same type; consequently, "u\'ab\' in\n\'abc\'" will return "True". Empty strings are always considered to be a\nsubstring of any other string, so """ in "abc"" will return "True".\n\nChanged in version 2.3: Previously, *x* was required to be a string of\nlength "1".\n\nFor user-defined classes which define the "__contains__()" method, "x\nin y" is true if and only if "y.__contains__(x)" is true.\n\nFor user-defined classes which do not define "__contains__()" but do\ndefine "__iter__()", "x in y" is true if some value "z" with "x == z"\nis produced while iterating over "y". If an exception is raised\nduring the iteration, it is as if "in" raised that exception.\n\nLastly, the old-style iteration protocol is tried: if a class defines\n"__getitem__()", "x in y" is true if and only if there is a non-\nnegative integer index *i* such that "x == y[i]", and all lower\ninteger indices do not raise "IndexError" exception. (If any other\nexception is raised, it is as if "in" raised that exception).\n\nThe operator "not in" is defined to have the inverse true value of\n"in".\n\nThe operators "is" and "is not" test for object identity: "x is y" is\ntrue if and only if *x* and *y* are the same object. "x is not y"\nyields the inverse truth value. [7]\n',
+ 'integers': u'\nInteger and long integer literals\n*********************************\n\nInteger and long integer literals are described by the following\nlexical definitions:\n\n longinteger ::= integer ("l" | "L")\n integer ::= decimalinteger | octinteger | hexinteger | bininteger\n decimalinteger ::= nonzerodigit digit* | "0"\n octinteger ::= "0" ("o" | "O") octdigit+ | "0" octdigit+\n hexinteger ::= "0" ("x" | "X") hexdigit+\n bininteger ::= "0" ("b" | "B") bindigit+\n nonzerodigit ::= "1"..."9"\n octdigit ::= "0"..."7"\n bindigit ::= "0" | "1"\n hexdigit ::= digit | "a"..."f" | "A"..."F"\n\nAlthough both lower case "\'l\'" and upper case "\'L\'" are allowed as\nsuffix for long integers, it is strongly recommended to always use\n"\'L\'", since the letter "\'l\'" looks too much like the digit "\'1\'".\n\nPlain integer literals that are above the largest representable plain\ninteger (e.g., 2147483647 when using 32-bit arithmetic) are accepted\nas if they were long integers instead. [1] There is no limit for long\ninteger literals apart from what can be stored in available memory.\n\nSome examples of plain integer literals (first row) and long integer\nliterals (second and third rows):\n\n 7 2147483647 0177\n 3L 79228162514264337593543950336L 0377L 0x100000000L\n 79228162514264337593543950336 0xdeadbeef\n',
+ 'lambda': u'\nLambdas\n*******\n\n lambda_expr ::= "lambda" [parameter_list]: expression\n old_lambda_expr ::= "lambda" [parameter_list]: old_expression\n\nLambda expressions (sometimes called lambda forms) have the same\nsyntactic position as expressions. They are a shorthand to create\nanonymous functions; the expression "lambda arguments: expression"\nyields a function object. The unnamed object behaves like a function\nobject defined with\n\n def name(arguments):\n return expression\n\nSee section Function definitions for the syntax of parameter lists.\nNote that functions created with lambda expressions cannot contain\nstatements.\n',
+ 'lists': u'\nList displays\n*************\n\nA list display is a possibly empty series of expressions enclosed in\nsquare brackets:\n\n list_display ::= "[" [expression_list | list_comprehension] "]"\n list_comprehension ::= expression list_for\n list_for ::= "for" target_list "in" old_expression_list [list_iter]\n old_expression_list ::= old_expression [("," old_expression)+ [","]]\n old_expression ::= or_test | old_lambda_expr\n list_iter ::= list_for | list_if\n list_if ::= "if" old_expression [list_iter]\n\nA list display yields a new list object. Its contents are specified\nby providing either a list of expressions or a list comprehension.\nWhen a comma-separated list of expressions is supplied, its elements\nare evaluated from left to right and placed into the list object in\nthat order. When a list comprehension is supplied, it consists of a\nsingle expression followed by at least one "for" clause and zero or\nmore "for" or "if" clauses. In this case, the elements of the new\nlist are those that would be produced by considering each of the "for"\nor "if" clauses a block, nesting from left to right, and evaluating\nthe expression to produce a list element each time the innermost block\nis reached [1].\n',
+ 'naming': u'\nNaming and binding\n******************\n\n*Names* refer to objects. Names are introduced by name binding\noperations. Each occurrence of a name in the program text refers to\nthe *binding* of that name established in the innermost function block\ncontaining the use.\n\nA *block* is a piece of Python program text that is executed as a\nunit. The following are blocks: a module, a function body, and a class\ndefinition. Each command typed interactively is a block. A script\nfile (a file given as standard input to the interpreter or specified\non the interpreter command line the first argument) is a code block.\nA script command (a command specified on the interpreter command line\nwith the \'**-c**\' option) is a code block. The file read by the\nbuilt-in function "execfile()" is a code block. The string argument\npassed to the built-in function "eval()" and to the "exec" statement\nis a code block. The expression read and evaluated by the built-in\nfunction "input()" is a code block.\n\nA code block is executed in an *execution frame*. A frame contains\nsome administrative information (used for debugging) and determines\nwhere and how execution continues after the code block\'s execution has\ncompleted.\n\nA *scope* defines the visibility of a name within a block. If a local\nvariable is defined in a block, its scope includes that block. If the\ndefinition occurs in a function block, the scope extends to any blocks\ncontained within the defining one, unless a contained block introduces\na different binding for the name. The scope of names defined in a\nclass block is limited to the class block; it does not extend to the\ncode blocks of methods -- this includes generator expressions since\nthey are implemented using a function scope. This means that the\nfollowing will fail:\n\n class A:\n a = 42\n b = list(a + i for i in range(10))\n\nWhen a name is used in a code block, it is resolved using the nearest\nenclosing scope. The set of all such scopes visible to a code block\nis called the block\'s *environment*.\n\nIf a name is bound in a block, it is a local variable of that block.\nIf a name is bound at the module level, it is a global variable. (The\nvariables of the module code block are local and global.) If a\nvariable is used in a code block but not defined there, it is a *free\nvariable*.\n\nWhen a name is not found at all, a "NameError" exception is raised.\nIf the name refers to a local variable that has not been bound, a\n"UnboundLocalError" exception is raised. "UnboundLocalError" is a\nsubclass of "NameError".\n\nThe following constructs bind names: formal parameters to functions,\n"import" statements, class and function definitions (these bind the\nclass or function name in the defining block), and targets that are\nidentifiers if occurring in an assignment, "for" loop header, in the\nsecond position of an "except" clause header or after "as" in a "with"\nstatement. The "import" statement of the form "from ... import *"\nbinds all names defined in the imported module, except those beginning\nwith an underscore. This form may only be used at the module level.\n\nA target occurring in a "del" statement is also considered bound for\nthis purpose (though the actual semantics are to unbind the name). It\nis illegal to unbind a name that is referenced by an enclosing scope;\nthe compiler will report a "SyntaxError".\n\nEach assignment or import statement occurs within a block defined by a\nclass or function definition or at the module level (the top-level\ncode block).\n\nIf a name binding operation occurs anywhere within a code block, all\nuses of the name within the block are treated as references to the\ncurrent block. This can lead to errors when a name is used within a\nblock before it is bound. This rule is subtle. Python lacks\ndeclarations and allows name binding operations to occur anywhere\nwithin a code block. The local variables of a code block can be\ndetermined by scanning the entire text of the block for name binding\noperations.\n\nIf the global statement occurs within a block, all uses of the name\nspecified in the statement refer to the binding of that name in the\ntop-level namespace. Names are resolved in the top-level namespace by\nsearching the global namespace, i.e. the namespace of the module\ncontaining the code block, and the builtins namespace, the namespace\nof the module "__builtin__". The global namespace is searched first.\nIf the name is not found there, the builtins namespace is searched.\nThe global statement must precede all uses of the name.\n\nThe builtins namespace associated with the execution of a code block\nis actually found by looking up the name "__builtins__" in its global\nnamespace; this should be a dictionary or a module (in the latter case\nthe module\'s dictionary is used). By default, when in the "__main__"\nmodule, "__builtins__" is the built-in module "__builtin__" (note: no\n\'s\'); when in any other module, "__builtins__" is an alias for the\ndictionary of the "__builtin__" module itself. "__builtins__" can be\nset to a user-created dictionary to create a weak form of restricted\nexecution.\n\n**CPython implementation detail:** Users should not touch\n"__builtins__"; it is strictly an implementation detail. Users\nwanting to override values in the builtins namespace should "import"\nthe "__builtin__" (no \'s\') module and modify its attributes\nappropriately.\n\nThe namespace for a module is automatically created the first time a\nmodule is imported. The main module for a script is always called\n"__main__".\n\nThe "global" statement has the same scope as a name binding operation\nin the same block. If the nearest enclosing scope for a free variable\ncontains a global statement, the free variable is treated as a global.\n\nA class definition is an executable statement that may use and define\nnames. These references follow the normal rules for name resolution.\nThe namespace of the class definition becomes the attribute dictionary\nof the class. Names defined at the class scope are not visible in\nmethods.\n\n\nInteraction with dynamic features\n=================================\n\nThere are several cases where Python statements are illegal when used\nin conjunction with nested scopes that contain free variables.\n\nIf a variable is referenced in an enclosing scope, it is illegal to\ndelete the name. An error will be reported at compile time.\n\nIf the wild card form of import --- "import *" --- is used in a\nfunction and the function contains or is a nested block with free\nvariables, the compiler will raise a "SyntaxError".\n\nIf "exec" is used in a function and the function contains or is a\nnested block with free variables, the compiler will raise a\n"SyntaxError" unless the exec explicitly specifies the local namespace\nfor the "exec". (In other words, "exec obj" would be illegal, but\n"exec obj in ns" would be legal.)\n\nThe "eval()", "execfile()", and "input()" functions and the "exec"\nstatement do not have access to the full environment for resolving\nnames. Names may be resolved in the local and global namespaces of\nthe caller. Free variables are not resolved in the nearest enclosing\nnamespace, but in the global namespace. [1] The "exec" statement and\nthe "eval()" and "execfile()" functions have optional arguments to\noverride the global and local namespace. If only one namespace is\nspecified, it is used for both.\n',
+ 'numbers': u'\nNumeric literals\n****************\n\nThere are four types of numeric literals: plain integers, long\nintegers, floating point numbers, and imaginary numbers. There are no\ncomplex literals (complex numbers can be formed by adding a real\nnumber and an imaginary number).\n\nNote that numeric literals do not include a sign; a phrase like "-1"\nis actually an expression composed of the unary operator \'"-"\' and the\nliteral "1".\n',
+ 'numeric-types': u'\nEmulating numeric types\n***********************\n\nThe following methods can be defined to emulate numeric objects.\nMethods corresponding to operations that are not supported by the\nparticular kind of number implemented (e.g., bitwise operations for\nnon-integral numbers) should be left undefined.\n\nobject.__add__(self, other)\nobject.__sub__(self, other)\nobject.__mul__(self, other)\nobject.__floordiv__(self, other)\nobject.__mod__(self, other)\nobject.__divmod__(self, other)\nobject.__pow__(self, other[, modulo])\nobject.__lshift__(self, other)\nobject.__rshift__(self, other)\nobject.__and__(self, other)\nobject.__xor__(self, other)\nobject.__or__(self, other)\n\n These methods are called to implement the binary arithmetic\n operations ("+", "-", "*", "//", "%", "divmod()", "pow()", "**",\n "<<", ">>", "&", "^", "|"). For instance, to evaluate the\n expression "x + y", where *x* is an instance of a class that has an\n "__add__()" method, "x.__add__(y)" is called. The "__divmod__()"\n method should be the equivalent to using "__floordiv__()" and\n "__mod__()"; it should not be related to "__truediv__()" (described\n below). Note that "__pow__()" should be defined to accept an\n optional third argument if the ternary version of the built-in\n "pow()" function is to be supported.\n\n If one of those methods does not support the operation with the\n supplied arguments, it should return "NotImplemented".\n\nobject.__div__(self, other)\nobject.__truediv__(self, other)\n\n The division operator ("/") is implemented by these methods. The\n "__truediv__()" method is used when "__future__.division" is in\n effect, otherwise "__div__()" is used. If only one of these two\n methods is defined, the object will not support division in the\n alternate context; "TypeError" will be raised instead.\n\nobject.__radd__(self, other)\nobject.__rsub__(self, other)\nobject.__rmul__(self, other)\nobject.__rdiv__(self, other)\nobject.__rtruediv__(self, other)\nobject.__rfloordiv__(self, other)\nobject.__rmod__(self, other)\nobject.__rdivmod__(self, other)\nobject.__rpow__(self, other)\nobject.__rlshift__(self, other)\nobject.__rrshift__(self, other)\nobject.__rand__(self, other)\nobject.__rxor__(self, other)\nobject.__ror__(self, other)\n\n These methods are called to implement the binary arithmetic\n operations ("+", "-", "*", "/", "%", "divmod()", "pow()", "**",\n "<<", ">>", "&", "^", "|") with reflected (swapped) operands.\n These functions are only called if the left operand does not\n support the corresponding operation and the operands are of\n different types. [2] For instance, to evaluate the expression "x -\n y", where *y* is an instance of a class that has an "__rsub__()"\n method, "y.__rsub__(x)" is called if "x.__sub__(y)" returns\n *NotImplemented*.\n\n Note that ternary "pow()" will not try calling "__rpow__()" (the\n coercion rules would become too complicated).\n\n Note: If the right operand\'s type is a subclass of the left\n operand\'s type and that subclass provides the reflected method\n for the operation, this method will be called before the left\n operand\'s non-reflected method. This behavior allows subclasses\n to override their ancestors\' operations.\n\nobject.__iadd__(self, other)\nobject.__isub__(self, other)\nobject.__imul__(self, other)\nobject.__idiv__(self, other)\nobject.__itruediv__(self, other)\nobject.__ifloordiv__(self, other)\nobject.__imod__(self, other)\nobject.__ipow__(self, other[, modulo])\nobject.__ilshift__(self, other)\nobject.__irshift__(self, other)\nobject.__iand__(self, other)\nobject.__ixor__(self, other)\nobject.__ior__(self, other)\n\n These methods are called to implement the augmented arithmetic\n assignments ("+=", "-=", "*=", "/=", "//=", "%=", "**=", "<<=",\n ">>=", "&=", "^=", "|="). These methods should attempt to do the\n operation in-place (modifying *self*) and return the result (which\n could be, but does not have to be, *self*). If a specific method\n is not defined, the augmented assignment falls back to the normal\n methods. For instance, to execute the statement "x += y", where\n *x* is an instance of a class that has an "__iadd__()" method,\n "x.__iadd__(y)" is called. If *x* is an instance of a class that\n does not define a "__iadd__()" method, "x.__add__(y)" and\n "y.__radd__(x)" are considered, as with the evaluation of "x + y".\n\nobject.__neg__(self)\nobject.__pos__(self)\nobject.__abs__(self)\nobject.__invert__(self)\n\n Called to implement the unary arithmetic operations ("-", "+",\n "abs()" and "~").\n\nobject.__complex__(self)\nobject.__int__(self)\nobject.__long__(self)\nobject.__float__(self)\n\n Called to implement the built-in functions "complex()", "int()",\n "long()", and "float()". Should return a value of the appropriate\n type.\n\nobject.__oct__(self)\nobject.__hex__(self)\n\n Called to implement the built-in functions "oct()" and "hex()".\n Should return a string value.\n\nobject.__index__(self)\n\n Called to implement "operator.index()". Also called whenever\n Python needs an integer object (such as in slicing). Must return\n an integer (int or long).\n\n New in version 2.5.\n\nobject.__coerce__(self, other)\n\n Called to implement "mixed-mode" numeric arithmetic. Should either\n return a 2-tuple containing *self* and *other* converted to a\n common numeric type, or "None" if conversion is impossible. When\n the common type would be the type of "other", it is sufficient to\n return "None", since the interpreter will also ask the other object\n to attempt a coercion (but sometimes, if the implementation of the\n other type cannot be changed, it is useful to do the conversion to\n the other type here). A return value of "NotImplemented" is\n equivalent to returning "None".\n',
+ 'objects': u'\nObjects, values and types\n*************************\n\n*Objects* are Python\'s abstraction for data. All data in a Python\nprogram is represented by objects or by relations between objects. (In\na sense, and in conformance to Von Neumann\'s model of a "stored\nprogram computer," code is also represented by objects.)\n\nEvery object has an identity, a type and a value. An object\'s\n*identity* never changes once it has been created; you may think of it\nas the object\'s address in memory. The \'"is"\' operator compares the\nidentity of two objects; the "id()" function returns an integer\nrepresenting its identity (currently implemented as its address). An\nobject\'s *type* is also unchangeable. [1] An object\'s type determines\nthe operations that the object supports (e.g., "does it have a\nlength?") and also defines the possible values for objects of that\ntype. The "type()" function returns an object\'s type (which is an\nobject itself). The *value* of some objects can change. Objects\nwhose value can change are said to be *mutable*; objects whose value\nis unchangeable once they are created are called *immutable*. (The\nvalue of an immutable container object that contains a reference to a\nmutable object can change when the latter\'s value is changed; however\nthe container is still considered immutable, because the collection of\nobjects it contains cannot be changed. So, immutability is not\nstrictly the same as having an unchangeable value, it is more subtle.)\nAn object\'s mutability is determined by its type; for instance,\nnumbers, strings and tuples are immutable, while dictionaries and\nlists are mutable.\n\nObjects are never explicitly destroyed; however, when they become\nunreachable they may be garbage-collected. An implementation is\nallowed to postpone garbage collection or omit it altogether --- it is\na matter of implementation quality how garbage collection is\nimplemented, as long as no objects are collected that are still\nreachable.\n\n**CPython implementation detail:** CPython currently uses a reference-\ncounting scheme with (optional) delayed detection of cyclically linked\ngarbage, which collects most objects as soon as they become\nunreachable, but is not guaranteed to collect garbage containing\ncircular references. See the documentation of the "gc" module for\ninformation on controlling the collection of cyclic garbage. Other\nimplementations act differently and CPython may change. Do not depend\non immediate finalization of objects when they become unreachable (ex:\nalways close files).\n\nNote that the use of the implementation\'s tracing or debugging\nfacilities may keep objects alive that would normally be collectable.\nAlso note that catching an exception with a \'"try"..."except"\'\nstatement may keep objects alive.\n\nSome objects contain references to "external" resources such as open\nfiles or windows. It is understood that these resources are freed\nwhen the object is garbage-collected, but since garbage collection is\nnot guaranteed to happen, such objects also provide an explicit way to\nrelease the external resource, usually a "close()" method. Programs\nare strongly recommended to explicitly close such objects. The\n\'"try"..."finally"\' statement provides a convenient way to do this.\n\nSome objects contain references to other objects; these are called\n*containers*. Examples of containers are tuples, lists and\ndictionaries. The references are part of a container\'s value. In\nmost cases, when we talk about the value of a container, we imply the\nvalues, not the identities of the contained objects; however, when we\ntalk about the mutability of a container, only the identities of the\nimmediately contained objects are implied. So, if an immutable\ncontainer (like a tuple) contains a reference to a mutable object, its\nvalue changes if that mutable object is changed.\n\nTypes affect almost all aspects of object behavior. Even the\nimportance of object identity is affected in some sense: for immutable\ntypes, operations that compute new values may actually return a\nreference to any existing object with the same type and value, while\nfor mutable objects this is not allowed. E.g., after "a = 1; b = 1",\n"a" and "b" may or may not refer to the same object with the value\none, depending on the implementation, but after "c = []; d = []", "c"\nand "d" are guaranteed to refer to two different, unique, newly\ncreated empty lists. (Note that "c = d = []" assigns the same object\nto both "c" and "d".)\n',
+ 'operator-summary': u'\nOperator precedence\n*******************\n\nThe following table summarizes the operator precedences in Python,\nfrom lowest precedence (least binding) to highest precedence (most\nbinding). Operators in the same box have the same precedence. Unless\nthe syntax is explicitly given, operators are binary. Operators in\nthe same box group left to right (except for comparisons, including\ntests, which all have the same precedence and chain from left to right\n--- see section Comparisons --- and exponentiation, which groups from\nright to left).\n\n+-------------------------------------------------+---------------------------------------+\n| Operator | Description |\n+=================================================+=======================================+\n| "lambda" | Lambda expression |\n+-------------------------------------------------+---------------------------------------+\n| "if" -- "else" | Conditional expression |\n+-------------------------------------------------+---------------------------------------+\n| "or" | Boolean OR |\n+-------------------------------------------------+---------------------------------------+\n| "and" | Boolean AND |\n+-------------------------------------------------+---------------------------------------+\n| "not" "x" | Boolean NOT |\n+-------------------------------------------------+---------------------------------------+\n| "in", "not in", "is", "is not", "<", "<=", ">", | Comparisons, including membership |\n| ">=", "<>", "!=", "==" | tests and identity tests |\n+-------------------------------------------------+---------------------------------------+\n| "|" | Bitwise OR |\n+-------------------------------------------------+---------------------------------------+\n| "^" | Bitwise XOR |\n+-------------------------------------------------+---------------------------------------+\n| "&" | Bitwise AND |\n+-------------------------------------------------+---------------------------------------+\n| "<<", ">>" | Shifts |\n+-------------------------------------------------+---------------------------------------+\n| "+", "-" | Addition and subtraction |\n+-------------------------------------------------+---------------------------------------+\n| "*", "/", "//", "%" | Multiplication, division, remainder |\n| | [8] |\n+-------------------------------------------------+---------------------------------------+\n| "+x", "-x", "~x" | Positive, negative, bitwise NOT |\n+-------------------------------------------------+---------------------------------------+\n| "**" | Exponentiation [9] |\n+-------------------------------------------------+---------------------------------------+\n| "x[index]", "x[index:index]", | Subscription, slicing, call, |\n| "x(arguments...)", "x.attribute" | attribute reference |\n+-------------------------------------------------+---------------------------------------+\n| "(expressions...)", "[expressions...]", "{key: | Binding or tuple display, list |\n| value...}", "`expressions...`" | display, dictionary display, string |\n| | conversion |\n+-------------------------------------------------+---------------------------------------+\n\n-[ Footnotes ]-\n\n[1] In Python 2.3 and later releases, a list comprehension "leaks"\n the control variables of each "for" it contains into the\n containing scope. However, this behavior is deprecated, and\n relying on it will not work in Python 3.\n\n[2] While "abs(x%y) < abs(y)" is true mathematically, for floats\n it may not be true numerically due to roundoff. For example, and\n assuming a platform on which a Python float is an IEEE 754 double-\n precision number, in order that "-1e-100 % 1e100" have the same\n sign as "1e100", the computed result is "-1e-100 + 1e100", which\n is numerically exactly equal to "1e100". The function\n "math.fmod()" returns a result whose sign matches the sign of the\n first argument instead, and so returns "-1e-100" in this case.\n Which approach is more appropriate depends on the application.\n\n[3] If x is very close to an exact integer multiple of y, it\'s\n possible for "floor(x/y)" to be one larger than "(x-x%y)/y" due to\n rounding. In such cases, Python returns the latter result, in\n order to preserve that "divmod(x,y)[0] * y + x % y" be very close\n to "x".\n\n[4] While comparisons between unicode strings make sense at the\n byte level, they may be counter-intuitive to users. For example,\n the strings "u"\\u00C7"" and "u"\\u0043\\u0327"" compare differently,\n even though they both represent the same unicode character (LATIN\n CAPITAL LETTER C WITH CEDILLA). To compare strings in a human\n recognizable way, compare using "unicodedata.normalize()".\n\n[5] The implementation computes this efficiently, without\n constructing lists or sorting.\n\n[6] Earlier versions of Python used lexicographic comparison of\n the sorted (key, value) lists, but this was very expensive for the\n common case of comparing for equality. An even earlier version of\n Python compared dictionaries by identity only, but this caused\n surprises because people expected to be able to test a dictionary\n for emptiness by comparing it to "{}".\n\n[7] Due to automatic garbage-collection, free lists, and the\n dynamic nature of descriptors, you may notice seemingly unusual\n behaviour in certain uses of the "is" operator, like those\n involving comparisons between instance methods, or constants.\n Check their documentation for more info.\n\n[8] The "%" operator is also used for string formatting; the same\n precedence applies.\n\n[9] The power operator "**" binds less tightly than an arithmetic\n or bitwise unary operator on its right, that is, "2**-1" is "0.5".\n',
+ 'pass': u'\nThe "pass" statement\n********************\n\n pass_stmt ::= "pass"\n\n"pass" is a null operation --- when it is executed, nothing happens.\nIt is useful as a placeholder when a statement is required\nsyntactically, but no code needs to be executed, for example:\n\n def f(arg): pass # a function that does nothing (yet)\n\n class C: pass # a class with no methods (yet)\n',
+ 'power': u'\nThe power operator\n******************\n\nThe power operator binds more tightly than unary operators on its\nleft; it binds less tightly than unary operators on its right. The\nsyntax is:\n\n power ::= primary ["**" u_expr]\n\nThus, in an unparenthesized sequence of power and unary operators, the\noperators are evaluated from right to left (this does not constrain\nthe evaluation order for the operands): "-1**2" results in "-1".\n\nThe power operator has the same semantics as the built-in "pow()"\nfunction, when called with two arguments: it yields its left argument\nraised to the power of its right argument. The numeric arguments are\nfirst converted to a common type. The result type is that of the\narguments after coercion.\n\nWith mixed operand types, the coercion rules for binary arithmetic\noperators apply. For int and long int operands, the result has the\nsame type as the operands (after coercion) unless the second argument\nis negative; in that case, all arguments are converted to float and a\nfloat result is delivered. For example, "10**2" returns "100", but\n"10**-2" returns "0.01". (This last feature was added in Python 2.2.\nIn Python 2.1 and before, if both arguments were of integer types and\nthe second argument was negative, an exception was raised).\n\nRaising "0.0" to a negative power results in a "ZeroDivisionError".\nRaising a negative number to a fractional power results in a\n"ValueError".\n',
+ 'print': u'\nThe "print" statement\n*********************\n\n print_stmt ::= "print" ([expression ("," expression)* [","]]\n | ">>" expression [("," expression)+ [","]])\n\n"print" evaluates each expression in turn and writes the resulting\nobject to standard output (see below). If an object is not a string,\nit is first converted to a string using the rules for string\nconversions. The (resulting or original) string is then written. A\nspace is written before each object is (converted and) written, unless\nthe output system believes it is positioned at the beginning of a\nline. This is the case (1) when no characters have yet been written\nto standard output, (2) when the last character written to standard\noutput is a whitespace character except "\' \'", or (3) when the last\nwrite operation on standard output was not a "print" statement. (In\nsome cases it may be functional to write an empty string to standard\noutput for this reason.)\n\nNote: Objects which act like file objects but which are not the\n built-in file objects often do not properly emulate this aspect of\n the file object\'s behavior, so it is best not to rely on this.\n\nA "\'\\n\'" character is written at the end, unless the "print" statement\nends with a comma. This is the only action if the statement contains\njust the keyword "print".\n\nStandard output is defined as the file object named "stdout" in the\nbuilt-in module "sys". If no such object exists, or if it does not\nhave a "write()" method, a "RuntimeError" exception is raised.\n\n"print" also has an extended form, defined by the second portion of\nthe syntax described above. This form is sometimes referred to as\n""print" chevron." In this form, the first expression after the ">>"\nmust evaluate to a "file-like" object, specifically an object that has\na "write()" method as described above. With this extended form, the\nsubsequent expressions are printed to this file object. If the first\nexpression evaluates to "None", then "sys.stdout" is used as the file\nfor output.\n',
+ 'raise': u'\nThe "raise" statement\n*********************\n\n raise_stmt ::= "raise" [expression ["," expression ["," expression]]]\n\nIf no expressions are present, "raise" re-raises the last exception\nthat was active in the current scope. If no exception is active in\nthe current scope, a "TypeError" exception is raised indicating that\nthis is an error (if running under IDLE, a "Queue.Empty" exception is\nraised instead).\n\nOtherwise, "raise" evaluates the expressions to get three objects,\nusing "None" as the value of omitted expressions. The first two\nobjects are used to determine the *type* and *value* of the exception.\n\nIf the first object is an instance, the type of the exception is the\nclass of the instance, the instance itself is the value, and the\nsecond object must be "None".\n\nIf the first object is a class, it becomes the type of the exception.\nThe second object is used to determine the exception value: If it is\nan instance of the class, the instance becomes the exception value. If\nthe second object is a tuple, it is used as the argument list for the\nclass constructor; if it is "None", an empty argument list is used,\nand any other object is treated as a single argument to the\nconstructor. The instance so created by calling the constructor is\nused as the exception value.\n\nIf a third object is present and not "None", it must be a traceback\nobject (see section The standard type hierarchy), and it is\nsubstituted instead of the current location as the place where the\nexception occurred. If the third object is present and not a\ntraceback object or "None", a "TypeError" exception is raised. The\nthree-expression form of "raise" is useful to re-raise an exception\ntransparently in an except clause, but "raise" with no expressions\nshould be preferred if the exception to be re-raised was the most\nrecently active exception in the current scope.\n\nAdditional information on exceptions can be found in section\nExceptions, and information about handling exceptions is in section\nThe try statement.\n',
+ 'return': u'\nThe "return" statement\n**********************\n\n return_stmt ::= "return" [expression_list]\n\n"return" may only occur syntactically nested in a function definition,\nnot within a nested class definition.\n\nIf an expression list is present, it is evaluated, else "None" is\nsubstituted.\n\n"return" leaves the current function call with the expression list (or\n"None") as return value.\n\nWhen "return" passes control out of a "try" statement with a "finally"\nclause, that "finally" clause is executed before really leaving the\nfunction.\n\nIn a generator function, the "return" statement is not allowed to\ninclude an "expression_list". In that context, a bare "return"\nindicates that the generator is done and will cause "StopIteration" to\nbe raised.\n',
+ 'sequence-types': u'\nEmulating container types\n*************************\n\nThe following methods can be defined to implement container objects.\nContainers usually are sequences (such as lists or tuples) or mappings\n(like dictionaries), but can represent other containers as well. The\nfirst set of methods is used either to emulate a sequence or to\nemulate a mapping; the difference is that for a sequence, the\nallowable keys should be the integers *k* for which "0 <= k < N" where\n*N* is the length of the sequence, or slice objects, which define a\nrange of items. (For backwards compatibility, the method\n"__getslice__()" (see below) can also be defined to handle simple, but\nnot extended slices.) It is also recommended that mappings provide the\nmethods "keys()", "values()", "items()", "has_key()", "get()",\n"clear()", "setdefault()", "iterkeys()", "itervalues()",\n"iteritems()", "pop()", "popitem()", "copy()", and "update()" behaving\nsimilar to those for Python\'s standard dictionary objects. The\n"UserDict" module provides a "DictMixin" class to help create those\nmethods from a base set of "__getitem__()", "__setitem__()",\n"__delitem__()", and "keys()". Mutable sequences should provide\nmethods "append()", "count()", "index()", "extend()", "insert()",\n"pop()", "remove()", "reverse()" and "sort()", like Python standard\nlist objects. Finally, sequence types should implement addition\n(meaning concatenation) and multiplication (meaning repetition) by\ndefining the methods "__add__()", "__radd__()", "__iadd__()",\n"__mul__()", "__rmul__()" and "__imul__()" described below; they\nshould not define "__coerce__()" or other numerical operators. It is\nrecommended that both mappings and sequences implement the\n"__contains__()" method to allow efficient use of the "in" operator;\nfor mappings, "in" should be equivalent of "has_key()"; for sequences,\nit should search through the values. It is further recommended that\nboth mappings and sequences implement the "__iter__()" method to allow\nefficient iteration through the container; for mappings, "__iter__()"\nshould be the same as "iterkeys()"; for sequences, it should iterate\nthrough the values.\n\nobject.__len__(self)\n\n Called to implement the built-in function "len()". Should return\n the length of the object, an integer ">=" 0. Also, an object that\n doesn\'t define a "__nonzero__()" method and whose "__len__()"\n method returns zero is considered to be false in a Boolean context.\n\nobject.__getitem__(self, key)\n\n Called to implement evaluation of "self[key]". For sequence types,\n the accepted keys should be integers and slice objects. Note that\n the special interpretation of negative indexes (if the class wishes\n to emulate a sequence type) is up to the "__getitem__()" method. If\n *key* is of an inappropriate type, "TypeError" may be raised; if of\n a value outside the set of indexes for the sequence (after any\n special interpretation of negative values), "IndexError" should be\n raised. For mapping types, if *key* is missing (not in the\n container), "KeyError" should be raised.\n\n Note: "for" loops expect that an "IndexError" will be raised for\n illegal indexes to allow proper detection of the end of the\n sequence.\n\nobject.__missing__(self, key)\n\n Called by "dict"."__getitem__()" to implement "self[key]" for dict\n subclasses when key is not in the dictionary.\n\nobject.__setitem__(self, key, value)\n\n Called to implement assignment to "self[key]". Same note as for\n "__getitem__()". This should only be implemented for mappings if\n the objects support changes to the values for keys, or if new keys\n can be added, or for sequences if elements can be replaced. The\n same exceptions should be raised for improper *key* values as for\n the "__getitem__()" method.\n\nobject.__delitem__(self, key)\n\n Called to implement deletion of "self[key]". Same note as for\n "__getitem__()". This should only be implemented for mappings if\n the objects support removal of keys, or for sequences if elements\n can be removed from the sequence. The same exceptions should be\n raised for improper *key* values as for the "__getitem__()" method.\n\nobject.__iter__(self)\n\n This method is called when an iterator is required for a container.\n This method should return a new iterator object that can iterate\n over all the objects in the container. For mappings, it should\n iterate over the keys of the container, and should also be made\n available as the method "iterkeys()".\n\n Iterator objects also need to implement this method; they are\n required to return themselves. For more information on iterator\n objects, see Iterator Types.\n\nobject.__reversed__(self)\n\n Called (if present) by the "reversed()" built-in to implement\n reverse iteration. It should return a new iterator object that\n iterates over all the objects in the container in reverse order.\n\n If the "__reversed__()" method is not provided, the "reversed()"\n built-in will fall back to using the sequence protocol ("__len__()"\n and "__getitem__()"). Objects that support the sequence protocol\n should only provide "__reversed__()" if they can provide an\n implementation that is more efficient than the one provided by\n "reversed()".\n\n New in version 2.6.\n\nThe membership test operators ("in" and "not in") are normally\nimplemented as an iteration through a sequence. However, container\nobjects can supply the following special method with a more efficient\nimplementation, which also does not require the object be a sequence.\n\nobject.__contains__(self, item)\n\n Called to implement membership test operators. Should return true\n if *item* is in *self*, false otherwise. For mapping objects, this\n should consider the keys of the mapping rather than the values or\n the key-item pairs.\n\n For objects that don\'t define "__contains__()", the membership test\n first tries iteration via "__iter__()", then the old sequence\n iteration protocol via "__getitem__()", see this section in the\n language reference.\n',
+ 'shifting': u'\nShifting operations\n*******************\n\nThe shifting operations have lower priority than the arithmetic\noperations:\n\n shift_expr ::= a_expr | shift_expr ( "<<" | ">>" ) a_expr\n\nThese operators accept plain or long integers as arguments. The\narguments are converted to a common type. They shift the first\nargument to the left or right by the number of bits given by the\nsecond argument.\n\nA right shift by *n* bits is defined as division by "pow(2, n)". A\nleft shift by *n* bits is defined as multiplication with "pow(2, n)".\nNegative shift counts raise a "ValueError" exception.\n\nNote: In the current implementation, the right-hand operand is\n required to be at most "sys.maxsize". If the right-hand operand is\n larger than "sys.maxsize" an "OverflowError" exception is raised.\n',
+ 'slicings': u'\nSlicings\n********\n\nA slicing selects a range of items in a sequence object (e.g., a\nstring, tuple or list). Slicings may be used as expressions or as\ntargets in assignment or "del" statements. The syntax for a slicing:\n\n slicing ::= simple_slicing | extended_slicing\n simple_slicing ::= primary "[" short_slice "]"\n extended_slicing ::= primary "[" slice_list "]"\n slice_list ::= slice_item ("," slice_item)* [","]\n slice_item ::= expression | proper_slice | ellipsis\n proper_slice ::= short_slice | long_slice\n short_slice ::= [lower_bound] ":" [upper_bound]\n long_slice ::= short_slice ":" [stride]\n lower_bound ::= expression\n upper_bound ::= expression\n stride ::= expression\n ellipsis ::= "..."\n\nThere is ambiguity in the formal syntax here: anything that looks like\nan expression list also looks like a slice list, so any subscription\ncan be interpreted as a slicing. Rather than further complicating the\nsyntax, this is disambiguated by defining that in this case the\ninterpretation as a subscription takes priority over the\ninterpretation as a slicing (this is the case if the slice list\ncontains no proper slice nor ellipses). Similarly, when the slice\nlist has exactly one short slice and no trailing comma, the\ninterpretation as a simple slicing takes priority over that as an\nextended slicing.\n\nThe semantics for a simple slicing are as follows. The primary must\nevaluate to a sequence object. The lower and upper bound expressions,\nif present, must evaluate to plain integers; defaults are zero and the\n"sys.maxint", respectively. If either bound is negative, the\nsequence\'s length is added to it. The slicing now selects all items\nwith index *k* such that "i <= k < j" where *i* and *j* are the\nspecified lower and upper bounds. This may be an empty sequence. It\nis not an error if *i* or *j* lie outside the range of valid indexes\n(such items don\'t exist so they aren\'t selected).\n\nThe semantics for an extended slicing are as follows. The primary\nmust evaluate to a mapping object, and it is indexed with a key that\nis constructed from the slice list, as follows. If the slice list\ncontains at least one comma, the key is a tuple containing the\nconversion of the slice items; otherwise, the conversion of the lone\nslice item is the key. The conversion of a slice item that is an\nexpression is that expression. The conversion of an ellipsis slice\nitem is the built-in "Ellipsis" object. The conversion of a proper\nslice is a slice object (see section The standard type hierarchy)\nwhose "start", "stop" and "step" attributes are the values of the\nexpressions given as lower bound, upper bound and stride,\nrespectively, substituting "None" for missing expressions.\n',
+ 'specialattrs': u'\nSpecial Attributes\n******************\n\nThe implementation adds a few special read-only attributes to several\nobject types, where they are relevant. Some of these are not reported\nby the "dir()" built-in function.\n\nobject.__dict__\n\n A dictionary or other mapping object used to store an object\'s\n (writable) attributes.\n\nobject.__methods__\n\n Deprecated since version 2.2: Use the built-in function "dir()" to\n get a list of an object\'s attributes. This attribute is no longer\n available.\n\nobject.__members__\n\n Deprecated since version 2.2: Use the built-in function "dir()" to\n get a list of an object\'s attributes. This attribute is no longer\n available.\n\ninstance.__class__\n\n The class to which a class instance belongs.\n\nclass.__bases__\n\n The tuple of base classes of a class object.\n\ndefinition.__name__\n\n The name of the class, type, function, method, descriptor, or\n generator instance.\n\nThe following attributes are only supported by *new-style class*es.\n\nclass.__mro__\n\n This attribute is a tuple of classes that are considered when\n looking for base classes during method resolution.\n\nclass.mro()\n\n This method can be overridden by a metaclass to customize the\n method resolution order for its instances. It is called at class\n instantiation, and its result is stored in "__mro__".\n\nclass.__subclasses__()\n\n Each new-style class keeps a list of weak references to its\n immediate subclasses. This method returns a list of all those\n references still alive. Example:\n\n >>> int.__subclasses__()\n [<type \'bool\'>]\n\n-[ Footnotes ]-\n\n[1] Additional information on these special methods may be found\n in the Python Reference Manual (Basic customization).\n\n[2] As a consequence, the list "[1, 2]" is considered equal to\n "[1.0, 2.0]", and similarly for tuples.\n\n[3] They must have since the parser can\'t tell the type of the\n operands.\n\n[4] Cased characters are those with general category property\n being one of "Lu" (Letter, uppercase), "Ll" (Letter, lowercase),\n or "Lt" (Letter, titlecase).\n\n[5] To format only a tuple you should therefore provide a\n singleton tuple whose only element is the tuple to be formatted.\n\n[6] The advantage of leaving the newline on is that returning an\n empty string is then an unambiguous EOF indication. It is also\n possible (in cases where it might matter, for example, if you want\n to make an exact copy of a file while scanning its lines) to tell\n whether the last line of a file ended in a newline or not (yes\n this happens!).\n',
+ 'specialnames': u'\nSpecial method names\n********************\n\nA class can implement certain operations that are invoked by special\nsyntax (such as arithmetic operations or subscripting and slicing) by\ndefining methods with special names. This is Python\'s approach to\n*operator overloading*, allowing classes to define their own behavior\nwith respect to language operators. For instance, if a class defines\na method named "__getitem__()", and "x" is an instance of this class,\nthen "x[i]" is roughly equivalent to "x.__getitem__(i)" for old-style\nclasses and "type(x).__getitem__(x, i)" for new-style classes. Except\nwhere mentioned, attempts to execute an operation raise an exception\nwhen no appropriate method is defined (typically "AttributeError" or\n"TypeError").\n\nWhen implementing a class that emulates any built-in type, it is\nimportant that the emulation only be implemented to the degree that it\nmakes sense for the object being modelled. For example, some\nsequences may work well with retrieval of individual elements, but\nextracting a slice may not make sense. (One example of this is the\n"NodeList" interface in the W3C\'s Document Object Model.)\n\n\nBasic customization\n===================\n\nobject.__new__(cls[, ...])\n\n Called to create a new instance of class *cls*. "__new__()" is a\n static method (special-cased so you need not declare it as such)\n that takes the class of which an instance was requested as its\n first argument. The remaining arguments are those passed to the\n object constructor expression (the call to the class). The return\n value of "__new__()" should be the new object instance (usually an\n instance of *cls*).\n\n Typical implementations create a new instance of the class by\n invoking the superclass\'s "__new__()" method using\n "super(currentclass, cls).__new__(cls[, ...])" with appropriate\n arguments and then modifying the newly-created instance as\n necessary before returning it.\n\n If "__new__()" returns an instance of *cls*, then the new\n instance\'s "__init__()" method will be invoked like\n "__init__(self[, ...])", where *self* is the new instance and the\n remaining arguments are the same as were passed to "__new__()".\n\n If "__new__()" does not return an instance of *cls*, then the new\n instance\'s "__init__()" method will not be invoked.\n\n "__new__()" is intended mainly to allow subclasses of immutable\n types (like int, str, or tuple) to customize instance creation. It\n is also commonly overridden in custom metaclasses in order to\n customize class creation.\n\nobject.__init__(self[, ...])\n\n Called after the instance has been created (by "__new__()"), but\n before it is returned to the caller. The arguments are those\n passed to the class constructor expression. If a base class has an\n "__init__()" method, the derived class\'s "__init__()" method, if\n any, must explicitly call it to ensure proper initialization of the\n base class part of the instance; for example:\n "BaseClass.__init__(self, [args...])".\n\n Because "__new__()" and "__init__()" work together in constructing\n objects ("__new__()" to create it, and "__init__()" to customise\n it), no non-"None" value may be returned by "__init__()"; doing so\n will cause a "TypeError" to be raised at runtime.\n\nobject.__del__(self)\n\n Called when the instance is about to be destroyed. This is also\n called a destructor. If a base class has a "__del__()" method, the\n derived class\'s "__del__()" method, if any, must explicitly call it\n to ensure proper deletion of the base class part of the instance.\n Note that it is possible (though not recommended!) for the\n "__del__()" method to postpone destruction of the instance by\n creating a new reference to it. It may then be called at a later\n time when this new reference is deleted. It is not guaranteed that\n "__del__()" methods are called for objects that still exist when\n the interpreter exits.\n\n Note: "del x" doesn\'t directly call "x.__del__()" --- the former\n decrements the reference count for "x" by one, and the latter is\n only called when "x"\'s reference count reaches zero. Some common\n situations that may prevent the reference count of an object from\n going to zero include: circular references between objects (e.g.,\n a doubly-linked list or a tree data structure with parent and\n child pointers); a reference to the object on the stack frame of\n a function that caught an exception (the traceback stored in\n "sys.exc_traceback" keeps the stack frame alive); or a reference\n to the object on the stack frame that raised an unhandled\n exception in interactive mode (the traceback stored in\n "sys.last_traceback" keeps the stack frame alive). The first\n situation can only be remedied by explicitly breaking the cycles;\n the latter two situations can be resolved by storing "None" in\n "sys.exc_traceback" or "sys.last_traceback". Circular references\n which are garbage are detected when the option cycle detector is\n enabled (it\'s on by default), but can only be cleaned up if there\n are no Python-level "__del__()" methods involved. Refer to the\n documentation for the "gc" module for more information about how\n "__del__()" methods are handled by the cycle detector,\n particularly the description of the "garbage" value.\n\n Warning: Due to the precarious circumstances under which\n "__del__()" methods are invoked, exceptions that occur during\n their execution are ignored, and a warning is printed to\n "sys.stderr" instead. Also, when "__del__()" is invoked in\n response to a module being deleted (e.g., when execution of the\n program is done), other globals referenced by the "__del__()"\n method may already have been deleted or in the process of being\n torn down (e.g. the import machinery shutting down). For this\n reason, "__del__()" methods should do the absolute minimum needed\n to maintain external invariants. Starting with version 1.5,\n Python guarantees that globals whose name begins with a single\n underscore are deleted from their module before other globals are\n deleted; if no other references to such globals exist, this may\n help in assuring that imported modules are still available at the\n time when the "__del__()" method is called.\n\n See also the "-R" command-line option.\n\nobject.__repr__(self)\n\n Called by the "repr()" built-in function and by string conversions\n (reverse quotes) to compute the "official" string representation of\n an object. If at all possible, this should look like a valid\n Python expression that could be used to recreate an object with the\n same value (given an appropriate environment). If this is not\n possible, a string of the form "<...some useful description...>"\n should be returned. The return value must be a string object. If a\n class defines "__repr__()" but not "__str__()", then "__repr__()"\n is also used when an "informal" string representation of instances\n of that class is required.\n\n This is typically used for debugging, so it is important that the\n representation is information-rich and unambiguous.\n\nobject.__str__(self)\n\n Called by the "str()" built-in function and by the "print"\n statement to compute the "informal" string representation of an\n object. This differs from "__repr__()" in that it does not have to\n be a valid Python expression: a more convenient or concise\n representation may be used instead. The return value must be a\n string object.\n\nobject.__lt__(self, other)\nobject.__le__(self, other)\nobject.__eq__(self, other)\nobject.__ne__(self, other)\nobject.__gt__(self, other)\nobject.__ge__(self, other)\n\n New in version 2.1.\n\n These are the so-called "rich comparison" methods, and are called\n for comparison operators in preference to "__cmp__()" below. The\n correspondence between operator symbols and method names is as\n follows: "x<y" calls "x.__lt__(y)", "x<=y" calls "x.__le__(y)",\n "x==y" calls "x.__eq__(y)", "x!=y" and "x<>y" call "x.__ne__(y)",\n "x>y" calls "x.__gt__(y)", and "x>=y" calls "x.__ge__(y)".\n\n A rich comparison method may return the singleton "NotImplemented"\n if it does not implement the operation for a given pair of\n arguments. By convention, "False" and "True" are returned for a\n successful comparison. However, these methods can return any value,\n so if the comparison operator is used in a Boolean context (e.g.,\n in the condition of an "if" statement), Python will call "bool()"\n on the value to determine if the result is true or false.\n\n There are no implied relationships among the comparison operators.\n The truth of "x==y" does not imply that "x!=y" is false.\n Accordingly, when defining "__eq__()", one should also define\n "__ne__()" so that the operators will behave as expected. See the\n paragraph on "__hash__()" for some important notes on creating\n *hashable* objects which support custom comparison operations and\n are usable as dictionary keys.\n\n There are no swapped-argument versions of these methods (to be used\n when the left argument does not support the operation but the right\n argument does); rather, "__lt__()" and "__gt__()" are each other\'s\n reflection, "__le__()" and "__ge__()" are each other\'s reflection,\n and "__eq__()" and "__ne__()" are their own reflection.\n\n Arguments to rich comparison methods are never coerced.\n\n To automatically generate ordering operations from a single root\n operation, see "functools.total_ordering()".\n\nobject.__cmp__(self, other)\n\n Called by comparison operations if rich comparison (see above) is\n not defined. Should return a negative integer if "self < other",\n zero if "self == other", a positive integer if "self > other". If\n no "__cmp__()", "__eq__()" or "__ne__()" operation is defined,\n class instances are compared by object identity ("address"). See\n also the description of "__hash__()" for some important notes on\n creating *hashable* objects which support custom comparison\n operations and are usable as dictionary keys. (Note: the\n restriction that exceptions are not propagated by "__cmp__()" has\n been removed since Python 1.5.)\n\nobject.__rcmp__(self, other)\n\n Changed in version 2.1: No longer supported.\n\nobject.__hash__(self)\n\n Called by built-in function "hash()" and for operations on members\n of hashed collections including "set", "frozenset", and "dict".\n "__hash__()" should return an integer. The only required property\n is that objects which compare equal have the same hash value; it is\n advised to somehow mix together (e.g. using exclusive or) the hash\n values for the components of the object that also play a part in\n comparison of objects.\n\n If a class does not define a "__cmp__()" or "__eq__()" method it\n should not define a "__hash__()" operation either; if it defines\n "__cmp__()" or "__eq__()" but not "__hash__()", its instances will\n not be usable in hashed collections. If a class defines mutable\n objects and implements a "__cmp__()" or "__eq__()" method, it\n should not implement "__hash__()", since hashable collection\n implementations require that an object\'s hash value is immutable\n (if the object\'s hash value changes, it will be in the wrong hash\n bucket).\n\n User-defined classes have "__cmp__()" and "__hash__()" methods by\n default; with them, all objects compare unequal (except with\n themselves) and "x.__hash__()" returns a result derived from\n "id(x)".\n\n Classes which inherit a "__hash__()" method from a parent class but\n change the meaning of "__cmp__()" or "__eq__()" such that the hash\n value returned is no longer appropriate (e.g. by switching to a\n value-based concept of equality instead of the default identity\n based equality) can explicitly flag themselves as being unhashable\n by setting "__hash__ = None" in the class definition. Doing so\n means that not only will instances of the class raise an\n appropriate "TypeError" when a program attempts to retrieve their\n hash value, but they will also be correctly identified as\n unhashable when checking "isinstance(obj, collections.Hashable)"\n (unlike classes which define their own "__hash__()" to explicitly\n raise "TypeError").\n\n Changed in version 2.5: "__hash__()" may now also return a long\n integer object; the 32-bit integer is then derived from the hash of\n that object.\n\n Changed in version 2.6: "__hash__" may now be set to "None" to\n explicitly flag instances of a class as unhashable.\n\nobject.__nonzero__(self)\n\n Called to implement truth value testing and the built-in operation\n "bool()"; should return "False" or "True", or their integer\n equivalents "0" or "1". When this method is not defined,\n "__len__()" is called, if it is defined, and the object is\n considered true if its result is nonzero. If a class defines\n neither "__len__()" nor "__nonzero__()", all its instances are\n considered true.\n\nobject.__unicode__(self)\n\n Called to implement "unicode()" built-in; should return a Unicode\n object. When this method is not defined, string conversion is\n attempted, and the result of string conversion is converted to\n Unicode using the system default encoding.\n\n\nCustomizing attribute access\n============================\n\nThe following methods can be defined to customize the meaning of\nattribute access (use of, assignment to, or deletion of "x.name") for\nclass instances.\n\nobject.__getattr__(self, name)\n\n Called when an attribute lookup has not found the attribute in the\n usual places (i.e. it is not an instance attribute nor is it found\n in the class tree for "self"). "name" is the attribute name. This\n method should return the (computed) attribute value or raise an\n "AttributeError" exception.\n\n Note that if the attribute is found through the normal mechanism,\n "__getattr__()" is not called. (This is an intentional asymmetry\n between "__getattr__()" and "__setattr__()".) This is done both for\n efficiency reasons and because otherwise "__getattr__()" would have\n no way to access other attributes of the instance. Note that at\n least for instance variables, you can fake total control by not\n inserting any values in the instance attribute dictionary (but\n instead inserting them in another object). See the\n "__getattribute__()" method below for a way to actually get total\n control in new-style classes.\n\nobject.__setattr__(self, name, value)\n\n Called when an attribute assignment is attempted. This is called\n instead of the normal mechanism (i.e. store the value in the\n instance dictionary). *name* is the attribute name, *value* is the\n value to be assigned to it.\n\n If "__setattr__()" wants to assign to an instance attribute, it\n should not simply execute "self.name = value" --- this would cause\n a recursive call to itself. Instead, it should insert the value in\n the dictionary of instance attributes, e.g., "self.__dict__[name] =\n value". For new-style classes, rather than accessing the instance\n dictionary, it should call the base class method with the same\n name, for example, "object.__setattr__(self, name, value)".\n\nobject.__delattr__(self, name)\n\n Like "__setattr__()" but for attribute deletion instead of\n assignment. This should only be implemented if "del obj.name" is\n meaningful for the object.\n\n\nMore attribute access for new-style classes\n-------------------------------------------\n\nThe following methods only apply to new-style classes.\n\nobject.__getattribute__(self, name)\n\n Called unconditionally to implement attribute accesses for\n instances of the class. If the class also defines "__getattr__()",\n the latter will not be called unless "__getattribute__()" either\n calls it explicitly or raises an "AttributeError". This method\n should return the (computed) attribute value or raise an\n "AttributeError" exception. In order to avoid infinite recursion in\n this method, its implementation should always call the base class\n method with the same name to access any attributes it needs, for\n example, "object.__getattribute__(self, name)".\n\n Note: This method may still be bypassed when looking up special\n methods as the result of implicit invocation via language syntax\n or built-in functions. See Special method lookup for new-style\n classes.\n\n\nImplementing Descriptors\n------------------------\n\nThe following methods only apply when an instance of the class\ncontaining the method (a so-called *descriptor* class) appears in an\n*owner* class (the descriptor must be in either the owner\'s class\ndictionary or in the class dictionary for one of its parents). In the\nexamples below, "the attribute" refers to the attribute whose name is\nthe key of the property in the owner class\' "__dict__".\n\nobject.__get__(self, instance, owner)\n\n Called to get the attribute of the owner class (class attribute\n access) or of an instance of that class (instance attribute\n access). *owner* is always the owner class, while *instance* is the\n instance that the attribute was accessed through, or "None" when\n the attribute is accessed through the *owner*. This method should\n return the (computed) attribute value or raise an "AttributeError"\n exception.\n\nobject.__set__(self, instance, value)\n\n Called to set the attribute on an instance *instance* of the owner\n class to a new value, *value*.\n\nobject.__delete__(self, instance)\n\n Called to delete the attribute on an instance *instance* of the\n owner class.\n\n\nInvoking Descriptors\n--------------------\n\nIn general, a descriptor is an object attribute with "binding\nbehavior", one whose attribute access has been overridden by methods\nin the descriptor protocol: "__get__()", "__set__()", and\n"__delete__()". If any of those methods are defined for an object, it\nis said to be a descriptor.\n\nThe default behavior for attribute access is to get, set, or delete\nthe attribute from an object\'s dictionary. For instance, "a.x" has a\nlookup chain starting with "a.__dict__[\'x\']", then\n"type(a).__dict__[\'x\']", and continuing through the base classes of\n"type(a)" excluding metaclasses.\n\nHowever, if the looked-up value is an object defining one of the\ndescriptor methods, then Python may override the default behavior and\ninvoke the descriptor method instead. Where this occurs in the\nprecedence chain depends on which descriptor methods were defined and\nhow they were called. Note that descriptors are only invoked for new\nstyle objects or classes (ones that subclass "object()" or "type()").\n\nThe starting point for descriptor invocation is a binding, "a.x". How\nthe arguments are assembled depends on "a":\n\nDirect Call\n The simplest and least common call is when user code directly\n invokes a descriptor method: "x.__get__(a)".\n\nInstance Binding\n If binding to a new-style object instance, "a.x" is transformed\n into the call: "type(a).__dict__[\'x\'].__get__(a, type(a))".\n\nClass Binding\n If binding to a new-style class, "A.x" is transformed into the\n call: "A.__dict__[\'x\'].__get__(None, A)".\n\nSuper Binding\n If "a" is an instance of "super", then the binding "super(B,\n obj).m()" searches "obj.__class__.__mro__" for the base class "A"\n immediately preceding "B" and then invokes the descriptor with the\n call: "A.__dict__[\'m\'].__get__(obj, obj.__class__)".\n\nFor instance bindings, the precedence of descriptor invocation depends\non the which descriptor methods are defined. A descriptor can define\nany combination of "__get__()", "__set__()" and "__delete__()". If it\ndoes not define "__get__()", then accessing the attribute will return\nthe descriptor object itself unless there is a value in the object\'s\ninstance dictionary. If the descriptor defines "__set__()" and/or\n"__delete__()", it is a data descriptor; if it defines neither, it is\na non-data descriptor. Normally, data descriptors define both\n"__get__()" and "__set__()", while non-data descriptors have just the\n"__get__()" method. Data descriptors with "__set__()" and "__get__()"\ndefined always override a redefinition in an instance dictionary. In\ncontrast, non-data descriptors can be overridden by instances.\n\nPython methods (including "staticmethod()" and "classmethod()") are\nimplemented as non-data descriptors. Accordingly, instances can\nredefine and override methods. This allows individual instances to\nacquire behaviors that differ from other instances of the same class.\n\nThe "property()" function is implemented as a data descriptor.\nAccordingly, instances cannot override the behavior of a property.\n\n\n__slots__\n---------\n\nBy default, instances of both old and new-style classes have a\ndictionary for attribute storage. This wastes space for objects\nhaving very few instance variables. The space consumption can become\nacute when creating large numbers of instances.\n\nThe default can be overridden by defining *__slots__* in a new-style\nclass definition. The *__slots__* declaration takes a sequence of\ninstance variables and reserves just enough space in each instance to\nhold a value for each variable. Space is saved because *__dict__* is\nnot created for each instance.\n\n__slots__\n\n This class variable can be assigned a string, iterable, or sequence\n of strings with variable names used by instances. If defined in a\n new-style class, *__slots__* reserves space for the declared\n variables and prevents the automatic creation of *__dict__* and\n *__weakref__* for each instance.\n\n New in version 2.2.\n\nNotes on using *__slots__*\n\n* When inheriting from a class without *__slots__*, the *__dict__*\n attribute of that class will always be accessible, so a *__slots__*\n definition in the subclass is meaningless.\n\n* Without a *__dict__* variable, instances cannot be assigned new\n variables not listed in the *__slots__* definition. Attempts to\n assign to an unlisted variable name raises "AttributeError". If\n dynamic assignment of new variables is desired, then add\n "\'__dict__\'" to the sequence of strings in the *__slots__*\n declaration.\n\n Changed in version 2.3: Previously, adding "\'__dict__\'" to the\n *__slots__* declaration would not enable the assignment of new\n attributes not specifically listed in the sequence of instance\n variable names.\n\n* Without a *__weakref__* variable for each instance, classes\n defining *__slots__* do not support weak references to its\n instances. If weak reference support is needed, then add\n "\'__weakref__\'" to the sequence of strings in the *__slots__*\n declaration.\n\n Changed in version 2.3: Previously, adding "\'__weakref__\'" to the\n *__slots__* declaration would not enable support for weak\n references.\n\n* *__slots__* are implemented at the class level by creating\n descriptors (Implementing Descriptors) for each variable name. As a\n result, class attributes cannot be used to set default values for\n instance variables defined by *__slots__*; otherwise, the class\n attribute would overwrite the descriptor assignment.\n\n* The action of a *__slots__* declaration is limited to the class\n where it is defined. As a result, subclasses will have a *__dict__*\n unless they also define *__slots__* (which must only contain names\n of any *additional* slots).\n\n* If a class defines a slot also defined in a base class, the\n instance variable defined by the base class slot is inaccessible\n (except by retrieving its descriptor directly from the base class).\n This renders the meaning of the program undefined. In the future, a\n check may be added to prevent this.\n\n* Nonempty *__slots__* does not work for classes derived from\n "variable-length" built-in types such as "long", "str" and "tuple".\n\n* Any non-string iterable may be assigned to *__slots__*. Mappings\n may also be used; however, in the future, special meaning may be\n assigned to the values corresponding to each key.\n\n* *__class__* assignment works only if both classes have the same\n *__slots__*.\n\n Changed in version 2.6: Previously, *__class__* assignment raised an\n error if either new or old class had *__slots__*.\n\n\nCustomizing class creation\n==========================\n\nBy default, new-style classes are constructed using "type()". A class\ndefinition is read into a separate namespace and the value of class\nname is bound to the result of "type(name, bases, dict)".\n\nWhen the class definition is read, if *__metaclass__* is defined then\nthe callable assigned to it will be called instead of "type()". This\nallows classes or functions to be written which monitor or alter the\nclass creation process:\n\n* Modifying the class dictionary prior to the class being created.\n\n* Returning an instance of another class -- essentially performing\n the role of a factory function.\n\nThese steps will have to be performed in the metaclass\'s "__new__()"\nmethod -- "type.__new__()" can then be called from this method to\ncreate a class with different properties. This example adds a new\nelement to the class dictionary before creating the class:\n\n class metacls(type):\n def __new__(mcs, name, bases, dict):\n dict[\'foo\'] = \'metacls was here\'\n return type.__new__(mcs, name, bases, dict)\n\nYou can of course also override other class methods (or add new\nmethods); for example defining a custom "__call__()" method in the\nmetaclass allows custom behavior when the class is called, e.g. not\nalways creating a new instance.\n\n__metaclass__\n\n This variable can be any callable accepting arguments for "name",\n "bases", and "dict". Upon class creation, the callable is used\n instead of the built-in "type()".\n\n New in version 2.2.\n\nThe appropriate metaclass is determined by the following precedence\nrules:\n\n* If "dict[\'__metaclass__\']" exists, it is used.\n\n* Otherwise, if there is at least one base class, its metaclass is\n used (this looks for a *__class__* attribute first and if not found,\n uses its type).\n\n* Otherwise, if a global variable named __metaclass__ exists, it is\n used.\n\n* Otherwise, the old-style, classic metaclass (types.ClassType) is\n used.\n\nThe potential uses for metaclasses are boundless. Some ideas that have\nbeen explored including logging, interface checking, automatic\ndelegation, automatic property creation, proxies, frameworks, and\nautomatic resource locking/synchronization.\n\n\nCustomizing instance and subclass checks\n========================================\n\nNew in version 2.6.\n\nThe following methods are used to override the default behavior of the\n"isinstance()" and "issubclass()" built-in functions.\n\nIn particular, the metaclass "abc.ABCMeta" implements these methods in\norder to allow the addition of Abstract Base Classes (ABCs) as\n"virtual base classes" to any class or type (including built-in\ntypes), including other ABCs.\n\nclass.__instancecheck__(self, instance)\n\n Return true if *instance* should be considered a (direct or\n indirect) instance of *class*. If defined, called to implement\n "isinstance(instance, class)".\n\nclass.__subclasscheck__(self, subclass)\n\n Return true if *subclass* should be considered a (direct or\n indirect) subclass of *class*. If defined, called to implement\n "issubclass(subclass, class)".\n\nNote that these methods are looked up on the type (metaclass) of a\nclass. They cannot be defined as class methods in the actual class.\nThis is consistent with the lookup of special methods that are called\non instances, only in this case the instance is itself a class.\n\nSee also:\n\n **PEP 3119** - Introducing Abstract Base Classes\n Includes the specification for customizing "isinstance()" and\n "issubclass()" behavior through "__instancecheck__()" and\n "__subclasscheck__()", with motivation for this functionality in\n the context of adding Abstract Base Classes (see the "abc"\n module) to the language.\n\n\nEmulating callable objects\n==========================\n\nobject.__call__(self[, args...])\n\n Called when the instance is "called" as a function; if this method\n is defined, "x(arg1, arg2, ...)" is a shorthand for\n "x.__call__(arg1, arg2, ...)".\n\n\nEmulating container types\n=========================\n\nThe following methods can be defined to implement container objects.\nContainers usually are sequences (such as lists or tuples) or mappings\n(like dictionaries), but can represent other containers as well. The\nfirst set of methods is used either to emulate a sequence or to\nemulate a mapping; the difference is that for a sequence, the\nallowable keys should be the integers *k* for which "0 <= k < N" where\n*N* is the length of the sequence, or slice objects, which define a\nrange of items. (For backwards compatibility, the method\n"__getslice__()" (see below) can also be defined to handle simple, but\nnot extended slices.) It is also recommended that mappings provide the\nmethods "keys()", "values()", "items()", "has_key()", "get()",\n"clear()", "setdefault()", "iterkeys()", "itervalues()",\n"iteritems()", "pop()", "popitem()", "copy()", and "update()" behaving\nsimilar to those for Python\'s standard dictionary objects. The\n"UserDict" module provides a "DictMixin" class to help create those\nmethods from a base set of "__getitem__()", "__setitem__()",\n"__delitem__()", and "keys()". Mutable sequences should provide\nmethods "append()", "count()", "index()", "extend()", "insert()",\n"pop()", "remove()", "reverse()" and "sort()", like Python standard\nlist objects. Finally, sequence types should implement addition\n(meaning concatenation) and multiplication (meaning repetition) by\ndefining the methods "__add__()", "__radd__()", "__iadd__()",\n"__mul__()", "__rmul__()" and "__imul__()" described below; they\nshould not define "__coerce__()" or other numerical operators. It is\nrecommended that both mappings and sequences implement the\n"__contains__()" method to allow efficient use of the "in" operator;\nfor mappings, "in" should be equivalent of "has_key()"; for sequences,\nit should search through the values. It is further recommended that\nboth mappings and sequences implement the "__iter__()" method to allow\nefficient iteration through the container; for mappings, "__iter__()"\nshould be the same as "iterkeys()"; for sequences, it should iterate\nthrough the values.\n\nobject.__len__(self)\n\n Called to implement the built-in function "len()". Should return\n the length of the object, an integer ">=" 0. Also, an object that\n doesn\'t define a "__nonzero__()" method and whose "__len__()"\n method returns zero is considered to be false in a Boolean context.\n\nobject.__getitem__(self, key)\n\n Called to implement evaluation of "self[key]". For sequence types,\n the accepted keys should be integers and slice objects. Note that\n the special interpretation of negative indexes (if the class wishes\n to emulate a sequence type) is up to the "__getitem__()" method. If\n *key* is of an inappropriate type, "TypeError" may be raised; if of\n a value outside the set of indexes for the sequence (after any\n special interpretation of negative values), "IndexError" should be\n raised. For mapping types, if *key* is missing (not in the\n container), "KeyError" should be raised.\n\n Note: "for" loops expect that an "IndexError" will be raised for\n illegal indexes to allow proper detection of the end of the\n sequence.\n\nobject.__missing__(self, key)\n\n Called by "dict"."__getitem__()" to implement "self[key]" for dict\n subclasses when key is not in the dictionary.\n\nobject.__setitem__(self, key, value)\n\n Called to implement assignment to "self[key]". Same note as for\n "__getitem__()". This should only be implemented for mappings if\n the objects support changes to the values for keys, or if new keys\n can be added, or for sequences if elements can be replaced. The\n same exceptions should be raised for improper *key* values as for\n the "__getitem__()" method.\n\nobject.__delitem__(self, key)\n\n Called to implement deletion of "self[key]". Same note as for\n "__getitem__()". This should only be implemented for mappings if\n the objects support removal of keys, or for sequences if elements\n can be removed from the sequence. The same exceptions should be\n raised for improper *key* values as for the "__getitem__()" method.\n\nobject.__iter__(self)\n\n This method is called when an iterator is required for a container.\n This method should return a new iterator object that can iterate\n over all the objects in the container. For mappings, it should\n iterate over the keys of the container, and should also be made\n available as the method "iterkeys()".\n\n Iterator objects also need to implement this method; they are\n required to return themselves. For more information on iterator\n objects, see Iterator Types.\n\nobject.__reversed__(self)\n\n Called (if present) by the "reversed()" built-in to implement\n reverse iteration. It should return a new iterator object that\n iterates over all the objects in the container in reverse order.\n\n If the "__reversed__()" method is not provided, the "reversed()"\n built-in will fall back to using the sequence protocol ("__len__()"\n and "__getitem__()"). Objects that support the sequence protocol\n should only provide "__reversed__()" if they can provide an\n implementation that is more efficient than the one provided by\n "reversed()".\n\n New in version 2.6.\n\nThe membership test operators ("in" and "not in") are normally\nimplemented as an iteration through a sequence. However, container\nobjects can supply the following special method with a more efficient\nimplementation, which also does not require the object be a sequence.\n\nobject.__contains__(self, item)\n\n Called to implement membership test operators. Should return true\n if *item* is in *self*, false otherwise. For mapping objects, this\n should consider the keys of the mapping rather than the values or\n the key-item pairs.\n\n For objects that don\'t define "__contains__()", the membership test\n first tries iteration via "__iter__()", then the old sequence\n iteration protocol via "__getitem__()", see this section in the\n language reference.\n\n\nAdditional methods for emulation of sequence types\n==================================================\n\nThe following optional methods can be defined to further emulate\nsequence objects. Immutable sequences methods should at most only\ndefine "__getslice__()"; mutable sequences might define all three\nmethods.\n\nobject.__getslice__(self, i, j)\n\n Deprecated since version 2.0: Support slice objects as parameters\n to the "__getitem__()" method. (However, built-in types in CPython\n currently still implement "__getslice__()". Therefore, you have to\n override it in derived classes when implementing slicing.)\n\n Called to implement evaluation of "self[i:j]". The returned object\n should be of the same type as *self*. Note that missing *i* or *j*\n in the slice expression are replaced by zero or "sys.maxsize",\n respectively. If negative indexes are used in the slice, the\n length of the sequence is added to that index. If the instance does\n not implement the "__len__()" method, an "AttributeError" is\n raised. No guarantee is made that indexes adjusted this way are not\n still negative. Indexes which are greater than the length of the\n sequence are not modified. If no "__getslice__()" is found, a slice\n object is created instead, and passed to "__getitem__()" instead.\n\nobject.__setslice__(self, i, j, sequence)\n\n Called to implement assignment to "self[i:j]". Same notes for *i*\n and *j* as for "__getslice__()".\n\n This method is deprecated. If no "__setslice__()" is found, or for\n extended slicing of the form "self[i:j:k]", a slice object is\n created, and passed to "__setitem__()", instead of "__setslice__()"\n being called.\n\nobject.__delslice__(self, i, j)\n\n Called to implement deletion of "self[i:j]". Same notes for *i* and\n *j* as for "__getslice__()". This method is deprecated. If no\n "__delslice__()" is found, or for extended slicing of the form\n "self[i:j:k]", a slice object is created, and passed to\n "__delitem__()", instead of "__delslice__()" being called.\n\nNotice that these methods are only invoked when a single slice with a\nsingle colon is used, and the slice method is available. For slice\noperations involving extended slice notation, or in absence of the\nslice methods, "__getitem__()", "__setitem__()" or "__delitem__()" is\ncalled with a slice object as argument.\n\nThe following example demonstrate how to make your program or module\ncompatible with earlier versions of Python (assuming that methods\n"__getitem__()", "__setitem__()" and "__delitem__()" support slice\nobjects as arguments):\n\n class MyClass:\n ...\n def __getitem__(self, index):\n ...\n def __setitem__(self, index, value):\n ...\n def __delitem__(self, index):\n ...\n\n if sys.version_info < (2, 0):\n # They won\'t be defined if version is at least 2.0 final\n\n def __getslice__(self, i, j):\n return self[max(0, i):max(0, j):]\n def __setslice__(self, i, j, seq):\n self[max(0, i):max(0, j):] = seq\n def __delslice__(self, i, j):\n del self[max(0, i):max(0, j):]\n ...\n\nNote the calls to "max()"; these are necessary because of the handling\nof negative indices before the "__*slice__()" methods are called.\nWhen negative indexes are used, the "__*item__()" methods receive them\nas provided, but the "__*slice__()" methods get a "cooked" form of the\nindex values. For each negative index value, the length of the\nsequence is added to the index before calling the method (which may\nstill result in a negative index); this is the customary handling of\nnegative indexes by the built-in sequence types, and the "__*item__()"\nmethods are expected to do this as well. However, since they should\nalready be doing that, negative indexes cannot be passed in; they must\nbe constrained to the bounds of the sequence before being passed to\nthe "__*item__()" methods. Calling "max(0, i)" conveniently returns\nthe proper value.\n\n\nEmulating numeric types\n=======================\n\nThe following methods can be defined to emulate numeric objects.\nMethods corresponding to operations that are not supported by the\nparticular kind of number implemented (e.g., bitwise operations for\nnon-integral numbers) should be left undefined.\n\nobject.__add__(self, other)\nobject.__sub__(self, other)\nobject.__mul__(self, other)\nobject.__floordiv__(self, other)\nobject.__mod__(self, other)\nobject.__divmod__(self, other)\nobject.__pow__(self, other[, modulo])\nobject.__lshift__(self, other)\nobject.__rshift__(self, other)\nobject.__and__(self, other)\nobject.__xor__(self, other)\nobject.__or__(self, other)\n\n These methods are called to implement the binary arithmetic\n operations ("+", "-", "*", "//", "%", "divmod()", "pow()", "**",\n "<<", ">>", "&", "^", "|"). For instance, to evaluate the\n expression "x + y", where *x* is an instance of a class that has an\n "__add__()" method, "x.__add__(y)" is called. The "__divmod__()"\n method should be the equivalent to using "__floordiv__()" and\n "__mod__()"; it should not be related to "__truediv__()" (described\n below). Note that "__pow__()" should be defined to accept an\n optional third argument if the ternary version of the built-in\n "pow()" function is to be supported.\n\n If one of those methods does not support the operation with the\n supplied arguments, it should return "NotImplemented".\n\nobject.__div__(self, other)\nobject.__truediv__(self, other)\n\n The division operator ("/") is implemented by these methods. The\n "__truediv__()" method is used when "__future__.division" is in\n effect, otherwise "__div__()" is used. If only one of these two\n methods is defined, the object will not support division in the\n alternate context; "TypeError" will be raised instead.\n\nobject.__radd__(self, other)\nobject.__rsub__(self, other)\nobject.__rmul__(self, other)\nobject.__rdiv__(self, other)\nobject.__rtruediv__(self, other)\nobject.__rfloordiv__(self, other)\nobject.__rmod__(self, other)\nobject.__rdivmod__(self, other)\nobject.__rpow__(self, other)\nobject.__rlshift__(self, other)\nobject.__rrshift__(self, other)\nobject.__rand__(self, other)\nobject.__rxor__(self, other)\nobject.__ror__(self, other)\n\n These methods are called to implement the binary arithmetic\n operations ("+", "-", "*", "/", "%", "divmod()", "pow()", "**",\n "<<", ">>", "&", "^", "|") with reflected (swapped) operands.\n These functions are only called if the left operand does not\n support the corresponding operation and the operands are of\n different types. [2] For instance, to evaluate the expression "x -\n y", where *y* is an instance of a class that has an "__rsub__()"\n method, "y.__rsub__(x)" is called if "x.__sub__(y)" returns\n *NotImplemented*.\n\n Note that ternary "pow()" will not try calling "__rpow__()" (the\n coercion rules would become too complicated).\n\n Note: If the right operand\'s type is a subclass of the left\n operand\'s type and that subclass provides the reflected method\n for the operation, this method will be called before the left\n operand\'s non-reflected method. This behavior allows subclasses\n to override their ancestors\' operations.\n\nobject.__iadd__(self, other)\nobject.__isub__(self, other)\nobject.__imul__(self, other)\nobject.__idiv__(self, other)\nobject.__itruediv__(self, other)\nobject.__ifloordiv__(self, other)\nobject.__imod__(self, other)\nobject.__ipow__(self, other[, modulo])\nobject.__ilshift__(self, other)\nobject.__irshift__(self, other)\nobject.__iand__(self, other)\nobject.__ixor__(self, other)\nobject.__ior__(self, other)\n\n These methods are called to implement the augmented arithmetic\n assignments ("+=", "-=", "*=", "/=", "//=", "%=", "**=", "<<=",\n ">>=", "&=", "^=", "|="). These methods should attempt to do the\n operation in-place (modifying *self*) and return the result (which\n could be, but does not have to be, *self*). If a specific method\n is not defined, the augmented assignment falls back to the normal\n methods. For instance, to execute the statement "x += y", where\n *x* is an instance of a class that has an "__iadd__()" method,\n "x.__iadd__(y)" is called. If *x* is an instance of a class that\n does not define a "__iadd__()" method, "x.__add__(y)" and\n "y.__radd__(x)" are considered, as with the evaluation of "x + y".\n\nobject.__neg__(self)\nobject.__pos__(self)\nobject.__abs__(self)\nobject.__invert__(self)\n\n Called to implement the unary arithmetic operations ("-", "+",\n "abs()" and "~").\n\nobject.__complex__(self)\nobject.__int__(self)\nobject.__long__(self)\nobject.__float__(self)\n\n Called to implement the built-in functions "complex()", "int()",\n "long()", and "float()". Should return a value of the appropriate\n type.\n\nobject.__oct__(self)\nobject.__hex__(self)\n\n Called to implement the built-in functions "oct()" and "hex()".\n Should return a string value.\n\nobject.__index__(self)\n\n Called to implement "operator.index()". Also called whenever\n Python needs an integer object (such as in slicing). Must return\n an integer (int or long).\n\n New in version 2.5.\n\nobject.__coerce__(self, other)\n\n Called to implement "mixed-mode" numeric arithmetic. Should either\n return a 2-tuple containing *self* and *other* converted to a\n common numeric type, or "None" if conversion is impossible. When\n the common type would be the type of "other", it is sufficient to\n return "None", since the interpreter will also ask the other object\n to attempt a coercion (but sometimes, if the implementation of the\n other type cannot be changed, it is useful to do the conversion to\n the other type here). A return value of "NotImplemented" is\n equivalent to returning "None".\n\n\nCoercion rules\n==============\n\nThis section used to document the rules for coercion. As the language\nhas evolved, the coercion rules have become hard to document\nprecisely; documenting what one version of one particular\nimplementation does is undesirable. Instead, here are some informal\nguidelines regarding coercion. In Python 3, coercion will not be\nsupported.\n\n* If the left operand of a % operator is a string or Unicode object,\n no coercion takes place and the string formatting operation is\n invoked instead.\n\n* It is no longer recommended to define a coercion operation. Mixed-\n mode operations on types that don\'t define coercion pass the\n original arguments to the operation.\n\n* New-style classes (those derived from "object") never invoke the\n "__coerce__()" method in response to a binary operator; the only\n time "__coerce__()" is invoked is when the built-in function\n "coerce()" is called.\n\n* For most intents and purposes, an operator that returns\n "NotImplemented" is treated the same as one that is not implemented\n at all.\n\n* Below, "__op__()" and "__rop__()" are used to signify the generic\n method names corresponding to an operator; "__iop__()" is used for\n the corresponding in-place operator. For example, for the operator\n \'"+"\', "__add__()" and "__radd__()" are used for the left and right\n variant of the binary operator, and "__iadd__()" for the in-place\n variant.\n\n* For objects *x* and *y*, first "x.__op__(y)" is tried. If this is\n not implemented or returns "NotImplemented", "y.__rop__(x)" is\n tried. If this is also not implemented or returns "NotImplemented",\n a "TypeError" exception is raised. But see the following exception:\n\n* Exception to the previous item: if the left operand is an instance\n of a built-in type or a new-style class, and the right operand is an\n instance of a proper subclass of that type or class and overrides\n the base\'s "__rop__()" method, the right operand\'s "__rop__()"\n method is tried *before* the left operand\'s "__op__()" method.\n\n This is done so that a subclass can completely override binary\n operators. Otherwise, the left operand\'s "__op__()" method would\n always accept the right operand: when an instance of a given class\n is expected, an instance of a subclass of that class is always\n acceptable.\n\n* When either operand type defines a coercion, this coercion is\n called before that type\'s "__op__()" or "__rop__()" method is\n called, but no sooner. If the coercion returns an object of a\n different type for the operand whose coercion is invoked, part of\n the process is redone using the new object.\n\n* When an in-place operator (like \'"+="\') is used, if the left\n operand implements "__iop__()", it is invoked without any coercion.\n When the operation falls back to "__op__()" and/or "__rop__()", the\n normal coercion rules apply.\n\n* In "x + y", if *x* is a sequence that implements sequence\n concatenation, sequence concatenation is invoked.\n\n* In "x * y", if one operand is a sequence that implements sequence\n repetition, and the other is an integer ("int" or "long"), sequence\n repetition is invoked.\n\n* Rich comparisons (implemented by methods "__eq__()" and so on)\n never use coercion. Three-way comparison (implemented by\n "__cmp__()") does use coercion under the same conditions as other\n binary operations use it.\n\n* In the current implementation, the built-in numeric types "int",\n "long", "float", and "complex" do not use coercion. All these types\n implement a "__coerce__()" method, for use by the built-in\n "coerce()" function.\n\n Changed in version 2.7: The complex type no longer makes implicit\n calls to the "__coerce__()" method for mixed-type binary arithmetic\n operations.\n\n\nWith Statement Context Managers\n===============================\n\nNew in version 2.5.\n\nA *context manager* is an object that defines the runtime context to\nbe established when executing a "with" statement. The context manager\nhandles the entry into, and the exit from, the desired runtime context\nfor the execution of the block of code. Context managers are normally\ninvoked using the "with" statement (described in section The with\nstatement), but can also be used by directly invoking their methods.\n\nTypical uses of context managers include saving and restoring various\nkinds of global state, locking and unlocking resources, closing opened\nfiles, etc.\n\nFor more information on context managers, see Context Manager Types.\n\nobject.__enter__(self)\n\n Enter the runtime context related to this object. The "with"\n statement will bind this method\'s return value to the target(s)\n specified in the "as" clause of the statement, if any.\n\nobject.__exit__(self, exc_type, exc_value, traceback)\n\n Exit the runtime context related to this object. The parameters\n describe the exception that caused the context to be exited. If the\n context was exited without an exception, all three arguments will\n be "None".\n\n If an exception is supplied, and the method wishes to suppress the\n exception (i.e., prevent it from being propagated), it should\n return a true value. Otherwise, the exception will be processed\n normally upon exit from this method.\n\n Note that "__exit__()" methods should not reraise the passed-in\n exception; this is the caller\'s responsibility.\n\nSee also:\n\n **PEP 343** - The "with" statement\n The specification, background, and examples for the Python "with"\n statement.\n\n\nSpecial method lookup for old-style classes\n===========================================\n\nFor old-style classes, special methods are always looked up in exactly\nthe same way as any other method or attribute. This is the case\nregardless of whether the method is being looked up explicitly as in\n"x.__getitem__(i)" or implicitly as in "x[i]".\n\nThis behaviour means that special methods may exhibit different\nbehaviour for different instances of a single old-style class if the\nappropriate special attributes are set differently:\n\n >>> class C:\n ... pass\n ...\n >>> c1 = C()\n >>> c2 = C()\n >>> c1.__len__ = lambda: 5\n >>> c2.__len__ = lambda: 9\n >>> len(c1)\n 5\n >>> len(c2)\n 9\n\n\nSpecial method lookup for new-style classes\n===========================================\n\nFor new-style classes, implicit invocations of special methods are\nonly guaranteed to work correctly if defined on an object\'s type, not\nin the object\'s instance dictionary. That behaviour is the reason why\nthe following code raises an exception (unlike the equivalent example\nwith old-style classes):\n\n >>> class C(object):\n ... pass\n ...\n >>> c = C()\n >>> c.__len__ = lambda: 5\n >>> len(c)\n Traceback (most recent call last):\n File "<stdin>", line 1, in <module>\n TypeError: object of type \'C\' has no len()\n\nThe rationale behind this behaviour lies with a number of special\nmethods such as "__hash__()" and "__repr__()" that are implemented by\nall objects, including type objects. If the implicit lookup of these\nmethods used the conventional lookup process, they would fail when\ninvoked on the type object itself:\n\n >>> 1 .__hash__() == hash(1)\n True\n >>> int.__hash__() == hash(int)\n Traceback (most recent call last):\n File "<stdin>", line 1, in <module>\n TypeError: descriptor \'__hash__\' of \'int\' object needs an argument\n\nIncorrectly attempting to invoke an unbound method of a class in this\nway is sometimes referred to as \'metaclass confusion\', and is avoided\nby bypassing the instance when looking up special methods:\n\n >>> type(1).__hash__(1) == hash(1)\n True\n >>> type(int).__hash__(int) == hash(int)\n True\n\nIn addition to bypassing any instance attributes in the interest of\ncorrectness, implicit special method lookup generally also bypasses\nthe "__getattribute__()" method even of the object\'s metaclass:\n\n >>> class Meta(type):\n ... def __getattribute__(*args):\n ... print "Metaclass getattribute invoked"\n ... return type.__getattribute__(*args)\n ...\n >>> class C(object):\n ... __metaclass__ = Meta\n ... def __len__(self):\n ... return 10\n ... def __getattribute__(*args):\n ... print "Class getattribute invoked"\n ... return object.__getattribute__(*args)\n ...\n >>> c = C()\n >>> c.__len__() # Explicit lookup via instance\n Class getattribute invoked\n 10\n >>> type(c).__len__(c) # Explicit lookup via type\n Metaclass getattribute invoked\n 10\n >>> len(c) # Implicit lookup\n 10\n\nBypassing the "__getattribute__()" machinery in this fashion provides\nsignificant scope for speed optimisations within the interpreter, at\nthe cost of some flexibility in the handling of special methods (the\nspecial method *must* be set on the class object itself in order to be\nconsistently invoked by the interpreter).\n\n-[ Footnotes ]-\n\n[1] It *is* possible in some cases to change an object\'s type,\n under certain controlled conditions. It generally isn\'t a good\n idea though, since it can lead to some very strange behaviour if\n it is handled incorrectly.\n\n[2] For operands of the same type, it is assumed that if the non-\n reflected method (such as "__add__()") fails the operation is not\n supported, which is why the reflected method is not called.\n',
+ 'string-methods': u'\nString Methods\n**************\n\nBelow are listed the string methods which both 8-bit strings and\nUnicode objects support. Some of them are also available on\n"bytearray" objects.\n\nIn addition, Python\'s strings support the sequence type methods\ndescribed in the Sequence Types --- str, unicode, list, tuple,\nbytearray, buffer, xrange section. To output formatted strings use\ntemplate strings or the "%" operator described in the String\nFormatting Operations section. Also, see the "re" module for string\nfunctions based on regular expressions.\n\nstr.capitalize()\n\n Return a copy of the string with its first character capitalized\n and the rest lowercased.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.center(width[, fillchar])\n\n Return centered in a string of length *width*. Padding is done\n using the specified *fillchar* (default is a space).\n\n Changed in version 2.4: Support for the *fillchar* argument.\n\nstr.count(sub[, start[, end]])\n\n Return the number of non-overlapping occurrences of substring *sub*\n in the range [*start*, *end*]. Optional arguments *start* and\n *end* are interpreted as in slice notation.\n\nstr.decode([encoding[, errors]])\n\n Decodes the string using the codec registered for *encoding*.\n *encoding* defaults to the default string encoding. *errors* may\n be given to set a different error handling scheme. The default is\n "\'strict\'", meaning that encoding errors raise "UnicodeError".\n Other possible values are "\'ignore\'", "\'replace\'" and any other\n name registered via "codecs.register_error()", see section Codec\n Base Classes.\n\n New in version 2.2.\n\n Changed in version 2.3: Support for other error handling schemes\n added.\n\n Changed in version 2.7: Support for keyword arguments added.\n\nstr.encode([encoding[, errors]])\n\n Return an encoded version of the string. Default encoding is the\n current default string encoding. *errors* may be given to set a\n different error handling scheme. The default for *errors* is\n "\'strict\'", meaning that encoding errors raise a "UnicodeError".\n Other possible values are "\'ignore\'", "\'replace\'",\n "\'xmlcharrefreplace\'", "\'backslashreplace\'" and any other name\n registered via "codecs.register_error()", see section Codec Base\n Classes. For a list of possible encodings, see section Standard\n Encodings.\n\n New in version 2.0.\n\n Changed in version 2.3: Support for "\'xmlcharrefreplace\'" and\n "\'backslashreplace\'" and other error handling schemes added.\n\n Changed in version 2.7: Support for keyword arguments added.\n\nstr.endswith(suffix[, start[, end]])\n\n Return "True" if the string ends with the specified *suffix*,\n otherwise return "False". *suffix* can also be a tuple of suffixes\n to look for. With optional *start*, test beginning at that\n position. With optional *end*, stop comparing at that position.\n\n Changed in version 2.5: Accept tuples as *suffix*.\n\nstr.expandtabs([tabsize])\n\n Return a copy of the string where all tab characters are replaced\n by one or more spaces, depending on the current column and the\n given tab size. Tab positions occur every *tabsize* characters\n (default is 8, giving tab positions at columns 0, 8, 16 and so on).\n To expand the string, the current column is set to zero and the\n string is examined character by character. If the character is a\n tab ("\\t"), one or more space characters are inserted in the result\n until the current column is equal to the next tab position. (The\n tab character itself is not copied.) If the character is a newline\n ("\\n") or return ("\\r"), it is copied and the current column is\n reset to zero. Any other character is copied unchanged and the\n current column is incremented by one regardless of how the\n character is represented when printed.\n\n >>> \'01\\t012\\t0123\\t01234\'.expandtabs()\n \'01 012 0123 01234\'\n >>> \'01\\t012\\t0123\\t01234\'.expandtabs(4)\n \'01 012 0123 01234\'\n\nstr.find(sub[, start[, end]])\n\n Return the lowest index in the string where substring *sub* is\n found within the slice "s[start:end]". Optional arguments *start*\n and *end* are interpreted as in slice notation. Return "-1" if\n *sub* is not found.\n\n Note: The "find()" method should be used only if you need to know\n the position of *sub*. To check if *sub* is a substring or not,\n use the "in" operator:\n\n >>> \'Py\' in \'Python\'\n True\n\nstr.format(*args, **kwargs)\n\n Perform a string formatting operation. The string on which this\n method is called can contain literal text or replacement fields\n delimited by braces "{}". Each replacement field contains either\n the numeric index of a positional argument, or the name of a\n keyword argument. Returns a copy of the string where each\n replacement field is replaced with the string value of the\n corresponding argument.\n\n >>> "The sum of 1 + 2 is {0}".format(1+2)\n \'The sum of 1 + 2 is 3\'\n\n See Format String Syntax for a description of the various\n formatting options that can be specified in format strings.\n\n This method of string formatting is the new standard in Python 3,\n and should be preferred to the "%" formatting described in String\n Formatting Operations in new code.\n\n New in version 2.6.\n\nstr.index(sub[, start[, end]])\n\n Like "find()", but raise "ValueError" when the substring is not\n found.\n\nstr.isalnum()\n\n Return true if all characters in the string are alphanumeric and\n there is at least one character, false otherwise.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.isalpha()\n\n Return true if all characters in the string are alphabetic and\n there is at least one character, false otherwise.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.isdigit()\n\n Return true if all characters in the string are digits and there is\n at least one character, false otherwise.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.islower()\n\n Return true if all cased characters [4] in the string are lowercase\n and there is at least one cased character, false otherwise.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.isspace()\n\n Return true if there are only whitespace characters in the string\n and there is at least one character, false otherwise.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.istitle()\n\n Return true if the string is a titlecased string and there is at\n least one character, for example uppercase characters may only\n follow uncased characters and lowercase characters only cased ones.\n Return false otherwise.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.isupper()\n\n Return true if all cased characters [4] in the string are uppercase\n and there is at least one cased character, false otherwise.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.join(iterable)\n\n Return a string which is the concatenation of the strings in the\n *iterable* *iterable*. The separator between elements is the\n string providing this method.\n\nstr.ljust(width[, fillchar])\n\n Return the string left justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to "len(s)".\n\n Changed in version 2.4: Support for the *fillchar* argument.\n\nstr.lower()\n\n Return a copy of the string with all the cased characters [4]\n converted to lowercase.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.lstrip([chars])\n\n Return a copy of the string with leading characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or "None", the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a prefix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.lstrip()\n \'spacious \'\n >>> \'www.example.com\'.lstrip(\'cmowz.\')\n \'example.com\'\n\n Changed in version 2.2.2: Support for the *chars* argument.\n\nstr.partition(sep)\n\n Split the string at the first occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing the string itself, followed by\n two empty strings.\n\n New in version 2.5.\n\nstr.replace(old, new[, count])\n\n Return a copy of the string with all occurrences of substring *old*\n replaced by *new*. If the optional argument *count* is given, only\n the first *count* occurrences are replaced.\n\nstr.rfind(sub[, start[, end]])\n\n Return the highest index in the string where substring *sub* is\n found, such that *sub* is contained within "s[start:end]".\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return "-1" on failure.\n\nstr.rindex(sub[, start[, end]])\n\n Like "rfind()" but raises "ValueError" when the substring *sub* is\n not found.\n\nstr.rjust(width[, fillchar])\n\n Return the string right justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to "len(s)".\n\n Changed in version 2.4: Support for the *fillchar* argument.\n\nstr.rpartition(sep)\n\n Split the string at the last occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing two empty strings, followed by\n the string itself.\n\n New in version 2.5.\n\nstr.rsplit([sep[, maxsplit]])\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit* splits\n are done, the *rightmost* ones. If *sep* is not specified or\n "None", any whitespace string is a separator. Except for splitting\n from the right, "rsplit()" behaves like "split()" which is\n described in detail below.\n\n New in version 2.4.\n\nstr.rstrip([chars])\n\n Return a copy of the string with trailing characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or "None", the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a suffix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.rstrip()\n \' spacious\'\n >>> \'mississippi\'.rstrip(\'ipz\')\n \'mississ\'\n\n Changed in version 2.2.2: Support for the *chars* argument.\n\nstr.split([sep[, maxsplit]])\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit*\n splits are done (thus, the list will have at most "maxsplit+1"\n elements). If *maxsplit* is not specified or "-1", then there is\n no limit on the number of splits (all possible splits are made).\n\n If *sep* is given, consecutive delimiters are not grouped together\n and are deemed to delimit empty strings (for example,\n "\'1,,2\'.split(\',\')" returns "[\'1\', \'\', \'2\']"). The *sep* argument\n may consist of multiple characters (for example,\n "\'1<>2<>3\'.split(\'<>\')" returns "[\'1\', \'2\', \'3\']"). Splitting an\n empty string with a specified separator returns "[\'\']".\n\n If *sep* is not specified or is "None", a different splitting\n algorithm is applied: runs of consecutive whitespace are regarded\n as a single separator, and the result will contain no empty strings\n at the start or end if the string has leading or trailing\n whitespace. Consequently, splitting an empty string or a string\n consisting of just whitespace with a "None" separator returns "[]".\n\n For example, "\' 1 2 3 \'.split()" returns "[\'1\', \'2\', \'3\']", and\n "\' 1 2 3 \'.split(None, 1)" returns "[\'1\', \'2 3 \']".\n\nstr.splitlines([keepends])\n\n Return a list of the lines in the string, breaking at line\n boundaries. This method uses the *universal newlines* approach to\n splitting lines. Line breaks are not included in the resulting list\n unless *keepends* is given and true.\n\n Python recognizes ""\\r"", ""\\n"", and ""\\r\\n"" as line boundaries\n for 8-bit strings.\n\n For example:\n\n >>> \'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()\n [\'ab c\', \'\', \'de fg\', \'kl\']\n >>> \'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines(True)\n [\'ab c\\n\', \'\\n\', \'de fg\\r\', \'kl\\r\\n\']\n\n Unlike "split()" when a delimiter string *sep* is given, this\n method returns an empty list for the empty string, and a terminal\n line break does not result in an extra line:\n\n >>> "".splitlines()\n []\n >>> "One line\\n".splitlines()\n [\'One line\']\n\n For comparison, "split(\'\\n\')" gives:\n\n >>> \'\'.split(\'\\n\')\n [\'\']\n >>> \'Two lines\\n\'.split(\'\\n\')\n [\'Two lines\', \'\']\n\nunicode.splitlines([keepends])\n\n Return a list of the lines in the string, like "str.splitlines()".\n However, the Unicode method splits on the following line\n boundaries, which are a superset of the *universal newlines*\n recognized for 8-bit strings.\n\n +-------------------------+-------------------------------+\n | Representation | Description |\n +=========================+===============================+\n | "\\n" | Line Feed |\n +-------------------------+-------------------------------+\n | "\\r" | Carriage Return |\n +-------------------------+-------------------------------+\n | "\\r\\n" | Carriage Return + Line Feed |\n +-------------------------+-------------------------------+\n | "\\v" or "\\x0b" | Line Tabulation |\n +-------------------------+-------------------------------+\n | "\\f" or "\\x0c" | Form Feed |\n +-------------------------+-------------------------------+\n | "\\x1c" | File Separator |\n +-------------------------+-------------------------------+\n | "\\x1d" | Group Separator |\n +-------------------------+-------------------------------+\n | "\\x1e" | Record Separator |\n +-------------------------+-------------------------------+\n | "\\x85" | Next Line (C1 Control Code) |\n +-------------------------+-------------------------------+\n | "\\u2028" | Line Separator |\n +-------------------------+-------------------------------+\n | "\\u2029" | Paragraph Separator |\n +-------------------------+-------------------------------+\n\n Changed in version 2.7: "\\v" and "\\f" added to list of line\n boundaries.\n\nstr.startswith(prefix[, start[, end]])\n\n Return "True" if string starts with the *prefix*, otherwise return\n "False". *prefix* can also be a tuple of prefixes to look for.\n With optional *start*, test string beginning at that position.\n With optional *end*, stop comparing string at that position.\n\n Changed in version 2.5: Accept tuples as *prefix*.\n\nstr.strip([chars])\n\n Return a copy of the string with the leading and trailing\n characters removed. The *chars* argument is a string specifying the\n set of characters to be removed. If omitted or "None", the *chars*\n argument defaults to removing whitespace. The *chars* argument is\n not a prefix or suffix; rather, all combinations of its values are\n stripped:\n\n >>> \' spacious \'.strip()\n \'spacious\'\n >>> \'www.example.com\'.strip(\'cmowz.\')\n \'example\'\n\n Changed in version 2.2.2: Support for the *chars* argument.\n\nstr.swapcase()\n\n Return a copy of the string with uppercase characters converted to\n lowercase and vice versa.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.title()\n\n Return a titlecased version of the string where words start with an\n uppercase character and the remaining characters are lowercase.\n\n The algorithm uses a simple language-independent definition of a\n word as groups of consecutive letters. The definition works in\n many contexts but it means that apostrophes in contractions and\n possessives form word boundaries, which may not be the desired\n result:\n\n >>> "they\'re bill\'s friends from the UK".title()\n "They\'Re Bill\'S Friends From The Uk"\n\n A workaround for apostrophes can be constructed using regular\n expressions:\n\n >>> import re\n >>> def titlecase(s):\n ... return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n ... lambda mo: mo.group(0)[0].upper() +\n ... mo.group(0)[1:].lower(),\n ... s)\n ...\n >>> titlecase("they\'re bill\'s friends.")\n "They\'re Bill\'s Friends."\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.translate(table[, deletechars])\n\n Return a copy of the string where all characters occurring in the\n optional argument *deletechars* are removed, and the remaining\n characters have been mapped through the given translation table,\n which must be a string of length 256.\n\n You can use the "maketrans()" helper function in the "string"\n module to create a translation table. For string objects, set the\n *table* argument to "None" for translations that only delete\n characters:\n\n >>> \'read this short text\'.translate(None, \'aeiou\')\n \'rd ths shrt txt\'\n\n New in version 2.6: Support for a "None" *table* argument.\n\n For Unicode objects, the "translate()" method does not accept the\n optional *deletechars* argument. Instead, it returns a copy of the\n *s* where all characters have been mapped through the given\n translation table which must be a mapping of Unicode ordinals to\n Unicode ordinals, Unicode strings or "None". Unmapped characters\n are left untouched. Characters mapped to "None" are deleted. Note,\n a more flexible approach is to create a custom character mapping\n codec using the "codecs" module (see "encodings.cp1251" for an\n example).\n\nstr.upper()\n\n Return a copy of the string with all the cased characters [4]\n converted to uppercase. Note that "str.upper().isupper()" might be\n "False" if "s" contains uncased characters or if the Unicode\n category of the resulting character(s) is not "Lu" (Letter,\n uppercase), but e.g. "Lt" (Letter, titlecase).\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.zfill(width)\n\n Return the numeric string left filled with zeros in a string of\n length *width*. A sign prefix is handled correctly. The original\n string is returned if *width* is less than or equal to "len(s)".\n\n New in version 2.2.2.\n\nThe following methods are present only on unicode objects:\n\nunicode.isnumeric()\n\n Return "True" if there are only numeric characters in S, "False"\n otherwise. Numeric characters include digit characters, and all\n characters that have the Unicode numeric value property, e.g.\n U+2155, VULGAR FRACTION ONE FIFTH.\n\nunicode.isdecimal()\n\n Return "True" if there are only decimal characters in S, "False"\n otherwise. Decimal characters include digit characters, and all\n characters that can be used to form decimal-radix numbers, e.g.\n U+0660, ARABIC-INDIC DIGIT ZERO.\n',
+ 'strings': u'\nString literals\n***************\n\nString literals are described by the following lexical definitions:\n\n stringliteral ::= [stringprefix](shortstring | longstring)\n stringprefix ::= "r" | "u" | "ur" | "R" | "U" | "UR" | "Ur" | "uR"\n | "b" | "B" | "br" | "Br" | "bR" | "BR"\n shortstring ::= "\'" shortstringitem* "\'" | \'"\' shortstringitem* \'"\'\n longstring ::= "\'\'\'" longstringitem* "\'\'\'"\n | \'"""\' longstringitem* \'"""\'\n shortstringitem ::= shortstringchar | escapeseq\n longstringitem ::= longstringchar | escapeseq\n shortstringchar ::= <any source character except "\\" or newline or the quote>\n longstringchar ::= <any source character except "\\">\n escapeseq ::= "\\" <any ASCII character>\n\nOne syntactic restriction not indicated by these productions is that\nwhitespace is not allowed between the "stringprefix" and the rest of\nthe string literal. The source character set is defined by the\nencoding declaration; it is ASCII if no encoding declaration is given\nin the source file; see section Encoding declarations.\n\nIn plain English: String literals can be enclosed in matching single\nquotes ("\'") or double quotes ("""). They can also be enclosed in\nmatching groups of three single or double quotes (these are generally\nreferred to as *triple-quoted strings*). The backslash ("\\")\ncharacter is used to escape characters that otherwise have a special\nmeaning, such as newline, backslash itself, or the quote character.\nString literals may optionally be prefixed with a letter "\'r\'" or\n"\'R\'"; such strings are called *raw strings* and use different rules\nfor interpreting backslash escape sequences. A prefix of "\'u\'" or\n"\'U\'" makes the string a Unicode string. Unicode strings use the\nUnicode character set as defined by the Unicode Consortium and ISO\n10646. Some additional escape sequences, described below, are\navailable in Unicode strings. A prefix of "\'b\'" or "\'B\'" is ignored in\nPython 2; it indicates that the literal should become a bytes literal\nin Python 3 (e.g. when code is automatically converted with 2to3). A\n"\'u\'" or "\'b\'" prefix may be followed by an "\'r\'" prefix.\n\nIn triple-quoted strings, unescaped newlines and quotes are allowed\n(and are retained), except that three unescaped quotes in a row\nterminate the string. (A "quote" is the character used to open the\nstring, i.e. either "\'" or """.)\n\nUnless an "\'r\'" or "\'R\'" prefix is present, escape sequences in\nstrings are interpreted according to rules similar to those used by\nStandard C. The recognized escape sequences are:\n\n+-------------------+-----------------------------------+---------+\n| Escape Sequence | Meaning | Notes |\n+===================+===================================+=========+\n| "\\newline" | Ignored | |\n+-------------------+-----------------------------------+---------+\n| "\\\\" | Backslash ("\\") | |\n+-------------------+-----------------------------------+---------+\n| "\\\'" | Single quote ("\'") | |\n+-------------------+-----------------------------------+---------+\n| "\\"" | Double quote (""") | |\n+-------------------+-----------------------------------+---------+\n| "\\a" | ASCII Bell (BEL) | |\n+-------------------+-----------------------------------+---------+\n| "\\b" | ASCII Backspace (BS) | |\n+-------------------+-----------------------------------+---------+\n| "\\f" | ASCII Formfeed (FF) | |\n+-------------------+-----------------------------------+---------+\n| "\\n" | ASCII Linefeed (LF) | |\n+-------------------+-----------------------------------+---------+\n| "\\N{name}" | Character named *name* in the | |\n| | Unicode database (Unicode only) | |\n+-------------------+-----------------------------------+---------+\n| "\\r" | ASCII Carriage Return (CR) | |\n+-------------------+-----------------------------------+---------+\n| "\\t" | ASCII Horizontal Tab (TAB) | |\n+-------------------+-----------------------------------+---------+\n| "\\uxxxx" | Character with 16-bit hex value | (1) |\n| | *xxxx* (Unicode only) | |\n+-------------------+-----------------------------------+---------+\n| "\\Uxxxxxxxx" | Character with 32-bit hex value | (2) |\n| | *xxxxxxxx* (Unicode only) | |\n+-------------------+-----------------------------------+---------+\n| "\\v" | ASCII Vertical Tab (VT) | |\n+-------------------+-----------------------------------+---------+\n| "\\ooo" | Character with octal value *ooo* | (3,5) |\n+-------------------+-----------------------------------+---------+\n| "\\xhh" | Character with hex value *hh* | (4,5) |\n+-------------------+-----------------------------------+---------+\n\nNotes:\n\n1. Individual code units which form parts of a surrogate pair can\n be encoded using this escape sequence.\n\n2. Any Unicode character can be encoded this way, but characters\n outside the Basic Multilingual Plane (BMP) will be encoded using a\n surrogate pair if Python is compiled to use 16-bit code units (the\n default).\n\n3. As in Standard C, up to three octal digits are accepted.\n\n4. Unlike in Standard C, exactly two hex digits are required.\n\n5. In a string literal, hexadecimal and octal escapes denote the\n byte with the given value; it is not necessary that the byte\n encodes a character in the source character set. In a Unicode\n literal, these escapes denote a Unicode character with the given\n value.\n\nUnlike Standard C, all unrecognized escape sequences are left in the\nstring unchanged, i.e., *the backslash is left in the string*. (This\nbehavior is useful when debugging: if an escape sequence is mistyped,\nthe resulting output is more easily recognized as broken.) It is also\nimportant to note that the escape sequences marked as "(Unicode only)"\nin the table above fall into the category of unrecognized escapes for\nnon-Unicode string literals.\n\nWhen an "\'r\'" or "\'R\'" prefix is present, a character following a\nbackslash is included in the string without change, and *all\nbackslashes are left in the string*. For example, the string literal\n"r"\\n"" consists of two characters: a backslash and a lowercase "\'n\'".\nString quotes can be escaped with a backslash, but the backslash\nremains in the string; for example, "r"\\""" is a valid string literal\nconsisting of two characters: a backslash and a double quote; "r"\\""\nis not a valid string literal (even a raw string cannot end in an odd\nnumber of backslashes). Specifically, *a raw string cannot end in a\nsingle backslash* (since the backslash would escape the following\nquote character). Note also that a single backslash followed by a\nnewline is interpreted as those two characters as part of the string,\n*not* as a line continuation.\n\nWhen an "\'r\'" or "\'R\'" prefix is used in conjunction with a "\'u\'" or\n"\'U\'" prefix, then the "\\uXXXX" and "\\UXXXXXXXX" escape sequences are\nprocessed while *all other backslashes are left in the string*. For\nexample, the string literal "ur"\\u0062\\n"" consists of three Unicode\ncharacters: \'LATIN SMALL LETTER B\', \'REVERSE SOLIDUS\', and \'LATIN\nSMALL LETTER N\'. Backslashes can be escaped with a preceding\nbackslash; however, both remain in the string. As a result, "\\uXXXX"\nescape sequences are only recognized when there are an odd number of\nbackslashes.\n',
+ 'subscriptions': u'\nSubscriptions\n*************\n\nA subscription selects an item of a sequence (string, tuple or list)\nor mapping (dictionary) object:\n\n subscription ::= primary "[" expression_list "]"\n\nThe primary must evaluate to an object of a sequence or mapping type.\n\nIf the primary is a mapping, the expression list must evaluate to an\nobject whose value is one of the keys of the mapping, and the\nsubscription selects the value in the mapping that corresponds to that\nkey. (The expression list is a tuple except if it has exactly one\nitem.)\n\nIf the primary is a sequence, the expression (list) must evaluate to a\nplain integer. If this value is negative, the length of the sequence\nis added to it (so that, e.g., "x[-1]" selects the last item of "x".)\nThe resulting value must be a nonnegative integer less than the number\nof items in the sequence, and the subscription selects the item whose\nindex is that value (counting from zero).\n\nA string\'s items are characters. A character is not a separate data\ntype but a string of exactly one character.\n',
+ 'truth': u'\nTruth Value Testing\n*******************\n\nAny object can be tested for truth value, for use in an "if" or\n"while" condition or as operand of the Boolean operations below. The\nfollowing values are considered false:\n\n* "None"\n\n* "False"\n\n* zero of any numeric type, for example, "0", "0L", "0.0", "0j".\n\n* any empty sequence, for example, "\'\'", "()", "[]".\n\n* any empty mapping, for example, "{}".\n\n* instances of user-defined classes, if the class defines a\n "__nonzero__()" or "__len__()" method, when that method returns the\n integer zero or "bool" value "False". [1]\n\nAll other values are considered true --- so objects of many types are\nalways true.\n\nOperations and built-in functions that have a Boolean result always\nreturn "0" or "False" for false and "1" or "True" for true, unless\notherwise stated. (Important exception: the Boolean operations "or"\nand "and" always return one of their operands.)\n',
+ 'try': u'\nThe "try" statement\n*******************\n\nThe "try" statement specifies exception handlers and/or cleanup code\nfor a group of statements:\n\n try_stmt ::= try1_stmt | try2_stmt\n try1_stmt ::= "try" ":" suite\n ("except" [expression [("as" | ",") identifier]] ":" suite)+\n ["else" ":" suite]\n ["finally" ":" suite]\n try2_stmt ::= "try" ":" suite\n "finally" ":" suite\n\nChanged in version 2.5: In previous versions of Python,\n"try"..."except"..."finally" did not work. "try"..."except" had to be\nnested in "try"..."finally".\n\nThe "except" clause(s) specify one or more exception handlers. When no\nexception occurs in the "try" clause, no exception handler is\nexecuted. When an exception occurs in the "try" suite, a search for an\nexception handler is started. This search inspects the except clauses\nin turn until one is found that matches the exception. An expression-\nless except clause, if present, must be last; it matches any\nexception. For an except clause with an expression, that expression\nis evaluated, and the clause matches the exception if the resulting\nobject is "compatible" with the exception. An object is compatible\nwith an exception if it is the class or a base class of the exception\nobject, or a tuple containing an item compatible with the exception.\n\nIf no except clause matches the exception, the search for an exception\nhandler continues in the surrounding code and on the invocation stack.\n[1]\n\nIf the evaluation of an expression in the header of an except clause\nraises an exception, the original search for a handler is canceled and\na search starts for the new exception in the surrounding code and on\nthe call stack (it is treated as if the entire "try" statement raised\nthe exception).\n\nWhen a matching except clause is found, the exception is assigned to\nthe target specified in that except clause, if present, and the except\nclause\'s suite is executed. All except clauses must have an\nexecutable block. When the end of this block is reached, execution\ncontinues normally after the entire try statement. (This means that\nif two nested handlers exist for the same exception, and the exception\noccurs in the try clause of the inner handler, the outer handler will\nnot handle the exception.)\n\nBefore an except clause\'s suite is executed, details about the\nexception are assigned to three variables in the "sys" module:\n"sys.exc_type" receives the object identifying the exception;\n"sys.exc_value" receives the exception\'s parameter;\n"sys.exc_traceback" receives a traceback object (see section The\nstandard type hierarchy) identifying the point in the program where\nthe exception occurred. These details are also available through the\n"sys.exc_info()" function, which returns a tuple "(exc_type,\nexc_value, exc_traceback)". Use of the corresponding variables is\ndeprecated in favor of this function, since their use is unsafe in a\nthreaded program. As of Python 1.5, the variables are restored to\ntheir previous values (before the call) when returning from a function\nthat handled an exception.\n\nThe optional "else" clause is executed if and when control flows off\nthe end of the "try" clause. [2] Exceptions in the "else" clause are\nnot handled by the preceding "except" clauses.\n\nIf "finally" is present, it specifies a \'cleanup\' handler. The "try"\nclause is executed, including any "except" and "else" clauses. If an\nexception occurs in any of the clauses and is not handled, the\nexception is temporarily saved. The "finally" clause is executed. If\nthere is a saved exception, it is re-raised at the end of the\n"finally" clause. If the "finally" clause raises another exception or\nexecutes a "return" or "break" statement, the saved exception is\ndiscarded:\n\n >>> def f():\n ... try:\n ... 1/0\n ... finally:\n ... return 42\n ...\n >>> f()\n 42\n\nThe exception information is not available to the program during\nexecution of the "finally" clause.\n\nWhen a "return", "break" or "continue" statement is executed in the\n"try" suite of a "try"..."finally" statement, the "finally" clause is\nalso executed \'on the way out.\' A "continue" statement is illegal in\nthe "finally" clause. (The reason is a problem with the current\nimplementation --- this restriction may be lifted in the future).\n\nThe return value of a function is determined by the last "return"\nstatement executed. Since the "finally" clause always executes, a\n"return" statement executed in the "finally" clause will always be the\nlast one executed:\n\n >>> def foo():\n ... try:\n ... return \'try\'\n ... finally:\n ... return \'finally\'\n ...\n >>> foo()\n \'finally\'\n\nAdditional information on exceptions can be found in section\nExceptions, and information on using the "raise" statement to generate\nexceptions may be found in section The raise statement.\n',
+ 'types': u'\nThe standard type hierarchy\n***************************\n\nBelow is a list of the types that are built into Python. Extension\nmodules (written in C, Java, or other languages, depending on the\nimplementation) can define additional types. Future versions of\nPython may add types to the type hierarchy (e.g., rational numbers,\nefficiently stored arrays of integers, etc.).\n\nSome of the type descriptions below contain a paragraph listing\n\'special attributes.\' These are attributes that provide access to the\nimplementation and are not intended for general use. Their definition\nmay change in the future.\n\nNone\n This type has a single value. There is a single object with this\n value. This object is accessed through the built-in name "None". It\n is used to signify the absence of a value in many situations, e.g.,\n it is returned from functions that don\'t explicitly return\n anything. Its truth value is false.\n\nNotImplemented\n This type has a single value. There is a single object with this\n value. This object is accessed through the built-in name\n "NotImplemented". Numeric methods and rich comparison methods may\n return this value if they do not implement the operation for the\n operands provided. (The interpreter will then try the reflected\n operation, or some other fallback, depending on the operator.) Its\n truth value is true.\n\nEllipsis\n This type has a single value. There is a single object with this\n value. This object is accessed through the built-in name\n "Ellipsis". It is used to indicate the presence of the "..." syntax\n in a slice. Its truth value is true.\n\n"numbers.Number"\n These are created by numeric literals and returned as results by\n arithmetic operators and arithmetic built-in functions. Numeric\n objects are immutable; once created their value never changes.\n Python numbers are of course strongly related to mathematical\n numbers, but subject to the limitations of numerical representation\n in computers.\n\n Python distinguishes between integers, floating point numbers, and\n complex numbers:\n\n "numbers.Integral"\n These represent elements from the mathematical set of integers\n (positive and negative).\n\n There are three types of integers:\n\n Plain integers\n These represent numbers in the range -2147483648 through\n 2147483647. (The range may be larger on machines with a\n larger natural word size, but not smaller.) When the result\n of an operation would fall outside this range, the result is\n normally returned as a long integer (in some cases, the\n exception "OverflowError" is raised instead). For the\n purpose of shift and mask operations, integers are assumed to\n have a binary, 2\'s complement notation using 32 or more bits,\n and hiding no bits from the user (i.e., all 4294967296\n different bit patterns correspond to different values).\n\n Long integers\n These represent numbers in an unlimited range, subject to\n available (virtual) memory only. For the purpose of shift\n and mask operations, a binary representation is assumed, and\n negative numbers are represented in a variant of 2\'s\n complement which gives the illusion of an infinite string of\n sign bits extending to the left.\n\n Booleans\n These represent the truth values False and True. The two\n objects representing the values "False" and "True" are the\n only Boolean objects. The Boolean type is a subtype of plain\n integers, and Boolean values behave like the values 0 and 1,\n respectively, in almost all contexts, the exception being\n that when converted to a string, the strings ""False"" or\n ""True"" are returned, respectively.\n\n The rules for integer representation are intended to give the\n most meaningful interpretation of shift and mask operations\n involving negative integers and the least surprises when\n switching between the plain and long integer domains. Any\n operation, if it yields a result in the plain integer domain,\n will yield the same result in the long integer domain or when\n using mixed operands. The switch between domains is transparent\n to the programmer.\n\n "numbers.Real" ("float")\n These represent machine-level double precision floating point\n numbers. You are at the mercy of the underlying machine\n architecture (and C or Java implementation) for the accepted\n range and handling of overflow. Python does not support single-\n precision floating point numbers; the savings in processor and\n memory usage that are usually the reason for using these are\n dwarfed by the overhead of using objects in Python, so there is\n no reason to complicate the language with two kinds of floating\n point numbers.\n\n "numbers.Complex"\n These represent complex numbers as a pair of machine-level\n double precision floating point numbers. The same caveats apply\n as for floating point numbers. The real and imaginary parts of a\n complex number "z" can be retrieved through the read-only\n attributes "z.real" and "z.imag".\n\nSequences\n These represent finite ordered sets indexed by non-negative\n numbers. The built-in function "len()" returns the number of items\n of a sequence. When the length of a sequence is *n*, the index set\n contains the numbers 0, 1, ..., *n*-1. Item *i* of sequence *a* is\n selected by "a[i]".\n\n Sequences also support slicing: "a[i:j]" selects all items with\n index *k* such that *i* "<=" *k* "<" *j*. When used as an\n expression, a slice is a sequence of the same type. This implies\n that the index set is renumbered so that it starts at 0.\n\n Some sequences also support "extended slicing" with a third "step"\n parameter: "a[i:j:k]" selects all items of *a* with index *x* where\n "x = i + n*k", *n* ">=" "0" and *i* "<=" *x* "<" *j*.\n\n Sequences are distinguished according to their mutability:\n\n Immutable sequences\n An object of an immutable sequence type cannot change once it is\n created. (If the object contains references to other objects,\n these other objects may be mutable and may be changed; however,\n the collection of objects directly referenced by an immutable\n object cannot change.)\n\n The following types are immutable sequences:\n\n Strings\n The items of a string are characters. There is no separate\n character type; a character is represented by a string of one\n item. Characters represent (at least) 8-bit bytes. The\n built-in functions "chr()" and "ord()" convert between\n characters and nonnegative integers representing the byte\n values. Bytes with the values 0--127 usually represent the\n corresponding ASCII values, but the interpretation of values\n is up to the program. The string data type is also used to\n represent arrays of bytes, e.g., to hold data read from a\n file.\n\n (On systems whose native character set is not ASCII, strings\n may use EBCDIC in their internal representation, provided the\n functions "chr()" and "ord()" implement a mapping between\n ASCII and EBCDIC, and string comparison preserves the ASCII\n order. Or perhaps someone can propose a better rule?)\n\n Unicode\n The items of a Unicode object are Unicode code units. A\n Unicode code unit is represented by a Unicode object of one\n item and can hold either a 16-bit or 32-bit value\n representing a Unicode ordinal (the maximum value for the\n ordinal is given in "sys.maxunicode", and depends on how\n Python is configured at compile time). Surrogate pairs may\n be present in the Unicode object, and will be reported as two\n separate items. The built-in functions "unichr()" and\n "ord()" convert between code units and nonnegative integers\n representing the Unicode ordinals as defined in the Unicode\n Standard 3.0. Conversion from and to other encodings are\n possible through the Unicode method "encode()" and the built-\n in function "unicode()".\n\n Tuples\n The items of a tuple are arbitrary Python objects. Tuples of\n two or more items are formed by comma-separated lists of\n expressions. A tuple of one item (a \'singleton\') can be\n formed by affixing a comma to an expression (an expression by\n itself does not create a tuple, since parentheses must be\n usable for grouping of expressions). An empty tuple can be\n formed by an empty pair of parentheses.\n\n Mutable sequences\n Mutable sequences can be changed after they are created. The\n subscription and slicing notations can be used as the target of\n assignment and "del" (delete) statements.\n\n There are currently two intrinsic mutable sequence types:\n\n Lists\n The items of a list are arbitrary Python objects. Lists are\n formed by placing a comma-separated list of expressions in\n square brackets. (Note that there are no special cases needed\n to form lists of length 0 or 1.)\n\n Byte Arrays\n A bytearray object is a mutable array. They are created by\n the built-in "bytearray()" constructor. Aside from being\n mutable (and hence unhashable), byte arrays otherwise provide\n the same interface and functionality as immutable bytes\n objects.\n\n The extension module "array" provides an additional example of a\n mutable sequence type.\n\nSet types\n These represent unordered, finite sets of unique, immutable\n objects. As such, they cannot be indexed by any subscript. However,\n they can be iterated over, and the built-in function "len()"\n returns the number of items in a set. Common uses for sets are fast\n membership testing, removing duplicates from a sequence, and\n computing mathematical operations such as intersection, union,\n difference, and symmetric difference.\n\n For set elements, the same immutability rules apply as for\n dictionary keys. Note that numeric types obey the normal rules for\n numeric comparison: if two numbers compare equal (e.g., "1" and\n "1.0"), only one of them can be contained in a set.\n\n There are currently two intrinsic set types:\n\n Sets\n These represent a mutable set. They are created by the built-in\n "set()" constructor and can be modified afterwards by several\n methods, such as "add()".\n\n Frozen sets\n These represent an immutable set. They are created by the\n built-in "frozenset()" constructor. As a frozenset is immutable\n and *hashable*, it can be used again as an element of another\n set, or as a dictionary key.\n\nMappings\n These represent finite sets of objects indexed by arbitrary index\n sets. The subscript notation "a[k]" selects the item indexed by "k"\n from the mapping "a"; this can be used in expressions and as the\n target of assignments or "del" statements. The built-in function\n "len()" returns the number of items in a mapping.\n\n There is currently a single intrinsic mapping type:\n\n Dictionaries\n These represent finite sets of objects indexed by nearly\n arbitrary values. The only types of values not acceptable as\n keys are values containing lists or dictionaries or other\n mutable types that are compared by value rather than by object\n identity, the reason being that the efficient implementation of\n dictionaries requires a key\'s hash value to remain constant.\n Numeric types used for keys obey the normal rules for numeric\n comparison: if two numbers compare equal (e.g., "1" and "1.0")\n then they can be used interchangeably to index the same\n dictionary entry.\n\n Dictionaries are mutable; they can be created by the "{...}"\n notation (see section Dictionary displays).\n\n The extension modules "dbm", "gdbm", and "bsddb" provide\n additional examples of mapping types.\n\nCallable types\n These are the types to which the function call operation (see\n section Calls) can be applied:\n\n User-defined functions\n A user-defined function object is created by a function\n definition (see section Function definitions). It should be\n called with an argument list containing the same number of items\n as the function\'s formal parameter list.\n\n Special attributes:\n\n +-------------------------+---------------------------------+-------------+\n | Attribute | Meaning | |\n +=========================+=================================+=============+\n | "__doc__" "func_doc" | The function\'s documentation | Writable |\n | | string, or "None" if | |\n | | unavailable. | |\n +-------------------------+---------------------------------+-------------+\n | "__name__" "func_name" | The function\'s name | Writable |\n +-------------------------+---------------------------------+-------------+\n | "__module__" | The name of the module the | Writable |\n | | function was defined in, or | |\n | | "None" if unavailable. | |\n +-------------------------+---------------------------------+-------------+\n | "__defaults__" | A tuple containing default | Writable |\n | "func_defaults" | argument values for those | |\n | | arguments that have defaults, | |\n | | or "None" if no arguments have | |\n | | a default value. | |\n +-------------------------+---------------------------------+-------------+\n | "__code__" "func_code" | The code object representing | Writable |\n | | the compiled function body. | |\n +-------------------------+---------------------------------+-------------+\n | "__globals__" | A reference to the dictionary | Read-only |\n | "func_globals" | that holds the function\'s | |\n | | global variables --- the global | |\n | | namespace of the module in | |\n | | which the function was defined. | |\n +-------------------------+---------------------------------+-------------+\n | "__dict__" "func_dict" | The namespace supporting | Writable |\n | | arbitrary function attributes. | |\n +-------------------------+---------------------------------+-------------+\n | "__closure__" | "None" or a tuple of cells that | Read-only |\n | "func_closure" | contain bindings for the | |\n | | function\'s free variables. | |\n +-------------------------+---------------------------------+-------------+\n\n Most of the attributes labelled "Writable" check the type of the\n assigned value.\n\n Changed in version 2.4: "func_name" is now writable.\n\n Changed in version 2.6: The double-underscore attributes\n "__closure__", "__code__", "__defaults__", and "__globals__"\n were introduced as aliases for the corresponding "func_*"\n attributes for forwards compatibility with Python 3.\n\n Function objects also support getting and setting arbitrary\n attributes, which can be used, for example, to attach metadata\n to functions. Regular attribute dot-notation is used to get and\n set such attributes. *Note that the current implementation only\n supports function attributes on user-defined functions. Function\n attributes on built-in functions may be supported in the\n future.*\n\n Additional information about a function\'s definition can be\n retrieved from its code object; see the description of internal\n types below.\n\n User-defined methods\n A user-defined method object combines a class, a class instance\n (or "None") and any callable object (normally a user-defined\n function).\n\n Special read-only attributes: "im_self" is the class instance\n object, "im_func" is the function object; "im_class" is the\n class of "im_self" for bound methods or the class that asked for\n the method for unbound methods; "__doc__" is the method\'s\n documentation (same as "im_func.__doc__"); "__name__" is the\n method name (same as "im_func.__name__"); "__module__" is the\n name of the module the method was defined in, or "None" if\n unavailable.\n\n Changed in version 2.2: "im_self" used to refer to the class\n that defined the method.\n\n Changed in version 2.6: For Python 3 forward-compatibility,\n "im_func" is also available as "__func__", and "im_self" as\n "__self__".\n\n Methods also support accessing (but not setting) the arbitrary\n function attributes on the underlying function object.\n\n User-defined method objects may be created when getting an\n attribute of a class (perhaps via an instance of that class), if\n that attribute is a user-defined function object, an unbound\n user-defined method object, or a class method object. When the\n attribute is a user-defined method object, a new method object\n is only created if the class from which it is being retrieved is\n the same as, or a derived class of, the class stored in the\n original method object; otherwise, the original method object is\n used as it is.\n\n When a user-defined method object is created by retrieving a\n user-defined function object from a class, its "im_self"\n attribute is "None" and the method object is said to be unbound.\n When one is created by retrieving a user-defined function object\n from a class via one of its instances, its "im_self" attribute\n is the instance, and the method object is said to be bound. In\n either case, the new method\'s "im_class" attribute is the class\n from which the retrieval takes place, and its "im_func"\n attribute is the original function object.\n\n When a user-defined method object is created by retrieving\n another method object from a class or instance, the behaviour is\n the same as for a function object, except that the "im_func"\n attribute of the new instance is not the original method object\n but its "im_func" attribute.\n\n When a user-defined method object is created by retrieving a\n class method object from a class or instance, its "im_self"\n attribute is the class itself, and its "im_func" attribute is\n the function object underlying the class method.\n\n When an unbound user-defined method object is called, the\n underlying function ("im_func") is called, with the restriction\n that the first argument must be an instance of the proper class\n ("im_class") or of a derived class thereof.\n\n When a bound user-defined method object is called, the\n underlying function ("im_func") is called, inserting the class\n instance ("im_self") in front of the argument list. For\n instance, when "C" is a class which contains a definition for a\n function "f()", and "x" is an instance of "C", calling "x.f(1)"\n is equivalent to calling "C.f(x, 1)".\n\n When a user-defined method object is derived from a class method\n object, the "class instance" stored in "im_self" will actually\n be the class itself, so that calling either "x.f(1)" or "C.f(1)"\n is equivalent to calling "f(C,1)" where "f" is the underlying\n function.\n\n Note that the transformation from function object to (unbound or\n bound) method object happens each time the attribute is\n retrieved from the class or instance. In some cases, a fruitful\n optimization is to assign the attribute to a local variable and\n call that local variable. Also notice that this transformation\n only happens for user-defined functions; other callable objects\n (and all non-callable objects) are retrieved without\n transformation. It is also important to note that user-defined\n functions which are attributes of a class instance are not\n converted to bound methods; this *only* happens when the\n function is an attribute of the class.\n\n Generator functions\n A function or method which uses the "yield" statement (see\n section The yield statement) is called a *generator function*.\n Such a function, when called, always returns an iterator object\n which can be used to execute the body of the function: calling\n the iterator\'s "next()" method will cause the function to\n execute until it provides a value using the "yield" statement.\n When the function executes a "return" statement or falls off the\n end, a "StopIteration" exception is raised and the iterator will\n have reached the end of the set of values to be returned.\n\n Built-in functions\n A built-in function object is a wrapper around a C function.\n Examples of built-in functions are "len()" and "math.sin()"\n ("math" is a standard built-in module). The number and type of\n the arguments are determined by the C function. Special read-\n only attributes: "__doc__" is the function\'s documentation\n string, or "None" if unavailable; "__name__" is the function\'s\n name; "__self__" is set to "None" (but see the next item);\n "__module__" is the name of the module the function was defined\n in or "None" if unavailable.\n\n Built-in methods\n This is really a different disguise of a built-in function, this\n time containing an object passed to the C function as an\n implicit extra argument. An example of a built-in method is\n "alist.append()", assuming *alist* is a list object. In this\n case, the special read-only attribute "__self__" is set to the\n object denoted by *alist*.\n\n Class Types\n Class types, or "new-style classes," are callable. These\n objects normally act as factories for new instances of\n themselves, but variations are possible for class types that\n override "__new__()". The arguments of the call are passed to\n "__new__()" and, in the typical case, to "__init__()" to\n initialize the new instance.\n\n Classic Classes\n Class objects are described below. When a class object is\n called, a new class instance (also described below) is created\n and returned. This implies a call to the class\'s "__init__()"\n method if it has one. Any arguments are passed on to the\n "__init__()" method. If there is no "__init__()" method, the\n class must be called without arguments.\n\n Class instances\n Class instances are described below. Class instances are\n callable only when the class has a "__call__()" method;\n "x(arguments)" is a shorthand for "x.__call__(arguments)".\n\nModules\n Modules are imported by the "import" statement (see section The\n import statement). A module object has a namespace implemented by a\n dictionary object (this is the dictionary referenced by the\n func_globals attribute of functions defined in the module).\n Attribute references are translated to lookups in this dictionary,\n e.g., "m.x" is equivalent to "m.__dict__["x"]". A module object\n does not contain the code object used to initialize the module\n (since it isn\'t needed once the initialization is done).\n\n Attribute assignment updates the module\'s namespace dictionary,\n e.g., "m.x = 1" is equivalent to "m.__dict__["x"] = 1".\n\n Special read-only attribute: "__dict__" is the module\'s namespace\n as a dictionary object.\n\n **CPython implementation detail:** Because of the way CPython\n clears module dictionaries, the module dictionary will be cleared\n when the module falls out of scope even if the dictionary still has\n live references. To avoid this, copy the dictionary or keep the\n module around while using its dictionary directly.\n\n Predefined (writable) attributes: "__name__" is the module\'s name;\n "__doc__" is the module\'s documentation string, or "None" if\n unavailable; "__file__" is the pathname of the file from which the\n module was loaded, if it was loaded from a file. The "__file__"\n attribute is not present for C modules that are statically linked\n into the interpreter; for extension modules loaded dynamically from\n a shared library, it is the pathname of the shared library file.\n\nClasses\n Both class types (new-style classes) and class objects (old-\n style/classic classes) are typically created by class definitions\n (see section Class definitions). A class has a namespace\n implemented by a dictionary object. Class attribute references are\n translated to lookups in this dictionary, e.g., "C.x" is translated\n to "C.__dict__["x"]" (although for new-style classes in particular\n there are a number of hooks which allow for other means of locating\n attributes). When the attribute name is not found there, the\n attribute search continues in the base classes. For old-style\n classes, the search is depth-first, left-to-right in the order of\n occurrence in the base class list. New-style classes use the more\n complex C3 method resolution order which behaves correctly even in\n the presence of \'diamond\' inheritance structures where there are\n multiple inheritance paths leading back to a common ancestor.\n Additional details on the C3 MRO used by new-style classes can be\n found in the documentation accompanying the 2.3 release at\n https://www.python.org/download/releases/2.3/mro/.\n\n When a class attribute reference (for class "C", say) would yield a\n user-defined function object or an unbound user-defined method\n object whose associated class is either "C" or one of its base\n classes, it is transformed into an unbound user-defined method\n object whose "im_class" attribute is "C". When it would yield a\n class method object, it is transformed into a bound user-defined\n method object whose "im_self" attribute is "C". When it would\n yield a static method object, it is transformed into the object\n wrapped by the static method object. See section Implementing\n Descriptors for another way in which attributes retrieved from a\n class may differ from those actually contained in its "__dict__"\n (note that only new-style classes support descriptors).\n\n Class attribute assignments update the class\'s dictionary, never\n the dictionary of a base class.\n\n A class object can be called (see above) to yield a class instance\n (see below).\n\n Special attributes: "__name__" is the class name; "__module__" is\n the module name in which the class was defined; "__dict__" is the\n dictionary containing the class\'s namespace; "__bases__" is a tuple\n (possibly empty or a singleton) containing the base classes, in the\n order of their occurrence in the base class list; "__doc__" is the\n class\'s documentation string, or "None" if undefined.\n\nClass instances\n A class instance is created by calling a class object (see above).\n A class instance has a namespace implemented as a dictionary which\n is the first place in which attribute references are searched.\n When an attribute is not found there, and the instance\'s class has\n an attribute by that name, the search continues with the class\n attributes. If a class attribute is found that is a user-defined\n function object or an unbound user-defined method object whose\n associated class is the class (call it "C") of the instance for\n which the attribute reference was initiated or one of its bases, it\n is transformed into a bound user-defined method object whose\n "im_class" attribute is "C" and whose "im_self" attribute is the\n instance. Static method and class method objects are also\n transformed, as if they had been retrieved from class "C"; see\n above under "Classes". See section Implementing Descriptors for\n another way in which attributes of a class retrieved via its\n instances may differ from the objects actually stored in the\n class\'s "__dict__". If no class attribute is found, and the\n object\'s class has a "__getattr__()" method, that is called to\n satisfy the lookup.\n\n Attribute assignments and deletions update the instance\'s\n dictionary, never a class\'s dictionary. If the class has a\n "__setattr__()" or "__delattr__()" method, this is called instead\n of updating the instance dictionary directly.\n\n Class instances can pretend to be numbers, sequences, or mappings\n if they have methods with certain special names. See section\n Special method names.\n\n Special attributes: "__dict__" is the attribute dictionary;\n "__class__" is the instance\'s class.\n\nFiles\n A file object represents an open file. File objects are created by\n the "open()" built-in function, and also by "os.popen()",\n "os.fdopen()", and the "makefile()" method of socket objects (and\n perhaps by other functions or methods provided by extension\n modules). The objects "sys.stdin", "sys.stdout" and "sys.stderr"\n are initialized to file objects corresponding to the interpreter\'s\n standard input, output and error streams. See File Objects for\n complete documentation of file objects.\n\nInternal types\n A few types used internally by the interpreter are exposed to the\n user. Their definitions may change with future versions of the\n interpreter, but they are mentioned here for completeness.\n\n Code objects\n Code objects represent *byte-compiled* executable Python code,\n or *bytecode*. The difference between a code object and a\n function object is that the function object contains an explicit\n reference to the function\'s globals (the module in which it was\n defined), while a code object contains no context; also the\n default argument values are stored in the function object, not\n in the code object (because they represent values calculated at\n run-time). Unlike function objects, code objects are immutable\n and contain no references (directly or indirectly) to mutable\n objects.\n\n Special read-only attributes: "co_name" gives the function name;\n "co_argcount" is the number of positional arguments (including\n arguments with default values); "co_nlocals" is the number of\n local variables used by the function (including arguments);\n "co_varnames" is a tuple containing the names of the local\n variables (starting with the argument names); "co_cellvars" is a\n tuple containing the names of local variables that are\n referenced by nested functions; "co_freevars" is a tuple\n containing the names of free variables; "co_code" is a string\n representing the sequence of bytecode instructions; "co_consts"\n is a tuple containing the literals used by the bytecode;\n "co_names" is a tuple containing the names used by the bytecode;\n "co_filename" is the filename from which the code was compiled;\n "co_firstlineno" is the first line number of the function;\n "co_lnotab" is a string encoding the mapping from bytecode\n offsets to line numbers (for details see the source code of the\n interpreter); "co_stacksize" is the required stack size\n (including local variables); "co_flags" is an integer encoding a\n number of flags for the interpreter.\n\n The following flag bits are defined for "co_flags": bit "0x04"\n is set if the function uses the "*arguments" syntax to accept an\n arbitrary number of positional arguments; bit "0x08" is set if\n the function uses the "**keywords" syntax to accept arbitrary\n keyword arguments; bit "0x20" is set if the function is a\n generator.\n\n Future feature declarations ("from __future__ import division")\n also use bits in "co_flags" to indicate whether a code object\n was compiled with a particular feature enabled: bit "0x2000" is\n set if the function was compiled with future division enabled;\n bits "0x10" and "0x1000" were used in earlier versions of\n Python.\n\n Other bits in "co_flags" are reserved for internal use.\n\n If a code object represents a function, the first item in\n "co_consts" is the documentation string of the function, or\n "None" if undefined.\n\n Frame objects\n Frame objects represent execution frames. They may occur in\n traceback objects (see below).\n\n Special read-only attributes: "f_back" is to the previous stack\n frame (towards the caller), or "None" if this is the bottom\n stack frame; "f_code" is the code object being executed in this\n frame; "f_locals" is the dictionary used to look up local\n variables; "f_globals" is used for global variables;\n "f_builtins" is used for built-in (intrinsic) names;\n "f_restricted" is a flag indicating whether the function is\n executing in restricted execution mode; "f_lasti" gives the\n precise instruction (this is an index into the bytecode string\n of the code object).\n\n Special writable attributes: "f_trace", if not "None", is a\n function called at the start of each source code line (this is\n used by the debugger); "f_exc_type", "f_exc_value",\n "f_exc_traceback" represent the last exception raised in the\n parent frame provided another exception was ever raised in the\n current frame (in all other cases they are "None"); "f_lineno"\n is the current line number of the frame --- writing to this from\n within a trace function jumps to the given line (only for the\n bottom-most frame). A debugger can implement a Jump command\n (aka Set Next Statement) by writing to f_lineno.\n\n Traceback objects\n Traceback objects represent a stack trace of an exception. A\n traceback object is created when an exception occurs. When the\n search for an exception handler unwinds the execution stack, at\n each unwound level a traceback object is inserted in front of\n the current traceback. When an exception handler is entered,\n the stack trace is made available to the program. (See section\n The try statement.) It is accessible as "sys.exc_traceback", and\n also as the third item of the tuple returned by\n "sys.exc_info()". The latter is the preferred interface, since\n it works correctly when the program is using multiple threads.\n When the program contains no suitable handler, the stack trace\n is written (nicely formatted) to the standard error stream; if\n the interpreter is interactive, it is also made available to the\n user as "sys.last_traceback".\n\n Special read-only attributes: "tb_next" is the next level in the\n stack trace (towards the frame where the exception occurred), or\n "None" if there is no next level; "tb_frame" points to the\n execution frame of the current level; "tb_lineno" gives the line\n number where the exception occurred; "tb_lasti" indicates the\n precise instruction. The line number and last instruction in\n the traceback may differ from the line number of its frame\n object if the exception occurred in a "try" statement with no\n matching except clause or with a finally clause.\n\n Slice objects\n Slice objects are used to represent slices when *extended slice\n syntax* is used. This is a slice using two colons, or multiple\n slices or ellipses separated by commas, e.g., "a[i:j:step]",\n "a[i:j, k:l]", or "a[..., i:j]". They are also created by the\n built-in "slice()" function.\n\n Special read-only attributes: "start" is the lower bound; "stop"\n is the upper bound; "step" is the step value; each is "None" if\n omitted. These attributes can have any type.\n\n Slice objects support one method:\n\n slice.indices(self, length)\n\n This method takes a single integer argument *length* and\n computes information about the extended slice that the slice\n object would describe if applied to a sequence of *length*\n items. It returns a tuple of three integers; respectively\n these are the *start* and *stop* indices and the *step* or\n stride length of the slice. Missing or out-of-bounds indices\n are handled in a manner consistent with regular slices.\n\n New in version 2.3.\n\n Static method objects\n Static method objects provide a way of defeating the\n transformation of function objects to method objects described\n above. A static method object is a wrapper around any other\n object, usually a user-defined method object. When a static\n method object is retrieved from a class or a class instance, the\n object actually returned is the wrapped object, which is not\n subject to any further transformation. Static method objects are\n not themselves callable, although the objects they wrap usually\n are. Static method objects are created by the built-in\n "staticmethod()" constructor.\n\n Class method objects\n A class method object, like a static method object, is a wrapper\n around another object that alters the way in which that object\n is retrieved from classes and class instances. The behaviour of\n class method objects upon such retrieval is described above,\n under "User-defined methods". Class method objects are created\n by the built-in "classmethod()" constructor.\n',
+ 'typesfunctions': u'\nFunctions\n*********\n\nFunction objects are created by function definitions. The only\noperation on a function object is to call it: "func(argument-list)".\n\nThere are really two flavors of function objects: built-in functions\nand user-defined functions. Both support the same operation (to call\nthe function), but the implementation is different, hence the\ndifferent object types.\n\nSee Function definitions for more information.\n',
+ 'typesmapping': u'\nMapping Types --- "dict"\n************************\n\nA *mapping* object maps *hashable* values to arbitrary objects.\nMappings are mutable objects. There is currently only one standard\nmapping type, the *dictionary*. (For other containers see the built\nin "list", "set", and "tuple" classes, and the "collections" module.)\n\nA dictionary\'s keys are *almost* arbitrary values. Values that are\nnot *hashable*, that is, values containing lists, dictionaries or\nother mutable types (that are compared by value rather than by object\nidentity) may not be used as keys. Numeric types used for keys obey\nthe normal rules for numeric comparison: if two numbers compare equal\n(such as "1" and "1.0") then they can be used interchangeably to index\nthe same dictionary entry. (Note however, that since computers store\nfloating-point numbers as approximations it is usually unwise to use\nthem as dictionary keys.)\n\nDictionaries can be created by placing a comma-separated list of "key:\nvalue" pairs within braces, for example: "{\'jack\': 4098, \'sjoerd\':\n4127}" or "{4098: \'jack\', 4127: \'sjoerd\'}", or by the "dict"\nconstructor.\n\nclass dict(**kwarg)\nclass dict(mapping, **kwarg)\nclass dict(iterable, **kwarg)\n\n Return a new dictionary initialized from an optional positional\n argument and a possibly empty set of keyword arguments.\n\n If no positional argument is given, an empty dictionary is created.\n If a positional argument is given and it is a mapping object, a\n dictionary is created with the same key-value pairs as the mapping\n object. Otherwise, the positional argument must be an *iterable*\n object. Each item in the iterable must itself be an iterable with\n exactly two objects. The first object of each item becomes a key\n in the new dictionary, and the second object the corresponding\n value. If a key occurs more than once, the last value for that key\n becomes the corresponding value in the new dictionary.\n\n If keyword arguments are given, the keyword arguments and their\n values are added to the dictionary created from the positional\n argument. If a key being added is already present, the value from\n the keyword argument replaces the value from the positional\n argument.\n\n To illustrate, the following examples all return a dictionary equal\n to "{"one": 1, "two": 2, "three": 3}":\n\n >>> a = dict(one=1, two=2, three=3)\n >>> b = {\'one\': 1, \'two\': 2, \'three\': 3}\n >>> c = dict(zip([\'one\', \'two\', \'three\'], [1, 2, 3]))\n >>> d = dict([(\'two\', 2), (\'one\', 1), (\'three\', 3)])\n >>> e = dict({\'three\': 3, \'one\': 1, \'two\': 2})\n >>> a == b == c == d == e\n True\n\n Providing keyword arguments as in the first example only works for\n keys that are valid Python identifiers. Otherwise, any valid keys\n can be used.\n\n New in version 2.2.\n\n Changed in version 2.3: Support for building a dictionary from\n keyword arguments added.\n\n These are the operations that dictionaries support (and therefore,\n custom mapping types should support too):\n\n len(d)\n\n Return the number of items in the dictionary *d*.\n\n d[key]\n\n Return the item of *d* with key *key*. Raises a "KeyError" if\n *key* is not in the map.\n\n If a subclass of dict defines a method "__missing__()" and *key*\n is not present, the "d[key]" operation calls that method with\n the key *key* as argument. The "d[key]" operation then returns\n or raises whatever is returned or raised by the\n "__missing__(key)" call. No other operations or methods invoke\n "__missing__()". If "__missing__()" is not defined, "KeyError"\n is raised. "__missing__()" must be a method; it cannot be an\n instance variable:\n\n >>> class Counter(dict):\n ... def __missing__(self, key):\n ... return 0\n >>> c = Counter()\n >>> c[\'red\']\n 0\n >>> c[\'red\'] += 1\n >>> c[\'red\']\n 1\n\n The example above shows part of the implementation of\n "collections.Counter". A different "__missing__" method is used\n by "collections.defaultdict".\n\n New in version 2.5: Recognition of __missing__ methods of dict\n subclasses.\n\n d[key] = value\n\n Set "d[key]" to *value*.\n\n del d[key]\n\n Remove "d[key]" from *d*. Raises a "KeyError" if *key* is not\n in the map.\n\n key in d\n\n Return "True" if *d* has a key *key*, else "False".\n\n New in version 2.2.\n\n key not in d\n\n Equivalent to "not key in d".\n\n New in version 2.2.\n\n iter(d)\n\n Return an iterator over the keys of the dictionary. This is a\n shortcut for "iterkeys()".\n\n clear()\n\n Remove all items from the dictionary.\n\n copy()\n\n Return a shallow copy of the dictionary.\n\n fromkeys(seq[, value])\n\n Create a new dictionary with keys from *seq* and values set to\n *value*.\n\n "fromkeys()" is a class method that returns a new dictionary.\n *value* defaults to "None".\n\n New in version 2.3.\n\n get(key[, default])\n\n Return the value for *key* if *key* is in the dictionary, else\n *default*. If *default* is not given, it defaults to "None", so\n that this method never raises a "KeyError".\n\n has_key(key)\n\n Test for the presence of *key* in the dictionary. "has_key()"\n is deprecated in favor of "key in d".\n\n items()\n\n Return a copy of the dictionary\'s list of "(key, value)" pairs.\n\n **CPython implementation detail:** Keys and values are listed in\n an arbitrary order which is non-random, varies across Python\n implementations, and depends on the dictionary\'s history of\n insertions and deletions.\n\n If "items()", "keys()", "values()", "iteritems()", "iterkeys()",\n and "itervalues()" are called with no intervening modifications\n to the dictionary, the lists will directly correspond. This\n allows the creation of "(value, key)" pairs using "zip()":\n "pairs = zip(d.values(), d.keys())". The same relationship\n holds for the "iterkeys()" and "itervalues()" methods: "pairs =\n zip(d.itervalues(), d.iterkeys())" provides the same value for\n "pairs". Another way to create the same list is "pairs = [(v, k)\n for (k, v) in d.iteritems()]".\n\n iteritems()\n\n Return an iterator over the dictionary\'s "(key, value)" pairs.\n See the note for "dict.items()".\n\n Using "iteritems()" while adding or deleting entries in the\n dictionary may raise a "RuntimeError" or fail to iterate over\n all entries.\n\n New in version 2.2.\n\n iterkeys()\n\n Return an iterator over the dictionary\'s keys. See the note for\n "dict.items()".\n\n Using "iterkeys()" while adding or deleting entries in the\n dictionary may raise a "RuntimeError" or fail to iterate over\n all entries.\n\n New in version 2.2.\n\n itervalues()\n\n Return an iterator over the dictionary\'s values. See the note\n for "dict.items()".\n\n Using "itervalues()" while adding or deleting entries in the\n dictionary may raise a "RuntimeError" or fail to iterate over\n all entries.\n\n New in version 2.2.\n\n keys()\n\n Return a copy of the dictionary\'s list of keys. See the note\n for "dict.items()".\n\n pop(key[, default])\n\n If *key* is in the dictionary, remove it and return its value,\n else return *default*. If *default* is not given and *key* is\n not in the dictionary, a "KeyError" is raised.\n\n New in version 2.3.\n\n popitem()\n\n Remove and return an arbitrary "(key, value)" pair from the\n dictionary.\n\n "popitem()" is useful to destructively iterate over a\n dictionary, as often used in set algorithms. If the dictionary\n is empty, calling "popitem()" raises a "KeyError".\n\n setdefault(key[, default])\n\n If *key* is in the dictionary, return its value. If not, insert\n *key* with a value of *default* and return *default*. *default*\n defaults to "None".\n\n update([other])\n\n Update the dictionary with the key/value pairs from *other*,\n overwriting existing keys. Return "None".\n\n "update()" accepts either another dictionary object or an\n iterable of key/value pairs (as tuples or other iterables of\n length two). If keyword arguments are specified, the dictionary\n is then updated with those key/value pairs: "d.update(red=1,\n blue=2)".\n\n Changed in version 2.4: Allowed the argument to be an iterable\n of key/value pairs and allowed keyword arguments.\n\n values()\n\n Return a copy of the dictionary\'s list of values. See the note\n for "dict.items()".\n\n viewitems()\n\n Return a new view of the dictionary\'s items ("(key, value)"\n pairs). See below for documentation of view objects.\n\n New in version 2.7.\n\n viewkeys()\n\n Return a new view of the dictionary\'s keys. See below for\n documentation of view objects.\n\n New in version 2.7.\n\n viewvalues()\n\n Return a new view of the dictionary\'s values. See below for\n documentation of view objects.\n\n New in version 2.7.\n\n Dictionaries compare equal if and only if they have the same "(key,\n value)" pairs.\n\n\nDictionary view objects\n=======================\n\nThe objects returned by "dict.viewkeys()", "dict.viewvalues()" and\n"dict.viewitems()" are *view objects*. They provide a dynamic view on\nthe dictionary\'s entries, which means that when the dictionary\nchanges, the view reflects these changes.\n\nDictionary views can be iterated over to yield their respective data,\nand support membership tests:\n\nlen(dictview)\n\n Return the number of entries in the dictionary.\n\niter(dictview)\n\n Return an iterator over the keys, values or items (represented as\n tuples of "(key, value)") in the dictionary.\n\n Keys and values are iterated over in an arbitrary order which is\n non-random, varies across Python implementations, and depends on\n the dictionary\'s history of insertions and deletions. If keys,\n values and items views are iterated over with no intervening\n modifications to the dictionary, the order of items will directly\n correspond. This allows the creation of "(value, key)" pairs using\n "zip()": "pairs = zip(d.values(), d.keys())". Another way to\n create the same list is "pairs = [(v, k) for (k, v) in d.items()]".\n\n Iterating views while adding or deleting entries in the dictionary\n may raise a "RuntimeError" or fail to iterate over all entries.\n\nx in dictview\n\n Return "True" if *x* is in the underlying dictionary\'s keys, values\n or items (in the latter case, *x* should be a "(key, value)"\n tuple).\n\nKeys views are set-like since their entries are unique and hashable.\nIf all values are hashable, so that (key, value) pairs are unique and\nhashable, then the items view is also set-like. (Values views are not\ntreated as set-like since the entries are generally not unique.) Then\nthese set operations are available ("other" refers either to another\nview or a set):\n\ndictview & other\n\n Return the intersection of the dictview and the other object as a\n new set.\n\ndictview | other\n\n Return the union of the dictview and the other object as a new set.\n\ndictview - other\n\n Return the difference between the dictview and the other object\n (all elements in *dictview* that aren\'t in *other*) as a new set.\n\ndictview ^ other\n\n Return the symmetric difference (all elements either in *dictview*\n or *other*, but not in both) of the dictview and the other object\n as a new set.\n\nAn example of dictionary view usage:\n\n >>> dishes = {\'eggs\': 2, \'sausage\': 1, \'bacon\': 1, \'spam\': 500}\n >>> keys = dishes.viewkeys()\n >>> values = dishes.viewvalues()\n\n >>> # iteration\n >>> n = 0\n >>> for val in values:\n ... n += val\n >>> print(n)\n 504\n\n >>> # keys and values are iterated over in the same order\n >>> list(keys)\n [\'eggs\', \'bacon\', \'sausage\', \'spam\']\n >>> list(values)\n [2, 1, 1, 500]\n\n >>> # view objects are dynamic and reflect dict changes\n >>> del dishes[\'eggs\']\n >>> del dishes[\'sausage\']\n >>> list(keys)\n [\'spam\', \'bacon\']\n\n >>> # set operations\n >>> keys & {\'eggs\', \'bacon\', \'salad\'}\n {\'bacon\'}\n',
+ 'typesmethods': u'\nMethods\n*******\n\nMethods are functions that are called using the attribute notation.\nThere are two flavors: built-in methods (such as "append()" on lists)\nand class instance methods. Built-in methods are described with the\ntypes that support them.\n\nThe implementation adds two special read-only attributes to class\ninstance methods: "m.im_self" is the object on which the method\noperates, and "m.im_func" is the function implementing the method.\nCalling "m(arg-1, arg-2, ..., arg-n)" is completely equivalent to\ncalling "m.im_func(m.im_self, arg-1, arg-2, ..., arg-n)".\n\nClass instance methods are either *bound* or *unbound*, referring to\nwhether the method was accessed through an instance or a class,\nrespectively. When a method is unbound, its "im_self" attribute will\nbe "None" and if called, an explicit "self" object must be passed as\nthe first argument. In this case, "self" must be an instance of the\nunbound method\'s class (or a subclass of that class), otherwise a\n"TypeError" is raised.\n\nLike function objects, methods objects support getting arbitrary\nattributes. However, since method attributes are actually stored on\nthe underlying function object ("meth.im_func"), setting method\nattributes on either bound or unbound methods is disallowed.\nAttempting to set an attribute on a method results in an\n"AttributeError" being raised. In order to set a method attribute,\nyou need to explicitly set it on the underlying function object:\n\n >>> class C:\n ... def method(self):\n ... pass\n ...\n >>> c = C()\n >>> c.method.whoami = \'my name is method\' # can\'t set on the method\n Traceback (most recent call last):\n File "<stdin>", line 1, in <module>\n AttributeError: \'instancemethod\' object has no attribute \'whoami\'\n >>> c.method.im_func.whoami = \'my name is method\'\n >>> c.method.whoami\n \'my name is method\'\n\nSee The standard type hierarchy for more information.\n',
+ 'typesmodules': u'\nModules\n*******\n\nThe only special operation on a module is attribute access: "m.name",\nwhere *m* is a module and *name* accesses a name defined in *m*\'s\nsymbol table. Module attributes can be assigned to. (Note that the\n"import" statement is not, strictly speaking, an operation on a module\nobject; "import foo" does not require a module object named *foo* to\nexist, rather it requires an (external) *definition* for a module\nnamed *foo* somewhere.)\n\nA special attribute of every module is "__dict__". This is the\ndictionary containing the module\'s symbol table. Modifying this\ndictionary will actually change the module\'s symbol table, but direct\nassignment to the "__dict__" attribute is not possible (you can write\n"m.__dict__[\'a\'] = 1", which defines "m.a" to be "1", but you can\'t\nwrite "m.__dict__ = {}"). Modifying "__dict__" directly is not\nrecommended.\n\nModules built into the interpreter are written like this: "<module\n\'sys\' (built-in)>". If loaded from a file, they are written as\n"<module \'os\' from \'/usr/local/lib/pythonX.Y/os.pyc\'>".\n',
+ 'typesseq': u'\nSequence Types --- "str", "unicode", "list", "tuple", "bytearray", "buffer", "xrange"\n*************************************************************************************\n\nThere are seven sequence types: strings, Unicode strings, lists,\ntuples, bytearrays, buffers, and xrange objects.\n\nFor other containers see the built in "dict" and "set" classes, and\nthe "collections" module.\n\nString literals are written in single or double quotes: "\'xyzzy\'",\n""frobozz"". See String literals for more about string literals.\nUnicode strings are much like strings, but are specified in the syntax\nusing a preceding "\'u\'" character: "u\'abc\'", "u"def"". In addition to\nthe functionality described here, there are also string-specific\nmethods described in the String Methods section. Lists are constructed\nwith square brackets, separating items with commas: "[a, b, c]".\nTuples are constructed by the comma operator (not within square\nbrackets), with or without enclosing parentheses, but an empty tuple\nmust have the enclosing parentheses, such as "a, b, c" or "()". A\nsingle item tuple must have a trailing comma, such as "(d,)".\n\nBytearray objects are created with the built-in function\n"bytearray()".\n\nBuffer objects are not directly supported by Python syntax, but can be\ncreated by calling the built-in function "buffer()". They don\'t\nsupport concatenation or repetition.\n\nObjects of type xrange are similar to buffers in that there is no\nspecific syntax to create them, but they are created using the\n"xrange()" function. They don\'t support slicing, concatenation or\nrepetition, and using "in", "not in", "min()" or "max()" on them is\ninefficient.\n\nMost sequence types support the following operations. The "in" and\n"not in" operations have the same priorities as the comparison\noperations. The "+" and "*" operations have the same priority as the\ncorresponding numeric operations. [3] Additional methods are provided\nfor Mutable Sequence Types.\n\nThis table lists the sequence operations sorted in ascending priority.\nIn the table, *s* and *t* are sequences of the same type; *n*, *i* and\n*j* are integers:\n\n+--------------------+----------------------------------+------------+\n| Operation | Result | Notes |\n+====================+==================================+============+\n| "x in s" | "True" if an item of *s* is | (1) |\n| | equal to *x*, else "False" | |\n+--------------------+----------------------------------+------------+\n| "x not in s" | "False" if an item of *s* is | (1) |\n| | equal to *x*, else "True" | |\n+--------------------+----------------------------------+------------+\n| "s + t" | the concatenation of *s* and *t* | (6) |\n+--------------------+----------------------------------+------------+\n| "s * n, n * s" | equivalent to adding *s* to | (2) |\n| | itself *n* times | |\n+--------------------+----------------------------------+------------+\n| "s[i]" | *i*th item of *s*, origin 0 | (3) |\n+--------------------+----------------------------------+------------+\n| "s[i:j]" | slice of *s* from *i* to *j* | (3)(4) |\n+--------------------+----------------------------------+------------+\n| "s[i:j:k]" | slice of *s* from *i* to *j* | (3)(5) |\n| | with step *k* | |\n+--------------------+----------------------------------+------------+\n| "len(s)" | length of *s* | |\n+--------------------+----------------------------------+------------+\n| "min(s)" | smallest item of *s* | |\n+--------------------+----------------------------------+------------+\n| "max(s)" | largest item of *s* | |\n+--------------------+----------------------------------+------------+\n| "s.index(x)" | index of the first occurrence of | |\n| | *x* in *s* | |\n+--------------------+----------------------------------+------------+\n| "s.count(x)" | total number of occurrences of | |\n| | *x* in *s* | |\n+--------------------+----------------------------------+------------+\n\nSequence types also support comparisons. In particular, tuples and\nlists are compared lexicographically by comparing corresponding\nelements. This means that to compare equal, every element must compare\nequal and the two sequences must be of the same type and have the same\nlength. (For full details see Comparisons in the language reference.)\n\nNotes:\n\n1. When *s* is a string or Unicode string object the "in" and "not\n in" operations act like a substring test. In Python versions\n before 2.3, *x* had to be a string of length 1. In Python 2.3 and\n beyond, *x* may be a string of any length.\n\n2. Values of *n* less than "0" are treated as "0" (which yields an\n empty sequence of the same type as *s*). Note that items in the\n sequence *s* are not copied; they are referenced multiple times.\n This often haunts new Python programmers; consider:\n\n >>> lists = [[]] * 3\n >>> lists\n [[], [], []]\n >>> lists[0].append(3)\n >>> lists\n [[3], [3], [3]]\n\n What has happened is that "[[]]" is a one-element list containing\n an empty list, so all three elements of "[[]] * 3" are references\n to this single empty list. Modifying any of the elements of\n "lists" modifies this single list. You can create a list of\n different lists this way:\n\n >>> lists = [[] for i in range(3)]\n >>> lists[0].append(3)\n >>> lists[1].append(5)\n >>> lists[2].append(7)\n >>> lists\n [[3], [5], [7]]\n\n Further explanation is available in the FAQ entry How do I create a\n multidimensional list?.\n\n3. If *i* or *j* is negative, the index is relative to the end of\n the string: "len(s) + i" or "len(s) + j" is substituted. But note\n that "-0" is still "0".\n\n4. The slice of *s* from *i* to *j* is defined as the sequence of\n items with index *k* such that "i <= k < j". If *i* or *j* is\n greater than "len(s)", use "len(s)". If *i* is omitted or "None",\n use "0". If *j* is omitted or "None", use "len(s)". If *i* is\n greater than or equal to *j*, the slice is empty.\n\n5. The slice of *s* from *i* to *j* with step *k* is defined as the\n sequence of items with index "x = i + n*k" such that "0 <= n <\n (j-i)/k". In other words, the indices are "i", "i+k", "i+2*k",\n "i+3*k" and so on, stopping when *j* is reached (but never\n including *j*). If *i* or *j* is greater than "len(s)", use\n "len(s)". If *i* or *j* are omitted or "None", they become "end"\n values (which end depends on the sign of *k*). Note, *k* cannot be\n zero. If *k* is "None", it is treated like "1".\n\n6. **CPython implementation detail:** If *s* and *t* are both\n strings, some Python implementations such as CPython can usually\n perform an in-place optimization for assignments of the form "s = s\n + t" or "s += t". When applicable, this optimization makes\n quadratic run-time much less likely. This optimization is both\n version and implementation dependent. For performance sensitive\n code, it is preferable to use the "str.join()" method which assures\n consistent linear concatenation performance across versions and\n implementations.\n\n Changed in version 2.4: Formerly, string concatenation never\n occurred in-place.\n\n\nString Methods\n==============\n\nBelow are listed the string methods which both 8-bit strings and\nUnicode objects support. Some of them are also available on\n"bytearray" objects.\n\nIn addition, Python\'s strings support the sequence type methods\ndescribed in the Sequence Types --- str, unicode, list, tuple,\nbytearray, buffer, xrange section. To output formatted strings use\ntemplate strings or the "%" operator described in the String\nFormatting Operations section. Also, see the "re" module for string\nfunctions based on regular expressions.\n\nstr.capitalize()\n\n Return a copy of the string with its first character capitalized\n and the rest lowercased.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.center(width[, fillchar])\n\n Return centered in a string of length *width*. Padding is done\n using the specified *fillchar* (default is a space).\n\n Changed in version 2.4: Support for the *fillchar* argument.\n\nstr.count(sub[, start[, end]])\n\n Return the number of non-overlapping occurrences of substring *sub*\n in the range [*start*, *end*]. Optional arguments *start* and\n *end* are interpreted as in slice notation.\n\nstr.decode([encoding[, errors]])\n\n Decodes the string using the codec registered for *encoding*.\n *encoding* defaults to the default string encoding. *errors* may\n be given to set a different error handling scheme. The default is\n "\'strict\'", meaning that encoding errors raise "UnicodeError".\n Other possible values are "\'ignore\'", "\'replace\'" and any other\n name registered via "codecs.register_error()", see section Codec\n Base Classes.\n\n New in version 2.2.\n\n Changed in version 2.3: Support for other error handling schemes\n added.\n\n Changed in version 2.7: Support for keyword arguments added.\n\nstr.encode([encoding[, errors]])\n\n Return an encoded version of the string. Default encoding is the\n current default string encoding. *errors* may be given to set a\n different error handling scheme. The default for *errors* is\n "\'strict\'", meaning that encoding errors raise a "UnicodeError".\n Other possible values are "\'ignore\'", "\'replace\'",\n "\'xmlcharrefreplace\'", "\'backslashreplace\'" and any other name\n registered via "codecs.register_error()", see section Codec Base\n Classes. For a list of possible encodings, see section Standard\n Encodings.\n\n New in version 2.0.\n\n Changed in version 2.3: Support for "\'xmlcharrefreplace\'" and\n "\'backslashreplace\'" and other error handling schemes added.\n\n Changed in version 2.7: Support for keyword arguments added.\n\nstr.endswith(suffix[, start[, end]])\n\n Return "True" if the string ends with the specified *suffix*,\n otherwise return "False". *suffix* can also be a tuple of suffixes\n to look for. With optional *start*, test beginning at that\n position. With optional *end*, stop comparing at that position.\n\n Changed in version 2.5: Accept tuples as *suffix*.\n\nstr.expandtabs([tabsize])\n\n Return a copy of the string where all tab characters are replaced\n by one or more spaces, depending on the current column and the\n given tab size. Tab positions occur every *tabsize* characters\n (default is 8, giving tab positions at columns 0, 8, 16 and so on).\n To expand the string, the current column is set to zero and the\n string is examined character by character. If the character is a\n tab ("\\t"), one or more space characters are inserted in the result\n until the current column is equal to the next tab position. (The\n tab character itself is not copied.) If the character is a newline\n ("\\n") or return ("\\r"), it is copied and the current column is\n reset to zero. Any other character is copied unchanged and the\n current column is incremented by one regardless of how the\n character is represented when printed.\n\n >>> \'01\\t012\\t0123\\t01234\'.expandtabs()\n \'01 012 0123 01234\'\n >>> \'01\\t012\\t0123\\t01234\'.expandtabs(4)\n \'01 012 0123 01234\'\n\nstr.find(sub[, start[, end]])\n\n Return the lowest index in the string where substring *sub* is\n found within the slice "s[start:end]". Optional arguments *start*\n and *end* are interpreted as in slice notation. Return "-1" if\n *sub* is not found.\n\n Note: The "find()" method should be used only if you need to know\n the position of *sub*. To check if *sub* is a substring or not,\n use the "in" operator:\n\n >>> \'Py\' in \'Python\'\n True\n\nstr.format(*args, **kwargs)\n\n Perform a string formatting operation. The string on which this\n method is called can contain literal text or replacement fields\n delimited by braces "{}". Each replacement field contains either\n the numeric index of a positional argument, or the name of a\n keyword argument. Returns a copy of the string where each\n replacement field is replaced with the string value of the\n corresponding argument.\n\n >>> "The sum of 1 + 2 is {0}".format(1+2)\n \'The sum of 1 + 2 is 3\'\n\n See Format String Syntax for a description of the various\n formatting options that can be specified in format strings.\n\n This method of string formatting is the new standard in Python 3,\n and should be preferred to the "%" formatting described in String\n Formatting Operations in new code.\n\n New in version 2.6.\n\nstr.index(sub[, start[, end]])\n\n Like "find()", but raise "ValueError" when the substring is not\n found.\n\nstr.isalnum()\n\n Return true if all characters in the string are alphanumeric and\n there is at least one character, false otherwise.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.isalpha()\n\n Return true if all characters in the string are alphabetic and\n there is at least one character, false otherwise.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.isdigit()\n\n Return true if all characters in the string are digits and there is\n at least one character, false otherwise.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.islower()\n\n Return true if all cased characters [4] in the string are lowercase\n and there is at least one cased character, false otherwise.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.isspace()\n\n Return true if there are only whitespace characters in the string\n and there is at least one character, false otherwise.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.istitle()\n\n Return true if the string is a titlecased string and there is at\n least one character, for example uppercase characters may only\n follow uncased characters and lowercase characters only cased ones.\n Return false otherwise.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.isupper()\n\n Return true if all cased characters [4] in the string are uppercase\n and there is at least one cased character, false otherwise.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.join(iterable)\n\n Return a string which is the concatenation of the strings in the\n *iterable* *iterable*. The separator between elements is the\n string providing this method.\n\nstr.ljust(width[, fillchar])\n\n Return the string left justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to "len(s)".\n\n Changed in version 2.4: Support for the *fillchar* argument.\n\nstr.lower()\n\n Return a copy of the string with all the cased characters [4]\n converted to lowercase.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.lstrip([chars])\n\n Return a copy of the string with leading characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or "None", the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a prefix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.lstrip()\n \'spacious \'\n >>> \'www.example.com\'.lstrip(\'cmowz.\')\n \'example.com\'\n\n Changed in version 2.2.2: Support for the *chars* argument.\n\nstr.partition(sep)\n\n Split the string at the first occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing the string itself, followed by\n two empty strings.\n\n New in version 2.5.\n\nstr.replace(old, new[, count])\n\n Return a copy of the string with all occurrences of substring *old*\n replaced by *new*. If the optional argument *count* is given, only\n the first *count* occurrences are replaced.\n\nstr.rfind(sub[, start[, end]])\n\n Return the highest index in the string where substring *sub* is\n found, such that *sub* is contained within "s[start:end]".\n Optional arguments *start* and *end* are interpreted as in slice\n notation. Return "-1" on failure.\n\nstr.rindex(sub[, start[, end]])\n\n Like "rfind()" but raises "ValueError" when the substring *sub* is\n not found.\n\nstr.rjust(width[, fillchar])\n\n Return the string right justified in a string of length *width*.\n Padding is done using the specified *fillchar* (default is a\n space). The original string is returned if *width* is less than or\n equal to "len(s)".\n\n Changed in version 2.4: Support for the *fillchar* argument.\n\nstr.rpartition(sep)\n\n Split the string at the last occurrence of *sep*, and return a\n 3-tuple containing the part before the separator, the separator\n itself, and the part after the separator. If the separator is not\n found, return a 3-tuple containing two empty strings, followed by\n the string itself.\n\n New in version 2.5.\n\nstr.rsplit([sep[, maxsplit]])\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit* splits\n are done, the *rightmost* ones. If *sep* is not specified or\n "None", any whitespace string is a separator. Except for splitting\n from the right, "rsplit()" behaves like "split()" which is\n described in detail below.\n\n New in version 2.4.\n\nstr.rstrip([chars])\n\n Return a copy of the string with trailing characters removed. The\n *chars* argument is a string specifying the set of characters to be\n removed. If omitted or "None", the *chars* argument defaults to\n removing whitespace. The *chars* argument is not a suffix; rather,\n all combinations of its values are stripped:\n\n >>> \' spacious \'.rstrip()\n \' spacious\'\n >>> \'mississippi\'.rstrip(\'ipz\')\n \'mississ\'\n\n Changed in version 2.2.2: Support for the *chars* argument.\n\nstr.split([sep[, maxsplit]])\n\n Return a list of the words in the string, using *sep* as the\n delimiter string. If *maxsplit* is given, at most *maxsplit*\n splits are done (thus, the list will have at most "maxsplit+1"\n elements). If *maxsplit* is not specified or "-1", then there is\n no limit on the number of splits (all possible splits are made).\n\n If *sep* is given, consecutive delimiters are not grouped together\n and are deemed to delimit empty strings (for example,\n "\'1,,2\'.split(\',\')" returns "[\'1\', \'\', \'2\']"). The *sep* argument\n may consist of multiple characters (for example,\n "\'1<>2<>3\'.split(\'<>\')" returns "[\'1\', \'2\', \'3\']"). Splitting an\n empty string with a specified separator returns "[\'\']".\n\n If *sep* is not specified or is "None", a different splitting\n algorithm is applied: runs of consecutive whitespace are regarded\n as a single separator, and the result will contain no empty strings\n at the start or end if the string has leading or trailing\n whitespace. Consequently, splitting an empty string or a string\n consisting of just whitespace with a "None" separator returns "[]".\n\n For example, "\' 1 2 3 \'.split()" returns "[\'1\', \'2\', \'3\']", and\n "\' 1 2 3 \'.split(None, 1)" returns "[\'1\', \'2 3 \']".\n\nstr.splitlines([keepends])\n\n Return a list of the lines in the string, breaking at line\n boundaries. This method uses the *universal newlines* approach to\n splitting lines. Line breaks are not included in the resulting list\n unless *keepends* is given and true.\n\n Python recognizes ""\\r"", ""\\n"", and ""\\r\\n"" as line boundaries\n for 8-bit strings.\n\n For example:\n\n >>> \'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines()\n [\'ab c\', \'\', \'de fg\', \'kl\']\n >>> \'ab c\\n\\nde fg\\rkl\\r\\n\'.splitlines(True)\n [\'ab c\\n\', \'\\n\', \'de fg\\r\', \'kl\\r\\n\']\n\n Unlike "split()" when a delimiter string *sep* is given, this\n method returns an empty list for the empty string, and a terminal\n line break does not result in an extra line:\n\n >>> "".splitlines()\n []\n >>> "One line\\n".splitlines()\n [\'One line\']\n\n For comparison, "split(\'\\n\')" gives:\n\n >>> \'\'.split(\'\\n\')\n [\'\']\n >>> \'Two lines\\n\'.split(\'\\n\')\n [\'Two lines\', \'\']\n\nunicode.splitlines([keepends])\n\n Return a list of the lines in the string, like "str.splitlines()".\n However, the Unicode method splits on the following line\n boundaries, which are a superset of the *universal newlines*\n recognized for 8-bit strings.\n\n +-------------------------+-------------------------------+\n | Representation | Description |\n +=========================+===============================+\n | "\\n" | Line Feed |\n +-------------------------+-------------------------------+\n | "\\r" | Carriage Return |\n +-------------------------+-------------------------------+\n | "\\r\\n" | Carriage Return + Line Feed |\n +-------------------------+-------------------------------+\n | "\\v" or "\\x0b" | Line Tabulation |\n +-------------------------+-------------------------------+\n | "\\f" or "\\x0c" | Form Feed |\n +-------------------------+-------------------------------+\n | "\\x1c" | File Separator |\n +-------------------------+-------------------------------+\n | "\\x1d" | Group Separator |\n +-------------------------+-------------------------------+\n | "\\x1e" | Record Separator |\n +-------------------------+-------------------------------+\n | "\\x85" | Next Line (C1 Control Code) |\n +-------------------------+-------------------------------+\n | "\\u2028" | Line Separator |\n +-------------------------+-------------------------------+\n | "\\u2029" | Paragraph Separator |\n +-------------------------+-------------------------------+\n\n Changed in version 2.7: "\\v" and "\\f" added to list of line\n boundaries.\n\nstr.startswith(prefix[, start[, end]])\n\n Return "True" if string starts with the *prefix*, otherwise return\n "False". *prefix* can also be a tuple of prefixes to look for.\n With optional *start*, test string beginning at that position.\n With optional *end*, stop comparing string at that position.\n\n Changed in version 2.5: Accept tuples as *prefix*.\n\nstr.strip([chars])\n\n Return a copy of the string with the leading and trailing\n characters removed. The *chars* argument is a string specifying the\n set of characters to be removed. If omitted or "None", the *chars*\n argument defaults to removing whitespace. The *chars* argument is\n not a prefix or suffix; rather, all combinations of its values are\n stripped:\n\n >>> \' spacious \'.strip()\n \'spacious\'\n >>> \'www.example.com\'.strip(\'cmowz.\')\n \'example\'\n\n Changed in version 2.2.2: Support for the *chars* argument.\n\nstr.swapcase()\n\n Return a copy of the string with uppercase characters converted to\n lowercase and vice versa.\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.title()\n\n Return a titlecased version of the string where words start with an\n uppercase character and the remaining characters are lowercase.\n\n The algorithm uses a simple language-independent definition of a\n word as groups of consecutive letters. The definition works in\n many contexts but it means that apostrophes in contractions and\n possessives form word boundaries, which may not be the desired\n result:\n\n >>> "they\'re bill\'s friends from the UK".title()\n "They\'Re Bill\'S Friends From The Uk"\n\n A workaround for apostrophes can be constructed using regular\n expressions:\n\n >>> import re\n >>> def titlecase(s):\n ... return re.sub(r"[A-Za-z]+(\'[A-Za-z]+)?",\n ... lambda mo: mo.group(0)[0].upper() +\n ... mo.group(0)[1:].lower(),\n ... s)\n ...\n >>> titlecase("they\'re bill\'s friends.")\n "They\'re Bill\'s Friends."\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.translate(table[, deletechars])\n\n Return a copy of the string where all characters occurring in the\n optional argument *deletechars* are removed, and the remaining\n characters have been mapped through the given translation table,\n which must be a string of length 256.\n\n You can use the "maketrans()" helper function in the "string"\n module to create a translation table. For string objects, set the\n *table* argument to "None" for translations that only delete\n characters:\n\n >>> \'read this short text\'.translate(None, \'aeiou\')\n \'rd ths shrt txt\'\n\n New in version 2.6: Support for a "None" *table* argument.\n\n For Unicode objects, the "translate()" method does not accept the\n optional *deletechars* argument. Instead, it returns a copy of the\n *s* where all characters have been mapped through the given\n translation table which must be a mapping of Unicode ordinals to\n Unicode ordinals, Unicode strings or "None". Unmapped characters\n are left untouched. Characters mapped to "None" are deleted. Note,\n a more flexible approach is to create a custom character mapping\n codec using the "codecs" module (see "encodings.cp1251" for an\n example).\n\nstr.upper()\n\n Return a copy of the string with all the cased characters [4]\n converted to uppercase. Note that "str.upper().isupper()" might be\n "False" if "s" contains uncased characters or if the Unicode\n category of the resulting character(s) is not "Lu" (Letter,\n uppercase), but e.g. "Lt" (Letter, titlecase).\n\n For 8-bit strings, this method is locale-dependent.\n\nstr.zfill(width)\n\n Return the numeric string left filled with zeros in a string of\n length *width*. A sign prefix is handled correctly. The original\n string is returned if *width* is less than or equal to "len(s)".\n\n New in version 2.2.2.\n\nThe following methods are present only on unicode objects:\n\nunicode.isnumeric()\n\n Return "True" if there are only numeric characters in S, "False"\n otherwise. Numeric characters include digit characters, and all\n characters that have the Unicode numeric value property, e.g.\n U+2155, VULGAR FRACTION ONE FIFTH.\n\nunicode.isdecimal()\n\n Return "True" if there are only decimal characters in S, "False"\n otherwise. Decimal characters include digit characters, and all\n characters that can be used to form decimal-radix numbers, e.g.\n U+0660, ARABIC-INDIC DIGIT ZERO.\n\n\nString Formatting Operations\n============================\n\nString and Unicode objects have one unique built-in operation: the "%"\noperator (modulo). This is also known as the string *formatting* or\n*interpolation* operator. Given "format % values" (where *format* is\na string or Unicode object), "%" conversion specifications in *format*\nare replaced with zero or more elements of *values*. The effect is\nsimilar to the using "sprintf()" in the C language. If *format* is a\nUnicode object, or if any of the objects being converted using the\n"%s" conversion are Unicode objects, the result will also be a Unicode\nobject.\n\nIf *format* requires a single argument, *values* may be a single non-\ntuple object. [5] Otherwise, *values* must be a tuple with exactly\nthe number of items specified by the format string, or a single\nmapping object (for example, a dictionary).\n\nA conversion specifier contains two or more characters and has the\nfollowing components, which must occur in this order:\n\n1. The "\'%\'" character, which marks the start of the specifier.\n\n2. Mapping key (optional), consisting of a parenthesised sequence\n of characters (for example, "(somename)").\n\n3. Conversion flags (optional), which affect the result of some\n conversion types.\n\n4. Minimum field width (optional). If specified as an "\'*\'"\n (asterisk), the actual width is read from the next element of the\n tuple in *values*, and the object to convert comes after the\n minimum field width and optional precision.\n\n5. Precision (optional), given as a "\'.\'" (dot) followed by the\n precision. If specified as "\'*\'" (an asterisk), the actual width\n is read from the next element of the tuple in *values*, and the\n value to convert comes after the precision.\n\n6. Length modifier (optional).\n\n7. Conversion type.\n\nWhen the right argument is a dictionary (or other mapping type), then\nthe formats in the string *must* include a parenthesised mapping key\ninto that dictionary inserted immediately after the "\'%\'" character.\nThe mapping key selects the value to be formatted from the mapping.\nFor example:\n\n>>> print \'%(language)s has %(number)03d quote types.\' % \\\n... {"language": "Python", "number": 2}\nPython has 002 quote types.\n\nIn this case no "*" specifiers may occur in a format (since they\nrequire a sequential parameter list).\n\nThe conversion flag characters are:\n\n+-----------+-----------------------------------------------------------------------+\n| Flag | Meaning |\n+===========+=======================================================================+\n| "\'#\'" | The value conversion will use the "alternate form" (where defined |\n| | below). |\n+-----------+-----------------------------------------------------------------------+\n| "\'0\'" | The conversion will be zero padded for numeric values. |\n+-----------+-----------------------------------------------------------------------+\n| "\'-\'" | The converted value is left adjusted (overrides the "\'0\'" conversion |\n| | if both are given). |\n+-----------+-----------------------------------------------------------------------+\n| "\' \'" | (a space) A blank should be left before a positive number (or empty |\n| | string) produced by a signed conversion. |\n+-----------+-----------------------------------------------------------------------+\n| "\'+\'" | A sign character ("\'+\'" or "\'-\'") will precede the conversion |\n| | (overrides a "space" flag). |\n+-----------+-----------------------------------------------------------------------+\n\nA length modifier ("h", "l", or "L") may be present, but is ignored as\nit is not necessary for Python -- so e.g. "%ld" is identical to "%d".\n\nThe conversion types are:\n\n+--------------+-------------------------------------------------------+---------+\n| Conversion | Meaning | Notes |\n+==============+=======================================================+=========+\n| "\'d\'" | Signed integer decimal. | |\n+--------------+-------------------------------------------------------+---------+\n| "\'i\'" | Signed integer decimal. | |\n+--------------+-------------------------------------------------------+---------+\n| "\'o\'" | Signed octal value. | (1) |\n+--------------+-------------------------------------------------------+---------+\n| "\'u\'" | Obsolete type -- it is identical to "\'d\'". | (7) |\n+--------------+-------------------------------------------------------+---------+\n| "\'x\'" | Signed hexadecimal (lowercase). | (2) |\n+--------------+-------------------------------------------------------+---------+\n| "\'X\'" | Signed hexadecimal (uppercase). | (2) |\n+--------------+-------------------------------------------------------+---------+\n| "\'e\'" | Floating point exponential format (lowercase). | (3) |\n+--------------+-------------------------------------------------------+---------+\n| "\'E\'" | Floating point exponential format (uppercase). | (3) |\n+--------------+-------------------------------------------------------+---------+\n| "\'f\'" | Floating point decimal format. | (3) |\n+--------------+-------------------------------------------------------+---------+\n| "\'F\'" | Floating point decimal format. | (3) |\n+--------------+-------------------------------------------------------+---------+\n| "\'g\'" | Floating point format. Uses lowercase exponential | (4) |\n| | format if exponent is less than -4 or not less than | |\n| | precision, decimal format otherwise. | |\n+--------------+-------------------------------------------------------+---------+\n| "\'G\'" | Floating point format. Uses uppercase exponential | (4) |\n| | format if exponent is less than -4 or not less than | |\n| | precision, decimal format otherwise. | |\n+--------------+-------------------------------------------------------+---------+\n| "\'c\'" | Single character (accepts integer or single character | |\n| | string). | |\n+--------------+-------------------------------------------------------+---------+\n| "\'r\'" | String (converts any Python object using repr()). | (5) |\n+--------------+-------------------------------------------------------+---------+\n| "\'s\'" | String (converts any Python object using "str()"). | (6) |\n+--------------+-------------------------------------------------------+---------+\n| "\'%\'" | No argument is converted, results in a "\'%\'" | |\n| | character in the result. | |\n+--------------+-------------------------------------------------------+---------+\n\nNotes:\n\n1. The alternate form causes a leading zero ("\'0\'") to be inserted\n between left-hand padding and the formatting of the number if the\n leading character of the result is not already a zero.\n\n2. The alternate form causes a leading "\'0x\'" or "\'0X\'" (depending\n on whether the "\'x\'" or "\'X\'" format was used) to be inserted\n between left-hand padding and the formatting of the number if the\n leading character of the result is not already a zero.\n\n3. The alternate form causes the result to always contain a decimal\n point, even if no digits follow it.\n\n The precision determines the number of digits after the decimal\n point and defaults to 6.\n\n4. The alternate form causes the result to always contain a decimal\n point, and trailing zeroes are not removed as they would otherwise\n be.\n\n The precision determines the number of significant digits before\n and after the decimal point and defaults to 6.\n\n5. The "%r" conversion was added in Python 2.0.\n\n The precision determines the maximal number of characters used.\n\n6. If the object or format provided is a "unicode" string, the\n resulting string will also be "unicode".\n\n The precision determines the maximal number of characters used.\n\n7. See **PEP 237**.\n\nSince Python strings have an explicit length, "%s" conversions do not\nassume that "\'\\0\'" is the end of the string.\n\nChanged in version 2.7: "%f" conversions for numbers whose absolute\nvalue is over 1e50 are no longer replaced by "%g" conversions.\n\nAdditional string operations are defined in standard modules "string"\nand "re".\n\n\nXRange Type\n===========\n\nThe "xrange" type is an immutable sequence which is commonly used for\nlooping. The advantage of the "xrange" type is that an "xrange"\nobject will always take the same amount of memory, no matter the size\nof the range it represents. There are no consistent performance\nadvantages.\n\nXRange objects have very little behavior: they only support indexing,\niteration, and the "len()" function.\n\n\nMutable Sequence Types\n======================\n\nList and "bytearray" objects support additional operations that allow\nin-place modification of the object. Other mutable sequence types\n(when added to the language) should also support these operations.\nStrings and tuples are immutable sequence types: such objects cannot\nbe modified once created. The following operations are defined on\nmutable sequence types (where *x* is an arbitrary object):\n\n+--------------------------------+----------------------------------+-----------------------+\n| Operation | Result | Notes |\n+================================+==================================+=======================+\n| "s[i] = x" | item *i* of *s* is replaced by | |\n| | *x* | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s[i:j] = t" | slice of *s* from *i* to *j* is | |\n| | replaced by the contents of the | |\n| | iterable *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| "del s[i:j]" | same as "s[i:j] = []" | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s[i:j:k] = t" | the elements of "s[i:j:k]" are | (1) |\n| | replaced by those of *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| "del s[i:j:k]" | removes the elements of | |\n| | "s[i:j:k]" from the list | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.append(x)" | same as "s[len(s):len(s)] = [x]" | (2) |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.extend(t)" or "s += t" | for the most part the same as | (3) |\n| | "s[len(s):len(s)] = t" | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s *= n" | updates *s* with its contents | (11) |\n| | repeated *n* times | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.count(x)" | return number of *i*\'s for which | |\n| | "s[i] == x" | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.index(x[, i[, j]])" | return smallest *k* such that | (4) |\n| | "s[k] == x" and "i <= k < j" | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.insert(i, x)" | same as "s[i:i] = [x]" | (5) |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.pop([i])" | same as "x = s[i]; del s[i]; | (6) |\n| | return x" | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.remove(x)" | same as "del s[s.index(x)]" | (4) |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.reverse()" | reverses the items of *s* in | (7) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.sort([cmp[, key[, | sort the items of *s* in place | (7)(8)(9)(10) |\n| reverse]]])" | | |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. The C implementation of Python has historically accepted\n multiple parameters and implicitly joined them into a tuple; this\n no longer works in Python 2.0. Use of this misfeature has been\n deprecated since Python 1.4.\n\n3. *t* can be any iterable object.\n\n4. Raises "ValueError" when *x* is not found in *s*. When a\n negative index is passed as the second or third parameter to the\n "index()" method, the list length is added, as for slice indices.\n If it is still negative, it is truncated to zero, as for slice\n indices.\n\n Changed in version 2.3: Previously, "index()" didn\'t have arguments\n for specifying start and stop positions.\n\n5. When a negative index is passed as the first parameter to the\n "insert()" method, the list length is added, as for slice indices.\n If it is still negative, it is truncated to zero, as for slice\n indices.\n\n Changed in version 2.3: Previously, all negative indices were\n truncated to zero.\n\n6. The "pop()" method\'s optional argument *i* defaults to "-1", so\n that by default the last item is removed and returned.\n\n7. The "sort()" and "reverse()" methods modify the list in place\n for economy of space when sorting or reversing a large list. To\n remind you that they operate by side effect, they don\'t return the\n sorted or reversed list.\n\n8. The "sort()" method takes optional arguments for controlling the\n comparisons.\n\n *cmp* specifies a custom comparison function of two arguments (list\n items) which should return a negative, zero or positive number\n depending on whether the first argument is considered smaller than,\n equal to, or larger than the second argument: "cmp=lambda x,y:\n cmp(x.lower(), y.lower())". The default value is "None".\n\n *key* specifies a function of one argument that is used to extract\n a comparison key from each list element: "key=str.lower". The\n default value is "None".\n\n *reverse* is a boolean value. If set to "True", then the list\n elements are sorted as if each comparison were reversed.\n\n In general, the *key* and *reverse* conversion processes are much\n faster than specifying an equivalent *cmp* function. This is\n because *cmp* is called multiple times for each list element while\n *key* and *reverse* touch each element only once. Use\n "functools.cmp_to_key()" to convert an old-style *cmp* function to\n a *key* function.\n\n Changed in version 2.3: Support for "None" as an equivalent to\n omitting *cmp* was added.\n\n Changed in version 2.4: Support for *key* and *reverse* was added.\n\n9. Starting with Python 2.3, the "sort()" method is guaranteed to\n be stable. A sort is stable if it guarantees not to change the\n relative order of elements that compare equal --- this is helpful\n for sorting in multiple passes (for example, sort by department,\n then by salary grade).\n\n10. **CPython implementation detail:** While a list is being\n sorted, the effect of attempting to mutate, or even inspect, the\n list is undefined. The C implementation of Python 2.3 and newer\n makes the list appear empty for the duration, and raises\n "ValueError" if it can detect that the list has been mutated\n during a sort.\n\n11. The value *n* is an integer, or an object implementing\n "__index__()". Zero and negative values of *n* clear the\n sequence. Items in the sequence are not copied; they are\n referenced multiple times, as explained for "s * n" under Sequence\n Types --- str, unicode, list, tuple, bytearray, buffer, xrange.\n',
+ 'typesseq-mutable': u'\nMutable Sequence Types\n**********************\n\nList and "bytearray" objects support additional operations that allow\nin-place modification of the object. Other mutable sequence types\n(when added to the language) should also support these operations.\nStrings and tuples are immutable sequence types: such objects cannot\nbe modified once created. The following operations are defined on\nmutable sequence types (where *x* is an arbitrary object):\n\n+--------------------------------+----------------------------------+-----------------------+\n| Operation | Result | Notes |\n+================================+==================================+=======================+\n| "s[i] = x" | item *i* of *s* is replaced by | |\n| | *x* | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s[i:j] = t" | slice of *s* from *i* to *j* is | |\n| | replaced by the contents of the | |\n| | iterable *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| "del s[i:j]" | same as "s[i:j] = []" | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s[i:j:k] = t" | the elements of "s[i:j:k]" are | (1) |\n| | replaced by those of *t* | |\n+--------------------------------+----------------------------------+-----------------------+\n| "del s[i:j:k]" | removes the elements of | |\n| | "s[i:j:k]" from the list | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.append(x)" | same as "s[len(s):len(s)] = [x]" | (2) |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.extend(t)" or "s += t" | for the most part the same as | (3) |\n| | "s[len(s):len(s)] = t" | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s *= n" | updates *s* with its contents | (11) |\n| | repeated *n* times | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.count(x)" | return number of *i*\'s for which | |\n| | "s[i] == x" | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.index(x[, i[, j]])" | return smallest *k* such that | (4) |\n| | "s[k] == x" and "i <= k < j" | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.insert(i, x)" | same as "s[i:i] = [x]" | (5) |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.pop([i])" | same as "x = s[i]; del s[i]; | (6) |\n| | return x" | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.remove(x)" | same as "del s[s.index(x)]" | (4) |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.reverse()" | reverses the items of *s* in | (7) |\n| | place | |\n+--------------------------------+----------------------------------+-----------------------+\n| "s.sort([cmp[, key[, | sort the items of *s* in place | (7)(8)(9)(10) |\n| reverse]]])" | | |\n+--------------------------------+----------------------------------+-----------------------+\n\nNotes:\n\n1. *t* must have the same length as the slice it is replacing.\n\n2. The C implementation of Python has historically accepted\n multiple parameters and implicitly joined them into a tuple; this\n no longer works in Python 2.0. Use of this misfeature has been\n deprecated since Python 1.4.\n\n3. *t* can be any iterable object.\n\n4. Raises "ValueError" when *x* is not found in *s*. When a\n negative index is passed as the second or third parameter to the\n "index()" method, the list length is added, as for slice indices.\n If it is still negative, it is truncated to zero, as for slice\n indices.\n\n Changed in version 2.3: Previously, "index()" didn\'t have arguments\n for specifying start and stop positions.\n\n5. When a negative index is passed as the first parameter to the\n "insert()" method, the list length is added, as for slice indices.\n If it is still negative, it is truncated to zero, as for slice\n indices.\n\n Changed in version 2.3: Previously, all negative indices were\n truncated to zero.\n\n6. The "pop()" method\'s optional argument *i* defaults to "-1", so\n that by default the last item is removed and returned.\n\n7. The "sort()" and "reverse()" methods modify the list in place\n for economy of space when sorting or reversing a large list. To\n remind you that they operate by side effect, they don\'t return the\n sorted or reversed list.\n\n8. The "sort()" method takes optional arguments for controlling the\n comparisons.\n\n *cmp* specifies a custom comparison function of two arguments (list\n items) which should return a negative, zero or positive number\n depending on whether the first argument is considered smaller than,\n equal to, or larger than the second argument: "cmp=lambda x,y:\n cmp(x.lower(), y.lower())". The default value is "None".\n\n *key* specifies a function of one argument that is used to extract\n a comparison key from each list element: "key=str.lower". The\n default value is "None".\n\n *reverse* is a boolean value. If set to "True", then the list\n elements are sorted as if each comparison were reversed.\n\n In general, the *key* and *reverse* conversion processes are much\n faster than specifying an equivalent *cmp* function. This is\n because *cmp* is called multiple times for each list element while\n *key* and *reverse* touch each element only once. Use\n "functools.cmp_to_key()" to convert an old-style *cmp* function to\n a *key* function.\n\n Changed in version 2.3: Support for "None" as an equivalent to\n omitting *cmp* was added.\n\n Changed in version 2.4: Support for *key* and *reverse* was added.\n\n9. Starting with Python 2.3, the "sort()" method is guaranteed to\n be stable. A sort is stable if it guarantees not to change the\n relative order of elements that compare equal --- this is helpful\n for sorting in multiple passes (for example, sort by department,\n then by salary grade).\n\n10. **CPython implementation detail:** While a list is being\n sorted, the effect of attempting to mutate, or even inspect, the\n list is undefined. The C implementation of Python 2.3 and newer\n makes the list appear empty for the duration, and raises\n "ValueError" if it can detect that the list has been mutated\n during a sort.\n\n11. The value *n* is an integer, or an object implementing\n "__index__()". Zero and negative values of *n* clear the\n sequence. Items in the sequence are not copied; they are\n referenced multiple times, as explained for "s * n" under Sequence\n Types --- str, unicode, list, tuple, bytearray, buffer, xrange.\n',
+ 'unary': u'\nUnary arithmetic and bitwise operations\n***************************************\n\nAll unary arithmetic and bitwise operations have the same priority:\n\n u_expr ::= power | "-" u_expr | "+" u_expr | "~" u_expr\n\nThe unary "-" (minus) operator yields the negation of its numeric\nargument.\n\nThe unary "+" (plus) operator yields its numeric argument unchanged.\n\nThe unary "~" (invert) operator yields the bitwise inversion of its\nplain or long integer argument. The bitwise inversion of "x" is\ndefined as "-(x+1)". It only applies to integral numbers.\n\nIn all three cases, if the argument does not have the proper type, a\n"TypeError" exception is raised.\n',
+ 'while': u'\nThe "while" statement\n*********************\n\nThe "while" statement is used for repeated execution as long as an\nexpression is true:\n\n while_stmt ::= "while" expression ":" suite\n ["else" ":" suite]\n\nThis repeatedly tests the expression and, if it is true, executes the\nfirst suite; if the expression is false (which may be the first time\nit is tested) the suite of the "else" clause, if present, is executed\nand the loop terminates.\n\nA "break" statement executed in the first suite terminates the loop\nwithout executing the "else" clause\'s suite. A "continue" statement\nexecuted in the first suite skips the rest of the suite and goes back\nto testing the expression.\n',
+ 'with': u'\nThe "with" statement\n********************\n\nNew in version 2.5.\n\nThe "with" statement is used to wrap the execution of a block with\nmethods defined by a context manager (see section With Statement\nContext Managers). This allows common "try"..."except"..."finally"\nusage patterns to be encapsulated for convenient reuse.\n\n with_stmt ::= "with" with_item ("," with_item)* ":" suite\n with_item ::= expression ["as" target]\n\nThe execution of the "with" statement with one "item" proceeds as\nfollows:\n\n1. The context expression (the expression given in the "with_item")\n is evaluated to obtain a context manager.\n\n2. The context manager\'s "__exit__()" is loaded for later use.\n\n3. The context manager\'s "__enter__()" method is invoked.\n\n4. If a target was included in the "with" statement, the return\n value from "__enter__()" is assigned to it.\n\n Note: The "with" statement guarantees that if the "__enter__()"\n method returns without an error, then "__exit__()" will always be\n called. Thus, if an error occurs during the assignment to the\n target list, it will be treated the same as an error occurring\n within the suite would be. See step 6 below.\n\n5. The suite is executed.\n\n6. The context manager\'s "__exit__()" method is invoked. If an\n exception caused the suite to be exited, its type, value, and\n traceback are passed as arguments to "__exit__()". Otherwise, three\n "None" arguments are supplied.\n\n If the suite was exited due to an exception, and the return value\n from the "__exit__()" method was false, the exception is reraised.\n If the return value was true, the exception is suppressed, and\n execution continues with the statement following the "with"\n statement.\n\n If the suite was exited for any reason other than an exception, the\n return value from "__exit__()" is ignored, and execution proceeds\n at the normal location for the kind of exit that was taken.\n\nWith more than one item, the context managers are processed as if\nmultiple "with" statements were nested:\n\n with A() as a, B() as b:\n suite\n\nis equivalent to\n\n with A() as a:\n with B() as b:\n suite\n\nNote: In Python 2.5, the "with" statement is only allowed when the\n "with_statement" feature has been enabled. It is always enabled in\n Python 2.6.\n\nChanged in version 2.7: Support for multiple context expressions.\n\nSee also:\n\n **PEP 343** - The "with" statement\n The specification, background, and examples for the Python "with"\n statement.\n',
+ 'yield': u'\nThe "yield" statement\n*********************\n\n yield_stmt ::= yield_expression\n\nThe "yield" statement is only used when defining a generator function,\nand is only used in the body of the generator function. Using a\n"yield" statement in a function definition is sufficient to cause that\ndefinition to create a generator function instead of a normal\nfunction.\n\nWhen a generator function is called, it returns an iterator known as a\ngenerator iterator, or more commonly, a generator. The body of the\ngenerator function is executed by calling the generator\'s "next()"\nmethod repeatedly until it raises an exception.\n\nWhen a "yield" statement is executed, the state of the generator is\nfrozen and the value of "expression_list" is returned to "next()"\'s\ncaller. By "frozen" we mean that all local state is retained,\nincluding the current bindings of local variables, the instruction\npointer, and the internal evaluation stack: enough information is\nsaved so that the next time "next()" is invoked, the function can\nproceed exactly as if the "yield" statement were just another external\ncall.\n\nAs of Python version 2.5, the "yield" statement is now allowed in the\n"try" clause of a "try" ... "finally" construct. If the generator is\nnot resumed before it is finalized (by reaching a zero reference count\nor by being garbage collected), the generator-iterator\'s "close()"\nmethod will be called, allowing any pending "finally" clauses to\nexecute.\n\nFor full details of "yield" semantics, refer to the Yield expressions\nsection.\n\nNote: In Python 2.2, the "yield" statement was only allowed when the\n "generators" feature has been enabled. This "__future__" import\n statement was used to enable the feature:\n\n from __future__ import generators\n\nSee also:\n\n **PEP 255** - Simple Generators\n The proposal for adding generators and the "yield" statement to\n Python.\n\n **PEP 342** - Coroutines via Enhanced Generators\n The proposal that, among other generator enhancements, proposed\n allowing "yield" to appear inside a "try" ... "finally" block.\n'}
if self.debug >= 2:
print "shlex: I see punctuation in word state"
self.state = ' '
- if self.token:
+ if self.token or (self.posix and quoted):
break # emit current token
else:
continue
with zipfile.ZipFile(zip_filename, "w",
compression=zipfile.ZIP_DEFLATED) as zf:
path = os.path.normpath(base_dir)
- zf.write(path, path)
- if logger is not None:
- logger.info("adding '%s'", path)
+ if path != os.curdir:
+ zf.write(path, path)
+ if logger is not None:
+ logger.info("adding '%s'", path)
for dirpath, dirnames, filenames in os.walk(base_dir):
for name in sorted(dirnames):
path = os.path.normpath(os.path.join(dirpath, name))
else:
sitepackages.append(prefix)
sitepackages.append(os.path.join(prefix, "lib", "site-packages"))
- if sys.platform == "darwin":
- # for framework builds *only* we add the standard Apple
- # locations.
- from sysconfig import get_config_var
- framework = get_config_var("PYTHONFRAMEWORK")
- if framework:
- sitepackages.append(
- os.path.join("/Library", framework,
- sys.version[:3], "site-packages"))
return sitepackages
def addsitepackages(known_paths):
self.con.close()
def CheckIsInstance(self):
- cur = self.con.cursor(factory=MyCursor)
+ cur = self.con.cursor()
+ self.assertIsInstance(cur, sqlite.Cursor)
+ cur = self.con.cursor(MyCursor)
+ self.assertIsInstance(cur, MyCursor)
+ cur = self.con.cursor(factory=lambda con: MyCursor(con))
self.assertIsInstance(cur, MyCursor)
+ def CheckInvalidFactory(self):
+ # not a callable at all
+ self.assertRaises(TypeError, self.con.cursor, None)
+ # invalid callable with not exact one argument
+ self.assertRaises(TypeError, self.con.cursor, lambda: None)
+ # invalid callable returning non-cursor
+ self.assertRaises(TypeError, self.con.cursor, lambda con: None)
+
class RowFactoryTestsBackwardsCompat(unittest.TestCase):
def setUp(self):
self.con = sqlite.connect(":memory:")
def CheckFakeCursorClass(self):
# Issue #24257: Incorrect use of PyObject_IsInstance() caused
# segmentation fault.
+ # Issue #27861: Also applies for cursor factory.
class FakeCursor(str):
__class__ = sqlite.Cursor
- cur = self.con.cursor(factory=FakeCursor)
- self.assertRaises(TypeError, sqlite.Row, cur, ())
+ self.con.row_factory = sqlite.Row
+ self.assertRaises(TypeError, self.con.cursor, FakeCursor)
+ self.assertRaises(TypeError, sqlite.Row, FakeCursor(), ())
def tearDown(self):
self.con.close()
def tearDown(self):
pass
+ def CheckCreateCollationNotString(self):
+ con = sqlite.connect(":memory:")
+ with self.assertRaises(TypeError):
+ con.create_collation(None, lambda x, y: (x > y) - (x < y))
+
def CheckCreateCollationNotCallable(self):
con = sqlite.connect(":memory:")
try:
except sqlite.ProgrammingError, e:
pass
+ def CheckCreateCollationBadUpper(self):
+ class BadUpperStr(str):
+ def upper(self):
+ return None
+ con = sqlite.connect(":memory:")
+ mycoll = lambda x, y: -((x > y) - (x < y))
+ con.create_collation(BadUpperStr("mycoll"), mycoll)
+ result = con.execute("""
+ select x from (
+ select 'a' as x
+ union
+ select 'b' as x
+ ) order by x collate mycoll
+ """).fetchall()
+ self.assertEqual(result[0][0], 'b')
+ self.assertEqual(result[1][0], 'a')
+
def CheckCollationIsUsed(self):
if sqlite.version_info < (3, 2, 1): # old SQLite versions crash on this test
return
def CheckUnicodeConnect(self):
"""
- With pysqlite 2.4.0 you needed to use a string or a APSW connection
+ With pysqlite 2.4.0 you needed to use a string or an APSW connection
object for opening database connections.
Formerly, both bytestrings and unicode strings used to work.
self.assertRaises(ValueError, cur.execute, " \0select 2")
self.assertRaises(ValueError, cur.execute, "select 2\0")
+ def CheckCommitCursorReset(self):
+ """
+ Connection.commit() did reset cursors, which made sqlite3
+ to return rows multiple times when fetched from cursors
+ after commit. See issues 10513 and 23129 for details.
+ """
+ con = sqlite.connect(":memory:")
+ con.executescript("""
+ create table t(c);
+ create table t2(c);
+ insert into t values(0);
+ insert into t values(1);
+ insert into t values(2);
+ """)
+
+ self.assertEqual(con.isolation_level, "")
+
+ counter = 0
+ for i, row in enumerate(con.execute("select c from t")):
+ con.execute("insert into t2(c) values (?)", (i,))
+ con.commit()
+ if counter == 0:
+ self.assertEqual(row[0], 0)
+ elif counter == 1:
+ self.assertEqual(row[0], 1)
+ elif counter == 2:
+ self.assertEqual(row[0], 2)
+ counter += 1
+ self.assertEqual(counter, 3, "should have returned exactly three rows")
+
def suite():
regression_suite = unittest.makeSuite(RegressionTests, "Check")
PROTOCOL_SSLv2
PROTOCOL_SSLv3
PROTOCOL_SSLv23
+PROTOCOL_TLS
PROTOCOL_TLSv1
PROTOCOL_TLSv1_1
PROTOCOL_TLSv1_2
from _ssl import _OPENSSL_API_VERSION
-_PROTOCOL_NAMES = {value: name for name, value in globals().items() if name.startswith('PROTOCOL_')}
+_PROTOCOL_NAMES = {value: name for name, value in globals().items()
+ if name.startswith('PROTOCOL_')
+ and name != 'PROTOCOL_SSLv23'}
+PROTOCOL_SSLv23 = PROTOCOL_TLS
try:
_SSLv2_IF_EXISTS = PROTOCOL_SSLv2
else:
CHANNEL_BINDING_TYPES = []
+
# Disable weak or insecure ciphers by default
# (OpenSSL's default setting is 'DEFAULT:!aNULL:!eNULL')
# Enable a better set of ciphers by default
# This list has been explicitly chosen to:
# * Prefer cipher suites that offer perfect forward secrecy (DHE/ECDHE)
# * Prefer ECDHE over DHE for better performance
-# * Prefer any AES-GCM over any AES-CBC for better performance and security
+# * Prefer AEAD over CBC for better performance and security
+# * Prefer AES-GCM over ChaCha20 because most platforms have AES-NI
+# (ChaCha20 needs OpenSSL 1.1.0 or patched 1.0.2)
+# * Prefer any AES-GCM and ChaCha20 over any AES-CBC for better
+# performance and security
# * Then Use HIGH cipher suites as a fallback
-# * Then Use 3DES as fallback which is secure but slow
-# * Disable NULL authentication, NULL encryption, and MD5 MACs for security
-# reasons
+# * Disable NULL authentication, NULL encryption, 3DES and MD5 MACs
+# for security reasons
_DEFAULT_CIPHERS = (
- 'ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+HIGH:'
- 'DH+HIGH:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+HIGH:RSA+3DES:!aNULL:'
- '!eNULL:!MD5'
-)
+ 'ECDH+AESGCM:ECDH+CHACHA20:DH+AESGCM:DH+CHACHA20:ECDH+AES256:DH+AES256:'
+ 'ECDH+AES128:DH+AES:ECDH+HIGH:DH+HIGH:RSA+AESGCM:RSA+AES:RSA+HIGH:'
+ '!aNULL:!eNULL:!MD5:!3DES'
+ )
# Restricted and more secure ciphers for the server side
# This list has been explicitly chosen to:
# * Prefer cipher suites that offer perfect forward secrecy (DHE/ECDHE)
# * Prefer ECDHE over DHE for better performance
-# * Prefer any AES-GCM over any AES-CBC for better performance and security
+# * Prefer AEAD over CBC for better performance and security
+# * Prefer AES-GCM over ChaCha20 because most platforms have AES-NI
+# * Prefer any AES-GCM and ChaCha20 over any AES-CBC for better
+# performance and security
# * Then Use HIGH cipher suites as a fallback
-# * Then Use 3DES as fallback which is secure but slow
-# * Disable NULL authentication, NULL encryption, MD5 MACs, DSS, and RC4 for
-# security reasons
+# * Disable NULL authentication, NULL encryption, MD5 MACs, DSS, RC4, and
+# 3DES for security reasons
_RESTRICTED_SERVER_CIPHERS = (
- 'ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+HIGH:'
- 'DH+HIGH:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+HIGH:RSA+3DES:!aNULL:'
- '!eNULL:!MD5:!DSS:!RC4'
+ 'ECDH+AESGCM:ECDH+CHACHA20:DH+AESGCM:DH+CHACHA20:ECDH+AES256:DH+AES256:'
+ 'ECDH+AES128:DH+AES:ECDH+HIGH:DH+HIGH:RSA+AESGCM:RSA+AES:RSA+HIGH:'
+ '!aNULL:!eNULL:!MD5:!DSS:!RC4:!3DES'
)
if not isinstance(purpose, _ASN1Object):
raise TypeError(purpose)
- context = SSLContext(PROTOCOL_SSLv23)
+ context = SSLContext(PROTOCOL_TLS)
# SSLv2 considered harmful.
context.options |= OP_NO_SSLv2
context.load_default_certs(purpose)
return context
-def _create_unverified_context(protocol=PROTOCOL_SSLv23, cert_reqs=None,
+def _create_unverified_context(protocol=PROTOCOL_TLS, cert_reqs=None,
check_hostname=False, purpose=Purpose.SERVER_AUTH,
certfile=None, keyfile=None,
cafile=None, capath=None, cadata=None):
def __init__(self, sock=None, keyfile=None, certfile=None,
server_side=False, cert_reqs=CERT_NONE,
- ssl_version=PROTOCOL_SSLv23, ca_certs=None,
+ ssl_version=PROTOCOL_TLS, ca_certs=None,
do_handshake_on_connect=True,
family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None,
suppress_ragged_eofs=True, npn_protocols=None, ciphers=None,
def wrap_socket(sock, keyfile=None, certfile=None,
server_side=False, cert_reqs=CERT_NONE,
- ssl_version=PROTOCOL_SSLv23, ca_certs=None,
+ ssl_version=PROTOCOL_TLS, ca_certs=None,
do_handshake_on_connect=True,
suppress_ragged_eofs=True,
ciphers=None):
d = pem_cert_string.strip()[len(PEM_HEADER):-len(PEM_FOOTER)]
return base64.decodestring(d.encode('ASCII', 'strict'))
-def get_server_certificate(addr, ssl_version=PROTOCOL_SSLv23, ca_certs=None):
+def get_server_certificate(addr, ssl_version=PROTOCOL_TLS, ca_certs=None):
"""Retrieve the certificate from the server at the specified address,
and return it as a PEM-encoded string.
If 'ca_certs' is specified, validate the server cert against it.
# Licensed to PSF under a Contributor Agreement.
# See http://www.python.org/2.4/license for licensing details.
-r"""subprocess - Subprocesses with accessible I/O streams
+r"""Subprocesses with accessible I/O streams
This module allows you to spawn processes, connect to their
-input/output/error pipes, and obtain their return codes. This module
-intends to replace several older modules and functions:
-
-os.system
-os.spawn*
-os.popen*
-popen2.*
-commands.*
-
-Information about how the subprocess module can be used to replace these
-modules and functions can be found below.
-
-
-
-Using the subprocess module
-===========================
-This module defines one class called Popen:
-
-class Popen(args, bufsize=0, executable=None,
- stdin=None, stdout=None, stderr=None,
- preexec_fn=None, close_fds=False, shell=False,
- cwd=None, env=None, universal_newlines=False,
- startupinfo=None, creationflags=0):
-
-
-Arguments are:
-
-args should be a string, or a sequence of program arguments. The
-program to execute is normally the first item in the args sequence or
-string, but can be explicitly set by using the executable argument.
-
-On UNIX, with shell=False (default): In this case, the Popen class
-uses os.execvp() to execute the child program. args should normally
-be a sequence. A string will be treated as a sequence with the string
-as the only item (the program to execute).
-
-On UNIX, with shell=True: If args is a string, it specifies the
-command string to execute through the shell. If args is a sequence,
-the first item specifies the command string, and any additional items
-will be treated as additional shell arguments.
-
-On Windows: the Popen class uses CreateProcess() to execute the child
-program, which operates on strings. If args is a sequence, it will be
-converted to a string using the list2cmdline method. Please note that
-not all MS Windows applications interpret the command line the same
-way: The list2cmdline is designed for applications using the same
-rules as the MS C runtime.
-
-bufsize, if given, has the same meaning as the corresponding argument
-to the built-in open() function: 0 means unbuffered, 1 means line
-buffered, any other positive value means use a buffer of
-(approximately) that size. A negative bufsize means to use the system
-default, which usually means fully buffered. The default value for
-bufsize is 0 (unbuffered).
-
-stdin, stdout and stderr specify the executed programs' standard
-input, standard output and standard error file handles, respectively.
-Valid values are PIPE, an existing file descriptor (a positive
-integer), an existing file object, and None. PIPE indicates that a
-new pipe to the child should be created. With None, no redirection
-will occur; the child's file handles will be inherited from the
-parent. Additionally, stderr can be STDOUT, which indicates that the
-stderr data from the applications should be captured into the same
-file handle as for stdout.
-
-If preexec_fn is set to a callable object, this object will be called
-in the child process just before the child is executed.
-
-If close_fds is true, all file descriptors except 0, 1 and 2 will be
-closed before the child process is executed.
-
-if shell is true, the specified command will be executed through the
-shell.
-
-If cwd is not None, the current directory will be changed to cwd
-before the child is executed.
-
-If env is not None, it defines the environment variables for the new
-process.
-
-If universal_newlines is true, the file objects stdout and stderr are
-opened as a text files, but lines may be terminated by any of '\n',
-the Unix end-of-line convention, '\r', the Macintosh convention or
-'\r\n', the Windows convention. All of these external representations
-are seen as '\n' by the Python program. Note: This feature is only
-available if Python is built with universal newline support (the
-default). Also, the newlines attribute of the file objects stdout,
-stdin and stderr are not updated by the communicate() method.
-
-The startupinfo and creationflags, if given, will be passed to the
-underlying CreateProcess() function. They can specify things such as
-appearance of the main window and priority for the new process.
-(Windows only)
-
-
-This module also defines some shortcut functions:
-
-call(*popenargs, **kwargs):
- Run command with arguments. Wait for command to complete, then
- return the returncode attribute.
-
- The arguments are the same as for the Popen constructor. Example:
-
- retcode = call(["ls", "-l"])
-
-check_call(*popenargs, **kwargs):
- Run command with arguments. Wait for command to complete. If the
- exit code was zero then return, otherwise raise
- CalledProcessError. The CalledProcessError object will have the
- return code in the returncode attribute.
-
- The arguments are the same as for the Popen constructor. Example:
-
- check_call(["ls", "-l"])
-
-check_output(*popenargs, **kwargs):
- Run command with arguments and return its output as a byte string.
-
- If the exit code was non-zero it raises a CalledProcessError. The
- CalledProcessError object will have the return code in the returncode
- attribute and output in the output attribute.
-
- The arguments are the same as for the Popen constructor. Example:
-
- output = check_output(["ls", "-l", "/dev/null"])
-
-
-Exceptions
-----------
-Exceptions raised in the child process, before the new program has
-started to execute, will be re-raised in the parent. Additionally,
-the exception object will have one extra attribute called
-'child_traceback', which is a string containing traceback information
-from the child's point of view.
-
-The most common exception raised is OSError. This occurs, for
-example, when trying to execute a non-existent file. Applications
-should prepare for OSErrors.
-
-A ValueError will be raised if Popen is called with invalid arguments.
-
-check_call() and check_output() will raise CalledProcessError, if the
-called process returns a non-zero return code.
-
-
-Security
---------
-Unlike some other popen functions, this implementation will never call
-/bin/sh implicitly. This means that all characters, including shell
-metacharacters, can safely be passed to child processes.
-
-
-Popen objects
-=============
-Instances of the Popen class have the following methods:
-
-poll()
- Check if child process has terminated. Returns returncode
- attribute.
-
-wait()
- Wait for child process to terminate. Returns returncode attribute.
-
-communicate(input=None)
- Interact with process: Send data to stdin. Read data from stdout
- and stderr, until end-of-file is reached. Wait for process to
- terminate. The optional input argument should be a string to be
- sent to the child process, or None, if no data should be sent to
- the child.
-
- communicate() returns a tuple (stdout, stderr).
-
- Note: The data read is buffered in memory, so do not use this
- method if the data size is large or unlimited.
-
-The following attributes are also available:
-
-stdin
- If the stdin argument is PIPE, this attribute is a file object
- that provides input to the child process. Otherwise, it is None.
-
-stdout
- If the stdout argument is PIPE, this attribute is a file object
- that provides output from the child process. Otherwise, it is
- None.
-
-stderr
- If the stderr argument is PIPE, this attribute is file object that
- provides error output from the child process. Otherwise, it is
- None.
-
-pid
- The process ID of the child process.
-
-returncode
- The child return code. A None value indicates that the process
- hasn't terminated yet. A negative value -N indicates that the
- child was terminated by signal N (UNIX only).
-
-
-Replacing older functions with the subprocess module
-====================================================
-In this section, "a ==> b" means that b can be used as a replacement
-for a.
-
-Note: All functions in this section fail (more or less) silently if
-the executed program cannot be found; this module raises an OSError
-exception.
-
-In the following examples, we assume that the subprocess module is
-imported with "from subprocess import *".
-
-
-Replacing /bin/sh shell backquote
----------------------------------
-output=`mycmd myarg`
-==>
-output = Popen(["mycmd", "myarg"], stdout=PIPE).communicate()[0]
-
-
-Replacing shell pipe line
--------------------------
-output=`dmesg | grep hda`
-==>
-p1 = Popen(["dmesg"], stdout=PIPE)
-p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
-output = p2.communicate()[0]
-
-
-Replacing os.system()
----------------------
-sts = os.system("mycmd" + " myarg")
-==>
-p = Popen("mycmd" + " myarg", shell=True)
-pid, sts = os.waitpid(p.pid, 0)
-
-Note:
-
-* Calling the program through the shell is usually not required.
-
-* It's easier to look at the returncode attribute than the
- exitstatus.
-
-A more real-world example would look like this:
-
-try:
- retcode = call("mycmd" + " myarg", shell=True)
- if retcode < 0:
- print >>sys.stderr, "Child was terminated by signal", -retcode
- else:
- print >>sys.stderr, "Child returned", retcode
-except OSError, e:
- print >>sys.stderr, "Execution failed:", e
-
-
-Replacing os.spawn*
--------------------
-P_NOWAIT example:
-
-pid = os.spawnlp(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg")
-==>
-pid = Popen(["/bin/mycmd", "myarg"]).pid
-
-
-P_WAIT example:
-
-retcode = os.spawnlp(os.P_WAIT, "/bin/mycmd", "mycmd", "myarg")
-==>
-retcode = call(["/bin/mycmd", "myarg"])
-
-
-Vector example:
-
-os.spawnvp(os.P_NOWAIT, path, args)
-==>
-Popen([path] + args[1:])
-
-
-Environment example:
-
-os.spawnlpe(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg", env)
-==>
-Popen(["/bin/mycmd", "myarg"], env={"PATH": "/usr/bin"})
-
-
-Replacing os.popen*
--------------------
-pipe = os.popen("cmd", mode='r', bufsize)
-==>
-pipe = Popen("cmd", shell=True, bufsize=bufsize, stdout=PIPE).stdout
-
-pipe = os.popen("cmd", mode='w', bufsize)
-==>
-pipe = Popen("cmd", shell=True, bufsize=bufsize, stdin=PIPE).stdin
-
-
-(child_stdin, child_stdout) = os.popen2("cmd", mode, bufsize)
-==>
-p = Popen("cmd", shell=True, bufsize=bufsize,
- stdin=PIPE, stdout=PIPE, close_fds=True)
-(child_stdin, child_stdout) = (p.stdin, p.stdout)
-
-
-(child_stdin,
- child_stdout,
- child_stderr) = os.popen3("cmd", mode, bufsize)
-==>
-p = Popen("cmd", shell=True, bufsize=bufsize,
- stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
-(child_stdin,
- child_stdout,
- child_stderr) = (p.stdin, p.stdout, p.stderr)
-
-
-(child_stdin, child_stdout_and_stderr) = os.popen4("cmd", mode,
- bufsize)
-==>
-p = Popen("cmd", shell=True, bufsize=bufsize,
- stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
-(child_stdin, child_stdout_and_stderr) = (p.stdin, p.stdout)
-
-On Unix, os.popen2, os.popen3 and os.popen4 also accept a sequence as
-the command to execute, in which case arguments will be passed
-directly to the program without shell intervention. This usage can be
-replaced as follows:
-
-(child_stdin, child_stdout) = os.popen2(["/bin/ls", "-l"], mode,
- bufsize)
-==>
-p = Popen(["/bin/ls", "-l"], bufsize=bufsize, stdin=PIPE, stdout=PIPE)
-(child_stdin, child_stdout) = (p.stdin, p.stdout)
-
-Return code handling translates as follows:
-
-pipe = os.popen("cmd", 'w')
-...
-rc = pipe.close()
-if rc is not None and rc % 256:
- print "There were some errors"
-==>
-process = Popen("cmd", 'w', shell=True, stdin=PIPE)
-...
-process.stdin.close()
-if process.wait() != 0:
- print "There were some errors"
-
-
-Replacing popen2.*
-------------------
-(child_stdout, child_stdin) = popen2.popen2("somestring", bufsize, mode)
-==>
-p = Popen(["somestring"], shell=True, bufsize=bufsize
- stdin=PIPE, stdout=PIPE, close_fds=True)
-(child_stdout, child_stdin) = (p.stdout, p.stdin)
-
-On Unix, popen2 also accepts a sequence as the command to execute, in
-which case arguments will be passed directly to the program without
-shell intervention. This usage can be replaced as follows:
-
-(child_stdout, child_stdin) = popen2.popen2(["mycmd", "myarg"], bufsize,
- mode)
-==>
-p = Popen(["mycmd", "myarg"], bufsize=bufsize,
- stdin=PIPE, stdout=PIPE, close_fds=True)
-(child_stdout, child_stdin) = (p.stdout, p.stdin)
-
-The popen2.Popen3 and popen2.Popen4 basically works as subprocess.Popen,
-except that:
-
-* subprocess.Popen raises an exception if the execution fails
-* the capturestderr argument is replaced with the stderr argument.
-* stdin=PIPE and stdout=PIPE must be specified.
-* popen2 closes all filedescriptors by default, but you have to specify
- close_fds=True with subprocess.Popen.
+input/output/error pipes, and obtain their return codes.
+
+For a complete description of this module see the Python documentation.
+
+Main API
+========
+call(...): Runs a command, waits for it to complete, then returns
+ the return code.
+check_call(...): Same as call() but raises CalledProcessError()
+ if return code is not 0
+check_output(...): Same as check_call() but returns the contents of
+ stdout instead of a return code
+Popen(...): A class for flexibly executing a command in a new process
+
+Constants
+---------
+PIPE: Special value that indicates a pipe should be created
+STDOUT: Special value that indicates that stderr should go to stdout
"""
import sys
class CalledProcessError(Exception):
"""This exception is raised when a process run by check_call() or
check_output() returns a non-zero exit status.
- The exit status will be stored in the returncode attribute;
- check_output() will also store the output in the output attribute.
+
+ Attributes:
+ cmd, returncode, output
"""
def __init__(self, returncode, cmd, output=None):
self.returncode = returncode
class Popen(object):
+ """ Execute a child program in a new process.
+
+ For a complete description of the arguments see the Python documentation.
+
+ Arguments:
+ args: A string, or a sequence of program arguments.
+
+ bufsize: supplied as the buffering argument to the open() function when
+ creating the stdin/stdout/stderr pipe file objects
+
+ executable: A replacement program to execute.
+
+ stdin, stdout and stderr: These specify the executed programs' standard
+ input, standard output and standard error file handles, respectively.
+
+ preexec_fn: (POSIX only) An object to be called in the child process
+ just before the child is executed.
+
+ close_fds: Controls closing or inheriting of file descriptors.
+
+ shell: If true, the command will be executed through the shell.
+
+ cwd: Sets the current directory before the child is executed.
+
+ env: Defines the environment variables for the new process.
+
+ universal_newlines: If true, use universal line endings for file
+ objects stdin, stdout and stderr.
+
+ startupinfo and creationflags (Windows only)
+
+ Attributes:
+ stdin, stdout, stderr, pid, returncode
+ """
_child_created = False # Set here since __del__ checks it
def __init__(self, args, bufsize=0, executable=None,
def poll(self):
+ """Check if child process has terminated. Set and return returncode
+ attribute."""
return self._internal_poll()
if mode in ("r", "r:*"):
# Find out which *open() is appropriate for opening the file.
- for comptype in cls.OPEN_METH:
+ def not_compressed(comptype):
+ return cls.OPEN_METH[comptype] == 'taropen'
+ for comptype in sorted(cls.OPEN_METH, key=not_compressed):
func = getattr(cls, cls.OPEN_METH[comptype])
if fileobj is not None:
saved_pos = fileobj.tell()
def _call_matcher(self, _call):
"""
- Given a call (or simply a (args, kwargs) tuple), return a
+ Given a call (or simply an (args, kwargs) tuple), return a
comparison key suitable for matching with other calls.
This is a best effort method which relies on the spec's signature,
if available, or falls back on the arguments themselves.
--- /dev/null
+-----BEGIN PRIVATE KEY-----
+MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAOoy7/QOtTjQ0niE
+6uDcTwtkC0R2Tvy1AjVnXohCntZfdzbTGDoYTgXSOLsP8A697jUiJ8VCePGH50xG
+Z4DKnAF3a9O3a9nr2pLXb0iY3XOMv+YEBii7CfI+3oxFYgCl0sMgHzDD2ZTVYAsm
+DWgLUVsE2gHEccRwrM2tPf2EgR+FAgMBAAECgYEA3qyfyYVSeTrTYxO93x6ZaVMu
+A2IZp9zSxMQL9bKiI2GRj+cV2ebSCGbg2btFnD6qBor7FWsmYz+8g6FNN/9sY4az
+61rMqMtQvLBe+7L8w70FeTze4qQ4Y1oQri0qD6tBWhDVlpnbI5Py9bkZKD67yVUk
+elcEA/5x4PrYXkuqsAECQQD80NjT0mDvaY0JOOaQFSEpMv6QiUA8GGX8Xli7IoKb
+tAolPG8rQBa+qSpcWfDMTrWw/aWHuMEEQoP/bVDH9W4FAkEA7SYQbBAKnojZ5A3G
+kOHdV7aeivRQxQk/JN8Fb8oKB9Csvpv/BsuGxPKXHdhFa6CBTTsNRtHQw/szPo4l
+xMIjgQJAPoMxqibR+0EBM6+TKzteSL6oPXsCnBl4Vk/J5vPgkbmR7KUl4+7j8N8J
+b2554TrxKEN/w7CGYZRE6UrRd7ATNQJAWD7Yz41sli+wfPdPU2xo1BHljyl4wMk/
+EPZYbI/PCbdyAH/F935WyQTIjNeEhZc1Zkq6FwdOWw8ns3hrv3rKgQJAHXv1BqUa
+czGPIFxX2TNoqtcl6/En4vrxVB1wzsfzkkDAg98kBl7qsF+S3qujSzKikjeaVbI2
+/CyWR2P3yLtOmA==
+-----END PRIVATE KEY-----
+-----BEGIN CERTIFICATE-----
+MIIDcjCCAtugAwIBAgIJAN5dc9TOWjB7MA0GCSqGSIb3DQEBCwUAMF0xCzAJBgNV
+BAYTAlhZMRcwFQYDVQQHDA5DYXN0bGUgQW50aHJheDEjMCEGA1UECgwaUHl0aG9u
+IFNvZnR3YXJlIEZvdW5kYXRpb24xEDAOBgNVBAMMB2FsbHNhbnMwHhcNMTYwODA1
+MTAyMTExWhcNMjYwODAzMTAyMTExWjBdMQswCQYDVQQGEwJYWTEXMBUGA1UEBwwO
+Q2FzdGxlIEFudGhyYXgxIzAhBgNVBAoMGlB5dGhvbiBTb2Z0d2FyZSBGb3VuZGF0
+aW9uMRAwDgYDVQQDDAdhbGxzYW5zMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB
+gQDqMu/0DrU40NJ4hOrg3E8LZAtEdk78tQI1Z16IQp7WX3c20xg6GE4F0ji7D/AO
+ve41IifFQnjxh+dMRmeAypwBd2vTt2vZ69qS129ImN1zjL/mBAYouwnyPt6MRWIA
+pdLDIB8ww9mU1WALJg1oC1FbBNoBxHHEcKzNrT39hIEfhQIDAQABo4IBODCCATQw
+ggEwBgNVHREEggEnMIIBI4IHYWxsc2Fuc6AeBgMqAwSgFwwVc29tZSBvdGhlciBp
+ZGVudGlmaWVyoDUGBisGAQUCAqArMCmgEBsOS0VSQkVST1MuUkVBTE2hFTAToAMC
+AQGhDDAKGwh1c2VybmFtZYEQdXNlckBleGFtcGxlLm9yZ4IPd3d3LmV4YW1wbGUu
+b3JnpGcwZTELMAkGA1UEBhMCWFkxFzAVBgNVBAcMDkNhc3RsZSBBbnRocmF4MSMw
+IQYDVQQKDBpQeXRob24gU29mdHdhcmUgRm91bmRhdGlvbjEYMBYGA1UEAwwPZGly
+bmFtZSBleGFtcGxlhhdodHRwczovL3d3dy5weXRob24ub3JnL4cEfwAAAYcQAAAA
+AAAAAAAAAAAAAAAAAYgEKgMEBTANBgkqhkiG9w0BAQsFAAOBgQAy16h+F+nOmeiT
+VWR0fc8F/j6FcadbLseAUaogcC15OGxCl4UYpLV88HBkABOoGCpP155qwWTwOrdG
+iYPGJSusf1OnJEbvzFejZf6u078bPd9/ZL4VWLjv+FPGkjd+N+/OaqMvgj8Lu99f
+3Y/C4S7YbHxxwff6C6l2Xli+q6gnuQ==
+-----END CERTIFICATE-----
+++ /dev/null
-rem Check for a working sound-card - exit with 0 if OK, 1 otherwise.
-set wmi = GetObject("winmgmts:")
-set scs = wmi.InstancesOf("win32_sounddevice")
-for each sc in scs
- set status = sc.Properties_("Status")
- wscript.Echo(sc.Properties_("Name") + "/" + status)
- if status = "OK" then
- wscript.Quit 0 rem normal exit
- end if
-next
-rem No sound card found - exit with status code of 1
-wscript.Quit 1
-
------------------------------------------------------------------------
version: 2.59
--- Tests of the exponential funtion. Currently all testcases here
+-- Tests of the exponential function. Currently all testcases here
-- show results which are correctly rounded (within <= 0.5 ulp).
extended: 1
fmax2019 fma -9.999999 9.999999 0E+999999 -> -100.000 Inexact Rounded
fmax2020 fma -9.999999 -9.999999 0E+999999 -> 100.000 Inexact Rounded
--- 1999.12.21: next one is a edge case if intermediate longs are used
+-- 1999.12.21: next one is an edge case if intermediate longs are used
precision: 15
fmax2059 fma 999999999999 9765625 0E+999999 -> 9.76562499999023E+18 Inexact Rounded
precision: 30
mulx019 multiply -9.999999999 9.999999999 -> -100.000 Inexact Rounded
mulx020 multiply -9.999999999 -9.999999999 -> 100.000 Inexact Rounded
--- 1999.12.21: next one is a edge case if intermediate longs are used
+-- 1999.12.21: next one is an edge case if intermediate longs are used
precision: 15
mulx059 multiply 999999999999 9765625 -> 9.76562499999023E+18 Inexact Rounded
precision: 30
CN = {hostname}
[req_x509_extensions]
- subjectAltName = DNS:{hostname}
+ subjectAltName = @san
+
+ [san]
+ DNS.1 = {hostname}
+ {extra_san}
+
+ [dir_sect]
+ C = XY
+ L = Castle Anthrax
+ O = Python Software Foundation
+ CN = dirname example
+
+ [princ_name]
+ realm = EXP:0, GeneralString:KERBEROS.REALM
+ principal_name = EXP:1, SEQUENCE:principal_seq
+
+ [principal_seq]
+ name_type = EXP:0, INTEGER:1
+ name_string = EXP:1, SEQUENCE:principals
+
+ [principals]
+ princ1 = GeneralString:username
[ ca ]
default_ca = CA_default
here = os.path.abspath(os.path.dirname(__file__))
-def make_cert_key(hostname, sign=False):
+def make_cert_key(hostname, sign=False, extra_san=''):
print("creating cert for " + hostname)
tempnames = []
for i in range(3):
tempnames.append(f.name)
req_file, cert_file, key_file = tempnames
try:
+ req = req_template.format(hostname=hostname, extra_san=extra_san)
with open(req_file, 'w') as f:
- f.write(req_template.format(hostname=hostname))
+ f.write(req)
args = ['req', '-new', '-days', '3650', '-nodes',
'-newkey', 'rsa:1024', '-keyout', key_file,
'-config', req_file]
f.write('unique_subject = no')
with tempfile.NamedTemporaryFile("w") as t:
- t.write(req_template.format(hostname='our-ca-server'))
+ t.write(req_template.format(hostname='our-ca-server', extra_san=''))
t.flush()
with tempfile.NamedTemporaryFile() as f:
args = ['req', '-new', '-days', '3650', '-extensions', 'v3_ca', '-nodes',
f.write(key)
f.write(cert)
+ extra_san = [
+ 'otherName.1 = 1.2.3.4;UTF8:some other identifier',
+ 'otherName.2 = 1.3.6.1.5.2.2;SEQUENCE:princ_name',
+ 'email.1 = user@example.org',
+ 'DNS.2 = www.example.org',
+ # GEN_X400
+ 'dirName.1 = dir_sect',
+ # GEN_EDIPARTY
+ 'URI.1 = https://www.python.org/',
+ 'IP.1 = 127.0.0.1',
+ 'IP.2 = ::1',
+ 'RID.1 = 1.2.3.4.5',
+ ]
+
+ cert, key = make_cert_key('allsans', extra_san='\n'.join(extra_san))
+ with open('allsans.pem', 'w') as f:
+ f.write(key)
+ f.write(cert)
+
unmake_ca()
print("\n\nPlease change the values in test_ssl.py, test_parse_cert function related to notAfter,notBefore and serialNumber")
check_call(['openssl','x509','-in','keycert.pem','-dates','-serial','-noout'])
self.items = items
def __eq__(self, other):
return type(self) is type(other) and self.items == other.items
+ __hash__ = None
def append(self, item):
self.items.append(item)
def extend(self, items):
self.table = table
def __eq__(self, other):
return type(self) is type(other) and self.table == other.table
+ __hash__ = None
def __setitem__(self, key, value):
self.table[key] = value
def __reduce__(self):
raise TypeError("SimpleNewObj.__init__() didn't expect to get called")
def __eq__(self, other):
return int(self) == int(other) and self.__dict__ == other.__dict__
+ __hash__ = None
class ComplexNewObj(SimpleNewObj):
def __getnewargs__(self):
else:
# Always import it from the test package
abstest = 'test.' + test
+ clear_caches()
with saved_test_environment(test, verbose, quiet, pgo) as environment:
start_time = time.time()
the_package = __import__(abstest, globals(), locals(), [])
def dash_R_cleanup(fs, ps, pic, zdc, abcs):
import gc, copy_reg
- import _strptime, linecache
- dircache = test_support.import_module('dircache', deprecated=True)
- import urlparse, urllib, urllib2, mimetypes, doctest
- import struct, filecmp
- from distutils.dir_util import _path_created
-
- # Clear the warnings registry, so they can be displayed again
- for mod in sys.modules.values():
- if hasattr(mod, '__warningregistry__'):
- del mod.__warningregistry__
# Restore some original values.
warnings.filters[:] = fs
abc._abc_cache.clear()
abc._abc_negative_cache.clear()
+ clear_caches()
+
+def clear_caches():
+ import gc
+
+ # Clear the warnings registry, so they can be displayed again
+ for mod in sys.modules.values():
+ if hasattr(mod, '__warningregistry__'):
+ del mod.__warningregistry__
+
# Clear assorted module caches.
- _path_created.clear()
+ # Don't worry about resetting the cache if the module is not loaded
+ try:
+ distutils_dir_util = sys.modules['distutils.dir_util']
+ except KeyError:
+ pass
+ else:
+ distutils_dir_util._path_created.clear()
+
re.purge()
- _strptime._regex_cache.clear()
- urlparse.clear_cache()
- urllib.urlcleanup()
- urllib2.install_opener(None)
- dircache.reset()
- linecache.clearcache()
- mimetypes._default_mime_types()
- filecmp._cache.clear()
- struct._clearcache()
- doctest.master = None
+
try:
- import ctypes
- except ImportError:
- # Don't worry about resetting the cache if ctypes is not supported
+ _strptime = sys.modules['_strptime']
+ except KeyError:
+ pass
+ else:
+ _strptime._regex_cache.clear()
+
+ try:
+ urlparse = sys.modules['urlparse']
+ except KeyError:
+ pass
+ else:
+ urlparse.clear_cache()
+
+ try:
+ urllib = sys.modules['urllib']
+ except KeyError:
+ pass
+ else:
+ urllib.urlcleanup()
+
+ try:
+ urllib2 = sys.modules['urllib2']
+ except KeyError:
+ pass
+ else:
+ urllib2.install_opener(None)
+
+ try:
+ dircache = sys.modules['dircache']
+ except KeyError:
+ pass
+ else:
+ dircache.reset()
+
+ try:
+ linecache = sys.modules['linecache']
+ except KeyError:
+ pass
+ else:
+ linecache.clearcache()
+
+ try:
+ mimetypes = sys.modules['mimetypes']
+ except KeyError:
+ pass
+ else:
+ mimetypes._default_mime_types()
+
+ try:
+ filecmp = sys.modules['filecmp']
+ except KeyError:
+ pass
+ else:
+ filecmp._cache.clear()
+
+ try:
+ struct = sys.modules['struct']
+ except KeyError:
+ pass
+ else:
+ struct._clearcache()
+
+ try:
+ doctest = sys.modules['doctest']
+ except KeyError:
+ pass
+ else:
+ doctest.master = None
+
+ try:
+ ctypes = sys.modules['ctypes']
+ except KeyError:
pass
else:
ctypes._reset_cache()
--- /dev/null
+# Convenience test module to run all of the OpenSSL-related tests in the
+# standard library.
+
+import ssl
+import sys
+import subprocess
+
+TESTS = [
+ 'test_ensurepip.py', 'test_ftplib', 'test_hashlib',
+ 'test_hmac', 'test_httplib', 'test_imaplib', 'test_nntplib',
+ 'test_poplib', 'test_ssl', 'test_smtplib', 'test_smtpnet',
+ 'test_urllib2_localnet', 'test_xmlrpc'
+]
+
+def run_regrtests(*extra_args):
+ print(ssl.OPENSSL_VERSION)
+ args = [
+ sys.executable,
+ '-Werror', '-bb', # turn warnings into exceptions
+ '-m', 'test.regrtest',
+ ]
+ if not extra_args:
+ args.extend([
+ '-r', # randomize
+ '-w', # re-run failed tests with -v
+ '-u', 'network', # use network
+ '-u', 'urlfetch', # download test vectors
+ ])
+ else:
+ args.extend(extra_args)
+ args.extend(TESTS)
+ result = subprocess.call(args)
+ sys.exit(result)
+
+if __name__ == '__main__':
+ run_regrtests(*sys.argv[1:])
if test_support.have_unicode:
typecodes += "u"
-class BadConstructorTest(unittest.TestCase):
+class MiscTest(unittest.TestCase):
- def test_constructor(self):
+ def test_bad_constructor(self):
self.assertRaises(TypeError, array.array)
self.assertRaises(TypeError, array.array, spam=42)
self.assertRaises(TypeError, array.array, 'xx')
self.assertRaises(ValueError, array.array, u'x')
self.assertRaises(ValueError, array.array, u'\x80')
-tests.append(BadConstructorTest)
+ def test_empty(self):
+ # Exercise code for handling zero-length arrays
+ a = array.array('B')
+ a[:] = a
+ self.assertEqual(len(a), 0)
+ self.assertEqual(len(a + a), 0)
+ self.assertEqual(len(a * 3), 0)
+ a += a
+ self.assertEqual(len(a), 0)
+
+tests.append(MiscTest)
class BaseTest(unittest.TestCase):
# Required class attributes (provided by subclasses
self.assertEqual(binascii.hexlify(unicode('a', 'ascii')), '61')
def test_qp(self):
+ type2test = self.type2test
+ a2b_qp = binascii.a2b_qp
+ b2a_qp = binascii.b2a_qp
+
+ a2b_qp(data=b"", header=False) # Keyword arguments allowed
+
# A test for SF bug 534347 (segfaults without the proper fix)
try:
- binascii.a2b_qp("", **{1:1})
+ a2b_qp(b"", **{1:1})
except TypeError:
pass
else:
self.fail("binascii.a2b_qp(**{1:1}) didn't raise TypeError")
- self.assertEqual(binascii.a2b_qp("= "), "= ")
- self.assertEqual(binascii.a2b_qp("=="), "=")
- self.assertEqual(binascii.a2b_qp("=AX"), "=AX")
- self.assertRaises(TypeError, binascii.b2a_qp, foo="bar")
- self.assertEqual(binascii.a2b_qp("=00\r\n=00"), "\x00\r\n\x00")
- self.assertEqual(
- binascii.b2a_qp("\xff\r\n\xff\n\xff"),
- "=FF\r\n=FF\r\n=FF"
- )
- self.assertEqual(
- binascii.b2a_qp("0"*75+"\xff\r\n\xff\r\n\xff"),
- "0"*75+"=\r\n=FF\r\n=FF\r\n=FF"
- )
-
- self.assertEqual(binascii.b2a_qp('\0\n'), '=00\n')
- self.assertEqual(binascii.b2a_qp('\0\n', quotetabs=True), '=00\n')
- self.assertEqual(binascii.b2a_qp('foo\tbar\t\n'), 'foo\tbar=09\n')
- self.assertEqual(binascii.b2a_qp('foo\tbar\t\n', quotetabs=True), 'foo=09bar=09\n')
-
- self.assertEqual(binascii.b2a_qp('.'), '=2E')
- self.assertEqual(binascii.b2a_qp('.\n'), '=2E\n')
- self.assertEqual(binascii.b2a_qp('a.\n'), 'a.\n')
+
+ self.assertEqual(a2b_qp(type2test(b"=")), b"")
+ self.assertEqual(a2b_qp(type2test(b"= ")), b"= ")
+ self.assertEqual(a2b_qp(type2test(b"==")), b"=")
+ self.assertEqual(a2b_qp(type2test(b"=\nAB")), b"AB")
+ self.assertEqual(a2b_qp(type2test(b"=\r\nAB")), b"AB")
+ self.assertEqual(a2b_qp(type2test(b"=\rAB")), b"") # ?
+ self.assertEqual(a2b_qp(type2test(b"=\rAB\nCD")), b"CD") # ?
+ self.assertEqual(a2b_qp(type2test(b"=AB")), b"\xab")
+ self.assertEqual(a2b_qp(type2test(b"=ab")), b"\xab")
+ self.assertEqual(a2b_qp(type2test(b"=AX")), b"=AX")
+ self.assertEqual(a2b_qp(type2test(b"=XA")), b"=XA")
+ self.assertEqual(a2b_qp(type2test(b"=AB")[:-1]), b"=A")
+
+ self.assertEqual(a2b_qp(type2test(b'_')), b'_')
+ self.assertEqual(a2b_qp(type2test(b'_'), header=True), b' ')
+
+ self.assertRaises(TypeError, b2a_qp, foo="bar")
+ self.assertEqual(a2b_qp(type2test(b"=00\r\n=00")), b"\x00\r\n\x00")
+ self.assertEqual(b2a_qp(type2test(b"\xff\r\n\xff\n\xff")),
+ b"=FF\r\n=FF\r\n=FF")
+ self.assertEqual(b2a_qp(type2test(b"0"*75+b"\xff\r\n\xff\r\n\xff")),
+ b"0"*75+b"=\r\n=FF\r\n=FF\r\n=FF")
+
+ self.assertEqual(b2a_qp(type2test(b'\x7f')), b'=7F')
+ self.assertEqual(b2a_qp(type2test(b'=')), b'=3D')
+
+ self.assertEqual(b2a_qp(type2test(b'_')), b'_')
+ self.assertEqual(b2a_qp(type2test(b'_'), header=True), b'=5F')
+ self.assertEqual(b2a_qp(type2test(b'x y'), header=True), b'x_y')
+ self.assertEqual(b2a_qp(type2test(b'x '), header=True), b'x=20')
+ self.assertEqual(b2a_qp(type2test(b'x y'), header=True, quotetabs=True),
+ b'x=20y')
+ self.assertEqual(b2a_qp(type2test(b'x\ty'), header=True), b'x\ty')
+
+ self.assertEqual(b2a_qp(type2test(b' ')), b'=20')
+ self.assertEqual(b2a_qp(type2test(b'\t')), b'=09')
+ self.assertEqual(b2a_qp(type2test(b' x')), b' x')
+ self.assertEqual(b2a_qp(type2test(b'\tx')), b'\tx')
+ self.assertEqual(b2a_qp(type2test(b' x')[:-1]), b'=20')
+ self.assertEqual(b2a_qp(type2test(b'\tx')[:-1]), b'=09')
+ self.assertEqual(b2a_qp(type2test(b'\0')), b'=00')
+
+ self.assertEqual(b2a_qp(type2test(b'\0\n')), b'=00\n')
+ self.assertEqual(b2a_qp(type2test(b'\0\n'), quotetabs=True), b'=00\n')
+
+ self.assertEqual(b2a_qp(type2test(b'x y\tz')), b'x y\tz')
+ self.assertEqual(b2a_qp(type2test(b'x y\tz'), quotetabs=True),
+ b'x=20y=09z')
+ self.assertEqual(b2a_qp(type2test(b'x y\tz'), istext=False),
+ b'x y\tz')
+ self.assertEqual(b2a_qp(type2test(b'x \ny\t\n')),
+ b'x=20\ny=09\n')
+ self.assertEqual(b2a_qp(type2test(b'x \ny\t\n'), quotetabs=True),
+ b'x=20\ny=09\n')
+ self.assertEqual(b2a_qp(type2test(b'x \ny\t\n'), istext=False),
+ b'x =0Ay\t=0A')
+ self.assertEqual(b2a_qp(type2test(b'x \ry\t\r')),
+ b'x \ry\t\r')
+ self.assertEqual(b2a_qp(type2test(b'x \ry\t\r'), quotetabs=True),
+ b'x=20\ry=09\r')
+ self.assertEqual(b2a_qp(type2test(b'x \ry\t\r'), istext=False),
+ b'x =0Dy\t=0D')
+ self.assertEqual(b2a_qp(type2test(b'x \r\ny\t\r\n')),
+ b'x=20\r\ny=09\r\n')
+ self.assertEqual(b2a_qp(type2test(b'x \r\ny\t\r\n'), quotetabs=True),
+ b'x=20\r\ny=09\r\n')
+ self.assertEqual(b2a_qp(type2test(b'x \r\ny\t\r\n'), istext=False),
+ b'x =0D=0Ay\t=0D=0A')
+
+ self.assertEqual(b2a_qp(type2test(b'x \r\n')[:-1]), b'x \r')
+ self.assertEqual(b2a_qp(type2test(b'x\t\r\n')[:-1]), b'x\t\r')
+ self.assertEqual(b2a_qp(type2test(b'x \r\n')[:-1], quotetabs=True),
+ b'x=20\r')
+ self.assertEqual(b2a_qp(type2test(b'x\t\r\n')[:-1], quotetabs=True),
+ b'x=09\r')
+ self.assertEqual(b2a_qp(type2test(b'x \r\n')[:-1], istext=False),
+ b'x =0D')
+ self.assertEqual(b2a_qp(type2test(b'x\t\r\n')[:-1], istext=False),
+ b'x\t=0D')
+
+ self.assertEqual(b2a_qp(type2test(b'.')), b'=2E')
+ self.assertEqual(b2a_qp(type2test(b'.\n')), b'=2E\n')
+ self.assertEqual(b2a_qp(type2test(b'.\r')), b'=2E\r')
+ self.assertEqual(b2a_qp(type2test(b'.\0')), b'=2E=00')
+ self.assertEqual(b2a_qp(type2test(b'a.\n')), b'a.\n')
+ self.assertEqual(b2a_qp(type2test(b'.a')[:-1]), b'=2E')
def test_empty_string(self):
# A test for SF bug #1022953. Make sure SystemError is not raised.
# see #15421
list(calendar.Calendar().itermonthdates(datetime.MAXYEAR, 12))
+ def test_itermonthdays(self):
+ for firstweekday in range(7):
+ cal = calendar.Calendar(firstweekday)
+ # Test the extremes, see #28253 and #26650
+ for y, m in [(1, 1), (9999, 12)]:
+ days = list(cal.itermonthdays(y, m))
+ self.assertIn(len(days), (35, 42))
+ # Test a short month
+ cal = calendar.Calendar(firstweekday=3)
+ days = list(cal.itermonthdays(2001, 2))
+ self.assertEqual(days, list(range(1, 29)))
+
+ def test_itermonthdays2(self):
+ for firstweekday in range(7):
+ cal = calendar.Calendar(firstweekday)
+ # Test the extremes, see #28253 and #26650
+ for y, m in [(1, 1), (9999, 12)]:
+ days = list(cal.itermonthdays2(y, m))
+ self.assertEqual(days[0][1], firstweekday)
+ self.assertEqual(days[-1][1], (firstweekday - 1) % 7)
+
class MonthCalendarTestCase(unittest.TestCase):
def setUp(self):
self.assertEqual(co.co_firstlineno, 15)
+def isinterned(s):
+ return s is intern(('_' + s + '_')[1:-1])
+
+class CodeConstsTest(unittest.TestCase):
+
+ def find_const(self, consts, value):
+ for v in consts:
+ if v == value:
+ return v
+ self.assertIn(value, consts) # raises an exception
+ self.fail('Should never be reached')
+
+ def assertIsInterned(self, s):
+ if not isinterned(s):
+ self.fail('String %r is not interned' % (s,))
+
+ def assertIsNotInterned(self, s):
+ if isinterned(s):
+ self.fail('String %r is interned' % (s,))
+
+ @cpython_only
+ def test_interned_string(self):
+ co = compile('res = "str_value"', '?', 'exec')
+ v = self.find_const(co.co_consts, 'str_value')
+ self.assertIsInterned(v)
+
+ @cpython_only
+ def test_interned_string_in_tuple(self):
+ co = compile('res = ("str_value",)', '?', 'exec')
+ v = self.find_const(co.co_consts, ('str_value',))
+ self.assertIsInterned(v[0])
+
+ @cpython_only
+ def test_interned_string_default(self):
+ def f(a='str_value'):
+ return a
+ self.assertIsInterned(f())
+
+ @cpython_only
+ def test_interned_string_with_null(self):
+ co = compile(r'res = "str\0value!"', '?', 'exec')
+ v = self.find_const(co.co_consts, 'str\0value!')
+ self.assertIsNotInterned(v)
+
+
class CodeWeakRefTest(unittest.TestCase):
def test_basic(self):
def test_main(verbose=None):
from test import test_code
run_doctest(test_code, verbose)
- run_unittest(CodeTest, CodeWeakRefTest)
+ run_unittest(CodeTest, CodeConstsTest, CodeWeakRefTest)
if __name__ == "__main__":
import re
import time
+from cookielib import http2time, time2isoz, time2netscape
from unittest import TestCase
from test import test_support
class DateTimeTests(TestCase):
def test_time2isoz(self):
- from cookielib import time2isoz
-
base = 1019227000
day = 24*3600
self.assertEqual(time2isoz(base), "2002-04-19 14:36:40Z")
r"^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$",
"bad time2isoz format: %s %s" % (az, bz))
- def test_http2time(self):
- from cookielib import http2time
+ def test_time2netscape(self):
+ base = 1019227000
+ day = 24*3600
+ self.assertEqual(time2netscape(base), "Fri, 19-Apr-2002 14:36:40 GMT")
+ self.assertEqual(time2netscape(base+day),
+ "Sat, 20-Apr-2002 14:36:40 GMT")
+
+ self.assertEqual(time2netscape(base+2*day),
+ "Sun, 21-Apr-2002 14:36:40 GMT")
+
+ self.assertEqual(time2netscape(base+3*day),
+ "Mon, 22-Apr-2002 14:36:40 GMT")
+ az = time2netscape()
+ bz = time2netscape(500000)
+ for text in (az, bz):
+ # Format "%s, %02d-%s-%04d %02d:%02d:%02d GMT"
+ self.assertRegexpMatches(
+ text,
+ r"[a-zA-Z]{3}, \d{2}-[a-zA-Z]{3}-\d{4} \d{2}:\d{2}:\d{2} GMT$",
+ "bad time2netscape format: %s %s" % (az, bz))
+
+ def test_http2time(self):
def parse_date(text):
return time.gmtime(http2time(text))[:6]
self.assertEqual(parse_date("03-Feb-98"), (1998, 2, 3, 0, 0, 0.0))
def test_http2time_formats(self):
- from cookielib import http2time, time2isoz
+
# test http2time for supported dates. Test cases with 2 digit year
# will probably break in year 2044.
self.assertEqual(http2time(s.upper()), test_t, s.upper())
def test_http2time_garbage(self):
- from cookielib import http2time
-
for test in [
'',
'Garbage',
## comma-separated list, it'll be a headache to parse (at least my head
## starts hurting every time I think of that code).
## - Expires: You'll get all sorts of date formats in the expires,
-## including emtpy expires attributes ("expires="). Be as flexible as you
+## including empty expires attributes ("expires="). Be as flexible as you
## can, and certainly don't expect the weekday to be there; if you can't
## parse it, just ignore it and pretend it's a session cookie.
## - Domain-matching: Netscape uses the 2-dot rule for _all_ domains, not
#
import os
+import string
import sys
import tempfile
import unittest
def setUp(self):
if verbose:
# just to make the test output a little more readable
- print()
+ print('')
self.stdscr = curses.initscr()
curses.savetty()
if hasattr(curses, 'enclose'):
stdscr.enclose()
+ self.assertRaises(ValueError, stdscr.getstr, -400)
+ self.assertRaises(ValueError, stdscr.getstr, 2, 3, -400)
+ self.assertRaises(ValueError, stdscr.instr, -2)
+ self.assertRaises(ValueError, stdscr.instr, 2, 3, -2)
+
def test_module_funcs(self):
"Test module-level functions"
class TestAscii(unittest.TestCase):
+ def test_controlnames(self):
+ for name in curses.ascii.controlnames:
+ self.assertTrue(hasattr(curses.ascii, name), name)
+
+ def test_ctypes(self):
+ def check(func, expected):
+ self.assertEqual(func(i), expected)
+ self.assertEqual(func(c), expected)
+
+ for i in range(256):
+ c = b = chr(i)
+ check(curses.ascii.isalnum, b.isalnum())
+ check(curses.ascii.isalpha, b.isalpha())
+ check(curses.ascii.isdigit, b.isdigit())
+ check(curses.ascii.islower, b.islower())
+ check(curses.ascii.isspace, b.isspace())
+ check(curses.ascii.isupper, b.isupper())
+
+ check(curses.ascii.isascii, i < 128)
+ check(curses.ascii.ismeta, i >= 128)
+ check(curses.ascii.isctrl, i < 32)
+ check(curses.ascii.iscntrl, i < 32 or i == 127)
+ check(curses.ascii.isblank, c in ' \t')
+ check(curses.ascii.isgraph, 32 < i <= 126)
+ check(curses.ascii.isprint, 32 <= i <= 126)
+ check(curses.ascii.ispunct, c in string.punctuation)
+ check(curses.ascii.isxdigit, c in string.hexdigits)
+
+ def test_ascii(self):
+ ascii = curses.ascii.ascii
+ self.assertEqual(ascii('\xc1'), 'A')
+ self.assertEqual(ascii('A'), 'A')
+ self.assertEqual(ascii(ord('\xc1')), ord('A'))
+
+ def test_ctrl(self):
+ ctrl = curses.ascii.ctrl
+ self.assertEqual(ctrl('J'), '\n')
+ self.assertEqual(ctrl('\n'), '\n')
+ self.assertEqual(ctrl('@'), '\0')
+ self.assertEqual(ctrl(ord('J')), ord('\n'))
+
+ def test_alt(self):
+ alt = curses.ascii.alt
+ self.assertEqual(alt('\n'), '\x8a')
+ self.assertEqual(alt('A'), '\xc1')
+ self.assertEqual(alt(ord('A')), 0xc1)
+
def test_unctrl(self):
unctrl = curses.ascii.unctrl
self.assertEqual(unctrl('a'), 'a')
self.assertEqual(unctrl('\x7f'), '^?')
self.assertEqual(unctrl('\n'), '^J')
self.assertEqual(unctrl('\0'), '^@')
+ self.assertEqual(unctrl(ord('A')), 'A')
+ self.assertEqual(unctrl(ord('\n')), '^J')
# Meta-bit characters
self.assertEqual(unctrl('\x8a'), '!^J')
self.assertEqual(unctrl('\xc1'), '!A')
+ self.assertEqual(unctrl(ord('\x8a')), '!^J')
+ self.assertEqual(unctrl(ord('\xc1')), '!A')
def test_main():
self.assertRaises(TypeError, lambda: as_date >= as_datetime)
self.assertRaises(TypeError, lambda: as_datetime >= as_date)
- # Neverthelss, comparison should work with the base-class (date)
+ # Nevertheless, comparison should work with the base-class (date)
# projection if use of a date method is forced.
self.assertTrue(as_date.__eq__(as_datetime))
different_day = (as_date.day + 1) % 20 + 1
d.clear()
self.assertEqual(len(d), 0)
self.assertEqual(list(d), [])
- d.clear() # clear an emtpy deque
+ d.clear() # clear an empty deque
self.assertEqual(list(d), [])
def test_remove(self):
self.fail("inheriting from ModuleType and str at the same time "
"should fail")
- def test_multiple_inheritence(self):
+ def test_multiple_inheritance(self):
# Testing multiple inheritance...
class C(object):
def __init__(self):
else:
self.fail("new class with only classic bases - shouldn't be")
- def test_diamond_inheritence(self):
+ def test_diamond_inheritance(self):
# Testing multiple inheritance special cases...
class A(object):
def spam(self): return "A"
...
AttributeError: 'module' object has no attribute 'sillySetup'
- The setUp and tearDown funtions are passed test objects. Here
+ The setUp and tearDown functions are passed test objects. Here
we'll use the setUp function to supply the missing variable y:
>>> def setUp(test):
...
AttributeError: 'module' object has no attribute 'sillySetup'
- The setUp and tearDown funtions are passed test objects.
+ The setUp and tearDown functions are passed test objects.
Here, we'll use a setUp function to set the favorite color in
test_doctest.txt:
import sys
from test import test_support
threading = test_support.import_module('threading')
-import time
-import socket
import unittest
-PORT = None
-
def make_request_and_skipIf(condition, reason):
# If we skip the test, we have to make a request because
# the server created in setUp blocks expecting one to come in.
return decorator
-def server(evt, numrequests):
+def make_server():
serv = DocXMLRPCServer(("localhost", 0), logRequests=False)
try:
- global PORT
- PORT = serv.socket.getsockname()[1]
-
# Add some documentation
serv.set_server_title("DocXMLRPCServer Test Documentation")
serv.set_server_name("DocXMLRPCServer Test Docs")
serv.register_function(add)
serv.register_function(lambda x, y: x-y)
-
- while numrequests > 0:
- serv.handle_request()
- numrequests -= 1
- except socket.timeout:
- pass
- finally:
+ return serv
+ except:
serv.server_close()
- PORT = None
- evt.set()
+ raise
class DocXMLRPCHTTPGETServer(unittest.TestCase):
def setUp(self):
- self._threads = test_support.threading_setup()
# Enable server feedback
DocXMLRPCServer._send_traceback_header = True
- self.evt = threading.Event()
- threading.Thread(target=server, args=(self.evt, 1)).start()
-
- # wait for port to be assigned
- n = 1000
- while n > 0 and PORT is None:
- time.sleep(0.001)
- n -= 1
+ self.serv = make_server()
+ self.thread = threading.Thread(target=self.serv.serve_forever)
+ self.thread.start()
+ PORT = self.serv.server_address[1]
self.client = httplib.HTTPConnection("localhost:%d" % PORT)
def tearDown(self):
self.client.close()
- self.evt.wait()
-
# Disable server feedback
DocXMLRPCServer._send_traceback_header = False
- test_support.threading_cleanup(*self._threads)
+ self.serv.shutdown()
+ self.thread.join()
+ self.serv.server_close()
def test_valid_get_response(self):
self.client.request("GET", "/")
@make_request_and_skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above")
def test_system_methods(self):
- """Test the precense of three consecutive system.* methods.
+ """Test the presence of three consecutive system.* methods.
This also tests their use of parameter type recognition and the
systems related to that process.
"""
import os
+import stat
import unittest
import dumbdbm
from test import test_support
dumbdbm.open(_fname).close()
self.assertEqual(stdout.getvalue(), '')
+ @unittest.skipUnless(hasattr(os, 'chmod'), 'test needs os.chmod()')
+ def test_readonly_files(self):
+ dir = _fname
+ os.mkdir(dir)
+ try:
+ fname = os.path.join(dir, 'db')
+ f = dumbdbm.open(fname, 'n')
+ self.assertEqual(list(f.keys()), [])
+ for key in self._dict:
+ f[key] = self._dict[key]
+ f.close()
+ os.chmod(fname + ".dir", stat.S_IRUSR)
+ os.chmod(fname + ".dat", stat.S_IRUSR)
+ os.chmod(dir, stat.S_IRUSR|stat.S_IXUSR)
+ f = dumbdbm.open(fname, 'r')
+ self.assertEqual(sorted(f.keys()), sorted(self._dict))
+ f.close() # don't write
+ finally:
+ test_support.rmtree(dir)
+
def tearDown(self):
_delete_files()
import ensurepip
import ensurepip._uninstall
-# pip currently requires ssl support, so we ensure we handle
-# it being missing (http://bugs.python.org/issue19744)
-ensurepip_no_ssl = test.test_support.import_fresh_module("ensurepip",
- blocked=["ssl"])
-try:
- import ssl
-except ImportError:
- ssl = None
-
- def requires_usable_pip(f):
- deco = unittest.skip(ensurepip._MISSING_SSL_MESSAGE)
- return deco(f)
-else:
- def requires_usable_pip(f):
- return f
-
class TestEnsurePipVersion(unittest.TestCase):
class TestBootstrap(EnsurepipMixin, unittest.TestCase):
- @requires_usable_pip
def test_basic_bootstrapping(self):
ensurepip.bootstrap()
additional_paths = self.run_pip.call_args[0][1]
self.assertEqual(len(additional_paths), 2)
- @requires_usable_pip
def test_bootstrapping_with_root(self):
ensurepip.bootstrap(root="/foo/bar/")
mock.ANY,
)
- @requires_usable_pip
def test_bootstrapping_with_user(self):
ensurepip.bootstrap(user=True)
mock.ANY,
)
- @requires_usable_pip
def test_bootstrapping_with_upgrade(self):
ensurepip.bootstrap(upgrade=True)
mock.ANY,
)
- @requires_usable_pip
def test_bootstrapping_with_verbosity_1(self):
ensurepip.bootstrap(verbosity=1)
mock.ANY,
)
- @requires_usable_pip
def test_bootstrapping_with_verbosity_2(self):
ensurepip.bootstrap(verbosity=2)
mock.ANY,
)
- @requires_usable_pip
def test_bootstrapping_with_verbosity_3(self):
ensurepip.bootstrap(verbosity=3)
mock.ANY,
)
- @requires_usable_pip
def test_bootstrapping_with_regular_install(self):
ensurepip.bootstrap()
self.assertEqual(self.os_environ["ENSUREPIP_OPTIONS"], "install")
- @requires_usable_pip
def test_bootstrapping_with_alt_install(self):
ensurepip.bootstrap(altinstall=True)
self.assertEqual(self.os_environ["ENSUREPIP_OPTIONS"], "altinstall")
- @requires_usable_pip
def test_bootstrapping_with_default_pip(self):
ensurepip.bootstrap(default_pip=True)
self.assertNotIn("ENSUREPIP_OPTIONS", self.os_environ)
ensurepip.bootstrap(altinstall=True, default_pip=True)
self.assertFalse(self.run_pip.called)
- @requires_usable_pip
def test_pip_environment_variables_removed(self):
# ensurepip deliberately ignores all pip environment variables
# See http://bugs.python.org/issue19734 for details
ensurepip.bootstrap()
self.assertNotIn("PIP_THIS_SHOULD_GO_AWAY", self.os_environ)
- @requires_usable_pip
def test_pip_config_file_disabled(self):
# ensurepip deliberately ignores the pip config file
# See http://bugs.python.org/issue20053 for details
self.assertIn("only uninstall a matching version", warning)
self.assertFalse(self.run_pip.called)
- @requires_usable_pip
def test_uninstall(self):
with fake_pip():
ensurepip._uninstall_helper()
]
)
- @requires_usable_pip
def test_uninstall_with_verbosity_1(self):
with fake_pip():
ensurepip._uninstall_helper(verbosity=1)
]
)
- @requires_usable_pip
def test_uninstall_with_verbosity_2(self):
with fake_pip():
ensurepip._uninstall_helper(verbosity=2)
]
)
- @requires_usable_pip
def test_uninstall_with_verbosity_3(self):
with fake_pip():
ensurepip._uninstall_helper(verbosity=3)
]
)
- @requires_usable_pip
def test_pip_environment_variables_removed(self):
# ensurepip deliberately ignores all pip environment variables
# See http://bugs.python.org/issue19734 for details
ensurepip._uninstall_helper()
self.assertNotIn("PIP_THIS_SHOULD_GO_AWAY", self.os_environ)
- @requires_usable_pip
def test_pip_config_file_disabled(self):
# ensurepip deliberately ignores the pip config file
# See http://bugs.python.org/issue20053 for details
self.assertEqual(self.os_environ["PIP_CONFIG_FILE"], os.devnull)
-class TestMissingSSL(EnsurepipMixin, unittest.TestCase):
-
- def setUp(self):
- sys.modules["ensurepip"] = ensurepip_no_ssl
-
- @self.addCleanup
- def restore_module():
- sys.modules["ensurepip"] = ensurepip
- super(TestMissingSSL, self).setUp()
-
- def test_bootstrap_requires_ssl(self):
- self.os_environ["PIP_THIS_SHOULD_STAY"] = "test fodder"
- with self.assertRaisesRegexp(RuntimeError, "requires SSL/TLS"):
- ensurepip_no_ssl.bootstrap()
- self.assertFalse(self.run_pip.called)
- self.assertIn("PIP_THIS_SHOULD_STAY", self.os_environ)
-
- def test_uninstall_requires_ssl(self):
- self.os_environ["PIP_THIS_SHOULD_STAY"] = "test fodder"
- with self.assertRaisesRegexp(RuntimeError, "requires SSL/TLS"):
- with fake_pip():
- ensurepip_no_ssl._uninstall_helper()
- self.assertFalse(self.run_pip.called)
- self.assertIn("PIP_THIS_SHOULD_STAY", self.os_environ)
-
- def test_main_exits_early_with_warning(self):
- with test.test_support.captured_stderr() as stderr:
- ensurepip_no_ssl._main(["--version"])
- warning = stderr.getvalue().strip()
- self.assertTrue(warning.endswith("requires SSL/TLS"), warning)
- self.assertFalse(self.run_pip.called)
-
# Basic testing of the main functions and their argument parsing
EXPECTED_VERSION_OUTPUT = "pip " + ensurepip._PIP_VERSION
class TestBootstrappingMainFunction(EnsurepipMixin, unittest.TestCase):
- @requires_usable_pip
def test_bootstrap_version(self):
with test.test_support.captured_stderr() as stderr:
with self.assertRaises(SystemExit):
self.assertEqual(result, EXPECTED_VERSION_OUTPUT)
self.assertFalse(self.run_pip.called)
- @requires_usable_pip
def test_basic_bootstrapping(self):
ensurepip._main([])
self.assertEqual(result, EXPECTED_VERSION_OUTPUT)
self.assertFalse(self.run_pip.called)
- @requires_usable_pip
def test_basic_uninstall(self):
with fake_pip():
ensurepip._uninstall._main([])
...
TypeError: h() argument after * must be an iterable, not function
+ >>> h(1, *h)
+ Traceback (most recent call last):
+ ...
+ TypeError: h() argument after * must be an iterable, not function
+
>>> dir(*h)
Traceback (most recent call last):
...
...
TypeError: h() argument after ** must be a mapping, not function
+ >>> h(**[])
+ Traceback (most recent call last):
+ ...
+ TypeError: h() argument after ** must be a mapping, not list
+
+ >>> h(a=1, **h)
+ Traceback (most recent call last):
+ ...
+ TypeError: h() argument after ** must be a mapping, not function
+
+ >>> h(a=1, **[])
+ Traceback (most recent call last):
+ ...
+ TypeError: h() argument after ** must be a mapping, not list
+
>>> dir(**h)
Traceback (most recent call last):
...
self.assertEqual(f.writable(), True)
if sys.platform != "darwin" and \
'bsd' not in sys.platform and \
- not sys.platform.startswith('sunos'):
+ not sys.platform.startswith(('sunos', 'aix')):
# Somehow /dev/tty appears seekable on some BSDs
self.assertEqual(f.seekable(), False)
self.assertEqual(f.isatty(), True)
finally:
os.unlink(TESTFN)
+ def testConstructorHandlesNULChars(self):
+ fn_with_NUL = 'foo\0bar'
+ self.assertRaises(TypeError, _FileIO, fn_with_NUL, 'w')
+ self.assertRaises(TypeError, _FileIO, fn_with_NUL.encode('ascii'), 'w')
+
def testInvalidFd(self):
self.assertRaises(ValueError, _FileIO, -10)
self.assertRaises(OSError, _FileIO, make_bad_fd())
else:
raise TestFailed, '"%*d"%(maxsize, -127) should fail'
+ def test_invalid_special_methods(self):
+ tests = []
+ for f in 'sriduoxXfge':
+ tests.append(('%' + f, 1, TypeError))
+ tests.append(('%#' + f, 1, TypeError))
+ for r in ['', '-', 'L', '-L']:
+ for f in 'iduoxX':
+ tests.append(('%' + f, r, ValueError))
+ tests.append(('%#' + f, r, ValueError))
+ tests.append(('%o', 'abc', ValueError))
+ for r in ('abc', '0abc', '0x', '0xL'):
+ for f in 'xX':
+ tests.append(('%' + f, r, ValueError))
+ for r in ('0x', '0xL'):
+ for f in 'xX':
+ tests.append(('%#' + f, r, ValueError))
+
+ class X(long):
+ def __repr__(self):
+ return result
+ def __str__(self):
+ return result
+ def __oct__(self):
+ return result
+ def __hex__(self):
+ return result
+ def __float__(self):
+ return result
+ for fmt, result, exc in tests:
+ try:
+ fmt % X()
+ except exc:
+ pass
+ else:
+ self.fail('%s not raised for %r format of %r' %
+ (exc.__name__, fmt, result))
+
+
def test_main():
test_support.run_unittest(FormatTest)
class TestPartial(unittest.TestCase):
- thetype = functools.partial
+ partial = functools.partial
def test_basic_examples(self):
- p = self.thetype(capture, 1, 2, a=10, b=20)
+ p = self.partial(capture, 1, 2, a=10, b=20)
self.assertEqual(p(3, 4, b=30, c=40),
((1, 2, 3, 4), dict(a=10, b=30, c=40)))
- p = self.thetype(map, lambda x: x*10)
+ p = self.partial(map, lambda x: x*10)
self.assertEqual(p([1,2,3,4]), [10, 20, 30, 40])
def test_attributes(self):
- p = self.thetype(capture, 1, 2, a=10, b=20)
+ p = self.partial(capture, 1, 2, a=10, b=20)
# attributes should be readable
self.assertEqual(p.func, capture)
self.assertEqual(p.args, (1, 2))
self.assertRaises(TypeError, setattr, p, 'args', (1, 2))
self.assertRaises(TypeError, setattr, p, 'keywords', dict(a=1, b=2))
- p = self.thetype(hex)
+ p = self.partial(hex)
try:
del p.__dict__
except TypeError:
self.fail('partial object allowed __dict__ to be deleted')
def test_argument_checking(self):
- self.assertRaises(TypeError, self.thetype) # need at least a func arg
+ self.assertRaises(TypeError, self.partial) # need at least a func arg
try:
- self.thetype(2)()
+ self.partial(2)()
except TypeError:
pass
else:
def func(a=10, b=20):
return a
d = {'a':3}
- p = self.thetype(func, a=5)
+ p = self.partial(func, a=5)
self.assertEqual(p(**d), 3)
self.assertEqual(d, {'a':3})
p(b=7)
def test_arg_combinations(self):
# exercise special code paths for zero args in either partial
# object or the caller
- p = self.thetype(capture)
+ p = self.partial(capture)
self.assertEqual(p(), ((), {}))
self.assertEqual(p(1,2), ((1,2), {}))
- p = self.thetype(capture, 1, 2)
+ p = self.partial(capture, 1, 2)
self.assertEqual(p(), ((1,2), {}))
self.assertEqual(p(3,4), ((1,2,3,4), {}))
def test_kw_combinations(self):
# exercise special code paths for no keyword args in
# either the partial object or the caller
- p = self.thetype(capture)
+ p = self.partial(capture)
self.assertEqual(p.keywords, {})
self.assertEqual(p(), ((), {}))
self.assertEqual(p(a=1), ((), {'a':1}))
- p = self.thetype(capture, a=1)
+ p = self.partial(capture, a=1)
self.assertEqual(p.keywords, {'a':1})
self.assertEqual(p(), ((), {'a':1}))
self.assertEqual(p(b=2), ((), {'a':1, 'b':2}))
def test_positional(self):
# make sure positional arguments are captured correctly
for args in [(), (0,), (0,1), (0,1,2), (0,1,2,3)]:
- p = self.thetype(capture, *args)
+ p = self.partial(capture, *args)
expected = args + ('x',)
got, empty = p('x')
self.assertTrue(expected == got and empty == {})
def test_keyword(self):
# make sure keyword arguments are captured correctly
for a in ['a', 0, None, 3.5]:
- p = self.thetype(capture, a=a)
+ p = self.partial(capture, a=a)
expected = {'a':a,'x':None}
empty, got = p(x=None)
self.assertTrue(expected == got and empty == ())
def test_no_side_effects(self):
# make sure there are no side effects that affect subsequent calls
- p = self.thetype(capture, 0, a=1)
+ p = self.partial(capture, 0, a=1)
args1, kw1 = p(1, b=2)
self.assertTrue(args1 == (0,1) and kw1 == {'a':1,'b':2})
args2, kw2 = p()
def test_error_propagation(self):
def f(x, y):
x // y
- self.assertRaises(ZeroDivisionError, self.thetype(f, 1, 0))
- self.assertRaises(ZeroDivisionError, self.thetype(f, 1), 0)
- self.assertRaises(ZeroDivisionError, self.thetype(f), 1, 0)
- self.assertRaises(ZeroDivisionError, self.thetype(f, y=0), 1)
+ self.assertRaises(ZeroDivisionError, self.partial(f, 1, 0))
+ self.assertRaises(ZeroDivisionError, self.partial(f, 1), 0)
+ self.assertRaises(ZeroDivisionError, self.partial(f), 1, 0)
+ self.assertRaises(ZeroDivisionError, self.partial(f, y=0), 1)
def test_weakref(self):
- f = self.thetype(int, base=16)
+ f = self.partial(int, base=16)
p = proxy(f)
self.assertEqual(f.func, p.func)
f = None
def test_with_bound_and_unbound_methods(self):
data = map(str, range(10))
- join = self.thetype(str.join, '')
+ join = self.partial(str.join, '')
self.assertEqual(join(data), '0123456789')
- join = self.thetype(''.join)
+ join = self.partial(''.join)
self.assertEqual(join(data), '0123456789')
def test_pickle(self):
- f = self.thetype(signature, ['asdf'], bar=[True])
+ f = self.partial(signature, ['asdf'], bar=[True])
f.attr = []
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
f_copy = pickle.loads(pickle.dumps(f, proto))
self.assertEqual(signature(f_copy), signature(f))
def test_copy(self):
- f = self.thetype(signature, ['asdf'], bar=[True])
+ f = self.partial(signature, ['asdf'], bar=[True])
f.attr = []
f_copy = copy.copy(f)
self.assertEqual(signature(f_copy), signature(f))
self.assertIs(f_copy.keywords, f.keywords)
def test_deepcopy(self):
- f = self.thetype(signature, ['asdf'], bar=[True])
+ f = self.partial(signature, ['asdf'], bar=[True])
f.attr = []
f_copy = copy.deepcopy(f)
self.assertEqual(signature(f_copy), signature(f))
self.assertIsNot(f_copy.keywords['bar'], f.keywords['bar'])
def test_setstate(self):
- f = self.thetype(signature)
+ f = self.partial(signature)
f.__setstate__((capture, (1,), dict(a=10), dict(attr=[])))
self.assertEqual(signature(f),
(capture, (1,), dict(a=10), dict(attr=[])))
self.assertEqual(f(), ((), {}))
def test_setstate_errors(self):
- f = self.thetype(signature)
+ f = self.partial(signature)
self.assertRaises(TypeError, f.__setstate__, (capture, (), {}))
self.assertRaises(TypeError, f.__setstate__, (capture, (), {}, {}, None))
self.assertRaises(TypeError, f.__setstate__, [capture, (), {}, None])
self.assertRaises(TypeError, f.__setstate__, (capture, (), [], None))
def test_setstate_subclasses(self):
- f = self.thetype(signature)
+ f = self.partial(signature)
f.__setstate__((capture, MyTuple((1,)), MyDict(a=10), None))
s = signature(f)
self.assertEqual(s, (capture, (1,), dict(a=10), {}))
self.assertEqual(r, ((1, 2), {}))
self.assertIs(type(r[0]), tuple)
+ def test_recursive_pickle(self):
+ f = self.partial(capture)
+ f.__setstate__((f, (), {}, {}))
+ try:
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ with self.assertRaises(RuntimeError):
+ pickle.dumps(f, proto)
+ finally:
+ f.__setstate__((capture, (), {}, {}))
+
+ f = self.partial(capture)
+ f.__setstate__((capture, (f,), {}, {}))
+ try:
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ f_copy = pickle.loads(pickle.dumps(f, proto))
+ try:
+ self.assertIs(f_copy.args[0], f_copy)
+ finally:
+ f_copy.__setstate__((capture, (), {}, {}))
+ finally:
+ f.__setstate__((capture, (), {}, {}))
+
+ f = self.partial(capture)
+ f.__setstate__((capture, (), {'a': f}, {}))
+ try:
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ f_copy = pickle.loads(pickle.dumps(f, proto))
+ try:
+ self.assertIs(f_copy.keywords['a'], f_copy)
+ finally:
+ f_copy.__setstate__((capture, (), {}, {}))
+ finally:
+ f.__setstate__((capture, (), {}, {}))
+
# Issue 6083: Reference counting bug
def test_setstate_refcount(self):
class BadSequence:
return {}
raise IndexError
- f = self.thetype(object)
+ f = self.partial(object)
self.assertRaises(TypeError, f.__setstate__, BadSequence())
class PartialSubclass(functools.partial):
class TestPartialSubclass(TestPartial):
- thetype = PartialSubclass
+ partial = PartialSubclass
class TestPythonPartial(TestPartial):
- thetype = PythonPartial
+ partial = PythonPartial
# the python version isn't picklable
test_pickle = None
test_setstate_errors = None
test_setstate_subclasses = None
test_setstate_refcount = None
+ test_recursive_pickle = None
# the python version isn't deepcopyable
test_deepcopy = None
import re
import subprocess
import sys
+import sysconfig
import unittest
import sysconfig
try:
proc = subprocess.Popen(["gdb", "-nx", "--version"],
stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
universal_newlines=True)
version = proc.communicate()[0]
except OSError:
).communicate()
return out, err
+if not sysconfig.is_python_build():
+ raise unittest.SkipTest("test_gdb only works on source builds at the moment.")
+
# Verify that "gdb" was built with the embedded python support enabled:
gdbpy_version, _ = run_gdb("--eval-command=python import sys; print(sys.version_info)")
if not gdbpy_version:
def get_sample_script(self):
return findfile('gdb_sample.py')
+
+@unittest.skipIf(python_is_optimized(),
+ "Python was compiled with optimizations")
class PrettyPrintTests(DebuggerTests):
def test_getting_backtrace(self):
gdb_output = self.get_stack_trace('print 42')
'Unable to find a newer python frame\n')
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
+ @unittest.skipIf(python_is_optimized(),
+ "Python was compiled with optimizations")
def test_up_at_top(self):
'Verify handling of "py-up" at the top of the stack'
bt = self.get_stack_trace(script=self.get_sample_script(),
@unittest.skipUnless(thread,
"Python was compiled without thread support")
+ @unittest.skipIf(python_is_optimized(),
+ "Python was compiled with optimizations")
def test_threads(self):
'Verify that "py-bt" indicates threads that are waiting for the GIL'
cmd = '''
def test_u(self):
from _testcapi import getargs_u
self.assertEqual(getargs_u(u'abc\xe9'), u'abc\xe9')
- self.assertEqual(getargs_u(u'nul:\0'), u'nul:')
+ self.assertRaises(TypeError, getargs_u, u'nul:\0')
self.assertRaises(TypeError, getargs_u, 'bytes')
self.assertRaises(TypeError, getargs_u, bytearray('bytearray'))
self.assertRaises(TypeError, getargs_u, memoryview('memoryview'))
x = t.ngettext('There is %s file', 'There are %s files', 2)
eq(x, 'Hay %s ficheros')
- def test_hu(self):
+ # Examples from http://www.gnu.org/software/gettext/manual/gettext.html
+
+ def test_ja(self):
eq = self.assertEqual
f = gettext.c2py('0')
s = ''.join([ str(f(x)) for x in range(200) ])
s = ''.join([ str(f(x)) for x in range(200) ])
eq(s, "00111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")
+ def test_lv(self):
+ eq = self.assertEqual
+ f = gettext.c2py('n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2')
+ s = ''.join([ str(f(x)) for x in range(200) ])
+ eq(s, "20111111111111111111101111111110111111111011111111101111111110111111111011111111101111111110111111111011111111111111111110111111111011111111101111111110111111111011111111101111111110111111111011111111")
+
def test_gd(self):
eq = self.assertEqual
f = gettext.c2py('n==1 ? 0 : n==2 ? 1 : 2')
s = ''.join([ str(f(x)) for x in range(200) ])
eq(s, "20122222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222")
+ def test_ro(self):
+ eq = self.assertEqual
+ f = gettext.c2py('n==1 ? 0 : (n==0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2')
+ s = ''.join([ str(f(x)) for x in range(200) ])
+ eq(s, "10111111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222111111111111111111122222222222222222222222222222222222222222222222222222222222222222222222222222222")
+
def test_lt(self):
eq = self.assertEqual
f = gettext.c2py('n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2')
s = ''.join([ str(f(x)) for x in range(200) ])
eq(s, "20111222222222222222201112222220111222222011122222201112222220111222222011122222201112222220111222222011122222222222222220111222222011122222201112222220111222222011122222201112222220111222222011122222")
+ def test_cs(self):
+ eq = self.assertEqual
+ f = gettext.c2py('(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2')
+ s = ''.join([ str(f(x)) for x in range(200) ])
+ eq(s, "20111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222")
+
def test_pl(self):
eq = self.assertEqual
f = gettext.c2py('n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2')
s = ''.join([ str(f(x)) for x in range(200) ])
eq(s, "30122333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333012233333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333")
+ def test_ar(self):
+ eq = self.assertEqual
+ f = gettext.c2py('n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5')
+ s = ''.join([ str(f(x)) for x in range(200) ])
+ eq(s, "01233333333444444444444444444444444444444444444444444444444444444444444444444444444444444444444444445553333333344444444444444444444444444444444444444444444444444444444444444444444444444444444444444444")
+
def test_security(self):
raises = self.assertRaises
# Test for a dangerous expression
raises(ValueError, gettext.c2py, "os.chmod('/etc/passwd',0777)")
+ # issue28563
+ raises(ValueError, gettext.c2py, '"(eval(foo) && ""')
+ raises(ValueError, gettext.c2py, 'f"{os.system(\'sh\')}"')
+ # Maximum recursion depth exceeded during compilation
+ raises(ValueError, gettext.c2py, 'n+'*10000 + 'n')
+ self.assertEqual(gettext.c2py('n+'*100 + 'n')(1), 101)
+ # MemoryError during compilation
+ raises(ValueError, gettext.c2py, '('*100 + 'n' + ')'*100)
+ # Maximum recursion depth exceeded in C to Python translator
+ raises(ValueError, gettext.c2py, '('*10000 + 'n' + ')'*10000)
+ self.assertEqual(gettext.c2py('('*20 + 'n' + ')'*20)(1), 1)
+
+ def test_chained_comparison(self):
+ # C doesn't chain comparison as Python so 2 == 2 == 2 gets different results
+ f = gettext.c2py('n == n == n')
+ self.assertEqual(''.join(str(f(x)) for x in range(3)), '010')
+ f = gettext.c2py('1 < n == n')
+ self.assertEqual(''.join(str(f(x)) for x in range(3)), '100')
+ f = gettext.c2py('n == n < 2')
+ self.assertEqual(''.join(str(f(x)) for x in range(3)), '010')
+ f = gettext.c2py('0 < n < 2')
+ self.assertEqual(''.join(str(f(x)) for x in range(3)), '111')
+
+ def test_decimal_number(self):
+ self.assertEqual(gettext.c2py('0123')(1), 123)
+
+ def test_invalid_syntax(self):
+ invalid_expressions = [
+ 'x>1', '(n>1', 'n>1)', '42**42**42', '0xa', '1.0', '1e2',
+ 'n>0x1', '+n', '-n', 'n()', 'n(1)', '1+', 'nn', 'n n',
+ ]
+ for expr in invalid_expressions:
+ with self.assertRaises(ValueError):
+ gettext.c2py(expr)
+
+ def test_nested_condition_operator(self):
+ self.assertEqual(gettext.c2py('n?1?2:3:4')(0), 4)
+ self.assertEqual(gettext.c2py('n?1?2:3:4')(1), 2)
+ self.assertEqual(gettext.c2py('n?1:3?4:5')(0), 4)
+ self.assertEqual(gettext.c2py('n?1:3?4:5')(1), 1)
+
+ def test_division(self):
+ f = gettext.c2py('2/n*3')
+ self.assertEqual(f(1), 6)
+ self.assertEqual(f(2), 3)
+ self.assertEqual(f(3), 0)
+ self.assertEqual(f(-1), -6)
+ self.assertRaises(ZeroDivisionError, f, 0)
+
+ def test_plural_number(self):
+ f = gettext.c2py('n != 1')
+ self.assertEqual(f(1), 0)
+ self.assertEqual(f(2), 1)
+ self.assertEqual(f(1.0), 0)
+ self.assertEqual(f(2.0), 1)
+ self.assertEqual(f(1.1), 1)
+ self.assertRaises(TypeError, f, '2')
+ self.assertRaises(TypeError, f, b'2')
+ self.assertRaises(TypeError, f, [])
+ self.assertRaises(TypeError, f, object())
+
class GNUTranslationParsingTest(GettextBaseTest):
def test_plural_form_error_issue17898(self):
self.assertEqual(resp.getheader('First'), 'val')
self.assertEqual(resp.getheader('Second'), 'val')
+ def test_malformed_truncation(self):
+ # Other malformed header lines, especially without colons, used to
+ # cause the rest of the header section to be truncated
+ resp = (
+ b'HTTP/1.1 200 OK\r\n'
+ b'Public-Key-Pins: \n'
+ b'pin-sha256="xxx=";\n'
+ b'report-uri="https://..."\r\n'
+ b'Transfer-Encoding: chunked\r\n'
+ b'\r\n'
+ b'4\r\nbody\r\n0\r\n\r\n'
+ )
+ resp = httplib.HTTPResponse(FakeSocket(resp))
+ resp.begin()
+ self.assertIsNotNone(resp.getheader('Public-Key-Pins'))
+ self.assertEqual(resp.getheader('Transfer-Encoding'), 'chunked')
+ self.assertEqual(resp.read(), b'body')
+
+ def test_blank_line_forms(self):
+ # Test that both CRLF and LF blank lines can terminate the header
+ # section and start the body
+ for blank in (b'\r\n', b'\n'):
+ resp = b'HTTP/1.1 200 OK\r\n' b'Transfer-Encoding: chunked\r\n'
+ resp += blank
+ resp += b'4\r\nbody\r\n0\r\n\r\n'
+ resp = httplib.HTTPResponse(FakeSocket(resp))
+ resp.begin()
+ self.assertEqual(resp.getheader('Transfer-Encoding'), 'chunked')
+ self.assertEqual(resp.read(), b'body')
+
+ resp = b'HTTP/1.0 200 OK\r\n' + blank + b'body'
+ resp = httplib.HTTPResponse(FakeSocket(resp))
+ resp.begin()
+ self.assertEqual(resp.read(), b'body')
+
+ # A blank line ending in CR is not treated as the end of the HTTP
+ # header section, therefore header fields following it should be
+ # parsed if possible
+ resp = (
+ b'HTTP/1.1 200 OK\r\n'
+ b'\r'
+ b'Name: value\r\n'
+ b'Transfer-Encoding: chunked\r\n'
+ b'\r\n'
+ b'4\r\nbody\r\n0\r\n\r\n'
+ )
+ resp = httplib.HTTPResponse(FakeSocket(resp))
+ resp.begin()
+ self.assertEqual(resp.getheader('Transfer-Encoding'), 'chunked')
+ self.assertEqual(resp.read(), b'body')
+
+ # No header fields nor blank line
+ resp = b'HTTP/1.0 200 OK\r\n'
+ resp = httplib.HTTPResponse(FakeSocket(resp))
+ resp.begin()
+ self.assertEqual(resp.read(), b'')
+
+ def test_from_line(self):
+ # The parser handles "From" lines specially, so test this does not
+ # affect parsing the rest of the header section
+ resp = (
+ b'HTTP/1.1 200 OK\r\n'
+ b'From start\r\n'
+ b' continued\r\n'
+ b'Name: value\r\n'
+ b'From middle\r\n'
+ b' continued\r\n'
+ b'Transfer-Encoding: chunked\r\n'
+ b'From end\r\n'
+ b'\r\n'
+ b'4\r\nbody\r\n0\r\n\r\n'
+ )
+ resp = httplib.HTTPResponse(FakeSocket(resp))
+ resp.begin()
+ self.assertIsNotNone(resp.getheader('Name'))
+ self.assertEqual(resp.getheader('Transfer-Encoding'), 'chunked')
+ self.assertEqual(resp.read(), b'body')
+
+ resp = (
+ b'HTTP/1.0 200 OK\r\n'
+ b'From alone\r\n'
+ b'\r\n'
+ b'body'
+ )
+ resp = httplib.HTTPResponse(FakeSocket(resp))
+ resp.begin()
+ self.assertEqual(resp.read(), b'body')
+
+ def test_parse_all_octets(self):
+ # Ensure no valid header field octet breaks the parser
+ body = (
+ b'HTTP/1.1 200 OK\r\n'
+ b"!#$%&'*+-.^_`|~: value\r\n" # Special token characters
+ b'VCHAR: ' + bytearray(range(0x21, 0x7E + 1)) + b'\r\n'
+ b'obs-text: ' + bytearray(range(0x80, 0xFF + 1)) + b'\r\n'
+ b'obs-fold: text\r\n'
+ b' folded with space\r\n'
+ b'\tfolded with tab\r\n'
+ b'Content-Length: 0\r\n'
+ b'\r\n'
+ )
+ sock = FakeSocket(body)
+ resp = httplib.HTTPResponse(sock)
+ resp.begin()
+ self.assertEqual(resp.getheader('Content-Length'), '0')
+ self.assertEqual(resp.getheader("!#$%&'*+-.^_`|~"), 'value')
+ vchar = ''.join(map(chr, range(0x21, 0x7E + 1)))
+ self.assertEqual(resp.getheader('VCHAR'), vchar)
+ self.assertIsNotNone(resp.getheader('obs-text'))
+ folded = resp.getheader('obs-fold')
+ self.assertTrue(folded.startswith('text'))
+ self.assertIn(' folded with space', folded)
+ self.assertTrue(folded.endswith('folded with tab'))
+
def test_invalid_headers(self):
conn = httplib.HTTPConnection('example.com')
conn.sock = FakeSocket('')
self.assertTrue(hasattr(resp,'fileno'),
'HTTPResponse should expose a fileno attribute')
- # Test lines overflowing the max line size (_MAXLINE in http.client)
+ # Test lines overflowing the max line size (_MAXLINE in httplib)
def test_overflowing_status_line(self):
self.skipTest("disabled for HTTP 0.9 support")
def testHTTPSConnectionSourceAddress(self):
self.conn = httplib.HTTPSConnection(HOST, self.port,
source_address=('', self.source_port))
- # We don't test anything here other the constructor not barfing as
+ # We don't test anything here other than the constructor not barfing as
# this code doesn't deal with setting up an active running SSL server
# for an ssl_wrapped connect() to actually return from.
import os
print("Content-type: text/html")
-print()
+print("")
print(os.environ["%s"])
"""
finally:
sys.path.pop(0)
+ def test_replace_parent_in_sys_modules(self):
+ dir_name = os.path.abspath(TESTFN)
+ os.mkdir(dir_name)
+ try:
+ pkg_dir = os.path.join(dir_name, 'sa')
+ os.mkdir(pkg_dir)
+ with open(os.path.join(pkg_dir, '__init__.py'), 'w') as init_file:
+ init_file.write("import v1")
+ with open(os.path.join(pkg_dir, 'v1.py'), 'w') as v1_file:
+ v1_file.write("import sys;"
+ "sys.modules['sa'] = sys.modules[__name__];"
+ "import sa")
+ sys.path.insert(0, dir_name)
+ # a segfault means the test failed!
+ import sa
+ finally:
+ rmtree(dir_name)
+
+ def test_fromlist_type(self):
+ with self.assertRaises(TypeError) as cm:
+ __import__('encodings', fromlist=[u'aliases'])
+ self.assertIn('must be str, not unicode', str(cm.exception))
+ with self.assertRaises(TypeError) as cm:
+ __import__('encodings', fromlist=[1])
+ self.assertIn('must be str, not int', str(cm.exception))
+
class PycRewritingTests(unittest.TestCase):
# Test that the `co_filename` attribute on code objects always points
self.assertRaises(IOError, fp.write, "blah")
self.assertRaises(IOError, fp.writelines, ["blah\n"])
+ def test_open_handles_NUL_chars(self):
+ fn_with_NUL = 'foo\0bar'
+ self.assertRaises(TypeError, self.open, fn_with_NUL, 'w')
+
+ bytes_fn = fn_with_NUL.encode('ascii')
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore", DeprecationWarning)
+ self.assertRaises(TypeError, self.open, bytes_fn, 'w')
+
def test_raw_file_io(self):
with self.open(support.TESTFN, "wb", buffering=0) as f:
self.assertEqual(f.readable(), False)
self.assertEqual(take(2, zip('abc',count(-3))), [('a', -3), ('b', -2)])
self.assertRaises(TypeError, count, 2, 3, 4)
self.assertRaises(TypeError, count, 'a')
- self.assertEqual(list(islice(count(maxsize-5), 10)), range(maxsize-5, maxsize+5))
- self.assertEqual(list(islice(count(-maxsize-5), 10)), range(-maxsize-5, -maxsize+5))
+ self.assertEqual(take(10, count(maxsize-5)), range(maxsize-5, maxsize+5))
+ self.assertEqual(take(10, count(-maxsize-5)), range(-maxsize-5, -maxsize+5))
+ self.assertEqual(take(3, count(3.25)), [3.25, 4.25, 5.25])
+ self.assertEqual(take(3, count(3.25-4j)), [3.25-4j, 4.25-4j, 5.25-4j])
+ self.assertEqual(take(3, count(Decimal('1.1'))),
+ [Decimal('1.1'), Decimal('2.1'), Decimal('3.1')])
+ self.assertEqual(take(3, count(Fraction(2, 3))),
+ [Fraction(2, 3), Fraction(5, 3), Fraction(8, 3)])
+ BIGINT = 1<<1000
+ self.assertEqual(take(3, count(BIGINT)), [BIGINT, BIGINT+1, BIGINT+2])
c = count(3)
self.assertEqual(repr(c), 'count(3)')
c.next()
c = count(-9)
self.assertEqual(repr(c), 'count(-9)')
c.next()
+ self.assertEqual(next(c), -8)
self.assertEqual(repr(count(10.25)), 'count(10.25)')
- self.assertEqual(c.next(), -8)
+ self.assertEqual(repr(count(10.0)), 'count(10.0)')
+ self.assertEqual(type(next(count(10.0))), float)
for i in (-sys.maxint-5, -sys.maxint+5 ,-10, -1, 0, 10, sys.maxint-5, sys.maxint+5):
# Test repr (ignoring the L in longs)
r1 = repr(count(i)).replace('L', '')
[('a', 2), ('b', 5), ('c', 8)])
self.assertEqual(zip('abc',count(step=-1)),
[('a', 0), ('b', -1), ('c', -2)])
+ self.assertRaises(TypeError, count, 'a', 'b')
self.assertEqual(zip('abc',count(2,0)), [('a', 2), ('b', 2), ('c', 2)])
self.assertEqual(zip('abc',count(2,1)), [('a', 2), ('b', 3), ('c', 4)])
+ self.assertEqual(zip('abc',count(2,3)), [('a', 2), ('b', 5), ('c', 8)])
+ self.assertEqual(zip('abc',count(2,1L)), [('a', 2), ('b', 3), ('c', 4)])
+ self.assertEqual(zip('abc',count(2,3L)), [('a', 2), ('b', 5), ('c', 8)])
self.assertEqual(take(20, count(maxsize-15, 3)), take(20, range(maxsize-15, maxsize+100, 3)))
self.assertEqual(take(20, count(-maxsize-15, 3)), take(20, range(-maxsize-15,-maxsize+100, 3)))
+ self.assertEqual(take(3, count(10, maxsize+5)),
+ range(10, 10+3*(maxsize+5), maxsize+5))
+ self.assertEqual(take(3, count(2, 1.25)), [2, 3.25, 4.5])
self.assertEqual(take(3, count(2, 3.25-4j)), [2, 5.25-4j, 8.5-8j])
self.assertEqual(take(3, count(Decimal('1.1'), Decimal('.1'))),
[Decimal('1.1'), Decimal('1.2'), Decimal('1.3')])
self.assertEqual(take(3, count(Fraction(2,3), Fraction(1,7))),
[Fraction(2,3), Fraction(17,21), Fraction(20,21)])
+ BIGINT = 1<<1000
+ self.assertEqual(take(3, count(step=BIGINT)), [0, BIGINT, 2*BIGINT])
self.assertEqual(repr(take(3, count(10, 2.5))), repr([10, 12.5, 15.0]))
c = count(3, 5)
self.assertEqual(repr(c), 'count(3, 5)')
self.assertEqual(repr(count(10.5, 1.25)), 'count(10.5, 1.25)')
self.assertEqual(repr(count(10.5, 1)), 'count(10.5)') # suppress step=1 when it's an int
self.assertEqual(repr(count(10.5, 1.00)), 'count(10.5, 1.0)') # do show float values lilke 1.0
+ self.assertEqual(repr(count(10, 1.00)), 'count(10, 1.0)')
+ c = count(10, 1.0)
+ self.assertEqual(type(next(c)), int)
+ self.assertEqual(type(next(c)), float)
for i in (-sys.maxint-5, -sys.maxint+5 ,-10, -1, 0, 10, sys.maxint-5, sys.maxint+5):
for j in (-sys.maxint-5, -sys.maxint+5 ,-10, -1, 0, 1, 10, sys.maxint-5, sys.maxint+5):
# Test repr (ignoring the L in longs)
self.assertEqual(x, y,
Frm("bad result for a*b: a=%r, b=%r, x=%r, y=%r", a, b, x, y))
+ def test_lshift_of_zero(self):
+ self.assertEqual(0L << 0, 0)
+ self.assertEqual(0L << 10, 0)
+ with self.assertRaises(ValueError):
+ 0L << -1
+
+ @test_support.cpython_only
+ def test_huge_lshift_of_zero(self):
+ # Shouldn't try to allocate memory for a huge shift. See issue #27870.
+ # Other implementations may have a different boundary for overflow,
+ # or not raise at all.
+ self.assertEqual(0L << sys.maxsize, 0)
+ with self.assertRaises(OverflowError):
+ 0L << (sys.maxsize + 1)
+
def check_bitop_identities_1(self, x):
eq = self.assertEqual
eq(x & 0, 0, Frm("x & 0 != 0 for x=%r", x))
# Create a deeply nested structure.
head = last = []
# The max stack depth should match the value in Python/marshal.c.
- MAX_MARSHAL_STACK_DEPTH = 2000
+ if os.name == 'nt' and hasattr(sys, 'gettotalrefcount'):
+ MAX_MARSHAL_STACK_DEPTH = 1000
+ else:
+ MAX_MARSHAL_STACK_DEPTH = 2000
for i in range(MAX_MARSHAL_STACK_DEPTH - 2):
last.append([0])
last = last[-1]
finally:
s.close()
+ @unittest.skipIf(os.name == 'nt', 'cannot resize anonymous mmaps on Windows')
+ def test_resize_past_pos(self):
+ m = mmap.mmap(-1, 8192)
+ self.addCleanup(m.close)
+ m.read(5000)
+ try:
+ m.resize(4096)
+ except SystemError:
+ self.skipTest("resizing not supported")
+ self.assertEqual(m.read(14), '')
+ self.assertRaises(ValueError, m.read_byte)
+ self.assertRaises(ValueError, m.write_byte, 'b')
+ self.assertRaises(ValueError, m.write, 'abc')
+
class LargeMmapTests(unittest.TestCase):
singles = ["fchdir", "fdopen", "dup", "fdatasync", "fstat",
"fstatvfs", "fsync", "tcgetpgrp", "ttyname"]
#singles.append("close")
- #We omit close because it doesn'r raise an exception on some platforms
+ #We omit close because it doesn't raise an exception on some platforms
def get_single(f):
def helper(self):
if hasattr(os, f):
except OSError as e:
self.assertEqual(e.errno, errno.EBADF)
else:
- self.fail("%r didn't raise a OSError with a bad file descriptor"
+ self.fail("%r didn't raise an OSError with a bad file descriptor"
% f)
@unittest.skipUnless(hasattr(os, 'isatty'), 'test needs os.isatty()')
"""
-Test suite to check compilance with PEP 247, the standard API
+Test suite to check compliance with PEP 247, the standard API
for hashing algorithms
"""
set([int(x) for x in groups.split()]),
set(posix.getgroups() + [posix.getegid()]))
+ @test_support.requires_unicode
+ def test_path_with_null_unicode(self):
+ fn = test_support.TESTFN_UNICODE
+ try:
+ fn.encode(test_support.TESTFN_ENCODING)
+ except (UnicodeError, TypeError):
+ self.skipTest("Requires unicode filenames support")
+ fn_with_NUL = fn + u'\0'
+ self.addCleanup(test_support.unlink, fn)
+ test_support.unlink(fn)
+ fd = None
+ try:
+ with self.assertRaises(TypeError):
+ fd = os.open(fn_with_NUL, os.O_WRONLY | os.O_CREAT) # raises
+ finally:
+ if fd is not None:
+ os.close(fd)
+ self.assertFalse(os.path.exists(fn))
+ self.assertRaises(TypeError, os.mkdir, fn_with_NUL)
+ self.assertFalse(os.path.exists(fn))
+ open(fn, 'wb').close()
+ self.assertRaises(TypeError, os.stat, fn_with_NUL)
+
+ def test_path_with_null_byte(self):
+ fn = test_support.TESTFN
+ fn_with_NUL = fn + '\0'
+ self.addCleanup(test_support.unlink, fn)
+ test_support.unlink(fn)
+ fd = None
+ try:
+ with self.assertRaises(TypeError):
+ fd = os.open(fn_with_NUL, os.O_WRONLY | os.O_CREAT) # raises
+ finally:
+ if fd is not None:
+ os.close(fd)
+ self.assertFalse(os.path.exists(fn))
+ self.assertRaises(TypeError, os.mkdir, fn_with_NUL)
+ self.assertFalse(os.path.exists(fn))
+ open(fn, 'wb').close()
+ self.assertRaises(TypeError, os.stat, fn_with_NUL)
+
+
class PosixGroupsTester(unittest.TestCase):
def setUp(self):
import sys
from posixpath import realpath, abspath, dirname, basename
+try:
+ import posix
+except ImportError:
+ posix = None
+
# An absolute path to a temporary filename for testing. We can't rely on TESTFN
# being an absolute path, so we need this.
f.write("foo")
f.close()
self.assertIs(posixpath.islink(test_support.TESTFN + "1"), False)
- if hasattr(os, "symlink"):
+ if hasattr(os, 'symlink'):
os.symlink(test_support.TESTFN + "1", test_support.TESTFN + "2")
self.assertIs(posixpath.islink(test_support.TESTFN + "2"), True)
os.remove(test_support.TESTFN + "1")
def test_ismount(self):
self.assertIs(posixpath.ismount("/"), True)
+ def test_ismount_non_existent(self):
+ # Non-existent mountpoint.
+ self.assertIs(posixpath.ismount(ABSTFN), False)
+ try:
+ os.mkdir(ABSTFN)
+ self.assertIs(posixpath.ismount(ABSTFN), False)
+ finally:
+ safe_rmdir(ABSTFN)
+
+ @unittest.skipUnless(hasattr(os, 'symlink'),
+ 'Requires functional symlink implementation')
+ def test_ismount_symlinks(self):
+ # Symlinks are never mountpoints.
+ try:
+ os.symlink("/", ABSTFN)
+ self.assertIs(posixpath.ismount(ABSTFN), False)
+ finally:
+ os.unlink(ABSTFN)
+
+ @unittest.skipIf(posix is None, "Test requires posix module")
+ def test_ismount_different_device(self):
+ # Simulate the path being on a different device from its parent by
+ # mocking out st_dev.
+ save_lstat = os.lstat
+ def fake_lstat(path):
+ st_ino = 0
+ st_dev = 0
+ if path == ABSTFN:
+ st_dev = 1
+ st_ino = 1
+ return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))
+ try:
+ os.lstat = fake_lstat
+ self.assertIs(posixpath.ismount(ABSTFN), True)
+ finally:
+ os.lstat = save_lstat
+
+ @unittest.skipIf(posix is None, "Test requires posix module")
+ def test_ismount_directory_not_readable(self):
+ # issue #2466: Simulate ismount run on a directory that is not
+ # readable, which used to return False.
+ save_lstat = os.lstat
+ def fake_lstat(path):
+ st_ino = 0
+ st_dev = 0
+ if path.startswith(ABSTFN) and path != ABSTFN:
+ # ismount tries to read something inside the ABSTFN directory;
+ # simulate this being forbidden (no read permission).
+ raise OSError("Fake [Errno 13] Permission denied")
+ if path == ABSTFN:
+ st_dev = 1
+ st_ino = 1
+ return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))
+ try:
+ os.lstat = fake_lstat
+ self.assertIs(posixpath.ismount(ABSTFN), True)
+ finally:
+ os.lstat = save_lstat
+
def test_expanduser(self):
self.assertEqual(posixpath.expanduser("foo"), "foo")
with test_support.EnvironmentVarGuard() as env:
class NoWarningOnlyHash(object):
def __hash__(self): pass
self.assertEqual(len(w.warnings), 0)
- # With an intermediate class in the heirarchy
+ # With an intermediate class in the hierarchy
class DefinesAllThree(object):
def __cmp__(self, other): pass
def __eq__(self, other): pass
import xml.etree
import types
import test.test_support
+import xml.etree.ElementTree
from collections import namedtuple
from test.script_helper import assert_python_ok
from test.test_support import (TESTFN, rmtree, reap_children, captured_stdout,
loc = "<br><a href=\"" + loc + "\">Module Docs</a>"
return output.strip(), loc
+def get_pydoc_link(module):
+ "Returns a documentation web link of a module"
+ dirname = os.path.dirname
+ basedir = dirname(dirname(__file__))
+ doc = pydoc.TextDoc()
+ loc = doc.getdocloc(module, basedir=basedir)
+ return loc
+
def get_pydoc_text(module):
"Returns pydoc generated output as text"
doc = pydoc.TextDoc()
print_diffs(expected_text, result)
self.fail("outputs are not equal, see diff above")
+ def test_mixed_case_module_names_are_lower_cased(self):
+ # issue16484
+ doc_link = get_pydoc_link(xml.etree.ElementTree)
+ self.assertIn('xml.etree.elementtree', doc_link)
+
def test_issue8225(self):
# Test issue8225 to ensure no doc link appears for xml.etree
result, doc_loc = get_pydoc_text(xml.etree)
def test2(self):
xml = "<?xml version\xc2\x85='1.0'?>\r\n"
parser = expat.ParserCreate()
- try:
+ err_pattern = r'XML declaration not well-formed: line 1, column \d+'
+ with self.assertRaisesRegexp(expat.ExpatError, err_pattern):
parser.Parse(xml, True)
- self.fail()
- except expat.ExpatError as e:
- self.assertEqual(str(e), 'XML declaration not well-formed: line 1, column 14')
class ForeignDTDTests(unittest.TestCase):
"""
q = p.match(upper_char)
self.assertTrue(q)
+ self.assertTrue(re.match('(?ixu) ' + upper_char, lower_char))
+ self.assertTrue(re.match('(?ixu) ' + lower_char, upper_char))
+
def test_dollar_matches_twice(self):
"$ matches the end of string, and just before the terminating \n"
pattern = re.compile('$')
class TestReadline(unittest.TestCase):
- @unittest.skipIf(readline._READLINE_VERSION < 0x0600
+ @unittest.skipIf(readline._READLINE_VERSION < 0x0601
and "libedit" not in readline.__doc__,
"not supported in this library version")
def test_init(self):
t = self.thetype(s)
self.assertNotEqual(id(s), id(t))
+ def test_set_literal_insertion_order(self):
+ # SF Issue #26020 -- Expect left to right insertion
+ s = {1, 1.0, True}
+ self.assertEqual(len(s), 1)
+ stored_value = s.pop()
+ self.assertEqual(type(stored_value), int)
+
+ def test_set_literal_evaluation_order(self):
+ # Expect left to right expression evaluation
+ events = []
+ def record(obj):
+ events.append(obj)
+ s = {record(1), record(2), record(3)}
+ self.assertEqual(events, [1, 2, 3])
+
def test_hash(self):
self.assertRaises(TypeError, hash, self.s)
"%s: %s != %s" %
(self.data[i][0], l, self.data[i][1:]))
+ def testEmptyStringHandling(self):
+ """Test that parsing of empty strings is correctly handled."""
+ # see Issue #21999
+ expected = ['', ')', 'abc']
+
+ s = shlex.shlex("'')abc", posix=True)
+ slist = list(s)
+ self.assertEqual(slist, expected)
+ expected = ["''", ')', 'abc']
+ s = shlex.shlex("'')abc")
+ self.assertEqual(list(s), expected)
+
+
# Allow this test to be used with old shlex.py
if not getattr(shlex, "split", None):
for methname in dir(ShlexTest):
with support.change_cwd(work_dir):
base_name = os.path.abspath(rel_base_name)
+ res = make_archive(rel_base_name, 'zip', root_dir)
+
+ self.assertEqual(res, base_name + '.zip')
+ self.assertTrue(os.path.isfile(res))
+ self.assertTrue(zipfile.is_zipfile(res))
+ with zipfile.ZipFile(res) as zf:
+ self.assertEqual(sorted(zf.namelist()),
+ ['dist/', 'dist/file1', 'dist/file2',
+ 'dist/sub/', 'dist/sub/file3', 'dist/sub2/',
+ 'outer'])
+
+ with support.change_cwd(work_dir):
+ base_name = os.path.abspath(rel_base_name)
res = make_archive(rel_base_name, 'zip', root_dir, base_dir)
self.assertEqual(res, base_name + '.zip')
self.assertEqual(len(dirs), 1)
wanted = os.path.join('xoxo', 'Lib', 'site-packages')
self.assertEqual(dirs[0], wanted)
- elif (sys.platform == "darwin" and
- sysconfig.get_config_var("PYTHONFRAMEWORK")):
- # OS X framework builds
- site.PREFIXES = ['Python.framework']
- dirs = site.getsitepackages()
- self.assertEqual(len(dirs), 3)
- wanted = os.path.join('/Library',
- sysconfig.get_config_var("PYTHONFRAMEWORK"),
- sys.version[:3],
- 'site-packages')
- self.assertEqual(dirs[2], wanted)
elif os.sep == '/':
- # OS X non-framwework builds, Linux, FreeBSD, etc
+ # OS X, Linux, FreeBSD, etc
self.assertEqual(len(dirs), 2)
wanted = os.path.join('xoxo', 'lib', 'python' + sys.version[:3],
'site-packages')
def testBasic(self):
# connect
- smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)
+ smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
smtp.quit()
def testNOOP(self):
- smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)
+ smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
expected = (250, 'Ok')
self.assertEqual(smtp.noop(), expected)
smtp.quit()
def testRSET(self):
- smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)
+ smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
expected = (250, 'Ok')
self.assertEqual(smtp.rset(), expected)
smtp.quit()
def testNotImplemented(self):
# EHLO isn't implemented in DebuggingServer
- smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)
+ smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
expected = (502, 'Error: command "EHLO" not implemented')
self.assertEqual(smtp.ehlo(), expected)
smtp.quit()
def testVRFY(self):
# VRFY isn't implemented in DebuggingServer
- smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)
+ smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
expected = (502, 'Error: command "VRFY" not implemented')
self.assertEqual(smtp.vrfy('nobody@nowhere.com'), expected)
self.assertEqual(smtp.verify('nobody@nowhere.com'), expected)
def testSecondHELO(self):
# check that a second HELO returns a message that it's a duplicate
# (this behavior is specific to smtpd.SMTPChannel)
- smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)
+ smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
smtp.helo()
expected = (503, 'Duplicate HELO/EHLO')
self.assertEqual(smtp.helo(), expected)
smtp.quit()
def testHELP(self):
- smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)
+ smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
self.assertEqual(smtp.help(), 'Error: command "HELP" not implemented')
smtp.quit()
def testSend(self):
# connect and send mail
m = 'A test message'
- smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3)
+ smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=15)
smtp.sendmail('John', 'Sally', m)
# XXX(nnorwitz): this test is flaky and dies with a bad file descriptor
# in asyncore. This sleep might help, but should really be fixed
"Error raising socket exception.")
def testSendtoErrors(self):
- # Testing that sendto doens't masks failures. See #10169.
+ # Testing that sendto doesn't mask failures. See #10169.
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.addCleanup(s.close)
s.bind(('', 0))
PROTOCOLS = sorted(ssl._PROTOCOL_NAMES)
HOST = support.HOST
+IS_LIBRESSL = ssl.OPENSSL_VERSION.startswith('LibreSSL')
+IS_OPENSSL_1_1 = not IS_LIBRESSL and ssl.OPENSSL_VERSION_INFO >= (1, 1, 0)
+
def data_file(*name):
return os.path.join(os.path.dirname(__file__), *name)
SIGNED_CERTFILE = data_file("keycert3.pem")
SIGNED_CERTFILE2 = data_file("keycert4.pem")
SIGNING_CA = data_file("pycacert.pem")
+# cert with all kinds of subject alt names
+ALLSANFILE = data_file("allsans.pem")
REMOTE_HOST = "self-signed.pythontest.net"
REMOTE_ROOT_CERT = data_file("selfsigned_pythontestdotnet.pem")
self.assertIn(ssl.HAS_SNI, {True, False})
self.assertIn(ssl.HAS_ECDH, {True, False})
-
def test_random(self):
v = ssl.RAND_status()
if support.verbose:
self.assertEqual(p['subjectAltName'], san)
+ def test_parse_all_sans(self):
+ p = ssl._ssl._test_decode_cert(ALLSANFILE)
+ self.assertEqual(p['subjectAltName'],
+ (
+ ('DNS', 'allsans'),
+ ('othername', '<unsupported>'),
+ ('othername', '<unsupported>'),
+ ('email', 'user@example.org'),
+ ('DNS', 'www.example.org'),
+ ('DirName',
+ ((('countryName', 'XY'),),
+ (('localityName', 'Castle Anthrax'),),
+ (('organizationName', 'Python Software Foundation'),),
+ (('commonName', 'dirname example'),))),
+ ('URI', 'https://www.python.org/'),
+ ('IP Address', '127.0.0.1'),
+ ('IP Address', '0:0:0:0:0:0:0:1\n'),
+ ('Registered ID', '1.2.3.4.5')
+ )
+ )
+
def test_DER_to_PEM(self):
with open(CAFILE_CACERT, 'r') as f:
pem = f.read()
self.assertGreaterEqual(status, 0)
self.assertLessEqual(status, 15)
# Version string as returned by {Open,Libre}SSL, the format might change
- if "LibreSSL" in s:
- self.assertTrue(s.startswith("LibreSSL {:d}.{:d}".format(major, minor)),
- (s, t))
+ if IS_LIBRESSL:
+ self.assertTrue(s.startswith("LibreSSL {:d}".format(major)),
+ (s, t, hex(n)))
else:
self.assertTrue(s.startswith("OpenSSL {:d}.{:d}.{:d}".format(major, minor, fix)),
(s, t))
def test_options(self):
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
# OP_ALL | OP_NO_SSLv2 | OP_NO_SSLv3 is the default value
- self.assertEqual(ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3,
- ctx.options)
+ default = (ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3)
+ if not IS_LIBRESSL and ssl.OPENSSL_VERSION_INFO >= (1, 1, 0):
+ default |= ssl.OP_NO_COMPRESSION
+ self.assertEqual(default, ctx.options)
ctx.options |= ssl.OP_NO_TLSv1
- self.assertEqual(ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3 | ssl.OP_NO_TLSv1,
- ctx.options)
+ self.assertEqual(default | ssl.OP_NO_TLSv1, ctx.options)
if can_clear_options():
- ctx.options = (ctx.options & ~ssl.OP_NO_SSLv2) | ssl.OP_NO_TLSv1
- self.assertEqual(ssl.OP_ALL | ssl.OP_NO_TLSv1 | ssl.OP_NO_SSLv3,
- ctx.options)
+ ctx.options = (ctx.options & ~ssl.OP_NO_TLSv1)
+ self.assertEqual(default, ctx.options)
ctx.options = 0
self.assertEqual(0, ctx.options)
else:
self.assertRaises(TypeError, ctx.load_default_certs, 'SERVER_AUTH')
@unittest.skipIf(sys.platform == "win32", "not-Windows specific")
+ @unittest.skipIf(IS_LIBRESSL, "LibreSSL doesn't support env vars")
def test_load_default_certs_env(self):
ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
with support.EnvironmentVarGuard() as env:
sys.stdout.write("%s\n" % x)
else:
self.fail("Got server certificate %s for %s:%s!" % (pem, host, port))
-
pem = ssl.get_server_certificate((host, port),
ca_certs=cert)
if not pem:
def test_asyncore_server(self):
"""Check the example asyncore integration."""
- indata = "TEST MESSAGE of mixed case\n"
-
if support.verbose:
sys.stdout.write("\n")
# consume data
s.read()
- data = b"data"
-
# read(-1, buffer) is supported, even though read(-1) is not
+ data = b"data"
s.send(data)
buffer = bytearray(len(data))
self.assertEqual(s.read(-1, buffer), len(data))
self.assertEqual(buffer, data)
- # recv/read(0) should return no data
- s.send(data)
- self.assertEqual(s.recv(0), b"")
- self.assertEqual(s.read(0), b"")
- self.assertEqual(s.read(), data)
-
s.write(b"over\n")
self.assertRaises(ValueError, s.recv, -1)
s.close()
+ def test_recv_zero(self):
+ server = ThreadedEchoServer(CERTFILE)
+ server.__enter__()
+ self.addCleanup(server.__exit__, None, None)
+ s = socket.create_connection((HOST, server.port))
+ self.addCleanup(s.close)
+ s = ssl.wrap_socket(s, suppress_ragged_eofs=False)
+ self.addCleanup(s.close)
+
+ # recv/read(0) should return no data
+ s.send(b"data")
+ self.assertEqual(s.recv(0), b"")
+ self.assertEqual(s.read(0), b"")
+ self.assertEqual(s.read(), b"data")
+
+ # Should not block if the other end sends no data
+ s.setblocking(False)
+ self.assertEqual(s.recv(0), b"")
+ self.assertEqual(s.recv_into(bytearray()), 0)
+
def test_handshake_timeout(self):
# Issue #5103: SSL handshake must respect the socket timeout
server = socket.socket(socket.AF_INET)
with closing(context.wrap_socket(socket.socket())) as s:
self.assertIs(s.version(), None)
s.connect((HOST, server.port))
- self.assertEqual(s.version(), "TLSv1")
+ self.assertEqual(s.version(), 'TLSv1')
self.assertIs(s.version(), None)
@unittest.skipUnless(ssl.HAS_ECDH, "test requires ECDH-enabled OpenSSL")
(['http/3.0', 'http/4.0'], None)
]
for client_protocols, expected in protocol_tests:
- server_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
+ server_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
server_context.load_cert_chain(CERTFILE)
server_context.set_alpn_protocols(server_protocols)
- client_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
+ client_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
client_context.load_cert_chain(CERTFILE)
client_context.set_alpn_protocols(client_protocols)
- stats = server_params_test(client_context, server_context,
- chatty=True, connectionchatty=True)
- msg = "failed trying %s (s) and %s (c).\n" \
- "was expecting %s, but got %%s from the %%s" \
- % (str(server_protocols), str(client_protocols),
- str(expected))
- client_result = stats['client_alpn_protocol']
- self.assertEqual(client_result, expected, msg % (client_result, "client"))
- server_result = stats['server_alpn_protocols'][-1] \
- if len(stats['server_alpn_protocols']) else 'nothing'
- self.assertEqual(server_result, expected, msg % (server_result, "server"))
+ try:
+ stats = server_params_test(client_context,
+ server_context,
+ chatty=True,
+ connectionchatty=True)
+ except ssl.SSLError as e:
+ stats = e
+
+ if expected is None and IS_OPENSSL_1_1:
+ # OpenSSL 1.1.0 raises handshake error
+ self.assertIsInstance(stats, ssl.SSLError)
+ else:
+ msg = "failed trying %s (s) and %s (c).\n" \
+ "was expecting %s, but got %%s from the %%s" \
+ % (str(server_protocols), str(client_protocols),
+ str(expected))
+ client_result = stats['client_alpn_protocol']
+ self.assertEqual(client_result, expected,
+ msg % (client_result, "client"))
+ server_result = stats['server_alpn_protocols'][-1] \
+ if len(stats['server_alpn_protocols']) else 'nothing'
+ self.assertEqual(server_result, expected,
+ msg % (server_result, "server"))
def test_selected_npn_protocol(self):
# selected_npn_protocol() is None unless NPN is used
class Exc(Exception):
pass
- # Devious code could crash structseqs' contructors
+ # Devious code could crash structseqs' constructors
class C:
def __getitem__(self, i):
raise Exc
def test_communicate_pipe_fd_leak(self):
fd_directory = '/proc/%d/fd' % os.getpid()
num_fds_before_popen = len(os.listdir(fd_directory))
- p = subprocess.Popen([sys.executable, "-c", "print()"],
+ p = subprocess.Popen([sys.executable, "-c", "print('')"],
stdout=subprocess.PIPE)
p.communicate()
num_fds_after_communicate = len(os.listdir(fd_directory))
import functools
import gc
import socket
+import stat
import sys
import os
import platform
except KeyError:
pass
+def _force_run(path, func, *args):
+ try:
+ return func(*args)
+ except EnvironmentError as err:
+ if verbose >= 2:
+ print('%s: %s' % (err.__class__.__name__, err))
+ print('re-run %s%r' % (func.__name__, args))
+ os.chmod(path, stat.S_IRWXU)
+ return func(*args)
+
if sys.platform.startswith("win"):
def _waitfor(func, pathname, waitall=False):
# Perform the operation
# The exponential backoff of the timeout amounts to a total
# of ~1 second after which the deletion is probably an error
# anyway.
- # Testing on a i7@4.3GHz shows that usually only 1 iteration is
+ # Testing on an i7@4.3GHz shows that usually only 1 iteration is
# required when contention occurs.
timeout = 0.001
while timeout < 1.0:
def _rmtree(path):
def _rmtree_inner(path):
- for name in os.listdir(path):
+ for name in _force_run(path, os.listdir, path):
fullname = os.path.join(path, name)
if os.path.isdir(fullname):
_waitfor(_rmtree_inner, fullname, waitall=True)
- os.rmdir(fullname)
+ _force_run(fullname, os.rmdir, fullname)
else:
- os.unlink(fullname)
+ _force_run(fullname, os.unlink, fullname)
_waitfor(_rmtree_inner, path, waitall=True)
- _waitfor(os.rmdir, path)
+ _waitfor(lambda p: _force_run(p, os.rmdir, p), path)
else:
_unlink = os.unlink
_rmdir = os.rmdir
- _rmtree = shutil.rmtree
+
+ def _rmtree(path):
+ try:
+ shutil.rmtree(path)
+ return
+ except EnvironmentError:
+ pass
+
+ def _rmtree_inner(path):
+ for name in _force_run(path, os.listdir, path):
+ fullname = os.path.join(path, name)
+ try:
+ mode = os.lstat(fullname).st_mode
+ except EnvironmentError:
+ mode = 0
+ if stat.S_ISDIR(mode):
+ _rmtree_inner(fullname)
+ _force_run(path, os.rmdir, fullname)
+ else:
+ _force_run(path, os.unlink, fullname)
+ _rmtree_inner(path)
+ os.rmdir(path)
def unlink(filename):
try:
try:
from Tkinter import Tk
root = Tk()
+ root.withdraw()
root.update()
root.destroy()
except Exception as e:
def requires(resource, msg=None):
"""Raise ResourceDenied if the specified resource is not available."""
- if resource == 'gui' and not _is_gui_available():
- raise ResourceDenied(_is_gui_available.reason)
if not is_resource_enabled(resource):
if msg is None:
msg = "Use of the `%s' resource not enabled" % resource
raise ResourceDenied(msg)
+ if resource == 'gui' and not _is_gui_available():
+ raise ResourceDenied(_is_gui_available.reason)
def requires_mac_ver(*min_version):
"""Decorator raising SkipTest if the OS is Mac OS X and the OS X
File "<doctest test.test_syntax[42]>", line 3
SyntaxError: 'break' outside loop
-This should probably raise a better error than a SystemError (or none at all).
+This raises a SyntaxError, it used to raise a SystemError.
+Context for this change can be found on issue #27514
+
In 2.5 there was a missing exception and an assert was triggered in a debug
build. The number of blocks must be greater than CO_MAXBLOCKS. SF #1565514
... break
Traceback (most recent call last):
...
- SystemError: too many statically nested blocks
+ SyntaxError: too many statically nested blocks
This tests assignment-context; there was a bug in Python 2.5 where compiling
a complex 'if' (one with 'elif') would fail to notice an invalid suite,
import os
import shutil
import StringIO
+from binascii import unhexlify
from hashlib import md5
+from random import Random
import errno
import unittest
else:
_open = open
+ # generate 512 pseudorandom bytes
+ data = unhexlify('%1024x' % Random(0).getrandbits(512*8))
for char in ('\0', 'a'):
# Test if EOFHeaderError ('\0') and InvalidHeaderError ('a')
# are ignored correctly.
with _open(tmpname, "wb") as fobj:
fobj.write(char * 1024)
- fobj.write(tarfile.TarInfo("foo").tobuf())
+ tarinfo = tarfile.TarInfo("foo")
+ tarinfo.size = len(data)
+ fobj.write(tarinfo.tobuf())
+ fobj.write(data)
tar = tarfile.open(tmpname, mode="r", ignore_zeros=True)
try:
def generator():
while 1:
- yield "genereator"
+ yield "generator"
def callback():
if callback.gen is None:
"""
import os
+import runpy
import sys
import unittest
import shutil
+from cStringIO import StringIO
import subprocess
import sysconfig
import tempfile
self.pindent_test(clean, closed)
+class FixcidTests(unittest.TestCase):
+ def test_parse_strings(self):
+ old1 = 'int xx = "xx\\"xx"[xx];\n'
+ old2 = "int xx = 'x\\'xx' + xx;\n"
+ output = self.run_script(old1 + old2)
+ new1 = 'int yy = "xx\\"xx"[yy];\n'
+ new2 = "int yy = 'x\\'xx' + yy;\n"
+ self.assertMultiLineEqual(output,
+ "1\n"
+ "< {old1}"
+ "> {new1}"
+ "{new1}"
+ "2\n"
+ "< {old2}"
+ "> {new2}"
+ "{new2}".format(old1=old1, old2=old2, new1=new1, new2=new2)
+ )
+
+ def test_alter_comments(self):
+ output = self.run_script(
+ substfile=
+ "xx yy\n"
+ "*aa bb\n",
+ args=("-c", "-",),
+ input=
+ "/* xx altered */\n"
+ "int xx;\n"
+ "/* aa unaltered */\n"
+ "int aa;\n",
+ )
+ self.assertMultiLineEqual(output,
+ "1\n"
+ "< /* xx altered */\n"
+ "> /* yy altered */\n"
+ "/* yy altered */\n"
+ "2\n"
+ "< int xx;\n"
+ "> int yy;\n"
+ "int yy;\n"
+ "/* aa unaltered */\n"
+ "4\n"
+ "< int aa;\n"
+ "> int bb;\n"
+ "int bb;\n"
+ )
+
+ def test_directory(self):
+ os.mkdir(test_support.TESTFN)
+ self.addCleanup(test_support.rmtree, test_support.TESTFN)
+ c_filename = os.path.join(test_support.TESTFN, "file.c")
+ with open(c_filename, "w") as file:
+ file.write("int xx;\n")
+ with open(os.path.join(test_support.TESTFN, "file.py"), "w") as file:
+ file.write("xx = 'unaltered'\n")
+ script = os.path.join(scriptsdir, "fixcid.py")
+ output = self.run_script(args=(test_support.TESTFN,))
+ self.assertMultiLineEqual(output,
+ "{}:\n"
+ "1\n"
+ '< int xx;\n'
+ '> int yy;\n'.format(c_filename)
+ )
+
+ def run_script(self, input="", args=("-",), substfile="xx yy\n"):
+ substfilename = test_support.TESTFN + ".subst"
+ with open(substfilename, "w") as file:
+ file.write(substfile)
+ self.addCleanup(test_support.unlink, substfilename)
+
+ argv = ["fixcid.py", "-s", substfilename] + list(args)
+ script = os.path.join(scriptsdir, "fixcid.py")
+ with test_support.swap_attr(sys, "argv", argv), \
+ test_support.swap_attr(sys, "stdin", StringIO(input)), \
+ test_support.captured_stdout() as output:
+ try:
+ runpy.run_path(script, run_name="__main__")
+ except SystemExit as exit:
+ self.assertEqual(exit.code, 0)
+ return output.getvalue()
+
+
def test_main():
test_support.run_unittest(*[obj for obj in globals().values()
if isinstance(obj, type)])
with captured_stdout() as stdout:
self._coverage(tracer)
stdout = stdout.getvalue()
- self.assertTrue("pprint.py" in stdout)
- self.assertTrue("case.py" in stdout) # from unittest
+ self.assertIn("pprint.py", stdout)
+ self.assertIn("case.py", stdout) # from unittest
files = os.listdir(TESTFN)
- self.assertTrue("pprint.cover" in files)
- self.assertTrue("unittest.case.cover" in files)
+ self.assertIn("pprint.cover", files)
+ self.assertIn("unittest.case.cover", files)
def test_coverage_ignore(self):
# Ignore all files, nothing should be traced nor printed
self.assertEqual("%s" % u, u'__unicode__ overridden')
self.assertEqual("{}".format(u), '__unicode__ overridden')
+ def test_free_after_iterating(self):
+ test_support.check_free_after_iterating(self, iter, unicode)
+ test_support.check_free_after_iterating(self, reversed, unicode)
+
+
+class CAPITest(unittest.TestCase):
+
# Test PyUnicode_FromFormat()
def test_from_format(self):
test_support.import_module('ctypes')
unicode_encodedecimal(u"123" + s, "xmlcharrefreplace"),
'123' + exp)
- def test_free_after_iterating(self):
- test_support.check_free_after_iterating(self, iter, unicode)
- test_support.check_free_after_iterating(self, reversed, unicode)
-
-
def test_main():
test_support.run_unittest(__name__)
-"""Regresssion tests for urllib"""
+"""Regression tests for urllib"""
import collections
import urllib
self.assertTrue(urllib.proxy_bypass_environment('anotherdomain.com:8888'))
self.assertTrue(urllib.proxy_bypass_environment('newdomain.com:1234'))
+ def test_proxy_cgi_ignore(self):
+ try:
+ self.env.set('HTTP_PROXY', 'http://somewhere:3128')
+ proxies = urllib.getproxies_environment()
+ self.assertEqual('http://somewhere:3128', proxies['http'])
+ self.env.set('REQUEST_METHOD', 'GET')
+ proxies = urllib.getproxies_environment()
+ self.assertNotIn('http', proxies)
+ finally:
+ self.env.unset('REQUEST_METHOD')
+ self.env.unset('HTTP_PROXY')
+
def test_proxy_bypass_environment_host_match(self):
bypass = urllib.proxy_bypass_environment
self.env.set('NO_PROXY',
BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
def log_message(self, format, *args):
- # Supress the HTTP Console log output
+ # Suppress the HTTP Console log output
pass
def do_HEAD(self):
def setUp(self):
super(ProxyAuthTests, self).setUp()
+ # Ignore proxy bypass settings in the environment.
+ def restore_environ(old_environ):
+ os.environ.clear()
+ os.environ.update(old_environ)
+ self.addCleanup(restore_environ, os.environ.copy())
+ os.environ['NO_PROXY'] = ''
+ os.environ['no_proxy'] = ''
+
self.digest_auth_handler = DigestAuthHandler()
self.digest_auth_handler.set_users({self.USER: self.PASSWD})
self.digest_auth_handler.set_realm(self.REALM)
self.assertEqual(str(w[-1].message), text)
self.assertTrue(w[-1].category is UserWarning)
+ def test_message_matching(self):
+ with original_warnings.catch_warnings(record=True,
+ module=self.module) as w:
+ self.module.simplefilter("ignore", UserWarning)
+ self.module.filterwarnings("error", "match", UserWarning)
+ self.assertRaises(UserWarning, self.module.warn, "match")
+ self.assertRaises(UserWarning, self.module.warn, "match prefix")
+ self.module.warn("suffix match")
+ self.assertEqual(w, [])
+ self.module.warn("something completely different")
+ self.assertEqual(w, [])
+
class CFilterTests(BaseTest, FilterTests):
module = c_warnings
DeleteKey(key, "sub_key")
try:
- # Shouldnt be able to delete it twice!
+ # Shouldn't be able to delete it twice!
DeleteKey(key, "sub_key")
self.fail("Deleting the key twice succeeded")
except EnvironmentError:
# Ridiculously simple test of the winsound module for Windows.
-import unittest
-from test import test_support
-test_support.requires('audio')
-import time
+from __future__ import print_function
+
+import functools
import os
import subprocess
+import time
+import unittest
+
+from test import test_support as support
-winsound = test_support.import_module('winsound')
-ctypes = test_support.import_module('ctypes')
-import _winreg
-
-def has_sound(sound):
- """Find out if a particular event is configured with a default sound"""
- try:
- # Ask the mixer API for the number of devices it knows about.
- # When there are no devices, PlaySound will fail.
- if ctypes.windll.winmm.mixerGetNumDevs() is 0:
- return False
-
- key = _winreg.OpenKeyEx(_winreg.HKEY_CURRENT_USER,
- "AppEvents\Schemes\Apps\.Default\{0}\.Default".format(sound))
- value = _winreg.EnumValue(key, 0)[1]
- if value is not u"":
- return True
+support.requires('audio')
+winsound = support.import_module('winsound')
+
+# Unless we actually have an ear in the room, we have no idea whether a sound
+# actually plays, and it's incredibly flaky trying to figure out if a sound
+# even *should* play. Instead of guessing, just call the function and assume
+# it either passed or raised the RuntimeError we expect in case of failure.
+def sound_func(func):
+ @functools.wraps(func)
+ def wrapper(*args, **kwargs):
+ try:
+ ret = func(*args, **kwargs)
+ except RuntimeError as e:
+ if support.verbose:
+ print(func.__name__, 'failed:', e)
else:
- return False
- except WindowsError:
- return False
+ if support.verbose:
+ print(func.__name__, 'returned')
+ return ret
+ return wrapper
+
+safe_Beep = sound_func(winsound.Beep)
+safe_MessageBeep = sound_func(winsound.MessageBeep)
+safe_PlaySound = sound_func(winsound.PlaySound)
class BeepTest(unittest.TestCase):
- # As with PlaySoundTest, incorporate the _have_soundcard() check
- # into our test methods. If there's no audio device present,
- # winsound.Beep returns 0 and GetLastError() returns 127, which
- # is: ERROR_PROC_NOT_FOUND ("The specified procedure could not
- # be found"). (FWIW, virtual/Hyper-V systems fall under this
- # scenario as they have no sound devices whatsoever (not even
- # a legacy Beep device).)
def test_errors(self):
self.assertRaises(TypeError, winsound.Beep)
self.assertRaises(ValueError, winsound.Beep, 32768, 75)
def test_extremes(self):
- self._beep(37, 75)
- self._beep(32767, 75)
+ safe_Beep(37, 75)
+ safe_Beep(32767, 75)
def test_increasingfrequency(self):
for i in xrange(100, 2000, 100):
- self._beep(i, 75)
-
- def _beep(self, *args):
- # these tests used to use _have_soundcard(), but it's quite
- # possible to have a soundcard, and yet have the beep driver
- # disabled. So basically, we have no way of knowing whether
- # a beep should be produced or not, so currently if these
- # tests fail we're ignoring them
- #
- # XXX the right fix for this is to define something like
- # _have_enabled_beep_driver() and use that instead of the
- # try/except below
- try:
- winsound.Beep(*args)
- except RuntimeError:
- pass
+ safe_Beep(i, 75)
+
class MessageBeepTest(unittest.TestCase):
def test_default(self):
self.assertRaises(TypeError, winsound.MessageBeep, "bad")
self.assertRaises(TypeError, winsound.MessageBeep, 42, 42)
- winsound.MessageBeep()
+ safe_MessageBeep()
def test_ok(self):
- winsound.MessageBeep(winsound.MB_OK)
+ safe_MessageBeep(winsound.MB_OK)
def test_asterisk(self):
- winsound.MessageBeep(winsound.MB_ICONASTERISK)
+ safe_MessageBeep(winsound.MB_ICONASTERISK)
def test_exclamation(self):
- winsound.MessageBeep(winsound.MB_ICONEXCLAMATION)
+ safe_MessageBeep(winsound.MB_ICONEXCLAMATION)
def test_hand(self):
- winsound.MessageBeep(winsound.MB_ICONHAND)
+ safe_MessageBeep(winsound.MB_ICONHAND)
def test_question(self):
- winsound.MessageBeep(winsound.MB_ICONQUESTION)
+ safe_MessageBeep(winsound.MB_ICONQUESTION)
class PlaySoundTest(unittest.TestCase):
"none", winsound.SND_ASYNC | winsound.SND_MEMORY
)
- @unittest.skipUnless(has_sound("SystemAsterisk"), "No default SystemAsterisk")
- def test_alias_asterisk(self):
- if _have_soundcard():
- winsound.PlaySound('SystemAsterisk', winsound.SND_ALIAS)
- else:
- self.assertRaises(
- RuntimeError,
- winsound.PlaySound,
- 'SystemAsterisk', winsound.SND_ALIAS
- )
-
- @unittest.skipUnless(has_sound("SystemExclamation"), "No default SystemExclamation")
- def test_alias_exclamation(self):
- if _have_soundcard():
- winsound.PlaySound('SystemExclamation', winsound.SND_ALIAS)
- else:
- self.assertRaises(
- RuntimeError,
- winsound.PlaySound,
- 'SystemExclamation', winsound.SND_ALIAS
- )
-
- @unittest.skipUnless(has_sound("SystemExit"), "No default SystemExit")
- def test_alias_exit(self):
- if _have_soundcard():
- winsound.PlaySound('SystemExit', winsound.SND_ALIAS)
- else:
- self.assertRaises(
- RuntimeError,
- winsound.PlaySound,
- 'SystemExit', winsound.SND_ALIAS
- )
-
- @unittest.skipUnless(has_sound("SystemHand"), "No default SystemHand")
- def test_alias_hand(self):
- if _have_soundcard():
- winsound.PlaySound('SystemHand', winsound.SND_ALIAS)
- else:
- self.assertRaises(
- RuntimeError,
- winsound.PlaySound,
- 'SystemHand', winsound.SND_ALIAS
- )
-
- @unittest.skipUnless(has_sound("SystemQuestion"), "No default SystemQuestion")
- def test_alias_question(self):
- if _have_soundcard():
- winsound.PlaySound('SystemQuestion', winsound.SND_ALIAS)
- else:
- self.assertRaises(
- RuntimeError,
- winsound.PlaySound,
- 'SystemQuestion', winsound.SND_ALIAS
- )
+ def test_aliases(self):
+ aliases = [
+ "SystemAsterisk",
+ "SystemExclamation",
+ "SystemExit",
+ "SystemHand",
+ "SystemQuestion",
+ ]
+ for alias in aliases:
+ safe_PlaySound(alias, winsound.SND_ALIAS)
def test_alias_fallback(self):
- # In the absence of the ability to tell if a sound was actually
- # played, this test has two acceptable outcomes: success (no error,
- # sound was theoretically played; although as issue #19987 shows
- # a box without a soundcard can "succeed") or RuntimeError. Any
- # other error is a failure.
- try:
- winsound.PlaySound('!"$%&/(#+*', winsound.SND_ALIAS)
- except RuntimeError:
- pass
+ safe_PlaySound('!"$%&/(#+*', winsound.SND_ALIAS)
def test_alias_nofallback(self):
- if _have_soundcard():
- # Note that this is not the same as asserting RuntimeError
- # will get raised: you cannot convert this to
- # self.assertRaises(...) form. The attempt may or may not
- # raise RuntimeError, but it shouldn't raise anything other
- # than RuntimeError, and that's all we're trying to test
- # here. The MS docs aren't clear about whether the SDK
- # PlaySound() with SND_ALIAS and SND_NODEFAULT will return
- # True or False when the alias is unknown. On Tim's WinXP
- # box today, it returns True (no exception is raised). What
- # we'd really like to test is that no sound is played, but
- # that requires first wiring an eardrum class into unittest
- # <wink>.
- try:
- winsound.PlaySound(
- '!"$%&/(#+*',
- winsound.SND_ALIAS | winsound.SND_NODEFAULT
- )
- except RuntimeError:
- pass
- else:
- self.assertRaises(
- RuntimeError,
- winsound.PlaySound,
- '!"$%&/(#+*', winsound.SND_ALIAS | winsound.SND_NODEFAULT
- )
+ safe_PlaySound('!"$%&/(#+*', winsound.SND_ALIAS | winsound.SND_NODEFAULT)
def test_stopasync(self):
- if _have_soundcard():
- winsound.PlaySound(
- 'SystemQuestion',
- winsound.SND_ALIAS | winsound.SND_ASYNC | winsound.SND_LOOP
- )
- time.sleep(0.5)
- try:
- winsound.PlaySound(
- 'SystemQuestion',
- winsound.SND_ALIAS | winsound.SND_NOSTOP
- )
- except RuntimeError:
- pass
- else: # the first sound might already be finished
- pass
- winsound.PlaySound(None, winsound.SND_PURGE)
- else:
- # Issue 8367: PlaySound(None, winsound.SND_PURGE)
- # does not raise on systems without a sound card.
- pass
-
-
-def _get_cscript_path():
- """Return the full path to cscript.exe or None."""
- for dir in os.environ.get("PATH", "").split(os.pathsep):
- cscript_path = os.path.join(dir, "cscript.exe")
- if os.path.exists(cscript_path):
- return cscript_path
-
-__have_soundcard_cache = None
-def _have_soundcard():
- """Return True iff this computer has a soundcard."""
- global __have_soundcard_cache
- if __have_soundcard_cache is None:
- cscript_path = _get_cscript_path()
- if cscript_path is None:
- # Could not find cscript.exe to run our VBScript helper. Default
- # to True: most computers these days *do* have a soundcard.
- return True
-
- check_script = os.path.join(os.path.dirname(__file__),
- "check_soundcard.vbs")
- p = subprocess.Popen([cscript_path, check_script],
- stdout=subprocess.PIPE)
- __have_soundcard_cache = not p.wait()
- return __have_soundcard_cache
+ safe_PlaySound(
+ 'SystemQuestion',
+ winsound.SND_ALIAS | winsound.SND_ASYNC | winsound.SND_LOOP
+ )
+ time.sleep(0.5)
+ safe_PlaySound('SystemQuestion', winsound.SND_ALIAS | winsound.SND_NOSTOP)
+ # Issue 8367: PlaySound(None, winsound.SND_PURGE)
+ # does not raise on systems without a sound card.
+ winsound.PlaySound(None, winsound.SND_PURGE)
def test_main():
- test_support.run_unittest(BeepTest, MessageBeepTest, PlaySoundTest)
+ support.run_unittest(BeepTest, MessageBeepTest, PlaySoundTest)
+
if __name__=="__main__":
test_main()
from random import randint, random, getrandbits
from unittest import skipUnless
+from test import script_helper
from test.test_support import TESTFN, TESTFN_UNICODE, TESTFN_ENCODING, \
- run_unittest, findfile, unlink, rmtree, check_warnings
+ run_unittest, findfile, unlink, rmtree, \
+ check_warnings, captured_stdout
try:
TESTFN_UNICODE.encode(TESTFN_ENCODING)
except (UnicodeError, TypeError):
f.seek(len(data))
with zipfile.ZipFile(f, "r") as zipfp:
self.assertEqual(zipfp.namelist(), [TESTFN])
+ self.assertEqual(zipfp.read(TESTFN), self.data)
+ with open(TESTFN2, 'rb') as f:
+ self.assertEqual(f.read(len(data)), data)
+ zipfiledata = f.read()
+ with io.BytesIO(zipfiledata) as bio, zipfile.ZipFile(bio) as zipfp:
+ self.assertEqual(zipfp.namelist(), [TESTFN])
+ self.assertEqual(zipfp.read(TESTFN), self.data)
+
+ def test_read_concatenated_zip_file(self):
+ with io.BytesIO() as bio:
+ with zipfile.ZipFile(bio, 'w', zipfile.ZIP_STORED) as zipfp:
+ zipfp.write(TESTFN, TESTFN)
+ zipfiledata = bio.getvalue()
+ data = b'I am not a ZipFile!'*10
+ with open(TESTFN2, 'wb') as f:
+ f.write(data)
+ f.write(zipfiledata)
+
+ with zipfile.ZipFile(TESTFN2) as zipfp:
+ self.assertEqual(zipfp.namelist(), [TESTFN])
+ self.assertEqual(zipfp.read(TESTFN), self.data)
+
+ def test_append_to_concatenated_zip_file(self):
+ with io.BytesIO() as bio:
+ with zipfile.ZipFile(bio, 'w', zipfile.ZIP_STORED) as zipfp:
+ zipfp.write(TESTFN, TESTFN)
+ zipfiledata = bio.getvalue()
+ data = b'I am not a ZipFile!'*1000000
+ with open(TESTFN2, 'wb') as f:
+ f.write(data)
+ f.write(zipfiledata)
+
+ with zipfile.ZipFile(TESTFN2, 'a') as zipfp:
+ self.assertEqual(zipfp.namelist(), [TESTFN])
+ zipfp.writestr('strfile', self.data)
+
+ with open(TESTFN2, 'rb') as f:
+ self.assertEqual(f.read(len(data)), data)
+ zipfiledata = f.read()
+ with io.BytesIO(zipfiledata) as bio, zipfile.ZipFile(bio) as zipfp:
+ self.assertEqual(zipfp.namelist(), [TESTFN, 'strfile'])
+ self.assertEqual(zipfp.read(TESTFN), self.data)
+ self.assertEqual(zipfp.read('strfile'), self.data)
def test_ignores_newline_at_end(self):
with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
unlink(TESTFN2)
+class CommandLineTest(unittest.TestCase):
+
+ def zipfilecmd(self, *args, **kwargs):
+ rc, out, err = script_helper.assert_python_ok('-m', 'zipfile', *args,
+ **kwargs)
+ return out.replace(os.linesep.encode(), b'\n')
+
+ def zipfilecmd_failure(self, *args):
+ return script_helper.assert_python_failure('-m', 'zipfile', *args)
+
+ def test_test_command(self):
+ zip_name = findfile('zipdir.zip')
+ out = self.zipfilecmd('-t', zip_name)
+ self.assertEqual(out.rstrip(), b'Done testing')
+ zip_name = findfile('testtar.tar')
+ rc, out, err = self.zipfilecmd_failure('-t', zip_name)
+ self.assertEqual(out, b'')
+
+ def test_list_command(self):
+ zip_name = findfile('zipdir.zip')
+ with captured_stdout() as t, zipfile.ZipFile(zip_name, 'r') as tf:
+ tf.printdir()
+ expected = t.getvalue().encode('ascii', 'backslashreplace')
+ out = self.zipfilecmd('-l', zip_name,
+ PYTHONIOENCODING='ascii:backslashreplace')
+ self.assertEqual(out, expected)
+
+ @skipUnless(zlib, "requires zlib")
+ def test_create_command(self):
+ self.addCleanup(unlink, TESTFN)
+ with open(TESTFN, 'w') as f:
+ f.write('test 1')
+ os.mkdir(TESTFNDIR)
+ self.addCleanup(rmtree, TESTFNDIR)
+ with open(os.path.join(TESTFNDIR, 'file.txt'), 'w') as f:
+ f.write('test 2')
+ files = [TESTFN, TESTFNDIR]
+ namelist = [TESTFN, TESTFNDIR + '/', TESTFNDIR + '/file.txt']
+ try:
+ out = self.zipfilecmd('-c', TESTFN2, *files)
+ self.assertEqual(out, b'')
+ with zipfile.ZipFile(TESTFN2) as zf:
+ self.assertEqual(zf.namelist(), namelist)
+ self.assertEqual(zf.read(namelist[0]), b'test 1')
+ self.assertEqual(zf.read(namelist[2]), b'test 2')
+ finally:
+ unlink(TESTFN2)
+
+ def test_extract_command(self):
+ zip_name = findfile('zipdir.zip')
+ extdir = TESTFNDIR
+ os.mkdir(extdir)
+ try:
+ out = self.zipfilecmd('-e', zip_name, extdir)
+ self.assertEqual(out, b'')
+ with zipfile.ZipFile(zip_name) as zf:
+ for zi in zf.infolist():
+ path = os.path.join(extdir,
+ zi.filename.replace('/', os.sep))
+ if zi.filename.endswith('/'):
+ self.assertTrue(os.path.isdir(path))
+ else:
+ self.assertTrue(os.path.isfile(path))
+ with open(path, 'rb') as f:
+ self.assertEqual(f.read(), zf.read(zi))
+ finally:
+ rmtree(extdir)
+
def test_main():
run_unittest(TestsWithSourceFile, TestZip64InSmallFiles, OtherTests,
PyZipFileTests, DecryptionTests, TestsWithMultipleOpens,
TestWithDirectory, UniversalNewlineTests,
- TestsWithRandomBinaryFiles)
+ TestsWithRandomBinaryFiles, CommandLineTest)
+
if __name__ == "__main__":
test_main()
import unittest
+from test import test_support as support
from test.test_support import TESTFN, run_unittest, import_module, unlink, requires
import binascii
import pickle
zlib.crc32('spam', (2**31)))
+# Issue #10276 - check that inputs >=4GB are handled correctly.
+class ChecksumBigBufferTestCase(unittest.TestCase):
+
+ @precisionbigmemtest(size=_4G + 4, memuse=1, dry_run=False)
+ def test_big_buffer(self, size):
+ data = b"nyan" * (_1G + 1)
+ self.assertEqual(zlib.crc32(data) & 0xFFFFFFFF, 1044521549)
+ self.assertEqual(zlib.adler32(data) & 0xFFFFFFFF, 2256789997)
+
+
class ExceptionTestCase(unittest.TestCase):
# make sure we generate some expected errors
def test_badlevel(self):
self.assertRaises(ValueError, zlib.decompressobj().flush, 0)
self.assertRaises(ValueError, zlib.decompressobj().flush, -1)
+ @support.cpython_only
+ def test_overflow(self):
+ with self.assertRaisesRegexp(OverflowError, 'int too large'):
+ zlib.decompress(b'', 15, sys.maxsize + 1)
+ with self.assertRaisesRegexp(OverflowError, 'int too large'):
+ zlib.decompressobj().decompress(b'', sys.maxsize + 1)
+ with self.assertRaisesRegexp(OverflowError, 'int too large'):
+ zlib.decompressobj().flush(sys.maxsize + 1)
+
class BaseCompressTestCase(object):
def check_big_compress_buffer(self, size, compress_func):
def test_big_decompress_buffer(self, size):
self.check_big_decompress_buffer(size, zlib.decompress)
+ @precisionbigmemtest(size=_4G, memuse=1)
+ def test_large_bufsize(self, size):
+ # Test decompress(bufsize) parameter greater than the internal limit
+ data = HAMLET_SCENE * 10
+ compressed = zlib.compress(data, 1)
+ self.assertEqual(zlib.decompress(compressed, 15, size), data)
+
+ def test_custom_bufsize(self):
+ data = HAMLET_SCENE * 10
+ compressed = zlib.compress(data, 1)
+ self.assertEqual(zlib.decompress(compressed, 15, CustomInt()), data)
+
+ @unittest.skipUnless(sys.maxsize > 2**32, 'requires 64bit platform')
+ @precisionbigmemtest(size=_4G + 100, memuse=4)
+ def test_64bit_compress(self, size):
+ data = b'x' * size
+ try:
+ comp = zlib.compress(data, 0)
+ self.assertEqual(zlib.decompress(comp), data)
+ finally:
+ comp = data = None
+
class CompressObjectTestCase(BaseCompressTestCase, unittest.TestCase):
# Test compression object
self.assertRaises(ValueError, dco.decompress, "", -1)
self.assertEqual('', dco.unconsumed_tail)
+ def test_maxlen_large(self):
+ # Sizes up to sys.maxsize should be accepted, although zlib is
+ # internally limited to expressing sizes with unsigned int
+ data = HAMLET_SCENE * 10
+ DEFAULTALLOC = 16 * 1024
+ self.assertGreater(len(data), DEFAULTALLOC)
+ compressed = zlib.compress(data, 1)
+ dco = zlib.decompressobj()
+ self.assertEqual(dco.decompress(compressed, sys.maxsize), data)
+
+ def test_maxlen_custom(self):
+ data = HAMLET_SCENE * 10
+ compressed = zlib.compress(data, 1)
+ dco = zlib.decompressobj()
+ self.assertEqual(dco.decompress(compressed, CustomInt()), data[:100])
+
def test_clear_unconsumed_tail(self):
# Issue #12050: calling decompress() without providing max_length
# should clear the unconsumed_tail attribute.
data = zlib.compress(input2)
self.assertEqual(dco.flush(), input1[1:])
+ @precisionbigmemtest(size=_4G, memuse=1)
+ def test_flush_large_length(self, size):
+ # Test flush(length) parameter greater than internal limit UINT_MAX
+ input = HAMLET_SCENE * 10
+ data = zlib.compress(input, 1)
+ dco = zlib.decompressobj()
+ dco.decompress(data, 1)
+ self.assertEqual(dco.flush(size), input[1:])
+
+ def test_flush_custom_length(self):
+ input = HAMLET_SCENE * 10
+ data = zlib.compress(input, 1)
+ dco = zlib.decompressobj()
+ dco.decompress(data, 1)
+ self.assertEqual(dco.flush(CustomInt()), input[1:])
+
@requires_Compress_copy
def test_compresscopy(self):
# Test copying a compression object
decompress = lambda s: d.decompress(s) + d.flush()
self.check_big_decompress_buffer(size, decompress)
+ @unittest.skipUnless(sys.maxsize > 2**32, 'requires 64bit platform')
+ @precisionbigmemtest(size=_4G + 100, memuse=4)
+ def test_64bit_compress(self, size):
+ data = b'x' * size
+ co = zlib.compressobj(0)
+ do = zlib.decompressobj()
+ try:
+ comp = co.compress(data) + co.flush()
+ uncomp = do.decompress(comp) + do.flush()
+ self.assertEqual(uncomp, data)
+ finally:
+ comp = uncomp = data = None
+
+ @unittest.skipUnless(sys.maxsize > 2**32, 'requires 64bit platform')
+ @precisionbigmemtest(size=_4G + 100, memuse=3)
+ def test_large_unused_data(self, size):
+ data = b'abcdefghijklmnop'
+ unused = b'x' * size
+ comp = zlib.compress(data) + unused
+ do = zlib.decompressobj()
+ try:
+ uncomp = do.decompress(comp) + do.flush()
+ self.assertEqual(unused, do.unused_data)
+ self.assertEqual(uncomp, data)
+ finally:
+ unused = comp = do = None
+
+ @unittest.skipUnless(sys.maxsize > 2**32, 'requires 64bit platform')
+ @precisionbigmemtest(size=_4G + 100, memuse=5)
+ def test_large_unconsumed_tail(self, size):
+ data = b'x' * size
+ do = zlib.decompressobj()
+ try:
+ comp = zlib.compress(data, 0)
+ uncomp = do.decompress(comp, 1) + do.flush()
+ self.assertEqual(uncomp, data)
+ self.assertEqual(do.unconsumed_tail, b'')
+ finally:
+ comp = uncomp = data = None
+
def test_wbits(self):
co = zlib.compressobj(1, zlib.DEFLATED, 15)
zlib15 = co.compress(HAMLET_SCENE) + co.flush()
"""
+class CustomInt:
+ def __int__(self):
+ return 100
+
+
def test_main():
run_unittest(
ChecksumTestCase,
+ ChecksumBigBufferTestCase,
ExceptionTestCase,
CompressTestCase,
CompressObjectTestCase
between the two objects is more than the given delta.
Note that decimal places (from zero) are usually not the same
- as significant digits (measured from the most signficant digit).
+ as significant digits (measured from the most significant digit).
If the two objects compare equal then they will automatically
compare almost equal.
between the two objects is less than the given delta.
Note that decimal places (from zero) are usually not the same
- as significant digits (measured from the most signficant digit).
+ as significant digits (measured from the most significant digit).
Objects that are equal automatically fail.
"""
self.key_file = x509.get('key_file')
self.cert_file = x509.get('cert_file')
self.context = context
- self.addheaders = [('User-Agent', self.version)]
+ self.addheaders = [('User-Agent', self.version), ('Accept', '*/*')]
self.__tempfiles = []
self.__unlink = os.unlink # See cleanup()
self.tempcache = None
If you need a different way, you can pass a proxies dictionary to the
[Fancy]URLopener constructor.
"""
+ # Get all variables
proxies = {}
for name, value in os.environ.items():
name = name.lower()
if value and name[-6:] == '_proxy':
proxies[name[:-6]] = value
+ # CVE-2016-1000110 - If we are running as CGI script, forget HTTP_PROXY
+ # (non-all-lowercase) as it may be set from the web server by a "Proxy:"
+ # header from the client
+ # If "proxy" is lowercase, it will still be used thanks to the next block
+ if 'REQUEST_METHOD' in os.environ:
+ proxies.pop('http', None)
+
+ # Get lowercase variables
for name, value in os.environ.items():
if name[-6:] == '_proxy':
name = name.lower()
assert data.itemsize == self._sampwidth
nitems = nframes * self._nchannels
if nitems * self._sampwidth > chunk.chunksize - chunk.size_read:
- nitems = (chunk.chunksize - chunk.size_read) / self._sampwidth
+ nitems = (chunk.chunksize - chunk.size_read) // self._sampwidth
data.fromfile(chunk.file.file, nitems)
# "tell" data chunk how much was read
chunk.size_read = chunk.size_read + nitems * self._sampwidth
# (but we prefer using the OS X specific stuff)
register("safari", None, MacOSXOSAScript('safari'), -1)
register("firefox", None, MacOSXOSAScript('firefox'), -1)
+ register("chrome", None, MacOSXOSAScript('chrome'), -1)
register("MacOSX", None, MacOSXOSAScript('default'), -1)
# minidom DOM and can't be used with other DOM implementations. This
# is due, in part, to a lack of appropriate methods in the DOM (there is
# no way to create Entity and Notation nodes via the DOM Level 2
-# interface), and for performance. The later is the cause of some fairly
+# interface), and for performance. The latter is the cause of some fairly
# cryptic code.
#
# Performance hacks:
"unexpected type in multicall result"
class MultiCall:
- """server -> a object used to boxcar method calls
+ """server -> an object used to boxcar method calls
server should be a ServerProxy object.
##
# Create parser.
#
- # @return A 2-tuple containing a parser and a unmarshaller.
+ # @return A 2-tuple containing a parser and an unmarshaller.
def getparser(self):
# get parser and unmarshaller
# set the modified flag so central directory gets written
# even if no files are added to the archive
self._didModify = True
+ self._start_disk = self.fp.tell()
elif key == 'a':
try:
# See if file is a zip file
# set the modified flag so central directory gets written
# even if no files are added to the archive
self._didModify = True
+ self._start_disk = self.fp.tell()
else:
raise RuntimeError('Mode must be "r", "w" or "a"')
except:
offset_cd = endrec[_ECD_OFFSET] # offset of central directory
self._comment = endrec[_ECD_COMMENT] # archive comment
- # "concat" is zero, unless zip was concatenated to another file
- concat = endrec[_ECD_LOCATION] - size_cd - offset_cd
+ # self._start_disk: Position of the start of ZIP archive
+ # It is zero, unless ZIP was concatenated to another file
+ self._start_disk = endrec[_ECD_LOCATION] - size_cd - offset_cd
if endrec[_ECD_SIGNATURE] == stringEndArchive64:
# If Zip64 extension structures are present, account for them
- concat -= (sizeEndCentDir64 + sizeEndCentDir64Locator)
+ self._start_disk -= (sizeEndCentDir64 + sizeEndCentDir64Locator)
if self.debug > 2:
- inferred = concat + offset_cd
- print "given, inferred, offset", offset_cd, inferred, concat
+ inferred = self._start_disk + offset_cd
+ print "given, inferred, offset", offset_cd, inferred, self._start_disk
# self.start_dir: Position of start of central directory
- self.start_dir = offset_cd + concat
+ self.start_dir = offset_cd + self._start_disk
fp.seek(self.start_dir, 0)
data = fp.read(size_cd)
fp = cStringIO.StringIO(data)
t>>11, (t>>5)&0x3F, (t&0x1F) * 2 )
x._decodeExtra()
- x.header_offset = x.header_offset + concat
+ x.header_offset = x.header_offset + self._start_disk
x.filename = x._decodeFilename()
self.filelist.append(x)
self.NameToInfo[x.filename] = x
raise RuntimeError('Compressed size larger than uncompressed size')
# Seek backwards and write file header (which will now include
# correct CRC and file sizes)
- position = self.fp.tell() # Preserve current position in file
+ position = self.fp.tell() # Preserve current position in file
self.fp.seek(zinfo.header_offset, 0)
self.fp.write(zinfo.FileHeader(zip64))
self.fp.seek(position, 0)
file_size = zinfo.file_size
compress_size = zinfo.compress_size
- if zinfo.header_offset > ZIP64_LIMIT:
- extra.append(zinfo.header_offset)
+ header_offset = zinfo.header_offset - self._start_disk
+ if header_offset > ZIP64_LIMIT:
+ extra.append(header_offset)
header_offset = 0xffffffffL
- else:
- header_offset = zinfo.header_offset
extra_data = zinfo.extra
if extra:
# Write end-of-zip-archive record
centDirCount = len(self.filelist)
centDirSize = pos2 - pos1
- centDirOffset = pos1
+ centDirOffset = pos1 - self._start_disk
requires_zip64 = None
if centDirCount > ZIP_FILECOUNT_LIMIT:
requires_zip64 = "Files count"
result.extend([
dict(
- name="OpenSSL 1.0.2h",
- url="https://www.openssl.org/source/openssl-1.0.2h.tar.gz",
- checksum='9392e65072ce4b614c1392eefc1f23d0',
+ name="OpenSSL 1.0.2j",
+ url="https://www.openssl.org/source/openssl-1.0.2j.tar.gz",
+ checksum='96322138f0b69e61b7212bc53d5e912b',
patches=[
"openssl_sdk_makedepend.patch",
],
# HG changeset patch
-# Parent d377390f787c0739a3e89f669def72d7167e5108
-# openssl_sdk_makedepend.patch
#
-# using openssl 1.0.2f
+# using openssl 1.0.2j
#
# - support building with an OS X SDK
diff --git a/Configure b/Configure
--- a/Configure
+++ b/Configure
-@@ -638,12 +638,12 @@
+@@ -642,12 +642,12 @@
##### MacOS X (a.k.a. Rhapsody or Darwin) setup
"rhapsody-ppc-cc","cc:-O3 -DB_ENDIAN::(unknown):MACOSX_RHAPSODY::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}::",
"debug-darwin-ppc-cc","cc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DB_ENDIAN -g -Wall -O::-D_REENTRANT:MACOSX::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc32_asm}:osx32:dlfcn:darwin-shared:-fPIC:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
# iPhoneOS/iOS
"iphoneos-cross","llvm-gcc:-O3 -isysroot \$(CROSS_TOP)/SDKs/\$(CROSS_SDK) -fomit-frame-pointer -fno-common::-D_REENTRANT:iOS:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
-@@ -1717,8 +1717,7 @@
- s/^CC=.*$/CC= $cc/;
+@@ -1728,8 +1728,7 @@
s/^AR=\s*ar/AR= $ar/;
s/^RANLIB=.*/RANLIB= $ranlib/;
+ s/^RC=.*/RC= $windres/;
- s/^MAKEDEPPROG=.*$/MAKEDEPPROG= $cc/ if $cc eq "gcc";
- s/^MAKEDEPPROG=.*$/MAKEDEPPROG= $cc/ if $ecc eq "gcc" || $ecc eq "clang";
-+ s/^MAKEDEPPROG=.*$/MAKEDEPPROG= $cc/
++ s/^MAKEDEPPROG=.*$/MAKEDEPPROG= $cc/;
}
s/^CFLAG=.*$/CFLAG= $cflags/;
s/^DEPFLAG=.*$/DEPFLAG=$depflags/;
-{\rtf1\ansi\ansicpg1252\cocoartf1347\cocoasubrtf570
+{\rtf1\ansi\ansicpg1252\cocoartf1504\cocoasubrtf750
{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fmodern\fcharset0 CourierNewPSMT;}
{\colortbl;\red255\green255\blue255;}
+{\*\expandedcolortbl;;}
\margl1440\margr1440\vieww15240\viewh15540\viewkind0
-\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
+\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
\f0\fs24 \cf0 This package will install Python $FULL_VERSION for Mac OS X $MACOSX_DEPLOYMENT_TARGET for the following architecture(s): $ARCHITECTURES.\
\
-\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
+\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
\b \cf0 \ul \ulc0 Which installer variant should I use?
\b0 \ulnone \
\i0 for this version of Python and of Mac OS X.\
\b \ul \
-Installing on OS X 10.8 (Mountain Lion) or later systems\
-\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
+\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
+\cf0 Packages installed with the system Python 2.7 are no longer searched for\
+\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
+\cf0 \ulnone [CHANGED for Python 2.7.13]
+\b0 \
+\
+As of Python 2.7.0, user-installed Python 2.7 versions from python.org installers added the system-wide site-packages directory for the Apple-supplied Python 2.7 to the end of their search path. This meant that packages installed with the system Python 2.7 could also be used by the user-installed Python 2.7. While sometimes convenient, this also often caused confusion with the implicit coupling between the two Python instances. Separately, as of macOS 10.12, Apple changed the layout of the system site-packages directory,
+\f1 /Library/Python/2.7/site-packages
+\f0 , in a way that can now cause installation of
+\f1 pip
+\f0 components to fail. To avoid the confusion and the installation failures, as of 2.7.13 user-installed Pythons no longer add
+\f1 /Library/Python/2.7/site-packages
+\f0 to
+\f1 sys.path
+\f0 . If you are using a package with both a user-installed Python 2.7 and the system Python 2.7, you will now need to ensure that separate copies of the package are installed for each instance.\
+\
+\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
+
+\b \cf0 \ul Installing on OS X 10.8 (Mountain Lion) or later systems\
+\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
\cf0 \ulnone [CHANGED for Python 2.7.9]
\b0 \
\
\i Install Python
\i0 installer window. Refer to Apple\'92s support pages for {\field{\*\fldinst{HYPERLINK "http://support.apple.com/kb/ht5290"}}{\fldrslt more information on Gatekeeper}}.\
\
-\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
+\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
\b \cf0 \ul Simplified web-based installs\
-\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
+\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
\cf0 \ulnone [NEW for Python 2.7.9]
\b0 \
\
\f1 .dmg
\f0 ) container. If you download the Python installer through a web browser, the OS X installer application may open automatically to allow you to perform the install. If your browser settings do not allow automatic open, double click on the downloaded installer file.\
\
-\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
+\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
\b \cf0 \ul New Installation Options and Defaults\
-\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
+\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
\cf0 \ulnone [NEW for Python 2.7.9]
\b0 \
\
\i Release Notes
\i0 link for this release at {\field{\*\fldinst{HYPERLINK "https://www.python.org/downloads/"}}{\fldrslt https://www.python.org/downloads/}}.\
\
-\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
+\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
\b \cf0 \ul Certificate verification and OpenSSL\
-\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
+\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
\cf0 \ulnone [CHANGED for Python 2.7.9]
\b0 \
\
The bundled
\f1 pip
\f0 included with 2.7.9 has its own default certificate store for verifying download connections.\
-\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
+\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
\b \cf0 \ul \
Binary installer support for OS X 10.4 and 10.3.9 discontinued\
-\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
+\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
\cf0 \ulnone [CHANGED for Python 2.7.9]
\b0 \
\
As previously announced, binary installers for Python 2.7.9 from python.org no longer support Mac OS X 10.3.9 (Panther) and 10.4.x (Tiger) systems. These systems were last updated by Apple in 2005 and 2007. As of 2.7.9, the 32-bit-only installer supports PPC and Intel Macs running OS X 10.5 (Leopard). 10.5 was the last OS X release for PPC machines (G4 and G5). The 64-/32-bit installer configuration remains unchanged and should normally be used on OS X 10.6 (Snow Leopard) and later systems. This aligns Python 2.7.x installer configurations with those currently provided with Python 3.x. If needed, it is still possible to build Python from source for 10.3.9 and 10.4.\
\
-\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
+\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
\b \cf0 \ul Python 3 and Python 2 Co-existence\
to do your own initializations and override <code>makeusermenus</code> to create your menus
(your menu callback routines may be here too, but this is by no means necessary).
The event handling code can be overridden at various levels, from very low-level (the
-<code>dispatch</code> method) to intermedeate level (<code>do_keyDown</code>, for instance)
+<code>dispatch</code> method) to intermediate level (<code>do_keyDown</code>, for instance)
to high-level (<code>do_key</code>). The application class knows about the <code>Window</code>
objects you create, and will forward events to the appropriate window (So, normally you
would have a <code>do_key</code> method in your window object, not your application object).
break
# Now it is safe to import idlelib.
-from idlelib import macosxSupport
-macosxSupport._appbundle = True
from idlelib.PyShell import main
if __name__ == '__main__':
main()
/* ----------------------------------------------------- */
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
static char cp_GetColor__doc__[] =
"GetColor(prompt, (r, g, b)) -> (r, g, b), ok"
return Py_BuildValue("O&h", QdRGB_New, &outColor, ok);
}
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
/* List of methods defined in the module */
static struct PyMethodDef cp_methods[] = {
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
{"GetColor", (PyCFunction)cp_GetColor, METH_VARARGS, cp_GetColor__doc__},
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
{NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */
};
if (PyErr_Occurred())
Py_FatalError("can't initialize module ColorPicker");
}
-
FileInfo* finfo;
if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSRef, &ref)) {
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
/* This function is documented to take an FSSpec as well,
* which only works in 32-bit mode.
*/
Py_DECREF(creator);
Py_DECREF(type);
return res;
-#else /* __LP64__ */
+#else /* APPLE_SUPPORTS_QUICKTIME */
return NULL;
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
}
err = FSGetCatalogInfo(&ref,
if (!PyArg_ParseTuple(args, "O&O&O&",
PyMac_GetFSRef, &ref, PyMac_GetOSType, &creator, PyMac_GetOSType, &type)) {
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
/* Try to handle FSSpec arguments, for backward compatibility */
FSSpec fss;
FInfo info;
return PyErr_Mac(MacOS_Error, err);
Py_INCREF(Py_None);
return Py_None;
-#else /* __LP64__ */
+#else /* APPLE_SUPPORTS_QUICKTIME */
return NULL;
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
}
err = FSGetCatalogInfo(&ref,
#include <Carbon/Carbon.h>
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
static PyObject *
PyOSA_GetAppTerminology(PyObject* self, PyObject* args)
{
if (err) return PyMac_Error(err);
return Py_BuildValue("O&", AEDesc_New, &theDesc);
}
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
/*
* List of methods defined in the module
*/
static struct PyMethodDef OSATerminology_methods[] =
{
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
{"GetAppTerminology",
(PyCFunction) PyOSA_GetAppTerminology,
METH_VARARGS,
(PyCFunction) PyOSA_GetSysTerminology,
METH_VARARGS,
"Get the AppleScript language's terminology. GetSysTerminology() --> AEDesc"},
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
{NULL, (PyCFunction) NULL, 0, NULL}
};
/* ========================== Module _App =========================== */
#include "Python.h"
+#include "pymactoolbox.h"
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
/* Carbon GUI stuff, not available in 64-bit mode */
-
-#include "pymactoolbox.h"
-
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
PyErr_SetString(PyExc_NotImplementedError, \
void init_App(void)
{
PyObject *m;
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
PyObject *d;
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
m = Py_InitModule("_App", App_methods);
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
d = PyModule_GetDict(m);
App_Error = PyMac_GetOSErrException();
if (App_Error == NULL ||
/* Backward-compatible name */
Py_INCREF(&ThemeDrawingState_Type);
PyModule_AddObject(m, "ThemeDrawingStateType", (PyObject *)&ThemeDrawingState_Type);
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
}
/* ======================== End module _App ========================= */
/* ======================= Module _CarbonEvt ======================== */
#include "Python.h"
+#include "pymactoolbox.h"
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
-#include "pymactoolbox.h"
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
{NULL, NULL, 0}
};
-#else /* __LP64__ */
+#else /* APPLE_SUPPORTS_QUICKTIME */
static PyMethodDef CarbonEvents_methods[] = {
{NULL, NULL, 0}
};
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
void init_CarbonEvt(void)
{
PyObject *m;
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
PyObject *d;
-#endif /* !__LP64__ */
+#endif /* !APPLE_SUPPORTS_QUICKTIME */
m = Py_InitModule("_CarbonEvt", CarbonEvents_methods);
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
myEventHandlerUPP = NewEventHandlerUPP(myEventHandler);
d = PyModule_GetDict(m);
CarbonEvents_Error = PyMac_GetOSErrException();
/* Backward-compatible name */
Py_INCREF(&EventHotKeyRef_Type);
PyModule_AddObject(m, "EventHotKeyRefType", (PyObject *)&EventHotKeyRef_Type);
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
}
/* ===================== End module _CarbonEvt ====================== */
*/
PyObject *CFRange_New(CFRange *itself)
{
-
return Py_BuildValue("ll", (long)itself->location, (long)itself->length);
}
OptionalCFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself)
{
if ( v == Py_None ) {
- p_itself = NULL;
- return 1;
+ p_itself = NULL;
+ return 1;
}
return CFURLRefObj_Convert(v, p_itself);
}
MoreAssertQ(fragToFix->sectionHeaders != nil);
MoreAssertQ(fragToFix->loaderSection != nil);
MoreAssertQ(fragToFix->section0Base != nil); // Technically, having a nil for these two is not a problem, ...
- MoreAssertQ(fragToFix->section1Base != nil); // but in practise it a wildly deviant case and we should know about it.
+ MoreAssertQ(fragToFix->section1Base != nil); // but in practice it a wildly deviant case and we should know about it.
MoreAssertQ(importLibrary != nil);
MoreAssertQ(lookup != nil);
/* ========================== Module _Ctl =========================== */
#include "Python.h"
+#include "pymactoolbox.h"
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
-#include "pymactoolbox.h"
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
return (ControlPartCode)c_rv;
}
-#else /* __LP64__ */
+#else /* APPLE_SUPPORTS_QUICKTIME */
static PyMethodDef Ctl_methods[] = {
{NULL, NULL, 0}
};
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
void init_Ctl(void)
{
PyObject *m;
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
PyObject *d;
mytracker_upp = NewControlActionUPP(mytracker);
mytrackingproc_upp = NewControlUserPaneTrackingUPP(mytrackingproc);
PyMac_INIT_TOOLBOX_OBJECT_NEW(ControlHandle, CtlObj_New);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ControlHandle, CtlObj_Convert);
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
m = Py_InitModule("_Ctl", Ctl_methods);
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
d = PyModule_GetDict(m);
Ctl_Error = PyMac_GetOSErrException();
if (Ctl_Error == NULL ||
/* Backward-compatible name */
Py_INCREF(&Control_Type);
PyModule_AddObject(m, "ControlType", (PyObject *)&Control_Type);
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
}
/* ======================== End module _Ctl ========================= */
-
/* ========================== Module _Dlg =========================== */
#include "Python.h"
-
-#ifndef __LP64__
-
-
#include "pymactoolbox.h"
+#if APPLE_SUPPORTS_QUICKTIME
+
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
void init_Dlg(void)
{
PyObject *m;
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
PyObject *d;
PyMac_INIT_TOOLBOX_OBJECT_NEW(DialogPtr, DlgObj_New);
PyMac_INIT_TOOLBOX_OBJECT_NEW(DialogPtr, DlgObj_WhichDialog);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DialogPtr, DlgObj_Convert);
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
m = Py_InitModule("_Dlg", Dlg_methods);
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
d = PyModule_GetDict(m);
Dlg_Error = PyMac_GetOSErrException();
if (Dlg_Error == NULL ||
/* Backward-compatible name */
Py_INCREF(&Dialog_Type);
PyModule_AddObject(m, "DialogType", (PyObject *)&Dialog_Type);
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
}
/* ======================== End module _Dlg ========================= */
/* ========================== Module _Drag ========================== */
#include "Python.h"
-
-#ifndef __LP64__
-
-
#include "pymactoolbox.h"
+#if APPLE_SUPPORTS_QUICKTIME
+
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
void init_Drag(void)
{
PyObject *m;
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
PyObject *d;
PyMac_INIT_TOOLBOX_OBJECT_NEW(DragRef, DragObj_New);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DragRef, DragObj_Convert);
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
m = Py_InitModule("_Drag", Drag_methods);
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
d = PyModule_GetDict(m);
Drag_Error = PyMac_GetOSErrException();
if (Drag_Error == NULL ||
dragglue_DrawingUPP = NewDragDrawingUPP(dragglue_Drawing);
#endif
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
}
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
/* ========================== Module _Help ========================== */
#include "Python.h"
-
-#ifndef __LP64__
-
-
#include "pymactoolbox.h"
+#if APPLE_SUPPORTS_QUICKTIME
+
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
return _res;
}
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
static PyMethodDef Help_methods[] = {
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
{"HMGetHelpMenu", (PyCFunction)Help_HMGetHelpMenu, 1,
PyDoc_STR("() -> (MenuRef outHelpMenu, MenuItemIndex outFirstCustomItemIndex)")},
{"HMAreHelpTagsDisplayed", (PyCFunction)Help_HMAreHelpTagsDisplayed, 1,
PyDoc_STR("(DialogPtr inDialog, SInt16 inHdlgRsrcID, SInt16 inItemStart) -> None")},
{"HMHideTag", (PyCFunction)Help_HMHideTag, 1,
PyDoc_STR("() -> None")},
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
{NULL, NULL, 0}
};
-
void init_Help(void)
{
PyObject *m;
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
PyObject *d;
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
m = Py_InitModule("_Help", Help_methods);
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
d = PyModule_GetDict(m);
Help_Error = PyMac_GetOSErrException();
if (Help_Error == NULL ||
PyDict_SetItemString(d, "Error", Help_Error) != 0)
return;
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
}
/* ======================== End module _Help ======================== */
/* ======================== Module _IBCarbon ======================== */
#include "Python.h"
+#include "pymactoolbox.h"
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
#include <Carbon/Carbon.h>
-#include "pymactoolbox.h"
#ifdef USE_TOOLBOX_OBJECT_GLUE
extern int _CFStringRefObj_Convert(PyObject *, CFStringRef *);
IBNibRefObj_New, outNibRef);
return _res;
}
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
static PyMethodDef IBCarbon_methods[] = {
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
{"CreateNibReference", (PyCFunction)IBCarbon_CreateNibReference, 1,
PyDoc_STR("(CFStringRef inNibName) -> (IBNibRef outNibRef)")},
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
{NULL, NULL, 0}
};
void init_IBCarbon(void)
{
PyObject *m;
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
PyObject *d;
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
m = Py_InitModule("_IBCarbon", IBCarbon_methods);
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
d = PyModule_GetDict(m);
IBCarbon_Error = PyMac_GetOSErrException();
if (IBCarbon_Error == NULL ||
/* Backward-compatible name */
Py_INCREF(&IBNibRef_Type);
PyModule_AddObject(m, "IBNibRefType", (PyObject *)&IBNibRef_Type);
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
}
/* ====================== End module _IBCarbon ====================== */
/* ========================== Module _Icn =========================== */
#include "Python.h"
+#include "pymactoolbox.h"
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
-#include "pymactoolbox.h"
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
_res = Py_None;
return _res;
}
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
static PyMethodDef Icn_methods[] = {
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
{"GetCIcon", (PyCFunction)Icn_GetCIcon, 1,
PyDoc_STR("(SInt16 iconID) -> (CIconHandle _rv)")},
{"PlotCIcon", (PyCFunction)Icn_PlotCIcon, 1,
PyDoc_STR("(FSRef ref) -> (IconFamilyHandle iconFamily)")},
{"WriteIconFile", (PyCFunction)Icn_WriteIconFile, 1,
PyDoc_STR("(IconFamilyHandle iconFamily, FSSpec iconFile) -> None")},
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
{NULL, NULL, 0}
};
void init_Icn(void)
{
PyObject *m;
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
PyObject *d;
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
m = Py_InitModule("_Icn", Icn_methods);
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
d = PyModule_GetDict(m);
Icn_Error = PyMac_GetOSErrException();
if (Icn_Error == NULL ||
PyDict_SetItemString(d, "Error", Icn_Error) != 0)
return;
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
}
/* ======================== End module _Icn ========================= */
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
/* ========================== Module _List ========================== */
#include "Python.h"
+#include "pymactoolbox.h"
-#ifndef __LP64__
-
+#if APPLE_SUPPORTS_QUICKTIME
-#include "pymactoolbox.h"
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
return _res;
}
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
static PyMethodDef List_methods[] = {
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
{"CreateCustomList", (PyCFunction)List_CreateCustomList, 1,
PyDoc_STR("(Rect rView, Rect dataBounds, Point cellSize, ListDefSpec theSpec, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle outList)")},
{"LNew", (PyCFunction)List_LNew, 1,
PyDoc_STR("(ListHandle list, OptionBits selectionFlags) -> None")},
{"as_List", (PyCFunction)List_as_List, 1,
PyDoc_STR("(Resource)->List.\nReturns List object (which is not auto-freed!)")},
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
{NULL, NULL, 0}
};
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
static void myListDefFunction(SInt16 message,
Py_DECREF(rv);
}
}
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
void init_List(void)
{
PyObject *m;
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
PyObject *d;
PyMac_INIT_TOOLBOX_OBJECT_NEW(ListHandle, ListObj_New);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ListHandle, ListObj_Convert);
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
m = Py_InitModule("_List", List_methods);
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
d = PyModule_GetDict(m);
List_Error = PyMac_GetOSErrException();
if (List_Error == NULL ||
/* Backward-compatible name */
Py_INCREF(&List_Type);
PyModule_AddObject(m, "ListType", (PyObject *)&List_Type);
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
}
/* ======================== End module _List ======================== */
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
/* ========================== Module _Mlte ========================== */
#include "Python.h"
+#include "pymactoolbox.h"
-#ifndef __LP64__
-
+#if APPLE_SUPPORTS_QUICKTIME
-#include "pymactoolbox.h"
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
}
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
static PyMethodDef Mlte_methods[] = {
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
{"TXNNewObject", (PyCFunction)Mlte_TXNNewObject, 1,
PyDoc_STR("(FSSpec * iFileSpec, WindowPtr iWindow, Rect iFrame, TXNFrameOptions iFrameOptions, TXNFrameType iFrameType, TXNFileType iFileType, TXNPermanentTextEncodingType iPermanentEncoding) -> (TXNObject oTXNObject, TXNFrameID oTXNFrameID)")},
{"TXNTerminateTextension", (PyCFunction)Mlte_TXNTerminateTextension, 1,
PyDoc_STR("() -> (TXNVersionValue _rv, TXNFeatureBits oFeatureFlags)")},
{"TXNInitTextension", (PyCFunction)Mlte_TXNInitTextension, 1,
PyDoc_STR("(TXNInitOptions) -> None")},
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
{NULL, NULL, 0}
};
void init_Mlte(void)
{
PyObject *m;
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
PyObject *d;
// PyMac_INIT_TOOLBOX_OBJECT_NEW(xxxx);
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
m = Py_InitModule("_Mlte", Mlte_methods);
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
d = PyModule_GetDict(m);
Mlte_Error = PyMac_GetOSErrException();
if (Mlte_Error == NULL ||
/* Backward-compatible name */
Py_INCREF(&TXNFontMenuObject_Type);
PyModule_AddObject(m, "TXNFontMenuObjectType", (PyObject *)&TXNFontMenuObject_Type);
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
}
/* ======================== End module _Mlte ======================== */
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
/* =========================== Module _Qt =========================== */
#include "Python.h"
+#include "pymactoolbox.h"
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
-#include "pymactoolbox.h"
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
_res = Py_None;
return _res;
}
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
static PyMethodDef Qt_methods[] = {
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
{"EnterMovies", (PyCFunction)Qt_EnterMovies, 1,
PyDoc_STR("() -> None")},
{"ExitMovies", (PyCFunction)Qt_ExitMovies, 1,
PyDoc_STR("(WindowPtr wp, Point startPt, Rect boundsRect) -> None")},
{"MoviesTask", (PyCFunction)Qt_MoviesTask, 1,
PyDoc_STR("(long maxMilliSecToUse) -> None")},
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
{NULL, NULL, 0}
};
void init_Qt(void)
{
PyObject *m;
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
PyObject *d;
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(UserData, UserDataObj_Convert);
PyMac_INIT_TOOLBOX_OBJECT_NEW(Media, MediaObj_New);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Media, MediaObj_Convert);
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
m = Py_InitModule("_Qt", Qt_methods);
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
d = PyModule_GetDict(m);
Qt_Error = PyMac_GetOSErrException();
if (Qt_Error == NULL ||
/* Backward-compatible name */
Py_INCREF(&SGOutput_Type);
PyModule_AddObject(m, "SGOutputType", (PyObject *)&SGOutput_Type);
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
}
/* ========================= End module _Qt ========================= */
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
HLock(self->ob_itself);
memcpy((char *)*self->ob_itself, data, size);
HUnlock(self->ob_itself);
- /* XXXX Should I do the Changed call immedeately? */
+ /* XXXX Should I do the Changed call immediately? */
return 0;
return 0;
HLock(self->ob_itself);
memcpy((char *)*self->ob_itself, data, size);
HUnlock(self->ob_itself);
- /* XXXX Should I do the Changed call immedeately? */
+ /* XXXX Should I do the Changed call immediately? */
return 0;
""",
'The resource data'
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
/* =========================== Module _TE =========================== */
#include "Python.h"
+#include "pymactoolbox.h"
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
-#include "pymactoolbox.h"
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
TEObj_New, _rv);
return _res;
}
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
static PyMethodDef TE_methods[] = {
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
{"TEScrapHandle", (PyCFunction)TE_TEScrapHandle, 1,
PyDoc_STR("() -> (Handle _rv)")},
{"TEGetScrapLength", (PyCFunction)TE_TEGetScrapLength, 1,
PyDoc_STR("(UInt8 value) -> None")},
{"as_TE", (PyCFunction)TE_as_TE, 1,
PyDoc_STR("(Handle h) -> (TEHandle _rv)")},
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
{NULL, NULL, 0}
};
void init_TE(void)
{
PyObject *m;
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
PyObject *d;
PyMac_INIT_TOOLBOX_OBJECT_NEW(TEHandle, TEObj_New);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(TEHandle, TEObj_Convert);
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
m = Py_InitModule("_TE", TE_methods);
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
d = PyModule_GetDict(m);
TE_Error = PyMac_GetOSErrException();
if (TE_Error == NULL ||
/* Backward-compatible name */
Py_INCREF(&TE_Type);
PyModule_AddObject(m, "TEType", (PyObject *)&TE_Type);
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
}
/* ========================= End module _TE ========================= */
/* ========================== Module _Win =========================== */
#include "Python.h"
+#include "pymactoolbox.h"
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
-#include "pymactoolbox.h"
/* Macro to test whether a weak-loaded CFM function exists */
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
- PyErr_SetString(PyExc_NotImplementedError, \
- "Not available in this shared library/OS version"); \
- return NULL; \
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
}} while(0)
WinObj_WhichWindow, theWindow);
return _res;
}
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
static PyMethodDef Win_methods[] = {
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
{"GetNewCWindow", (PyCFunction)Win_GetNewCWindow, 1,
PyDoc_STR("(short windowID, WindowPtr behind) -> (WindowPtr _rv)")},
{"NewWindow", (PyCFunction)Win_NewWindow, 1,
{"FindWindow", (PyCFunction)Win_FindWindow, 1,
PyDoc_STR("(Point thePoint) -> (short _rv, WindowPtr theWindow)")},
{NULL, NULL, 0}
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
};
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
/* Return the object corresponding to the window, or NULL */
PyObject *
return it;
}
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
void init_Win(void)
{
PyObject *m;
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
PyObject *d;
PyMac_INIT_TOOLBOX_OBJECT_NEW(WindowPtr, WinObj_New);
PyMac_INIT_TOOLBOX_OBJECT_NEW(WindowPtr, WinObj_WhichWindow);
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(WindowPtr, WinObj_Convert);
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
m = Py_InitModule("_Win", Win_methods);
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
d = PyModule_GetDict(m);
Win_Error = PyMac_GetOSErrException();
if (Win_Error == NULL ||
/* Backward-compatible name */
Py_INCREF(&Window_Type);
PyModule_AddObject(m, "WindowType", (PyObject *)&Window_Type);
-#endif /* __LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
}
/* ======================== End module _Win ========================= */
- (BOOL)shouldShowUI
{
// if this call comes before applicationDidFinishLaunching: we
- // should terminate immedeately after starting the script.
+ // should terminate immediately after starting the script.
if (!initial_action_done)
should_terminate = YES;
initial_action_done = YES;
PYTHON= python$(EXE)
BUILDPYTHON= python$(BUILDEXE)
-cross_compiling=@cross_compiling@
PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
_PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@
HOST_GNU_TYPE= @host@
# Rules
# Default target
-all: build_all
+all: @DEF_MAKE_ALL_RULE@
build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks
# Compile a binary with profile guided optimization.
$(MAKE) profile-removal
build_all_generate_profile:
- $(MAKE) all CFLAGS="$(CFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LIBS="$(LIBS)"
+ $(MAKE) @DEF_MAKE_RULE@ CFLAGS="$(CFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LIBS="$(LIBS)"
run_profile_task:
: # FIXME: can't run for a cross build
$(LLVM_PROF_MERGER)
build_all_use_profile:
- $(MAKE) all CFLAGS="$(CFLAGS) $(PGO_PROF_USE_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) @LTOFLAGS@"
+ $(MAKE) @DEF_MAKE_RULE@ CFLAGS="$(CFLAGS) $(PGO_PROF_USE_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) @LTOFLAGS@"
# Compile and run with gcov
.PHONY=coverage coverage-lcov coverage-report
coverage:
@echo "Building with support for coverage checking:"
$(MAKE) clean profile-removal
- $(MAKE) all CFLAGS="$(CFLAGS) -O0 -pg -fprofile-arcs -ftest-coverage" LIBS="$(LIBS) -lgcov"
+ $(MAKE) @DEF_MAKE_RULE@ CFLAGS="$(CFLAGS) -O0 -pg -fprofile-arcs -ftest-coverage" LIBS="$(LIBS) -lgcov"
coverage-lcov:
@echo "Creating Coverage HTML report with LCOV:"
Modules/pwdmodule.o: $(srcdir)/Modules/pwdmodule.c $(srcdir)/Modules/posixmodule.h
-$(GRAMMAR_H): $(GRAMMAR_INPUT) $(PGEN)
+$(GRAMMAR_H): @GENERATED_COMMENT@ $(GRAMMAR_INPUT) $(PGEN)
@$(MKDIR_P) Include
- # Avoid copying the file onto itself for an in-tree build
- if test "$(cross_compiling)" != "yes"; then \
- $(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C); \
- else \
- cp $(srcdir)/Include/graminit.h $(GRAMMAR_H).tmp; \
- mv $(GRAMMAR_H).tmp $(GRAMMAR_H); \
- fi
-$(GRAMMAR_C): $(GRAMMAR_H)
- if test "$(cross_compiling)" != "yes"; then \
- touch $(GRAMMAR_C); \
- else \
- cp $(srcdir)/Python/graminit.c $(GRAMMAR_C).tmp; \
- mv $(GRAMMAR_C).tmp $(GRAMMAR_C); \
- fi
+ $(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
+$(GRAMMAR_C): @GENERATED_COMMENT@ $(GRAMMAR_H)
+ touch $(GRAMMAR_C)
$(PGEN): $(PGENOBJS)
$(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
# Like testall, but with a single pass only
# run an optional script to include some information about the build environment
-buildbottest: all platform
+buildbottest: build_all platform
-@if which pybuildbot.identify >/dev/null 2>&1; then \
pybuildbot.identify "CC='$(CC)'" "CXX='$(CXX)'"; \
fi
$(INSTALL_SCRIPT) $(srcdir)/Modules/makexp_aix \
$(DESTDIR)$(LIBPL)/makexp_aix; \
echo "$(LIBPL)/makexp_aix"; \
- $(INSTALL_SCRIPT) $(srcdir)/Modules/ld_so_aix \
+ $(INSTALL_SCRIPT) Modules/ld_so_aix \
$(DESTDIR)$(LIBPL)/ld_so_aix; \
echo "$(LIBPL)/ld_so_aix"; \
echo; echo "See Misc/AIX-NOTES for details."; \
find build -name 'fficonfig.h' -exec rm -f {} ';' || true
find build -name 'fficonfig.py' -exec rm -f {} ';' || true
-rm -f Lib/lib2to3/*Grammar*.pickle
- -rm -rf build
+ -find build -type f -a ! -name '*.gc??' -exec rm -f {} ';'
profile-removal:
find . -name '*.gc??' -exec rm -f {} ';'
Modules/ld_so_aix Modules/python.exp Misc/python.pc
-rm -f python*-gdb.py
-rm -f pybuilddir.txt
- find $(srcdir)/[a-zA-Z]* '(' -name '*.fdc' -o -name '*~' \
+ # Issue #28258: set LC_ALL to avoid issues with Estonian locale.
+ # Expansion is performed here by shell (spawned by make) itself before
+ # arguments are passed to find. So LC_ALL=C must be set as a separate
+ # command.
+ LC_ALL=C; find $(srcdir)/[a-zA-Z]* '(' -name '*.fdc' -o -name '*~' \
-o -name '[@,#]*' -o -name '*.old' \
-o -name '*.orig' -o -name '*.rej' \
-o -name '*.bak' ')' \
Lars Buitinck
Dick Bulterman
Bill Bumgarner
+Aleks Bunin
Jimmy Burgett
Edmond Burnett
Tommy Burnette
Daniel Calvelo
Tony Campbell
Brett Cannon
+Tristan Carel
Mike Carlton
Pierre Carrier
Terry Carroll
Felipe Cruz
Drew Csillag
Joaquin Cuenca Abela
+Sebastian Cufre
John Cugini
Tom Culliton
Antonio Cuni
Larry Hastings
Tim Hatch
Shane Hathaway
+Michael Haubenwallner
Janko Hauser
Rycharde Hawkes
Ben Hayden
David Jacobs
Kevin Jacobs
Kjetil Jacobsen
+Eddie James
Bertrand Janin
Geert Jansen
Jack Jansen
Kubilay Kocak
Greg Kochanski
Manvisha Kodali
+Niklas Koep
Damon Kohler
Marko Kohtala
Vajrasky Kok
Andrii V. Mishkovskyi
Dom Mitchell
Dustin J. Mitchell
+Tim Mitchell
Zubin Mithra
Florian Mladitsch
Doug Moen
R. David Murray
Matti Mäki
Jörg Müller
+Kaushik N
Dale Nagata
John Nagle
Takahiro Nakayama
Bo Peng
Santiago Peresón
George Peristerakis
+Thomas Perl
Mathieu Perreault
Mark Perrego
Trevor Perrin
Jérôme Radix
Burton Radons
Jeff Ramnani
+Bayard Randel
Varpu Rantala
Brodie Rao
+Rémi Rampin
Senko Rasic
Antti Rasinen
Nikolaus Rath
Just van Rossum
Hugo van Rossum
Saskia van Rossum
+Robin Roth
Clement Rouault
Donald Wallace Rouse II
Liam Routt
James Rutherford
Chris Ryland
Constantina S.
+Matthieu S
Patrick Sabin
Sébastien Sablé
Suman Saha
Thenault Sylvain
Péter Szabó
John Szakmeister
+Piotr Szczepaniak
Amir Szekely
Arfrever Frehtes Taifersar Arahesis
Hideaki Takahashi
Indra Talip
Neil Tallim
Geoff Talvola
+Anish Tambe
Musashi Tamura
William Tanksley
Christian Tanzer
Felix Wiemann
Gerry Wiener
Frank Wierzbicki
+Mariatta Wijaya
Santoso Wijaya
Bryce "Zooko" Wilcox-O'Hearn
Timothy Wild
Xiang Zhang
Robert Xiao
Florent Xicluna
+Alakshendra Yadav
Hirokazu Yamamoto
Ka-Ping Yee
Jason Yeo
Cheng Zhang
Kai Zhu
Tarek Ziadé
+Jelle Zijlstra
Gennadiy Zlobin
Peter Ã…strand
-----------------
- Bug #1441486: The literal representation of -(sys.maxint - 1)
- again evaluates to a int object, not a long.
+ again evaluates to an int object, not a long.
- Bug #1501934: The scope of global variables that are locally assigned
using augmented assignment is now correctly determined.
- Bug #947906: An object oriented interface has been added to the calendar
module. It's possible to generate HTML calendar now and the module can be
called as a script (e.g. via ``python -mcalendar``). Localized month and
- weekday names can be ouput (even if an exotic encoding is used) using
+ weekday names can be output (even if an exotic encoding is used) using
special classes that use unicode.
Build
``True`` for ``!=``, and raises ``TypeError`` for other comparison
operators. Because datetime is a subclass of date, comparing only the
base class (date) members can still be done, if that's desired, by
- forcing using of the approprate date method; e.g.,
+ forcing using of the appropriate date method; e.g.,
``a_date.__eq__(a_datetime)`` is true if and only if the year, month
and day members of ``a_date`` and ``a_datetime`` are equal.
interpreter executions, would fail.
- "%c" % u"a" now returns a unicode string instead of raising a
- TypeError. u"%c" % 0xffffffff now raises a OverflowError instead
+ TypeError. u"%c" % 0xffffffff now raises an OverflowError instead
of a ValueError to be consistent with "%c" % 256. See SF patch #710127.
Extension modules
Bow to font-lock at the end of the docstring, since it throws stuff
off.
- Make sure the path paramter to readmodule() is a list before adding it
+ Make sure the path parameter to readmodule() is a list before adding it
with sys.path, or the addition could fail.
- The interfaces for the bind*() and unbind() widget methods have been
redesigned; the bind*() methods now return the name of the Tcl command
-created for the callback, and this can be passed as a optional
+created for the callback, and this can be passed as an optional
argument to unbind() in order to delete the command (normally, such
commands are automatically unbound when the widget is destroyed, but
for some applications this isn't enough).
decimal numbers).
- In string.atof(), don't fail when the "re" module is unavailable.
-Plug the ensueing security leak by supplying an empty __builtins__
+Plug the ensuing security leak by supplying an empty __builtins__
directory to eval().
- A bunch of small fixes and improvements to Tkinter.py.
- The warning about a thread still having a frame now only happens in
verbose mode.
-- Change the signal finialization so that it also resets the signal
+- Change the signal finalization so that it also resets the signal
handlers. After this has been called, our signal handlers are no
longer active!
- copy.py: Make sure the objects returned by __getinitargs__() are
kept alive (in the memo) to avoid a certain kind of nasty crash. (Not
-easily reproducable because it requires a later call to
+easily reproducible because it requires a later call to
__getinitargs__() to return a tuple that happens to be allocated at
the same address.)
- The traceback.py module has a new function tb_lineno() by Marc-Andre
Lemburg which extracts the line number from the linenumber table in
-the code object. Apparently the traceback object doesn't contains the
+the code object. Apparently the traceback object doesn't contain the
right linenumber when -O is used. Rather than guessing whether -O is
on or off, the module itself uses tb_lineno() unconditionally.
fixed.
- The test of negative number to the float power has been moved from the
-built-in pow() functin to floatobject.c (so complex numbers can yield the
+built-in pow() function to floatobject.c (so complex numbers can yield the
correct result).
- The bug introduced in beta2 where shared libraries loaded (using
module implementing deepcopy and normal (shallow) copy operations.
See the library reference manual.
-- Documentation strings for many objects types are accessible through
+- Documentation strings for many object types are accessible through
the __doc__ attribute. Modules, classes and functions support special
syntax to initialize the __doc__ attribute: if the first statement
consists of just a string literal, that string literal becomes the
There is now a script to patch Makefile and config.c to add a new
optional built-in module: Addmodule.sh. Read the script before using!
-Useing Addmodule.sh, all optional modules can now be configured at
+Using Addmodule.sh, all optional modules can now be configured at
compile time using Configure.py, so there are no modules left that
require dynamic loading.
SUNAUDIODEV: symbolic constant definitions for sunaudiodef (sun only)
-SV: symbolic constat definitions for sv (sgi only)
+SV: symbolic constant definitions for sv (sgi only)
-CD: symbolic constat definitions for cd (sgi only)
+CD: symbolic constant definitions for cd (sgi only)
New demos
Python News
+++++++++++
+What's New in Python 2.7.13
+===========================
+
+*Release date: 2016-12-17*
+
+Core and Builtins
+-----------------
+
+- Revert a37cc3d926ec (Issue #5322).
+
+
+What's New in Python 2.7.13 release candidate 1?
+================================================
+
+*Release date: 2016-12-03*
+
+Core and Builtins
+-----------------
+
+- Issue #28847: dumbdbm no longer writes the index file in when it is not
+ changed and supports reading read-only files.
+
+- Issue #11145: Fixed miscellaneous issues with C-style formatting of types
+ with custom __oct__ and __hex__.
+
+- Issue #24469: Fixed memory leak caused by int subclasses without overridden
+ tp_free (e.g. C-inherited Cython classes).
+
+- Issue #19398: Extra slash no longer added to sys.path components in case of
+ empty compile-time PYTHONPATH components.
+
+- Issue #21720: Improve exception message when the type of fromlist is unicode.
+ fromlist parameter of __import__() only accepts str in Python 2 and this
+ will help to identify the problem especially when the unicode_literals
+ future import is used.
+
+- Issue #26906: Resolving special methods of uninitialized type now causes
+ implicit initialization of the type instead of a fail.
+
+- Issue #18287: PyType_Ready() now checks that tp_name is not NULL.
+ Original patch by Niklas Koep.
+
+- Issue #24098: Fixed possible crash when AST is changed in process of
+ compiling it.
+
+- Issue #28350: String constants with null character no longer interned.
+
+- Issue #27942: String constants now interned recursively in tuples and frozensets.
+
+- Issue #15578: Correctly incref the parent module while importing.
+
+- Issue #26307: The profile-opt build now applies PGO to the built-in modules.
+
+- Issue #26020: set literal evaluation order did not match documented behaviour.
+
+- Issue #27870: A left shift of zero by a large integer no longer attempts
+ to allocate large amounts of memory.
+
+- Issue #25604: Fix a minor bug in integer true division; this bug could
+ potentially have caused off-by-one-ulp results on platforms with
+ unreliable ldexp implementations.
+
+- Issue #27473: Fixed possible integer overflow in str, unicode and bytearray
+ concatenations and repetitions. Based on patch by Xiang Zhang.
+
+- Issue #27507: Add integer overflow check in bytearray.extend(). Patch by
+ Xiang Zhang.
+
+- Issue #27581: Don't rely on wrapping for overflow check in
+ PySequence_Tuple(). Patch by Xiang Zhang.
+
+- Issue #23908: os functions, open() and the io.FileIO constructor now reject
+ unicode paths with embedded null character on Windows instead of silently
+ truncating them.
+
+- Issue #27514: Make having too many statically nested blocks a SyntaxError
+ instead of SystemError.
+
+Library
+-------
+
+- Issue #25659: In ctypes, prevent a crash calling the from_buffer() and
+ from_buffer_copy() methods on abstract classes like Array.
+
+- Issue #28563: Fixed possible DoS and arbitrary code execution when handle
+ plural form selections in the gettext module. The expression parser now
+ supports exact syntax supported by GNU gettext.
+
+- Issue #28387: Fixed possible crash in _io.TextIOWrapper deallocator when
+ the garbage collector is invoked in other thread. Based on patch by
+ Sebastian Cufre.
+
+- Issue #28449: tarfile.open() with mode "r" or "r:" now tries to open a tar
+ file with compression before trying to open it without compression. Otherwise
+ it had 50% chance failed with ignore_zeros=True.
+
+- Issue #25464: Fixed HList.header_exists() in Tix module by adding
+ a workaround to Tix library bug.
+
+- Issue #28488: shutil.make_archive() no longer adds entry "./" to ZIP archive.
+
+- Issue #28480: Fix error building _sqlite3 module when multithreading is
+ disabled.
+
+- Issue #24452: Make webbrowser support Chrome on Mac OS X.
+
+- Issue #26293: Fixed writing ZIP files that starts not from the start of the
+ file. Offsets in ZIP file now are relative to the start of the archive in
+ conforming to the specification.
+
+- Fix possible integer overflows and crashes in the mmap module with unusual
+ usage patterns.
+
+- Issue #27897: Fixed possible crash in sqlite3.Connection.create_collation()
+ if pass invalid string-like object as a name. Original patch by Xiang Zhang.
+
+- Issue #1703178: Fix the ability to pass the --link-objects option to the
+ distutils build_ext command.
+
+- Issue #28253: Fixed calendar functions for extreme months: 0001-01
+ and 9999-12.
+
+ Methods itermonthdays() and itermonthdays2() are reimplemented so
+ that they don't call itermonthdates() which can cause datetime.date
+ under/overflow.
+
+- Issue #27963: Fixed possible null pointer dereference in
+ ctypes.set_conversion_mode(). Patch by Xiang Zhang.
+
+- Issue #28284: Strengthen resistance of ``_json.encode_basestring_ascii()`` to
+ integer overflow.
+
+- Issue #27611: Fixed support of default root window in the Tix module.
+
+- Issue #24363: When parsing HTTP header fields, if an invalid line is
+ encountered, skip it and continue parsing. Previously, no more header
+ fields were parsed, which could lead to fields for HTTP framing like
+ Content-Length and Transfer-Encoding being overlooked.
+
+- Issue #27599: Fixed buffer overrun in binascii.b2a_qp() and binascii.a2b_qp().
+
+- Issue #25969: Update the lib2to3 grammar to handle the unpacking
+ generalizations added in 3.5.
+
+- Issue #24594: Validates persist parameter when opening MSI database
+
+- Issue #27570: Avoid zero-length memcpy() etc calls with null source
+ pointers in the "ctypes" and "array" modules.
+
+- Issue #22450: urllib now includes an "Accept: */*" header among the
+ default headers. This makes the results of REST API requests more
+ consistent and predictable especially when proxy servers are involved.
+
+- lib2to3.pgen3.driver.load_grammar() now creates a stable cache file
+ between runs given the same Grammar.txt input regardless of the hash
+ randomization setting.
+
+- Issue #27691: Fix ssl module's parsing of GEN_RID subject alternative name
+ fields in X.509 certs.
+
+- Issue #27850: Remove 3DES from ssl module's default cipher list to counter
+ measure sweet32 attack (CVE-2016-2183).
+
+- Issue #27766: Add ChaCha20 Poly1305 to ssl module's default ciper list.
+ (Required OpenSSL 1.1.0 or LibreSSL).
+
+- Issue #26470: Port ssl and hashlib module to OpenSSL 1.1.0.
+
+- Issue #27944: Fix some memory-corruption bugs in the log reading code of the
+ _hotshot module.
+
+- Issue #27934: Use ``float.__repr__`` instead of plain ``repr`` when JSON-
+ encoding an instance of a float subclass. Thanks Eddie James.
+
+- Issue #27861: Fixed a crash in sqlite3.Connection.cursor() when a factory
+ creates not a cursor. Patch by Xiang Zhang.
+
+- Issue #19884: Avoid spurious output on OS X with Gnu Readline.
+
+- Issue #10513: Fix a regression in Connection.commit(). Statements should
+ not be reset after a commit.
+
+- Issue #2466: posixpath.ismount now correctly recognizes mount points which
+ the user does not have permission to access.
+
+- Issue #27783: Fix possible usage of uninitialized memory in operator.methodcaller.
+
+- Issue #27774: Fix possible Py_DECREF on unowned object in _sre.
+
+- Issue #27760: Fix possible integer overflow in binascii.b2a_qp.
+
+- In the curses module, raise an error if window.getstr() or window.instr() is
+ passed a negative value.
+
+- Issue #27758: Fix possible integer overflow in the _csv module for large record
+ lengths.
+
+- Issue #23369: Fixed possible integer overflow in
+ _json.encode_basestring_ascii.
+
+- Issue #27568: Prevent HTTPoxy attack (CVE-2016-1000110). Ignore the
+ HTTP_PROXY variable when REQUEST_METHOD environment is set, which indicates
+ that the script is in CGI mode.
+
+- Issue #27130: In the "zlib" module, fix handling of large buffers
+ (typically 2 or 4 GiB). Previously, inputs were limited to 2 GiB, and
+ compression and decompression operations did not properly handle results of
+ 2 or 4 GiB.
+
+- Issue #23804: Fix SSL zero-length recv() calls to not block and not raise
+ an error about unclean EOF.
+
+- Issue #27466: Change time format returned by http.cookie.time2netscape,
+ confirming the netscape cookie format and making it consistent with
+ documentation.
+
+- Issue #22115: Fixed tracing Tkinter variables: trace_vdelete() with wrong
+ mode no longer break tracing, trace_vinfo() now always returns a list of
+ pairs of strings.
+
+- Issue #27079: Fixed curses.ascii functions isblank(), iscntrl() and ispunct().
+
+- Issue #22636: Avoid shell injection problems with
+ ctypes.util.find_library().
+
+- Issue #27330: Fixed possible leaks in the ctypes module.
+
+- Issue #27238: Got rid of bare excepts in the turtle module. Original patch
+ by Jelle Zijlstra.
+
+- Issue #26386: Fixed ttk.TreeView selection operations with item id's
+ containing spaces.
+
+- Issue #25455: Fixed a crash in repr of cElementTree.Element with recursive tag.
+
+- Issue #21201: Improves readability of multiprocessing error message. Thanks
+ to Wojciech Walczak for patch.
+
+IDLE
+----
+
+- Issue #27854: Make Help => IDLE Help work again on Windows.
+ Include idlelib/help.html in 2.7 Windows installer.
+
+- Issue #25507: Add back import needed for 2.x encoding warning box.
+ Add pointer to 'Encoding declaration' in Language Reference.
+
+- Issue #15308: Add 'interrupt execution' (^C) to Shell menu.
+ Patch by Roger Serwy, updated by Bayard Randel.
+
+- Issue #27922: Stop IDLE tests from 'flashing' gui widgets on the screen.
+
+- Issue #17642: add larger font sizes for classroom projection.
+
+- Add version to title of IDLE help window.
+
+- Issue #25564: In section on IDLE -- console differences, mention that
+ using exec means that __builtins__ is defined for each statement.
+
+- Issue #27714: text_textview and test_autocomplete now pass when re-run
+ in the same process. This occurs when test_idle fails when run with the
+ -w option but without -jn. Fix warning from test_config.
+
+- Issue #27452: add line counter and crc to IDLE configHandler test dump.
+
+- Issue #27365: Allow non-ascii chars in IDLE NEWS.txt, for contributor names.
+
+- Issue #27245: IDLE: Cleanly delete custom themes and key bindings.
+ Previously, when IDLE was started from a console or by import, a cascade
+ of warnings was emitted. Patch by Serhiy Storchaka.
+
+Documentation
+-------------
+
+- Issue #28513: Documented command-line interface of zipfile.
+
+- Issue #16484: Change the default PYTHONDOCS URL to "https:", and fix the
+ resulting links to use lowercase. Patch by Sean Rodman, test by Kaushik
+ Nadikuditi.
+
+Tests
+-----
+
+- Issue #28666: Now test.test_support.rmtree is able to remove unwritable or
+ unreadable directories.
+
+- Issue #23839: Various caches now are cleared before running every test file.
+
+- Issue #27369: In test_pyexpat, avoid testing an error message detail that
+ changed in Expat 2.2.0.
+
+Build
+-----
+
+- Issue #10656: Fix out-of-tree building on AIX. Patch by Tristan Carel and
+ Michael Haubenwallner.
+
+- Issue #26359: Rename --with-optimiations to --enable-optimizations.
+
+- Issue #28248: Update Windows build and OS X installers to use OpenSSL 1.0.2j.
+
+- Issue #28258: Fixed build with Estonian locale (distclean target in
+ Makefile). Patch by Arfrever Frehtes Taifersar Arahesis.
+
+- Issue #26661: setup.py now detects system libffi with multiarch wrapper.
+
+- Issue #15819: The Include directory in the build tree is already searched;
+ drop unused code trying to add it again.
+
+- Issue #27566: Fix clean target in freeze makefile (patch by Lisa Roach)
+
+- Issue #27983: Cause lack of llvm-profdata tool when using clang as
+ required for PGO linking to be a configure time error rather than
+ make time when --with-optimizations is enabled. Also improve our
+ ability to find the llvm-profdata tool on MacOS and some Linuxes.
+
+- Issue #26359: Add the --with-optimizations configure flag.
+
+- Issue #10910: Avoid C++ compilation errors on FreeBSD and OS X.
+ Also update FreedBSD version checks for the original ctype UTF-8 workaround.
+
+- Issue #27806: Fix 32-bit builds on macOS Sierra 10.12 broken by removal of
+ deprecated QuickTime/QuickTime.h header file. Patch by Aleks Bunin.
+
+- Issue #28676: Prevent missing 'getentropy' declaration warning on macOS.
+ Initial patch by Gareth Rees.
+
+Tools/Demos
+-----------
+
+- Issue #27952: Get Tools/scripts/fixcid.py working with the current "re"
+ module, avoid invalid Python backslash escapes, and fix a bug parsing
+ escaped C quote signs.
+
+Windows
+-------
+
+- Issue #27932: Prevent memory leak in win32_ver().
+
+- Issue #27888: Prevent Windows installer from displaying console windows and
+ failing when pip cannot be installed/uninstalled.
+
+Mac OS X
+--------
+
+- Issue #28440: No longer add /Library/Python/site-packages, the Apple-supplied
+ system Python site-packages directory, to sys.path for macOS framework builds.
+ The coupling between the two Python instances often caused confusion and, as
+ of macOS 10.12, changes to the site-packages layout can cause pip component
+ installations to fail. This change reverts the effects introduced in 2.7.0
+ by Issue #4865. If you are using a package with both the Apple system Python
+ 2.7 and a user-installed Python 2.7, you will need to ensure that copies of
+ the package are installed with both Python instances.
+
+
What's New in Python 2.7.12?
============================
Build
-----
+- Issue #27641: The configure script now inserts comments into the makefile
+ to prevent the pgen executable from being cross-compiled.
+
- Issue #26930: Update Windows builds to use OpenSSL 1.0.2h.
IDLE
- Issue #26385: Remove the file if the internal fdopen() call in
NamedTemporaryFile() fails. Based on patch by Silent Ghost.
-- Issue #26309: In the "socketserver" module, shut down the request (closing
+- Issue #26309: In the "SocketServer" module, shut down the request (closing
the connected socket) when verify_request() returns false. Based on patch
by Aviv Palivoda.
(including empty directories) in ZIP file.
- Issue #22449: In the ssl.SSLContext.load_default_certs, consult the
- enviromental variables SSL_CERT_DIR and SSL_CERT_FILE on Windows.
+ environmental variables SSL_CERT_DIR and SSL_CERT_FILE on Windows.
- Issue #8473: doctest.testfile now uses universal newline mode to read
the test file.
- Issue #22530: Allow the ``group()`` method of regular expression match objects
to take a ``long`` as an index.
-- Issue #22517: When a io.BufferedRWPair object is deallocated, clear its
+- Issue #22517: When an io.BufferedRWPair object is deallocated, clear its
weakrefs.
- Issue #10510: distutils register and upload methods now use HTML standards
Sergey Bobrov.
- Issue #21147: sqlite3 now raises an exception if the request contains a null
- character instead of truncate it. Based on patch by Victor Stinner.
+ character instead of truncating it. Based on patch by Victor Stinner.
- Issue #21951: Fixed a crash in Tkinter on AIX when called Tcl command with
empty string or tuple argument.
- Issue #21350: Fix file.writelines() to accept arbitrary buffer objects,
as advertised. Patch by Brian Kearns.
-- Issue #20437: Fixed 43 potential bugs when deleting objects references.
+- Issue #20437: Fixed 43 potential bugs when deleting object references.
- Issue #21134: Fix segfault when str is called on an uninitialized
UnicodeEncodeError, UnicodeDecodeError, or UnicodeTranslateError object.
- Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
inside subjectAltName correctly. Formerly the module has used OpenSSL's
- GENERAL_NAME_print() function to get the string represention of ASN.1
+ GENERAL_NAME_print() function to get the string representation of ASN.1
strings for ``rfc822Name`` (email), ``dNSName`` (DNS) and
``uniformResourceIdentifier`` (URI).
created with PyFile_FromString().
- Issue #14474: Save and restore exception state in thread.start_new_thread()
- while writing error message if the thread leaves a unhandled exception.
+ while writing error message if the thread leaves an unhandled exception.
- Issue #13019: Fix potential reference leaks in bytearray.extend(). Patch
by Suman Saha.
using the same sys.flags as the current process. Initial patch by
Sergey Mezentsev.
-- Issue #8862: Fixed curses cleanup when getkey is interrputed by a signal.
+- Issue #8862: Fixed curses cleanup when getkey is interrupted by a signal.
- Issue #9090: When a socket with a timeout fails with EWOULDBLOCK or EAGAIN,
retry the select() loop instead of bailing out. This is because select()
- Issue #14829: Fix bisect issues under 64-bit Windows.
- Issue #14777: tkinter may return undecoded UTF-8 bytes as a string when
- accessing the Tk clipboard. Modify clipboad_get() to first request type
+ accessing the Tk clipboard. Modify clipboard_get() to first request type
UTF8_STRING when no specific type is requested in an X11 windowing
environment, falling back to the current default type STRING if that fails.
Original patch by Thomas Kluyver.
- Issue #14157: Fix time.strptime failing without a year on February 29th.
Patch by Hynek Schlawack.
-- Issue #14768: os.path.expanduser('~/a') doesn't works correctly when HOME is '/'.
+- Issue #14768: os.path.expanduser('~/a') doesn't work correctly when HOME is '/'.
- Issue #13183: Fix pdb skipping frames after hitting a breakpoint and running
step. Patch by Xavier de Gaye.
- Issues #12610 and #12609: Verify that user generated AST has correct string
and identifier types before compiling.
-- Issue #11627: Fix segfault when __new__ on a exception returns a
+- Issue #11627: Fix segfault when __new__ on an exception returns a
non-exception class.
- Issue #12149: Update the method cache after a type's dictionnary gets
- Issue #12502: asyncore: fix polling loop with AF_UNIX sockets.
-- Issue #4376: ctypes now supports nested structures in a endian different than
+- Issue #4376: ctypes now supports nested structures in an endian different than
the parent structure. Patch by Vlad Riscutia.
- Issue #12493: subprocess: Popen.communicate() now also handles EINTR errors
- Issue #11450: Don't truncate hg version info in Py_GetBuildInfo() when
there are many tags (e.g. when using mq). Patch by Nadeem Vawda.
-- Issue #10451: memoryview objects could allow to mutate a readable buffer.
+- Issue #10451: memoryview objects could allow mutating a readable buffer.
Initial patch by Ross Lagerwall.
- Issue #10892: Don't segfault when trying to delete __abstractmethods__ from a
seeking a bit forward, writing, then seeking before the previous write but
still within buffered data, and writing again).
-- Issue #8498: In socket.accept(), allow to specify 0 as a backlog value in
+- Issue #8498: In socket.accept(), allow specifying 0 as a backlog value in
order to accept exactly one connection. Patch by Daniel Evers.
- Issue #12012: ssl.PROTOCOL_SSLv2 becomes optional.
- Build the ossaudio extension on GNU/kFreeBSD.
-- On Windows, ctypes does no longer check the stack before and after calling a
- foreign function. This allows to use the unmodified libffi library.
+- On Windows, ctypes no longer checks the stack before and after calling a
+ foreign function. This allows using the unmodified libffi library.
Tests
-----
- Issue #8140: Extend compileall to compile single files. Add -i option.
- Issue #7774: Set sys.executable to an empty string if ``argv[0]`` has been set
- to an non existent program name and Python is unable to retrieve the real
+ to a non existent program name and Python is unable to retrieve the real
program name.
- Issue #8117: logging: Improved algorithm for computing initial rollover time
- Issue #7610: Reworked implementation of the internal ``zipfile.ZipExtFile``
class used to represent files stored inside an archive. The new
- implementation is significantly faster and can be wrapped in a
+ implementation is significantly faster and can be wrapped in an
``io.BufferedReader`` object for more speedups. It also solves an issue
where interleaved calls to ``read()`` and ``readline()`` give wrong results.
Patch by Nir Aides.
is used. Original patch by Floris Bruynooghe.
- Issue #5941: Distutils build_clib command was not working anymore because of
- an incomplete costumization of the archiver command. Added ARFLAGS in the
+ an incomplete customization of the archiver command. Added ARFLAGS in the
Makefile besides AR and make Distutils use it. Original patch by David
Cournapeau.
mailbox.MH.get_message().
- Issue #5585: Add the ability to call an initializer to
- mulitiprocessing.manager so that users can install custom handlers/etc.
+ multiprocessing.manager so that users can install custom handlers/etc.
- Issue #3551: Patch multiprocessing to raise a proper exception if the size of
- the object when writefile is called causes a ERROR_NO_SYSTEM_RESOURCES. Added
+ the object when writefile is called causes an ERROR_NO_SYSTEM_RESOURCES. Added
docs to note the limitation.
- unittest.assertNotEqual() now uses the inequality operator (!=) instead of the
- The mimetools module has been deprecated for removal in 3.0.
- The ctypes.byref function now takes an optional second parameter
- which allows to specify an offset in bytes for the constructed
- pointer-like object.
+ which specifies an offset in bytes for the constructed pointer-like object.
- Added the ast module.
module is:
from future_builtins import hex, oct
-- Issue #1600: Modifed PyOS_ascii_formatd to use at most 2 digit
+- Issue #1600: Modified PyOS_ascii_formatd to use at most 2 digit
exponents for exponents with absolute value < 100. Follows C99
standard. This is a change on Windows, which would use 3 digits.
Also, added 'n' to the formats that PyOS_ascii_formatd understands,
-- the failure just occurred later, with a more cumbersome
exception.
-- Patch #787789: allow to pass custom TestRunner instances to
+- Patch #787789: allow passing custom TestRunner instances to
unittest's main() function.
- Patches #1550273, #1550272: fix a few bugs in unittest and add a
defaultVal, and adds k to map with value defaultVal. defaultVal is
optional. When not provided and k is not in the map, None is returned and
added to map.
- (6) Raises a KeyError if the dictionary is emtpy.
+ (6) Raises a KeyError if the dictionary is empty.
(7) While iterating over a dictionary, the values may be updated but
the keys cannot be changed.
instanceobject as arg, returns list of names in its attr.
dict.
divmod(a,b) Returns tuple of (a/b, a%b)
-enumerate(seq) Return a iterator giving: (0, seq[0]), (1, seq[1]), ...
+enumerate(seq) Return an iterator giving: (0, seq[0]), (1, seq[1]), ...
eval(s[, globals[, Eval string s in (optional) globals, locals contexts.s must
locals]]) have no NUL's or newlines. s can also be acode object.
Example: x = 1; incr_x = eval('x + 1')
id(object) Returns a unique 'identity' integer for an object.
input([prompt]) Prints prompt if given. Reads input and evaluates it.
Converts a number or a string to a plain integer. Optional
-int(x[, base]) base paramenter specifies base from which to convert string
+int(x[, base]) base parameter specifies base from which to convert string
values.
intern(aString) Enters aString in the table of "interned strings"
andreturns the string. Interned strings are 'immortals'.
copy of it.
locals() Returns a dictionary containing current local variables.
Converts a number or a string to a long integer. Optional
-long(x[, base]) base paramenter specifies base from which to convert string
+long(x[, base]) base parameter specifies base from which to convert string
values.
Applies function to every item of list and returns a listof
map(function, list, the results. If additional arguments are passed,function
for general contributions to Python.
- Mark Dickinson was given SVN access on 6 January 2008 by Facundo
- Batista for his work on mathemathics and number related issues.
+ Batista for his work on mathematics and number related issues.
- Amaury Forgeot d'Arc was given SVN access on 9 November 2007 by MvL,
for general contributions to Python.
int i, rec_len;
char *lineterm;
-#define ADDCH(c) \
+#define INCLEN \
+ do {\
+ if (!copy_phase && rec_len == INT_MAX) { \
+ goto overflow; \
+ } \
+ rec_len++; \
+ } while(0)
+
+#define ADDCH(c) \
do {\
if (copy_phase) \
self->rec[rec_len] = c;\
- rec_len++;\
+ INCLEN;\
} while(0)
lineterm = PyString_AsString(dialect->lineterminator);
if (*quoted) {
if (copy_phase)
ADDCH(dialect->quotechar);
- else
- rec_len += 2;
+ else {
+ INCLEN; /* starting quote */
+ INCLEN; /* ending quote */
+ }
}
return rec_len;
+
+ overflow:
+ PyErr_NoMemory();
+ return -1;
#undef ADDCH
+#undef INCLEN
}
static int
/*
PyCStructType_Type - a meta type/class. Creating a new class using this one as
- __metaclass__ will call the contructor StructUnionType_new. It replaces the
+ __metaclass__ will call the constructor StructUnionType_new. It replaces the
tp_dict member with a new instance of StgDict, and initializes the C
accessible fields somehow.
*/
Py_ssize_t offset = 0;
PyObject *obj, *result;
StgDictObject *dict = PyType_stgdict(type);
- assert (dict);
+ if (!dict) {
+ PyErr_SetString(PyExc_TypeError, "abstract class");
+ return NULL;
+ }
if (!PyArg_ParseTuple(args,
#if (PY_VERSION_HEX < 0x02050000)
Py_ssize_t offset = 0;
PyObject *obj, *result;
StgDictObject *dict = PyType_stgdict(type);
- assert (dict);
+ if (!dict) {
+ PyErr_SetString(PyExc_TypeError, "abstract class");
+ return NULL;
+ }
if (!PyArg_ParseTuple(args,
#if (PY_VERSION_HEX < 0x02050000)
- "O|i:from_buffer",
+ "O|i:from_buffer_copy",
#else
- "O|n:from_buffer",
+ "O|n:from_buffer_copy",
#endif
&obj, &offset))
return NULL;
static PyObject *
CharArray_get_value(CDataObject *self)
{
- int i;
+ Py_ssize_t i;
char *ptr = self->b_ptr;
for (i = 0; i < self->b_size; ++i)
if (*ptr++ == '\0')
static PyObject *
WCharArray_get_value(CDataObject *self)
{
- unsigned int i;
+ Py_ssize_t i;
wchar_t *ptr = (wchar_t *)self->b_ptr;
- for (i = 0; i < self->b_size/sizeof(wchar_t); ++i)
+ for (i = 0; i < self->b_size/(Py_ssize_t)sizeof(wchar_t); ++i)
if (*ptr++ == (wchar_t)0)
break;
return PyUnicode_FromWideChar((wchar_t *)self->b_ptr, i);
return -1;
} else
Py_INCREF(value);
- if ((unsigned)PyUnicode_GET_SIZE(value) > self->b_size/sizeof(wchar_t)) {
+ if ((size_t)PyUnicode_GET_SIZE(value) > self->b_size/sizeof(wchar_t)) {
PyErr_SetString(PyExc_ValueError,
"string too long");
result = -1;
descr = PyDescr_NewMethod(type, meth);
if (descr == NULL)
return -1;
- if (PyDict_SetItemString(dict,meth->ml_name, descr) < 0)
+ if (PyDict_SetItemString(dict, meth->ml_name, descr) < 0) {
+ Py_DECREF(descr);
return -1;
+ }
Py_DECREF(descr);
}
return 0;
descr = PyDescr_NewMember(type, memb);
if (descr == NULL)
return -1;
- if (PyDict_SetItemString(dict, memb->name, descr) < 0)
+ if (PyDict_SetItemString(dict, memb->name, descr) < 0) {
+ Py_DECREF(descr);
return -1;
+ }
Py_DECREF(descr);
}
return 0;
descr = PyDescr_NewGetSet(type, gsp);
if (descr == NULL)
return -1;
- if (PyDict_SetItemString(dict, gsp->name, descr) < 0)
+ if (PyDict_SetItemString(dict, gsp->name, descr) < 0) {
+ Py_DECREF(descr);
return -1;
+ }
Py_DECREF(descr);
}
return 0;
return NULL;
}
stgdict->shape[0] = length;
- memmove(&stgdict->shape[1], itemdict->shape,
- sizeof(Py_ssize_t) * (stgdict->ndim - 1));
+ if (stgdict->ndim > 1) {
+ memmove(&stgdict->shape[1], itemdict->shape,
+ sizeof(Py_ssize_t) * (stgdict->ndim - 1));
+ }
itemsize = itemdict->size;
if (length * itemsize < 0) {
Py_INCREF(name);
PyString_Concat(&name, suffix);
- if (name == NULL)
+ if (name == NULL) {
+ Py_DECREF(swapped_args);
return NULL;
+ }
PyTuple_SET_ITEM(swapped_args, 0, name);
for (i=1; i<PyTuple_GET_SIZE(args); ++i) {
stgdict = (StgDictObject *)PyObject_CallObject(
(PyObject *)&PyCStgDict_Type, NULL);
- if (!stgdict) /* XXX leaks result! */
+ if (!stgdict) {
+ Py_DECREF(result);
return NULL;
+ }
stgdict->ffi_type_pointer = *fmt->pffi_type;
stgdict->align = fmt->pffi_type->alignment;
PyObject *meth;
int x;
meth = PyDescr_NewClassMethod(result, ml);
- if (!meth)
+ if (!meth) {
+ Py_DECREF(result);
return NULL;
+ }
#else
#error
PyObject *meth, *func;
int x;
func = PyCFunction_New(ml, NULL);
- if (!func)
+ if (!func) {
+ Py_DECREF(result);
return NULL;
+ }
meth = PyObject_CallFunctionObjArgs(
(PyObject *)&PyClassMethod_Type,
func, NULL);
Py_DECREF(func);
if (!meth) {
+ Py_DECREF(result);
return NULL;
}
#endif
nArgs = PyTuple_GET_SIZE(ob);
converters = PyTuple_New(nArgs);
- if (!converters)
+ if (!converters) {
+ Py_DECREF(ob);
return NULL;
+ }
/* I have to check if this is correct. Using c_char, which has a size
of 1, will be assumed to be pushed as only one byte!
self,
callargs,
NULL);
- /* If the errcheck funtion failed, return NULL.
+ /* If the errcheck function failed, return NULL.
If the errcheck function returned callargs unchanged,
continue normal processing.
If the errcheck function returned something else,
a = PySequence_GetSlice(args, 1, PySequence_Size(args));
if (!a)
- return NULL;
+ return NULL;
status = PyObject_SetAttrString(self, "args", a);
Py_DECREF(a);
if (status < 0)
- return NULL;
+ return NULL;
if (PyObject_SetAttrString(self, "hresult", hresult) < 0)
return NULL;
PyUnicodeObject *unicode;
if (w == NULL) {
- PyErr_BadInternalCall();
- return NULL;
+ PyErr_BadInternalCall();
+ return NULL;
}
unicode = (PyUnicodeObject *)PyUnicode_FromUnicode(NULL, size);
if (!unicode)
- return NULL;
+ return NULL;
/* Copy the wchar_t data into the new object */
#ifdef HAVE_USABLE_WCHAR_T
memcpy(unicode->str, w, size * sizeof(wchar_t));
#else
{
- register Py_UNICODE *u;
- register int i;
- u = PyUnicode_AS_UNICODE(unicode);
- /* In Python, the following line has a one-off error */
- for (i = size; i > 0; i--)
- *u++ = *w++;
+ register Py_UNICODE *u;
+ register int i;
+ u = PyUnicode_AS_UNICODE(unicode);
+ /* In Python, the following line has a one-off error */
+ for (i = size; i > 0; i--)
+ *u++ = *w++;
}
#endif
Py_ssize_t size)
{
if (unicode == NULL) {
- PyErr_BadInternalCall();
- return -1;
+ PyErr_BadInternalCall();
+ return -1;
}
if (size > PyUnicode_GET_SIZE(unicode))
- size = PyUnicode_GET_SIZE(unicode);
+ size = PyUnicode_GET_SIZE(unicode);
#ifdef HAVE_USABLE_WCHAR_T
memcpy(w, unicode->str, size * sizeof(wchar_t));
#else
{
- register Py_UNICODE *u;
- register int i;
- u = PyUnicode_AS_UNICODE(unicode);
- /* In Python, the following line has a one-off error */
- for (i = size; i > 0; i--)
- *w++ = *u++;
+ register Py_UNICODE *u;
+ register int i;
+ u = PyUnicode_AS_UNICODE(unicode);
+ /* In Python, the following line has a one-off error */
+ for (i = size; i > 0; i--)
+ *w++ = *u++;
}
#endif
return func(a*a, b*b, c*c, d*d, e*e);
}
+/*
+ * This structure should be the same as in test_callbacks.py and the
+ * method test_callback_large_struct. See issues 17310 and 20160: the
+ * structure must be larger than 8 bytes long.
+ */
+
+typedef struct {
+ unsigned long first;
+ unsigned long second;
+ unsigned long third;
+} Test;
+
+EXPORT(void)
+_testfunc_cbk_large_struct(Test in, void (*func)(Test))
+{
+ func(in);
+}
+
EXPORT(void)testfunc_array(int values[4])
{
printf("testfunc_array %d %d %d %d\n",
static CThunkObject* CThunkObject_new(Py_ssize_t nArgs)
{
CThunkObject *p;
- int i;
+ Py_ssize_t i;
p = PyObject_GC_NewVar(CThunkObject, &PyCThunk_Type, nArgs);
if (p == NULL) {
return NULL;
}
- p->pcl_exec = NULL;
p->pcl_write = NULL;
+ p->pcl_exec = NULL;
memset(&p->cif, 0, sizeof(p->cif));
+ p->flags = 0;
p->converters = NULL;
p->callable = NULL;
+ p->restype = NULL;
p->setfunc = NULL;
p->ffi_restype = NULL;
#define CTYPES_CAPSULE_ERROROBJ "_ctypes/callproc.c error object"
CTYPES_CAPSULE_INSTANTIATE_DESTRUCTOR(CTYPES_CAPSULE_ERROROBJ)
-#define CTYPES_CAPSULE_WCHAR_T "_ctypes/callproc.c wchar_t buffer from unicode"
+#if defined(CTYPES_UNICODE) && !defined(HAVE_USABLE_WCHAR_T)
+# define CTYPES_CAPSULE_WCHAR_T "_ctypes/callproc.c wchar_t buffer from unicode"
CTYPES_CAPSULE_INSTANTIATE_DESTRUCTOR(CTYPES_CAPSULE_WCHAR_T)
+#endif
/*
ctypes maintains thread-local storage that has space for two error numbers:
return NULL;
memset(space, 0, sizeof(int) * 2);
errobj = CAPSULE_NEW(space, CTYPES_CAPSULE_ERROROBJ);
- if (errobj == NULL)
+ if (errobj == NULL) {
+ PyMem_Free(space);
return NULL;
+ }
if (-1 == PyDict_SetItem(dict, error_object_name,
errobj)) {
Py_DECREF(errobj);
PyObject *nameobj;
PyObject *ignored;
HMODULE hMod;
- if (!PyArg_ParseTuple(args, "O|O:LoadLibrary", &nameobj, &ignored))
+ if (!PyArg_ParseTuple(args, "S|O:LoadLibrary", &nameobj, &ignored))
return NULL;
#ifdef _UNICODE
name = alloca((PyString_Size(nameobj) + 1) * sizeof(WCHAR));
static PyObject *
set_conversion_mode(PyObject *self, PyObject *args)
{
- char *coding, *mode;
+ char *coding, *mode, *errors, *encoding=NULL;
PyObject *result;
if (!PyArg_ParseTuple(args, "zs:set_conversion_mode", &coding, &mode))
return NULL;
- result = Py_BuildValue("(zz)", _ctypes_conversion_encoding, _ctypes_conversion_errors);
+
+ result = Py_BuildValue("(zz)", _ctypes_conversion_encoding,
+ _ctypes_conversion_errors);
+ if (!result) {
+ return NULL;
+ }
+
if (coding) {
- PyMem_Free(_ctypes_conversion_encoding);
- _ctypes_conversion_encoding = PyMem_Malloc(strlen(coding) + 1);
- strcpy(_ctypes_conversion_encoding, coding);
- } else {
- _ctypes_conversion_encoding = NULL;
+ encoding = PyMem_Malloc(strlen(coding) + 1);
+ if (!encoding) {
+ Py_DECREF(result);
+ return PyErr_NoMemory();
+ }
+ strcpy(encoding, coding);
}
+
+ errors = PyMem_Malloc(strlen(mode) + 1);
+ if (!errors) {
+ Py_DECREF(result);
+ PyMem_Free(encoding);
+ return PyErr_NoMemory();
+ }
+ strcpy(errors, mode);
+
+ PyMem_Free(_ctypes_conversion_encoding);
+ _ctypes_conversion_encoding = encoding;
+
PyMem_Free(_ctypes_conversion_errors);
- _ctypes_conversion_errors = PyMem_Malloc(strlen(mode) + 1);
- strcpy(_ctypes_conversion_errors, mode);
+ _ctypes_conversion_errors = errors;
+
return result;
}
#endif
if (result == NULL)
return result;
key = PyLong_FromVoidPtr(result);
+ if (key == NULL) {
+ Py_DECREF(result);
+ return NULL;
+ }
} else if (PyType_Check(cls)) {
typ = (PyTypeObject *)cls;
buf = PyMem_Malloc(strlen(typ->tp_name) + 3 + 1);
#include "ctypes.h"
-#define CTYPES_CAPSULE_WCHAR_T "_ctypes/cfield.c wchar_t buffer from unicode"
+#if defined(CTYPES_UNICODE) && !defined(HAVE_USABLE_WCHAR_T)
+# define CTYPES_CAPSULE_WCHAR_T "_ctypes/cfield.c wchar_t buffer from unicode"
CTYPES_CAPSULE_INSTANTIATE_DESTRUCTOR(CTYPES_CAPSULE_WCHAR_T)
+#endif
/******************************************************************/
{
CFieldObject *self;
PyObject *proto;
- Py_ssize_t size, align, length;
+ Py_ssize_t size, align;
SETFUNC setfunc = NULL;
GETFUNC getfunc = NULL;
StgDictObject *dict;
}
size = dict->size;
- length = dict->length;
proto = desc;
/* Field descriptors for 'c_char * n' are be scpecial cased to
return NULL;
size = strlen(data);
if (size < length) {
- /* This will copy the leading NUL character
+ /* This will copy the trailing NUL character
* if there is space for it.
*/
++size;
if (value) {
Py_ssize_t size = PyUnicode_GET_SIZE(value);
if ((unsigned) size != size) {
+ Py_DECREF(value);
PyErr_SetString(PyExc_ValueError, "String too long for BSTR");
return NULL;
}
remember is that in PyCArrayType_new the ffi_type fields must be filled in -
so far it was unneeded because libffi doesn't support arrays at all
(because they are passed as pointers to function calls anyway). But it's
- too much risk to change that now, and there are other fields which doen't
+ too much risk to change that now, and there are other fields which doesn't
belong into this structure anyway. Maybe in ctypes 2.0... (ctypes 2000?)
*/
Py_ssize_t size; /* number of bytes */
StgDictObject function to a generic one.
Currently, PyCFuncPtr types have 'converters' and 'checker' entries in their
- type dict. They are only used to cache attributes from other entries, whihc
+ type dict. They are only used to cache attributes from other entries, which
is wrong.
One use case is the .value attribute that all simple types have. But some
case " $hookable_fns " in
*" $1 "*) ;;
- *) func_fatal_error "'$1' does not support hook funcions.n" ;;
+ *) func_fatal_error "'$1' does not support hook functions." ;;
esac
eval _G_hook_fns=\$$1_hooks; shift
.set L$set$3,LUW1-LUW0
.long L$set$3
- /* New stack frame based off rbp. This is a itty bit of unwind
+ /* New stack frame based off rbp. This is an itty bit of unwind
trickery in that the CFA *has* changed. There is no easy way
to describe it correctly on entry to the function. Fortunately,
it doesn't matter too much since at all points we can correctly
.byte 0x4 /* DW_CFA_advance_loc4 */
.long .LUW1-.LUW0
- /* New stack frame based off rbp. This is a itty bit of unwind
+ /* New stack frame based off rbp. This is an itty bit of unwind
trickery in that the CFA *has* changed. There is no easy way
to describe it correctly on entry to the function. Fortunately,
it doesn't matter too much since at all points we can correctly
if ( cif->rtype->type == FFI_TYPE_STRUCT ) {
*rvalue = *(void **) argp;
- argp += 4;
+ argp += sizeof(void *);
}
p_argv = avalue;
/* Align if necessary */
if ((sizeof(char *) - 1) & (size_t) argp) {
- argp = (char *) ALIGN(argp, sizeof(char*));
+ argp = (char *) ALIGN(argp, sizeof(char*));
}
z = (*p_arg)->size;
/* because we're little endian, this is what it turns into. */
+#ifdef _WIN64
+ if (z > 8) {
+ /* On Win64, if a single argument takes more than 8 bytes,
+ * then it is always passed by reference.
+ */
+ *p_argv = *((void**) argp);
+ z = 8;
+ }
+ else
+#endif
*p_argv = (void*) argp;
p_argv++;
/* Perform machine independent ffi_cif preparation, then call
machine dependent routine. */
-#if defined(X86_DARWIN)
+#if defined(X86_DARWIN) && !defined __x86_64__
static inline bool
struct_on_stack(
}
}
-#endif // defined(X86_DARWIN)
+#endif // defined(X86_DARWIN) && !defined __x86_64__
// Arguments' ffi_type->alignment must be nonzero.
ffi_status
.set L$set$3,LUW1-LUW0
.long L$set$3
- /* New stack frame based off rbp. This is a itty bit of unwind
+ /* New stack frame based off rbp. This is an itty bit of unwind
trickery in that the CFA *has* changed. There is no easy way
to describe it correctly on entry to the function. Fortunately,
it doesn't matter too much since at all points we can correctly
}
memset(stgdict->ffi_type_pointer.elements, 0,
sizeof(ffi_type *) * (basedict->length + len + 1));
- memcpy(stgdict->ffi_type_pointer.elements,
- basedict->ffi_type_pointer.elements,
- sizeof(ffi_type *) * (basedict->length));
+ if (basedict->length > 0) {
+ memcpy(stgdict->ffi_type_pointer.elements,
+ basedict->ffi_type_pointer.elements,
+ sizeof(ffi_type *) * (basedict->length));
+ }
ffi_ofs = basedict->length;
} else {
offset = 0;
case 1:
if (!PyArg_ParseTuple(args,"i;n", &n))
return NULL;
+ if (n < 0) {
+ PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
+ return NULL;
+ }
Py_BEGIN_ALLOW_THREADS
rtn2 = wgetnstr(self->win,rtn,MIN(n, 1023));
Py_END_ALLOW_THREADS
case 3:
if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n))
return NULL;
+ if (n < 0) {
+ PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
+ return NULL;
+ }
#ifdef STRICT_SYSV_CURSES
Py_BEGIN_ALLOW_THREADS
rtn2 = wmove(self->win,y,x)==ERR ? ERR :
case 1:
if (!PyArg_ParseTuple(args,"i;n", &n))
return NULL;
+ if (n < 0) {
+ PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
+ return NULL;
+ }
rtn2 = winnstr(self->win,rtn,MIN(n,1023));
break;
case 2:
case 3:
if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))
return NULL;
+ if (n < 0) {
+ PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
+ return NULL;
+ }
rtn2 = mvwinnstr(self->win, y, x, rtn, MIN(n,1023));
break;
default:
static PyObject*
element_repr(ElementObject* self)
{
- PyObject *repr, *tag;
+ int status;
- tag = PyObject_Repr(self->tag);
- if (!tag)
- return NULL;
+ if (self->tag == NULL)
+ return PyUnicode_FromFormat("<Element at %p>", self);
- repr = PyString_FromFormat("<Element %s at %p>",
- PyString_AS_STRING(tag), self);
-
- Py_DECREF(tag);
+ status = Py_ReprEnter((PyObject *)self);
+ if (status == 0) {
+ PyObject *repr, *tag;
+ tag = PyObject_Repr(self->tag);
+ if (!tag)
+ return NULL;
- return repr;
+ repr = PyString_FromFormat("<Element %s at %p>",
+ PyString_AS_STRING(tag), self);
+ Py_ReprLeave((PyObject *)self);
+ Py_DECREF(tag);
+ return repr;
+ }
+ if (status > 0)
+ PyErr_Format(PyExc_RuntimeError,
+ "reentrant call inside %s.__repr__",
+ Py_TYPE(self)->tp_name);
+ return NULL;
}
static PyObject*
/* EVP is the preferred interface to hashing in OpenSSL */
#include <openssl/evp.h>
-#include <openssl/hmac.h>
#include <openssl/err.h>
+/* We use the object interface to discover what hashes OpenSSL supports. */
+#include <openssl/objects.h>
+#include "openssl/err.h"
#define MUNCH_SIZE INT_MAX
#define HASH_OBJ_CONSTRUCTOR 0
#endif
-/* Minimum OpenSSL version needed to support sha224 and higher. */
#if defined(OPENSSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER >= 0x00908000)
#define _OPENSSL_SUPPORTS_SHA2
#endif
+#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined(LIBRESSL_VERSION_NUMBER)
+/* OpenSSL < 1.1.0 */
+#define EVP_MD_CTX_new EVP_MD_CTX_create
+#define EVP_MD_CTX_free EVP_MD_CTX_destroy
+#define HAS_FAST_PKCS5_PBKDF2_HMAC 0
+#include <openssl/hmac.h>
+#else
+/* OpenSSL >= 1.1.0 */
+#define HAS_FAST_PKCS5_PBKDF2_HMAC 1
+#endif
+
+
typedef struct {
PyObject_HEAD
PyObject *name; /* name of this hash algorithm */
- EVP_MD_CTX ctx; /* OpenSSL message digest context */
+ EVP_MD_CTX *ctx; /* OpenSSL message digest context */
#ifdef WITH_THREAD
PyThread_type_lock lock; /* OpenSSL context lock */
#endif
#define DEFINE_CONSTS_FOR_NEW(Name) \
static PyObject *CONST_ ## Name ## _name_obj = NULL; \
- static EVP_MD_CTX CONST_new_ ## Name ## _ctx; \
static EVP_MD_CTX *CONST_new_ ## Name ## _ctx_p = NULL;
DEFINE_CONSTS_FOR_NEW(md5)
#endif
+/* LCOV_EXCL_START */
+static PyObject *
+_setException(PyObject *exc)
+{
+ unsigned long errcode;
+ const char *lib, *func, *reason;
+
+ errcode = ERR_peek_last_error();
+ if (!errcode) {
+ PyErr_SetString(exc, "unknown reasons");
+ return NULL;
+ }
+ ERR_clear_error();
+
+ lib = ERR_lib_error_string(errcode);
+ func = ERR_func_error_string(errcode);
+ reason = ERR_reason_error_string(errcode);
+
+ if (lib && func) {
+ PyErr_Format(exc, "[%s: %s] %s", lib, func, reason);
+ }
+ else if (lib) {
+ PyErr_Format(exc, "[%s] %s", lib, reason);
+ }
+ else {
+ PyErr_SetString(exc, reason);
+ }
+ return NULL;
+}
+/* LCOV_EXCL_STOP */
+
static EVPobject *
newEVPobject(PyObject *name)
{
EVPobject *retval = (EVPobject *)PyObject_New(EVPobject, &EVPtype);
+ if (retval == NULL)
+ return NULL;
+
+ retval->ctx = EVP_MD_CTX_new();
+ if (retval->ctx == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
/* save the name for .name to return */
- if (retval != NULL) {
- Py_INCREF(name);
- retval->name = name;
+ Py_INCREF(name);
+ retval->name = name;
#ifdef WITH_THREAD
- retval->lock = NULL;
+ retval->lock = NULL;
#endif
- }
return retval;
}
process = MUNCH_SIZE;
else
process = Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int);
- EVP_DigestUpdate(&self->ctx, (const void*)cp, process);
+ EVP_DigestUpdate(self->ctx, (const void*)cp, process);
len -= process;
cp += process;
}
if (self->lock != NULL)
PyThread_free_lock(self->lock);
#endif
- EVP_MD_CTX_cleanup(&self->ctx);
+ EVP_MD_CTX_free(self->ctx);
Py_XDECREF(self->name);
PyObject_Del(self);
}
-static void locked_EVP_MD_CTX_copy(EVP_MD_CTX *new_ctx_p, EVPobject *self)
+static int
+locked_EVP_MD_CTX_copy(EVP_MD_CTX *new_ctx_p, EVPobject *self)
{
+ int result;
ENTER_HASHLIB(self);
- EVP_MD_CTX_copy(new_ctx_p, &self->ctx);
+ /* XXX no error reporting */
+ result = EVP_MD_CTX_copy(new_ctx_p, self->ctx);
LEAVE_HASHLIB(self);
+ return result;
}
/* External methods for a hash object */
if ( (newobj = newEVPobject(self->name))==NULL)
return NULL;
- locked_EVP_MD_CTX_copy(&newobj->ctx, self);
+ if (!locked_EVP_MD_CTX_copy(newobj->ctx, self)) {
+ return _setException(PyExc_ValueError);
+ }
return (PyObject *)newobj;
}
EVP_digest(EVPobject *self, PyObject *unused)
{
unsigned char digest[EVP_MAX_MD_SIZE];
- EVP_MD_CTX temp_ctx;
+ EVP_MD_CTX *temp_ctx;
PyObject *retval;
unsigned int digest_size;
- locked_EVP_MD_CTX_copy(&temp_ctx, self);
- digest_size = EVP_MD_CTX_size(&temp_ctx);
- EVP_DigestFinal(&temp_ctx, digest, NULL);
+ temp_ctx = EVP_MD_CTX_new();
+ if (temp_ctx == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ if (!locked_EVP_MD_CTX_copy(temp_ctx, self)) {
+ return _setException(PyExc_ValueError);
+ }
+ digest_size = EVP_MD_CTX_size(temp_ctx);
+ EVP_DigestFinal(temp_ctx, digest, NULL);
retval = PyString_FromStringAndSize((const char *)digest, digest_size);
- EVP_MD_CTX_cleanup(&temp_ctx);
+ EVP_MD_CTX_free(temp_ctx);
return retval;
}
EVP_hexdigest(EVPobject *self, PyObject *unused)
{
unsigned char digest[EVP_MAX_MD_SIZE];
- EVP_MD_CTX temp_ctx;
+ EVP_MD_CTX *temp_ctx;
PyObject *retval;
char *hex_digest;
unsigned int i, j, digest_size;
+ temp_ctx = EVP_MD_CTX_new();
+ if (temp_ctx == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+
/* Get the raw (binary) digest value */
- locked_EVP_MD_CTX_copy(&temp_ctx, self);
- digest_size = EVP_MD_CTX_size(&temp_ctx);
- EVP_DigestFinal(&temp_ctx, digest, NULL);
+ if (!locked_EVP_MD_CTX_copy(temp_ctx, self)) {
+ return _setException(PyExc_ValueError);
+ }
+ digest_size = EVP_MD_CTX_size(temp_ctx);
+ EVP_DigestFinal(temp_ctx, digest, NULL);
- EVP_MD_CTX_cleanup(&temp_ctx);
+ EVP_MD_CTX_free(temp_ctx);
/* Create a new string */
/* NOTE: not thread safe! modifying an already created string object */
EVP_get_block_size(EVPobject *self, void *closure)
{
long block_size;
- block_size = EVP_MD_CTX_block_size(&self->ctx);
+ block_size = EVP_MD_CTX_block_size(self->ctx);
return PyLong_FromLong(block_size);
}
EVP_get_digest_size(EVPobject *self, void *closure)
{
long size;
- size = EVP_MD_CTX_size(&self->ctx);
+ size = EVP_MD_CTX_size(self->ctx);
return PyLong_FromLong(size);
}
PyBuffer_Release(&view);
return -1;
}
- EVP_DigestInit(&self->ctx, digest);
+ EVP_DigestInit(self->ctx, digest);
self->name = name_obj;
Py_INCREF(self->name);
return NULL;
if (initial_ctx) {
- EVP_MD_CTX_copy(&self->ctx, initial_ctx);
+ EVP_MD_CTX_copy(self->ctx, initial_ctx);
} else {
- EVP_DigestInit(&self->ctx, digest);
+ EVP_DigestInit(self->ctx, digest);
}
if (cp && len) {
#define PY_PBKDF2_HMAC 1
+#if !HAS_FAST_PKCS5_PBKDF2_HMAC
/* Improved implementation of PKCS5_PBKDF2_HMAC()
*
* PKCS5_PBKDF2_HMAC_fast() hashes the password exactly one time instead of
HMAC_CTX_cleanup(&hctx_tpl);
return 1;
}
+#endif
-/* LCOV_EXCL_START */
-static PyObject *
-_setException(PyObject *exc)
-{
- unsigned long errcode;
- const char *lib, *func, *reason;
-
- errcode = ERR_peek_last_error();
- if (!errcode) {
- PyErr_SetString(exc, "unknown reasons");
- return NULL;
- }
- ERR_clear_error();
-
- lib = ERR_lib_error_string(errcode);
- func = ERR_func_error_string(errcode);
- reason = ERR_reason_error_string(errcode);
-
- if (lib && func) {
- PyErr_Format(exc, "[%s: %s] %s", lib, func, reason);
- }
- else if (lib) {
- PyErr_Format(exc, "[%s] %s", lib, reason);
- }
- else {
- PyErr_SetString(exc, reason);
- }
- return NULL;
-}
-/* LCOV_EXCL_STOP */
PyDoc_STRVAR(pbkdf2_hmac__doc__,
"pbkdf2_hmac(hash_name, password, salt, iterations, dklen=None) -> key\n\
key = PyBytes_AS_STRING(key_obj);
Py_BEGIN_ALLOW_THREADS
+#if HAS_FAST_PKCS5_PBKDF2_HMAC
+ retval = PKCS5_PBKDF2_HMAC((char*)password.buf, (int)password.len,
+ (unsigned char *)salt.buf, (int)salt.len,
+ iterations, digest, dklen,
+ (unsigned char *)key);
+#else
retval = PKCS5_PBKDF2_HMAC_fast((char*)password.buf, (int)password.len,
(unsigned char *)salt.buf, (int)salt.len,
iterations, digest, dklen,
(unsigned char *)key);
+#endif
Py_END_ALLOW_THREADS
if (!retval) {
if (openssl_obj_name == NULL)
return;
/* Ignore aliased names, they pollute the list and OpenSSL appears to
- * have a its own definition of alias as the resulting list still
+ * have its own definition of alias as the resulting list still
* contains duplicate and alternate names for several algorithms. */
if (openssl_obj_name->alias)
return;
/*
* This macro generates constructor function definitions for specific
* hash algorithms. These constructors are much faster than calling
- * the generic one passing it a python string and are noticably
+ * the generic one passing it a python string and are noticeably
* faster than calling a python new() wrapper. Thats important for
* code that wants to make hashes of a bunch of small strings.
*/
if (CONST_ ## NAME ## _name_obj == NULL) { \
CONST_ ## NAME ## _name_obj = PyString_FromString(#NAME); \
if (EVP_get_digestbyname(#NAME)) { \
- CONST_new_ ## NAME ## _ctx_p = &CONST_new_ ## NAME ## _ctx; \
+ CONST_new_ ## NAME ## _ctx_p = EVP_MD_CTX_new(); \
EVP_DigestInit(CONST_new_ ## NAME ## _ctx_p, EVP_get_digestbyname(#NAME)); \
} \
} \
static int
unpack_add_info(LogReaderObject *self)
{
- PyObject *key;
+ PyObject *key = NULL;
PyObject *value = NULL;
+ PyObject *list;
int err;
err = unpack_string(self, &key);
- if (!err) {
- err = unpack_string(self, &value);
- if (err)
- Py_DECREF(key);
- else {
- PyObject *list = PyDict_GetItem(self->info, key);
- if (list == NULL) {
- list = PyList_New(0);
- if (list == NULL) {
- err = ERR_EXCEPTION;
- goto finally;
- }
- if (PyDict_SetItem(self->info, key, list)) {
- Py_DECREF(list);
- err = ERR_EXCEPTION;
- goto finally;
- }
- Py_DECREF(list);
- }
- if (PyList_Append(list, value))
- err = ERR_EXCEPTION;
+ if (err)
+ goto finally;
+ err = unpack_string(self, &value);
+ if (err)
+ goto finally;
+ list = PyDict_GetItem(self->info, key);
+ if (list == NULL) {
+ list = PyList_New(0);
+ if (list == NULL) {
+ err = ERR_EXCEPTION;
+ goto finally;
+ }
+ if (PyDict_SetItem(self->info, key, list)) {
+ Py_DECREF(list);
+ err = ERR_EXCEPTION;
+ goto finally;
}
+ Py_DECREF(list);
}
+ if (PyList_Append(list, value))
+ err = ERR_EXCEPTION;
+
finally:
Py_XDECREF(key);
Py_XDECREF(value);
"Another IOBase subclass, TextIOBase, deals with the encoding and decoding\n"
"of streams into text. TextIOWrapper, which extends it, is a buffered text\n"
"interface to a buffered raw stream (`BufferedIOBase`). Finally, StringIO\n"
-"is a in-memory stream for text.\n"
+"is an in-memory stream for text.\n"
"\n"
"Argument names are not part of the specification, and only the arguments\n"
"of open() are intended to be used as keyword arguments.\n"
}
#ifdef MS_WINDOWS
- if (PyUnicode_Check(nameobj))
+ if (PyUnicode_Check(nameobj)) {
widename = PyUnicode_AS_UNICODE(nameobj);
+ if (wcslen(widename) != (size_t)PyUnicode_GET_SIZE(nameobj)) {
+ PyErr_SetString(PyExc_TypeError, "embedded NUL character");
+ return -1;
+ }
+ }
if (widename == NULL)
#endif
if (fd < 0)
Py_ssize_t namelen;
if (PyObject_AsCharBuffer(nameobj, &name, &namelen) < 0)
return -1;
+ if (strlen(name) != (size_t)namelen) {
+ PyErr_SetString(PyExc_TypeError, "embedded NUL character");
+ return -1;
+ }
}
else {
PyObject *u = PyUnicode_FromObject(nameobj);
goto error;
}
name = PyBytes_AS_STRING(stringobj);
+ if (strlen(name) != (size_t)PyBytes_GET_SIZE(stringobj)) {
+ PyErr_SetString(PyExc_TypeError, "embedded NUL character");
+ goto error;
+ }
}
}
"Even though IOBase does not declare read, readinto, or write because\n"
"their signatures will vary, implementations and clients should\n"
"consider those methods part of the interface. Also, implementations\n"
- "may raise a IOError when operations they do not support are called.\n"
+ "may raise an IOError when operations they do not support are called.\n"
"\n"
"The basic type used for binary data read from or written to a file is\n"
"the bytes type. Method arguments may also be bytearray or memoryview\n"
return NULL;
}
-/* Positionning */
+/* Positioning */
PyDoc_STRVAR(iobase_seek_doc,
"Change stream position.\n"
if (self->encoding == NULL) {
catch_ImportError:
/*
- Importing locale can raise a ImportError because of
- _functools, and locale.getpreferredencoding can raise a
+ Importing locale can raise an ImportError because of
+ _functools, and locale.getpreferredencoding can raise an
ImportError if _locale is not available. These will happen
during module building.
*/
return -1;
}
-static int
+static void
_textiowrapper_clear(textio *self)
{
- if (self->ok && _PyIOBase_finalize((PyObject *) self) < 0)
- return -1;
self->ok = 0;
Py_CLEAR(self->buffer);
Py_CLEAR(self->encoding);
Py_CLEAR(self->snapshot);
Py_CLEAR(self->errors);
Py_CLEAR(self->raw);
- return 0;
+
+ Py_CLEAR(self->dict);
}
static void
textiowrapper_dealloc(textio *self)
{
- if (_textiowrapper_clear(self) < 0)
+ if (self->ok && _PyIOBase_finalize((PyObject *) self) < 0)
return;
_PyObject_GC_UNTRACK(self);
if (self->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *)self);
- Py_CLEAR(self->dict);
+ _textiowrapper_clear(self);
Py_TYPE(self)->tp_free((PyObject *)self);
}
static int
textiowrapper_clear(textio *self)
{
- if (_textiowrapper_clear(self) < 0)
+ if (self->ok && _PyIOBase_finalize((PyObject *) self) < 0)
return -1;
- Py_CLEAR(self->dict);
+ _textiowrapper_clear(self);
return 0;
}
Py_ssize_t output_size;
Py_ssize_t max_output_size;
Py_ssize_t chars;
+ Py_ssize_t incr;
PyObject *rval;
char *output;
Py_UNICODE *input_unicode;
input_chars = PyUnicode_GET_SIZE(pystr);
input_unicode = PyUnicode_AS_UNICODE(pystr);
+ output_size = input_chars;
+ incr = 2; /* for quotes */
/* One char input can be up to 6 chars output, estimate 4 of these */
- output_size = 2 + (MIN_EXPANSION * 4) + input_chars;
- max_output_size = 2 + (input_chars * MAX_EXPANSION);
+ incr += MIN_EXPANSION * 4;
+ if (PY_SSIZE_T_MAX - incr < output_size) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ output_size += incr;
+ if (PY_SSIZE_T_MAX / MAX_EXPANSION < input_chars ||
+ PY_SSIZE_T_MAX - 2 < input_chars * MAX_EXPANSION)
+ max_output_size = PY_SSIZE_T_MAX;
+ else
+ max_output_size = 2 + (input_chars * MAX_EXPANSION);
rval = PyString_FromStringAndSize(NULL, output_size);
if (rval == NULL) {
return NULL;
chars = ascii_escape_char(c, output, chars);
}
if (output_size - chars < (1 + MAX_EXPANSION)) {
- /* There's more than four, so let's resize by a lot */
- Py_ssize_t new_output_size = output_size * 2;
- /* This is an upper bound */
- if (new_output_size > max_output_size) {
- new_output_size = max_output_size;
+ if (output_size == PY_SSIZE_T_MAX) {
+ Py_DECREF(rval);
+ PyErr_NoMemory();
+ return NULL;
}
- /* Make sure that the output size changed before resizing */
- if (new_output_size != output_size) {
- output_size = new_output_size;
- if (_PyString_Resize(&rval, output_size) == -1) {
- return NULL;
- }
- output = PyString_AS_STRING(rval);
+ /* There's more than four, so let's resize by a lot */
+ if (PY_SSIZE_T_MAX / 2 >= output_size && output_size * 2 < max_output_size)
+ output_size *= 2;
+ else
+ output_size = max_output_size;
+ if (_PyString_Resize(&rval, output_size) == -1) {
+ return NULL;
}
+ output = PyString_AS_STRING(rval);
}
}
output[chars++] = '"';
Py_ssize_t i;
Py_ssize_t input_chars;
Py_ssize_t output_size;
+ Py_ssize_t max_output_size;
Py_ssize_t chars;
+ Py_ssize_t incr;
PyObject *rval;
char *output;
char *input_str;
}
}
- if (i == input_chars) {
- /* Input is already ASCII */
- output_size = 2 + input_chars;
- }
- else {
+ output_size = input_chars;
+ incr = 2; /* for quotes */
+ if (i != input_chars) {
/* One char input can be up to 6 chars output, estimate 4 of these */
- output_size = 2 + (MIN_EXPANSION * 4) + input_chars;
+ incr += MIN_EXPANSION * 4;
+ }
+ if (PY_SSIZE_T_MAX - incr < output_size) {
+ PyErr_NoMemory();
+ return NULL;
}
+ output_size += incr;
+ if (PY_SSIZE_T_MAX / MIN_EXPANSION < input_chars ||
+ PY_SSIZE_T_MAX - 2 < input_chars * MIN_EXPANSION)
+ max_output_size = PY_SSIZE_T_MAX;
+ else
+ max_output_size = 2 + (input_chars * MIN_EXPANSION);
rval = PyString_FromStringAndSize(NULL, output_size);
if (rval == NULL) {
return NULL;
}
/* An ASCII char can't possibly expand to a surrogate! */
if (output_size - chars < (1 + MIN_EXPANSION)) {
- /* There's more than four, so let's resize by a lot */
- output_size *= 2;
- if (output_size > 2 + (input_chars * MIN_EXPANSION)) {
- output_size = 2 + (input_chars * MIN_EXPANSION);
+ if (output_size == PY_SSIZE_T_MAX) {
+ Py_DECREF(rval);
+ PyErr_NoMemory();
+ return NULL;
}
+ /* There's more than four, so let's resize by a lot */
+ if (PY_SSIZE_T_MAX / 2 >= output_size && output_size * 2 < max_output_size)
+ output_size *= 2;
+ else
+ output_size = max_output_size;
if (_PyString_Resize(&rval, output_size) == -1) {
return NULL;
}
return PyString_FromString("NaN");
}
}
- /* Use a better float format here? */
- return PyObject_Repr(obj);
+ /* Make sure to use the base float class repr method */
+ return PyFloat_Type.tp_repr(obj);
}
static PyObject *
int i;
PyObject *result, *val = NULL;
- if (s[0] == '\0')
- /* empty string: no grouping at all */
- return PyList_New(0);
+ if (s[0] == '\0') {
+ /* empty string: no grouping at all */
+ return PyList_New(0);
+ }
for (i = 0; s[i] != '\0' && s[i] != CHAR_MAX; i++)
; /* nothing */
#endif
if (locale) {
- /* set locale */
- result = setlocale(category, locale);
- if (!result) {
- /* operation failed, no setting was changed */
- PyErr_SetString(Error, "unsupported locale setting");
- return NULL;
- }
- result_object = PyString_FromString(result);
- if (!result_object)
- return NULL;
- /* record changes to LC_CTYPE */
- if (category == LC_CTYPE || category == LC_ALL)
- fixup_ulcase();
+ /* set locale */
+ result = setlocale(category, locale);
+ if (!result) {
+ /* operation failed, no setting was changed */
+ PyErr_SetString(Error, "unsupported locale setting");
+ return NULL;
+ }
+ result_object = PyString_FromString(result);
+ if (!result_object)
+ return NULL;
+ /* record changes to LC_CTYPE */
+ if (category == LC_CTYPE || category == LC_ALL)
+ fixup_ulcase();
/* things that got wrong up to here are ignored */
PyErr_Clear();
} else {
- /* get locale */
+ /* get locale */
result = setlocale(category, NULL);
if (!result) {
PyErr_SetString(Error, "locale query failed");
}
/* Convert the non-unicode argument to unicode. */
if (!PyUnicode_Check(os1)) {
- os1 = PyUnicode_FromObject(os1);
- if (!os1)
- return NULL;
+ os1 = PyUnicode_FromObject(os1);
+ if (!os1)
+ return NULL;
rel1 = 1;
}
if (!PyUnicode_Check(os2)) {
{
int item, i;
if (!PyArg_ParseTuple(args, "i:nl_langinfo", &item))
- return NULL;
+ return NULL;
/* Check whether this is a supported constant. GNU libc sometimes
returns numeric values in the char* return value, which would
crash PyString_FromString. */
static const double ln2 = 6.93147180559945286227E-01;
static const double two_pow_m28 = 3.7252902984619141E-09; /* 2**-28 */
static const double two_pow_p28 = 268435456.0; /* 2**28 */
-static const double zero = 0.0;
/* acosh(x)
* Method :
#ifdef Py_NAN
return Py_NAN;
#else
- return x/zero;
+ return x/0.0;
#endif
}
if (absx < two_pow_m28) { /* |x| < 2**-28 */
#define CHECK_READABLE(self) \
if (!(self->flags & READABLE)) { \
- PyErr_SetString(PyExc_IOError, "connection is write-only"); \
- return NULL; \
+ PyErr_SetString(PyExc_IOError, "connection is write-only"); \
+ return NULL; \
}
#define CHECK_WRITABLE(self) \
if (!(self->flags & WRITABLE)) { \
- PyErr_SetString(PyExc_IOError, "connection is read-only"); \
- return NULL; \
+ PyErr_SetString(PyExc_IOError, "connection is read-only"); \
+ return NULL; \
}
/*
return -1;
}
} else {
- /* Create a pysqlite connection from a APSW connection */
+ /* Create a pysqlite connection from an APSW connection */
class_attr = PyObject_GetAttrString(database, "__class__");
if (class_attr) {
class_attr_str = PyObject_Str(class_attr);
PyObject* pysqlite_connection_cursor(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
{
- static char *kwlist[] = {"factory", NULL, NULL};
+ static char *kwlist[] = {"factory", NULL};
PyObject* factory = NULL;
PyObject* cursor;
factory = (PyObject*)&pysqlite_CursorType;
}
- cursor = PyObject_CallFunction(factory, "O", self);
+ cursor = PyObject_CallFunctionObjArgs(factory, (PyObject *)self, NULL);
+ if (cursor == NULL)
+ return NULL;
+ if (!PyObject_TypeCheck(cursor, &pysqlite_CursorType)) {
+ PyErr_Format(PyExc_TypeError,
+ "factory must return a cursor, not %.100s",
+ Py_TYPE(cursor)->tp_name);
+ Py_DECREF(cursor);
+ return NULL;
+ }
_pysqlite_drop_unused_cursor_references(self);
}
if (self->inTransaction) {
- pysqlite_do_all_statements(self, ACTION_RESET, 0);
Py_BEGIN_ALLOW_THREADS
rc = sqlite3_prepare(self->db, "COMMIT", -1, &statement, &tail);
}
error:
+ ; /* necessary for --without-threads flag */
#ifdef WITH_THREAD
PyGILState_Release(threadstate);
#endif
goto finally;
}
- if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", &PyString_Type, &name, &callable)) {
+ if (!PyArg_ParseTuple(args, "SO:create_collation(name, callback)",
+ &name, &callable)) {
goto finally;
}
- uppercase_name = PyObject_CallMethod(name, "upper", "");
+ uppercase_name = PyObject_CallMethod((PyObject *)&PyString_Type,
+ "upper", "O", name);
if (!uppercase_name) {
goto finally;
}
- chk = PyString_AsString(uppercase_name);
+ chk = PyString_AS_STRING(uppercase_name);
while (*chk) {
if ((*chk >= '0' && *chk <= '9')
|| (*chk >= 'A' && *chk <= 'Z')
/* a dictionary of registered collation name => collation callable mappings */
PyObject* collations;
- /* if our connection was created from a APSW connection, we keep a
+ /* if our connection was created from an APSW connection, we keep a
* reference to the APSW connection around and get rid of it in our
* destructor */
PyObject* apsw_connection;
static void pysqlite_cursor_dealloc(pysqlite_Cursor* self)
{
- int rc;
-
/* Reset the statement if the user has not closed the cursor */
if (self->statement) {
- rc = pysqlite_statement_reset(self->statement);
+ pysqlite_statement_reset(self->statement);
Py_DECREF(self->statement);
}
rc = PYSQLITE_SQL_WRONG_TYPE;
return rc;
}
- sql_cstr = PyString_AsString(sql_str);
+ sql_cstr = PyString_AS_STRING(sql_str);
if (strlen(sql_cstr) != (size_t)PyString_GET_SIZE(sql_str)) {
+ Py_DECREF(sql_str);
PyErr_SetString(PyExc_ValueError, "the query contains a null character");
return PYSQLITE_SQL_WRONG_TYPE;
}
void pysqlite_statement_dealloc(pysqlite_Statement* self)
{
- int rc;
-
if (self->st) {
Py_BEGIN_ALLOW_THREADS
- rc = sqlite3_finalize(self->st);
+ sqlite3_finalize(self->st);
Py_END_ALLOW_THREADS
}
if (!key)
goto failed;
value = match_getslice(self, key, def);
- if (!value) {
- Py_DECREF(key);
+ if (!value)
goto failed;
- }
status = PyDict_SetItem(result, key, value);
Py_DECREF(value);
if (status < 0)
#include <sys/poll.h>
#endif
+/* Don't warn about deprecated functions */
+#ifdef __GNUC__
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#endif
+#ifdef __clang__
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
/* Include OpenSSL header files */
#include "openssl/rsa.h"
#include "openssl/crypto.h"
/* Include generated data (error codes) */
#include "_ssl_data.h"
+#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER)
+# define OPENSSL_VERSION_1_1 1
+#endif
+
/* Openssl comes with TLSv1.1 and TLSv1.2 between 1.0.0h and 1.0.1
http://www.openssl.org/news/changelog.html
*/
# define HAVE_ALPN
#endif
+#ifndef INVALID_SOCKET /* MS defines this */
+#define INVALID_SOCKET (-1)
+#endif
+
+#ifdef OPENSSL_VERSION_1_1
+/* OpenSSL 1.1.0+ */
+#ifndef OPENSSL_NO_SSL2
+#define OPENSSL_NO_SSL2
+#endif
+#else /* OpenSSL < 1.1.0 */
+#if defined(WITH_THREAD)
+#define HAVE_OPENSSL_CRYPTO_LOCK
+#endif
+
+#define TLS_method SSLv23_method
+
+static int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne)
+{
+ return ne->set;
+}
+
+#ifndef OPENSSL_NO_COMP
+static int COMP_get_type(const COMP_METHOD *meth)
+{
+ return meth->type;
+}
+#endif
+
+static pem_password_cb *SSL_CTX_get_default_passwd_cb(SSL_CTX *ctx)
+{
+ return ctx->default_passwd_callback;
+}
+
+static void *SSL_CTX_get_default_passwd_cb_userdata(SSL_CTX *ctx)
+{
+ return ctx->default_passwd_callback_userdata;
+}
+
+static int X509_OBJECT_get_type(X509_OBJECT *x)
+{
+ return x->type;
+}
+
+static X509 *X509_OBJECT_get0_X509(X509_OBJECT *x)
+{
+ return x->data.x509;
+}
+
+static STACK_OF(X509_OBJECT) *X509_STORE_get0_objects(X509_STORE *store) {
+ return store->objs;
+}
+
+static X509_VERIFY_PARAM *X509_STORE_get0_param(X509_STORE *store)
+{
+ return store->param;
+}
+#endif /* OpenSSL < 1.1.0 or LibreSSL */
+
+
enum py_ssl_error {
/* these mirror ssl.h */
PY_SSL_ERROR_NONE,
enum py_ssl_version {
PY_SSL_VERSION_SSL2,
PY_SSL_VERSION_SSL3=1,
- PY_SSL_VERSION_SSL23,
+ PY_SSL_VERSION_TLS,
#if HAVE_TLSv1_2
PY_SSL_VERSION_TLS1,
PY_SSL_VERSION_TLS1_1,
/* check to see if we've gotten to a new RDN */
if (rdn_level >= 0) {
- if (rdn_level != entry->set) {
+ if (rdn_level != X509_NAME_ENTRY_set(entry)) {
/* yes, new RDN */
/* add old RDN to DN */
rdnt = PyList_AsTuple(rdn);
goto fail0;
}
}
- rdn_level = entry->set;
+ rdn_level = X509_NAME_ENTRY_set(entry);
/* now add this attribute to the current RDN */
name = X509_NAME_ENTRY_get_object(entry);
goto fail;
}
- p = ext->value->data;
+ p = X509_EXTENSION_get_data(ext)->data;
if (method->it)
names = (GENERAL_NAMES*)
(ASN1_item_d2i(NULL,
&p,
- ext->value->length,
+ X509_EXTENSION_get_data(ext)->length,
ASN1_ITEM_ptr(method->it)));
else
names = (GENERAL_NAMES*)
(method->d2i(NULL,
&p,
- ext->value->length));
+ X509_EXTENSION_get_data(ext)->length));
for(j = 0; j < sk_GENERAL_NAME_num(names); j++) {
/* get a rendering of each name in the set of names */
PyTuple_SET_ITEM(t, 1, v);
break;
+ case GEN_RID:
+ t = PyTuple_New(2);
+ if (t == NULL)
+ goto fail;
+
+ v = PyUnicode_FromString("Registered ID");
+ if (v == NULL) {
+ Py_DECREF(t);
+ goto fail;
+ }
+ PyTuple_SET_ITEM(t, 0, v);
+
+ len = i2t_ASN1_OBJECT(buf, sizeof(buf)-1, name->d.rid);
+ if (len < 0) {
+ Py_DECREF(t);
+ _setSSLError(NULL, 0, __FILE__, __LINE__);
+ goto fail;
+ } else if (len >= (int)sizeof(buf)) {
+ v = PyUnicode_FromString("<INVALID>");
+ } else {
+ v = PyUnicode_FromStringAndSize(buf, len);
+ }
+ if (v == NULL) {
+ Py_DECREF(t);
+ goto fail;
+ }
+ PyTuple_SET_ITEM(t, 1, v);
+ break;
+
default:
/* for everything else, we use the OpenSSL print form */
switch (gntype) {
goto fail;
}
vptr = strchr(buf, ':');
- if (vptr == NULL)
+ if (vptr == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "Invalid value %.200s",
+ buf);
goto fail;
+ }
t = PyTuple_New(2);
if (t == NULL)
goto fail;
int i, j;
PyObject *lst, *res = NULL;
-#if OPENSSL_VERSION_NUMBER < 0x10001000L
- dps = X509_get_ext_d2i(certificate, NID_crl_distribution_points, NULL, NULL);
-#else
+#if OPENSSL_VERSION_NUMBER >= 0x10001000L
/* Calls x509v3_cache_extensions and sets up crldp */
X509_check_ca(certificate);
- dps = certificate->crldp;
#endif
+ dps = X509_get_ext_d2i(certificate, NID_crl_distribution_points, NULL, NULL);
if (dps == NULL)
return Py_None;
if (self->ssl == NULL)
Py_RETURN_NONE;
comp_method = SSL_get_current_compression(self->ssl);
- if (comp_method == NULL || comp_method->type == NID_undef)
+ if (comp_method == NULL || COMP_get_type(comp_method) == NID_undef)
Py_RETURN_NONE;
- short_name = OBJ_nid2sn(comp_method->type);
+ short_name = OBJ_nid2sn(COMP_get_type(comp_method));
if (short_name == NULL)
Py_RETURN_NONE;
return PyBytes_FromString(short_name);
dest = PyBytes_FromStringAndSize(NULL, len);
if (dest == NULL)
goto error;
+ if (len == 0) {
+ Py_XDECREF(sock);
+ return dest;
+ }
mem = PyBytes_AS_STRING(dest);
}
else {
"maximum length can't fit in a C 'int'");
goto error;
}
+ if (len == 0) {
+ count = 0;
+ goto done;
+ }
}
}
{
char *kwlist[] = {"protocol", NULL};
PySSLContext *self;
- int proto_version = PY_SSL_VERSION_SSL23;
+ int proto_version = PY_SSL_VERSION_TLS;
long options;
SSL_CTX *ctx = NULL;
else if (proto_version == PY_SSL_VERSION_SSL2)
ctx = SSL_CTX_new(SSLv2_method());
#endif
- else if (proto_version == PY_SSL_VERSION_SSL23)
- ctx = SSL_CTX_new(SSLv23_method());
+ else if (proto_version == PY_SSL_VERSION_TLS)
+ ctx = SSL_CTX_new(TLS_method());
else
proto_version = -1;
PySSL_END_ALLOW_THREADS
#ifndef OPENSSL_NO_ECDH
/* Allow automatic ECDH curve selection (on OpenSSL 1.0.2+), or use
prime256v1 by default. This is Apache mod_ssl's initialization
- policy, so we should be safe. */
-#if defined(SSL_CTX_set_ecdh_auto)
+ policy, so we should be safe. OpenSSL 1.1 has it enabled by default.
+ */
+#if defined(SSL_CTX_set_ecdh_auto) && !defined(OPENSSL_VERSION_1_1)
SSL_CTX_set_ecdh_auto(self->ctx, 1);
#else
{
get_verify_flags(PySSLContext *self, void *c)
{
X509_STORE *store;
+ X509_VERIFY_PARAM *param;
unsigned long flags;
store = SSL_CTX_get_cert_store(self->ctx);
- flags = X509_VERIFY_PARAM_get_flags(store->param);
+ param = X509_STORE_get0_param(store);
+ flags = X509_VERIFY_PARAM_get_flags(param);
return PyLong_FromUnsignedLong(flags);
}
set_verify_flags(PySSLContext *self, PyObject *arg, void *c)
{
X509_STORE *store;
+ X509_VERIFY_PARAM *param;
unsigned long new_flags, flags, set, clear;
if (!PyArg_Parse(arg, "k", &new_flags))
return -1;
store = SSL_CTX_get_cert_store(self->ctx);
- flags = X509_VERIFY_PARAM_get_flags(store->param);
+ param = X509_STORE_get0_param(store);
+ flags = X509_VERIFY_PARAM_get_flags(param);
clear = flags & ~new_flags;
set = ~flags & new_flags;
if (clear) {
- if (!X509_VERIFY_PARAM_clear_flags(store->param, clear)) {
+ if (!X509_VERIFY_PARAM_clear_flags(param, clear)) {
_setSSLError(NULL, 0, __FILE__, __LINE__);
return -1;
}
}
if (set) {
- if (!X509_VERIFY_PARAM_set_flags(store->param, set)) {
+ if (!X509_VERIFY_PARAM_set_flags(param, set)) {
_setSSLError(NULL, 0, __FILE__, __LINE__);
return -1;
}
char *kwlist[] = {"certfile", "keyfile", "password", NULL};
PyObject *keyfile = NULL, *keyfile_bytes = NULL, *password = NULL;
char *certfile_bytes = NULL;
- pem_password_cb *orig_passwd_cb = self->ctx->default_passwd_callback;
- void *orig_passwd_userdata = self->ctx->default_passwd_callback_userdata;
+ pem_password_cb *orig_passwd_cb = SSL_CTX_get_default_passwd_cb(self->ctx);
+ void *orig_passwd_userdata = SSL_CTX_get_default_passwd_cb_userdata(self->ctx);
_PySSLPasswordInfo pw_info = { NULL, NULL, NULL, 0, 0 };
int r;
cert = d2i_X509_bio(biobuf, NULL);
} else {
cert = PEM_read_bio_X509(biobuf, NULL,
- self->ctx->default_passwd_callback,
- self->ctx->default_passwd_callback_userdata);
+ SSL_CTX_get_default_passwd_cb(self->ctx),
+ SSL_CTX_get_default_passwd_cb_userdata(self->ctx)
+ );
}
if (cert == NULL) {
break;
cert_store_stats(PySSLContext *self)
{
X509_STORE *store;
+ STACK_OF(X509_OBJECT) *objs;
X509_OBJECT *obj;
- int x509 = 0, crl = 0, pkey = 0, ca = 0, i;
+ int x509 = 0, crl = 0, ca = 0, i;
store = SSL_CTX_get_cert_store(self->ctx);
- for (i = 0; i < sk_X509_OBJECT_num(store->objs); i++) {
- obj = sk_X509_OBJECT_value(store->objs, i);
- switch (obj->type) {
+ objs = X509_STORE_get0_objects(store);
+ for (i = 0; i < sk_X509_OBJECT_num(objs); i++) {
+ obj = sk_X509_OBJECT_value(objs, i);
+ switch (X509_OBJECT_get_type(obj)) {
case X509_LU_X509:
x509++;
- if (X509_check_ca(obj->data.x509)) {
+ if (X509_check_ca(X509_OBJECT_get0_X509(obj))) {
ca++;
}
break;
case X509_LU_CRL:
crl++;
break;
- case X509_LU_PKEY:
- pkey++;
- break;
default:
/* Ignore X509_LU_FAIL, X509_LU_RETRY, X509_LU_PKEY.
* As far as I can tell they are internal states and never
char *kwlist[] = {"binary_form", NULL};
X509_STORE *store;
PyObject *ci = NULL, *rlist = NULL, *py_binary_mode = Py_False;
+ STACK_OF(X509_OBJECT) *objs;
int i;
int binary_mode = 0;
}
store = SSL_CTX_get_cert_store(self->ctx);
- for (i = 0; i < sk_X509_OBJECT_num(store->objs); i++) {
+ objs = X509_STORE_get0_objects(store);
+ for (i = 0; i < sk_X509_OBJECT_num(objs); i++) {
X509_OBJECT *obj;
X509 *cert;
- obj = sk_X509_OBJECT_value(store->objs, i);
- if (obj->type != X509_LU_X509) {
+ obj = sk_X509_OBJECT_value(objs, i);
+ if (X509_OBJECT_get_type(obj) != X509_LU_X509) {
/* not a x509 cert */
continue;
}
/* CA for any purpose */
- cert = obj->data.x509;
+ cert = X509_OBJECT_get0_X509(obj);
if (!X509_check_ca(cert)) {
continue;
}
#endif /* HAVE_OPENSSL_RAND */
-#ifdef HAVE_RAND_EGD
+#ifndef OPENSSL_NO_EGD
static PyObject *
PySSL_RAND_egd(PyObject *self, PyObject *arg)
Returns number of bytes read. Raises SSLError if connection to EGD\n\
fails or if it does not provide enough data to seed PRNG.");
-#endif /* HAVE_RAND_EGD */
+#endif /* !OPENSSL_NO_EGD */
PyDoc_STRVAR(PySSL_get_default_verify_paths_doc,
{"RAND_status", (PyCFunction)PySSL_RAND_status, METH_NOARGS,
PySSL_RAND_status_doc},
#endif
-#ifdef HAVE_RAND_EGD
+#ifndef OPENSSL_NO_EGD
{"RAND_egd", PySSL_RAND_egd, METH_VARARGS,
PySSL_RAND_egd_doc},
#endif
};
-#ifdef WITH_THREAD
+#ifdef HAVE_OPENSSL_CRYPTO_LOCK
/* an implementation of OpenSSL threading operations in terms
- of the Python C thread library */
+ * of the Python C thread library
+ * Only used up to 1.0.2. OpenSSL 1.1.0+ has its own locking code.
+ */
static PyThread_type_lock *_ssl_locks = NULL;
return 1;
}
-#endif /* def HAVE_THREAD */
+#endif /* HAVE_OPENSSL_CRYPTO_LOCK for WITH_THREAD && OpenSSL < 1.1.0 */
PyDoc_STRVAR(module_doc,
"Implementation module for SSL socket operations. See the socket module\n\
SSL_load_error_strings();
SSL_library_init();
#ifdef WITH_THREAD
+#ifdef HAVE_OPENSSL_CRYPTO_LOCK
/* note that this will start threading if not already started */
if (!_setup_ssl_threads()) {
return;
}
+#elif OPENSSL_VERSION_1_1 && defined(OPENSSL_THREADS)
+ /* OpenSSL 1.1.0 builtin thread support is enabled */
+ _ssl_locks_count++;
#endif
+#endif /* WITH_THREAD */
OpenSSL_add_all_algorithms();
/* Add symbols to module dict */
PY_SSL_VERSION_SSL3);
#endif
PyModule_AddIntConstant(m, "PROTOCOL_SSLv23",
- PY_SSL_VERSION_SSL23);
+ PY_SSL_VERSION_TLS);
+ PyModule_AddIntConstant(m, "PROTOCOL_TLS",
+ PY_SSL_VERSION_TLS);
PyModule_AddIntConstant(m, "PROTOCOL_TLSv1",
PY_SSL_VERSION_TLS1);
#if HAVE_TLSv1_2
(size_t)(size) <= UINT_MAX / (size_t)(elemsize))
/* Starting with Tcl 8.4, many APIs offer const-correctness. Unfortunately,
- making _tkinter correct for this API means to break earlier
- versions. USE_COMPAT_CONST allows to make _tkinter work with both 8.4 and
+ making _tkinter correct for this API means breaking earlier
+ versions. USE_COMPAT_CONST allows making _tkinter work with both 8.4 and
earlier versions. Once Tcl releases before 8.4 don't need to be supported
anymore, this should go. */
#define USE_COMPAT_CONST
PyErr_NormalizeException(&exc, &val, &tb);
*(ev->exc_type) = exc;
*(ev->exc_val) = val;
- Py_DECREF(tb);
+ Py_XDECREF(tb);
}
}
np = (arrayobject *) newarrayobject(&Arraytype, ihigh - ilow, a->ob_descr);
if (np == NULL)
return NULL;
- memcpy(np->ob_item, a->ob_item + ilow * a->ob_descr->itemsize,
- (ihigh-ilow) * a->ob_descr->itemsize);
+ if (ihigh > ilow) {
+ memcpy(np->ob_item, a->ob_item + ilow * a->ob_descr->itemsize,
+ (ihigh-ilow) * a->ob_descr->itemsize);
+ }
return (PyObject *)np;
}
if (np == NULL) {
return NULL;
}
- memcpy(np->ob_item, a->ob_item, Py_SIZE(a)*a->ob_descr->itemsize);
- memcpy(np->ob_item + Py_SIZE(a)*a->ob_descr->itemsize,
- b->ob_item, Py_SIZE(b)*b->ob_descr->itemsize);
+ if (Py_SIZE(a) > 0) {
+ memcpy(np->ob_item, a->ob_item, Py_SIZE(a)*a->ob_descr->itemsize);
+ }
+ if (Py_SIZE(b) > 0) {
+ memcpy(np->ob_item + Py_SIZE(a)*a->ob_descr->itemsize,
+ b->ob_item, Py_SIZE(b)*b->ob_descr->itemsize);
+ }
return (PyObject *)np;
#undef b
}
np = (arrayobject *) newarrayobject(&Arraytype, size, a->ob_descr);
if (np == NULL)
return NULL;
+ if (size == 0)
+ return (PyObject *)np;
p = np->ob_item;
nbytes = Py_SIZE(a) * a->ob_descr->itemsize;
for (i = 0; i < n; i++) {
PyErr_NoMemory();
return -1;
}
- memcpy(self->ob_item + Py_SIZE(self)*self->ob_descr->itemsize,
- b->ob_item, Py_SIZE(b)*b->ob_descr->itemsize);
+ if (Py_SIZE(b) > 0) {
+ memcpy(self->ob_item + Py_SIZE(self)*self->ob_descr->itemsize,
+ b->ob_item, Py_SIZE(b)*b->ob_descr->itemsize);
+ }
Py_SIZE(self) = size;
self->allocated = size;
static PyObject *
array_buffer_info(arrayobject *self, PyObject *unused)
{
- PyObject* retval = NULL;
+ PyObject *retval = NULL, *v;
+
retval = PyTuple_New(2);
if (!retval)
return NULL;
- PyTuple_SET_ITEM(retval, 0, PyLong_FromVoidPtr(self->ob_item));
- PyTuple_SET_ITEM(retval, 1, PyInt_FromLong((long)(Py_SIZE(self))));
+ v = PyLong_FromVoidPtr(self->ob_item);
+ if (v == NULL) {
+ Py_DECREF(retval);
+ return NULL;
+ }
+ PyTuple_SET_ITEM(retval, 0, v);
+
+ v = PyInt_FromSsize_t(Py_SIZE(self));
+ if (v == NULL) {
+ Py_DECREF(retval);
+ return NULL;
+ }
+ PyTuple_SET_ITEM(retval, 1, v);
return retval;
}
/*
* linear2ulaw() accepts a 14-bit signed integer and encodes it as u-law data
- * stored in a unsigned char. This function should only be called with
+ * stored in an unsigned char. This function should only be called with
* the data shifted such that it only contains information in the lower
* 14-bits.
*
int signed_val;
if (!PyArg_ParseTuple(args, "s*|I:crc32", &pbuf, &crc32val))
- return NULL;
+ return NULL;
/* In Python 2.x we return a signed integer regardless of native platform
* long size (the 32bit unsigned long is treated as 32-bit signed and sign
* extended into a 64-bit long inside the integer object). 3.0 does the
odata[out++] = '=';
in++;
}
- else if (((data[in] >= 'A' && data[in] <= 'F') ||
+ else if ((in + 1 < datalen) &&
+ ((data[in] >= 'A' && data[in] <= 'F') ||
(data[in] >= 'a' && data[in] <= 'f') ||
(data[in] >= '0' && data[in] <= '9')) &&
((data[in+1] >= 'A' && data[in+1] <= 'F') ||
/* First, scan to see how many characters need to be encoded */
in = 0;
while (in < datalen) {
+ Py_ssize_t delta = 0;
if ((data[in] > 126) ||
(data[in] == '=') ||
(header && data[in] == '_') ||
((data[in] == '.') && (linelen == 0) &&
- (data[in+1] == '\n' || data[in+1] == '\r' || data[in+1] == 0)) ||
+ (in + 1 == datalen || data[in+1] == '\n' ||
+ data[in+1] == '\r' || data[in+1] == 0)) ||
(!istext && ((data[in] == '\r') || (data[in] == '\n'))) ||
((data[in] == '\t' || data[in] == ' ') && (in + 1 == datalen)) ||
((data[in] < 33) &&
if ((linelen + 3) >= MAXLINESIZE) {
linelen = 0;
if (crlf)
- odatalen += 3;
+ delta += 3;
else
- odatalen += 2;
+ delta += 2;
}
linelen += 3;
- odatalen += 3;
+ delta += 3;
in++;
}
else {
linelen = 0;
/* Protect against whitespace on end of line */
if (in && ((data[in-1] == ' ') || (data[in-1] == '\t')))
- odatalen += 2;
+ delta += 2;
if (crlf)
- odatalen += 2;
+ delta += 2;
else
- odatalen += 1;
+ delta += 1;
if (data[in] == '\r')
in += 2;
else
(linelen + 1) >= MAXLINESIZE) {
linelen = 0;
if (crlf)
- odatalen += 3;
+ delta += 3;
else
- odatalen += 2;
+ delta += 2;
}
linelen++;
- odatalen++;
+ delta++;
in++;
}
}
+ if (PY_SSIZE_T_MAX - delta < odatalen) {
+ PyBuffer_Release(&pdata);
+ PyErr_NoMemory();
+ return NULL;
+ }
+ odatalen += delta;
}
/* We allocate the output same size as input, this is overkill.
(data[in] == '=') ||
(header && data[in] == '_') ||
((data[in] == '.') && (linelen == 0) &&
- (data[in+1] == '\n' || data[in+1] == '\r' || data[in+1] == 0)) ||
+ (in + 1 == datalen || data[in+1] == '\n' ||
+ data[in+1] == '\r' || data[in+1] == 0)) ||
(!istext && ((data[in] == '\r') || (data[in] == '\n'))) ||
((data[in] == '\t' || data[in] == ' ') && (in + 1 == datalen)) ||
((data[in] < 33) &&
(data[in] != '\r') && (data[in] != '\n') &&
- (quotetabs ||
- (!quotetabs && ((data[in] != '\t') && (data[in] != ' '))))))
+ (quotetabs || ((data[in] != '\t') && (data[in] != ' ')))))
{
if ((linelen + 3 )>= MAXLINESIZE) {
odata[out++] = '=';
if (PyErr_WarnPy3k("the bsddb185 module has been removed in "
"Python 3.0", 2) < 0)
- return;
+ return;
Bsddbtype.ob_type = &PyType_Type;
m = Py_InitModule("bsddb185", bsddbmodule_methods);
#endif
if (size > PY_SSIZE_T_MAX / expandsize)
- return PyErr_NoMemory();
+ return PyErr_NoMemory();
repr = PyString_FromStringAndSize(NULL, expandsize * size);
if (repr == NULL)
- return NULL;
+ return NULL;
if (size == 0)
- return repr;
+ return repr;
p = q = PyString_AS_STRING(repr);
while (size-- > 0) {
- Py_UNICODE ch = *s++;
+ Py_UNICODE ch = *s++;
#ifdef Py_UNICODE_WIDE
- /* Map 32-bit characters to '\Uxxxxxxxx' */
- if (ch >= 0x10000) {
- *p++ = '\\';
- *p++ = 'U';
- *p++ = hexdigit[(ch >> 28) & 0xf];
- *p++ = hexdigit[(ch >> 24) & 0xf];
- *p++ = hexdigit[(ch >> 20) & 0xf];
- *p++ = hexdigit[(ch >> 16) & 0xf];
- *p++ = hexdigit[(ch >> 12) & 0xf];
- *p++ = hexdigit[(ch >> 8) & 0xf];
- *p++ = hexdigit[(ch >> 4) & 0xf];
- *p++ = hexdigit[ch & 15];
- }
- else
+ /* Map 32-bit characters to '\Uxxxxxxxx' */
+ if (ch >= 0x10000) {
+ *p++ = '\\';
+ *p++ = 'U';
+ *p++ = hexdigit[(ch >> 28) & 0xf];
+ *p++ = hexdigit[(ch >> 24) & 0xf];
+ *p++ = hexdigit[(ch >> 20) & 0xf];
+ *p++ = hexdigit[(ch >> 16) & 0xf];
+ *p++ = hexdigit[(ch >> 12) & 0xf];
+ *p++ = hexdigit[(ch >> 8) & 0xf];
+ *p++ = hexdigit[(ch >> 4) & 0xf];
+ *p++ = hexdigit[ch & 15];
+ }
+ else
#else
- /* Map UTF-16 surrogate pairs to '\U00xxxxxx' */
- if (ch >= 0xD800 && ch < 0xDC00) {
- Py_UNICODE ch2;
- Py_UCS4 ucs;
-
- ch2 = *s++;
- size--;
- if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) {
- ucs = (((ch & 0x03FF) << 10) | (ch2 & 0x03FF)) + 0x00010000;
- *p++ = '\\';
- *p++ = 'U';
- *p++ = hexdigit[(ucs >> 28) & 0xf];
- *p++ = hexdigit[(ucs >> 24) & 0xf];
- *p++ = hexdigit[(ucs >> 20) & 0xf];
- *p++ = hexdigit[(ucs >> 16) & 0xf];
- *p++ = hexdigit[(ucs >> 12) & 0xf];
- *p++ = hexdigit[(ucs >> 8) & 0xf];
- *p++ = hexdigit[(ucs >> 4) & 0xf];
- *p++ = hexdigit[ucs & 0xf];
- continue;
- }
- /* Fall through: isolated surrogates are copied as-is */
- s--;
- size++;
- }
+ /* Map UTF-16 surrogate pairs to '\U00xxxxxx' */
+ if (ch >= 0xD800 && ch < 0xDC00) {
+ Py_UNICODE ch2;
+ Py_UCS4 ucs;
+
+ ch2 = *s++;
+ size--;
+ if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) {
+ ucs = (((ch & 0x03FF) << 10) | (ch2 & 0x03FF)) + 0x00010000;
+ *p++ = '\\';
+ *p++ = 'U';
+ *p++ = hexdigit[(ucs >> 28) & 0xf];
+ *p++ = hexdigit[(ucs >> 24) & 0xf];
+ *p++ = hexdigit[(ucs >> 20) & 0xf];
+ *p++ = hexdigit[(ucs >> 16) & 0xf];
+ *p++ = hexdigit[(ucs >> 12) & 0xf];
+ *p++ = hexdigit[(ucs >> 8) & 0xf];
+ *p++ = hexdigit[(ucs >> 4) & 0xf];
+ *p++ = hexdigit[ucs & 0xf];
+ continue;
+ }
+ /* Fall through: isolated surrogates are copied as-is */
+ s--;
+ size++;
+ }
#endif
- /* Map 16-bit characters to '\uxxxx' */
- if (ch >= 256 || ch == '\\' || ch == '\n') {
- *p++ = '\\';
- *p++ = 'u';
- *p++ = hexdigit[(ch >> 12) & 0xf];
- *p++ = hexdigit[(ch >> 8) & 0xf];
- *p++ = hexdigit[(ch >> 4) & 0xf];
- *p++ = hexdigit[ch & 15];
- }
- /* Copy everything else as-is */
- else
- *p++ = (char) ch;
+ /* Map 16-bit characters to '\uxxxx' */
+ if (ch >= 256 || ch == '\\' || ch == '\n') {
+ *p++ = '\\';
+ *p++ = 'u';
+ *p++ = hexdigit[(ch >> 12) & 0xf];
+ *p++ = hexdigit[(ch >> 8) & 0xf];
+ *p++ = hexdigit[(ch >> 4) & 0xf];
+ *p++ = hexdigit[ch & 15];
+ }
+ /* Copy everything else as-is */
+ else
+ *p++ = (char) ch;
}
*p = '\0';
_PyString_Resize(&repr, p - q);
Py_DECREF(it);
Py_DECREF(s);
return NULL;
- }
- Py_DECREF(s);
- }
+ }
+ Py_DECREF(s);
+ }
- Py_DECREF(it);
+ Py_DECREF(it);
- /* See if PyIter_Next failed */
- if (PyErr_Occurred())
- return NULL;
+ /* See if PyIter_Next failed */
+ if (PyErr_Occurred())
+ return NULL;
- Py_RETURN_NONE;
+ Py_RETURN_NONE;
}
static struct PyMethodDef O_methods[] = {
/* Common methods: */
if (_PyString_Resize(&buf.outobj, finalsize) == -1)
goto errorexit;
- *data = buf.inbuf;
+ *data = buf.inbuf;
Py_XDECREF(buf.excobj);
return buf.outobj;
if (PyString_GET_SIZE(cres) > PY_SSIZE_T_MAX - self->pendingsize) {
PyErr_NoMemory();
goto errorexit;
- }
- rsize = PyString_GET_SIZE(cres) + self->pendingsize;
- ctr = PyString_FromStringAndSize(NULL, rsize);
- if (ctr == NULL)
- goto errorexit;
- ctrdata = PyString_AS_STRING(ctr);
- memcpy(ctrdata, self->pending, self->pendingsize);
- memcpy(ctrdata + self->pendingsize,
- PyString_AS_STRING(cres),
- PyString_GET_SIZE(cres));
- Py_DECREF(cres);
- cres = ctr;
- self->pendingsize = 0;
+ }
+ rsize = PyString_GET_SIZE(cres) + self->pendingsize;
+ ctr = PyString_FromStringAndSize(NULL, rsize);
+ if (ctr == NULL)
+ goto errorexit;
+ ctrdata = PyString_AS_STRING(ctr);
+ memcpy(ctrdata, self->pending, self->pendingsize);
+ memcpy(ctrdata + self->pendingsize,
+ PyString_AS_STRING(cres),
+ PyString_GET_SIZE(cres));
+ Py_DECREF(cres);
+ cres = ctr;
+ self->pendingsize = 0;
}
rsize = PyString_GET_SIZE(cres);
if (PyErr_WarnPy3k("the cl module has been removed in "
"Python 3.0", 2) < 0)
- return;
+ return;
m = Py_InitModule("cl", cl_methods);
if (m == NULL)
sizeof(_PyDateTime_BaseTime));
if (self == NULL)
return (PyObject *)PyErr_NoMemory();
- PyObject_INIT(self, type);
+ (void)PyObject_INIT(self, type);
return self;
}
sizeof(_PyDateTime_BaseDateTime));
if (self == NULL)
return (PyObject *)PyErr_NoMemory();
- PyObject_INIT(self, type);
+ (void)PyObject_INIT(self, type);
return self;
}
if (PyErr_WarnPy3k("the dl module has been removed in "
"Python 3.0; use the ctypes module instead", 2) < 0)
- return;
+ return;
/* Initialize object type */
Py_TYPE(&Dltype) = &PyType_Type;
*
*
* The Solution:
- * Prefix all a exported symbols with "PyExpat_". This is similar to
+ * Prefix all exported symbols with "PyExpat_". This is similar to
* what Mozilla does for some common libs:
* http://lxr.mozilla.org/seamonkey/source/modules/libimg/png/mozpngconf.h#115
*
See the file COPYING for copying permission.
*/
-#include <stddef.h>
-#include <string.h> /* memset(), memcpy() */
-#include <assert.h>
-#include <limits.h> /* UINT_MAX */
-#include <time.h> /* time() */
-
#define XML_BUILDING_EXPAT 1
#ifdef COMPILED_FROM_DSP
#include <expat_config.h>
#endif /* ndef COMPILED_FROM_DSP */
+#include <stddef.h>
+#include <string.h> /* memset(), memcpy() */
+#include <assert.h>
+#include <limits.h> /* UINT_MAX */
+#include <time.h> /* time() */
+
#include "ascii.h"
#include "expat.h"
int fd = PyObject_AsFileDescriptor(object);
if (fd < 0)
- return 0;
+ return 0;
*target = fd;
return 1;
}
g->ob_callback_arg = NULL;
}
else {
- PyObject *a, *b;
- if (!PyArg_UnpackTuple(args, "set_call_back", 2, 2, &a, &b))
- return NULL;
+ PyObject *a, *b;
+ if (!PyArg_UnpackTuple(args, "set_call_back", 2, 2, &a, &b))
+ return NULL;
Py_XDECREF(g->ob_callback);
Py_XDECREF(g->ob_callback_arg);
g->ob_callback = a;
PyMODINIT_FUNC
initfl(void)
{
-
if (PyErr_WarnPy3k("the fl module has been removed in "
"Python 3.0", 2) < 0)
- return;
+ return;
Py_InitModule("fl", forms_methods);
if (m == NULL)
void
initfm(void)
{
-
if (PyErr_WarnPy3k("the fm module has been removed in "
"Python 3.0", 2) < 0)
- return;
+ return;
Py_InitModule("fm", fm_methods);
if (m == NULL)
n = fread(rel_builddir_path, 1, MAXPATHLEN, f);
rel_builddir_path[n] = '\0';
fclose(f);
- if (n >= 0) {
- strcpy(exec_prefix, argv0_path);
- joinpath(exec_prefix, rel_builddir_path);
- return -1;
- }
+ strcpy(exec_prefix, argv0_path);
+ joinpath(exec_prefix, rel_builddir_path);
+ return -1;
}
}
if (defpath[0] != SEP) {
strcat(buf, prefix);
- strcat(buf, separator);
+ if (prefixsz >= 2 && prefix[prefixsz - 2] != SEP &&
+ defpath[0] != (delim ? DELIM : L'\0')) { /* not empty */
+ strcat(buf, separator);
+ }
}
if (delim) {
void
initgl(void)
{
-
if (PyErr_WarnPy3k("the gl module has been removed in "
"Python 3.0", 2) < 0)
- return;
+ return;
(void) Py_InitModule("gl", gl_methods);
}
PyDoc_STRVAR(chain_from_iterable_doc,
"chain.from_iterable(iterable) --> chain object\n\
\n\
-Alternate chain() contructor taking a single iterable argument\n\
+Alternate chain() constructor taking a single iterable argument\n\
that evaluates lazily.");
static PyMethodDef chain_methods[] = {
fi
makexp=`dirname $0`/makexp_aix
+test -x "${makexp}" || makexp="@abs_srcdir@/makexp_aix"
# Check for existence of compiler.
CC=$1; shift
(void) PyRun_SimpleFileExFlags(fp, startup, 0, cf);
PyErr_Clear();
fclose(fp);
- } else {
- int save_errno;
- save_errno = errno;
- PySys_WriteStderr("Could not open PYTHONSTARTUP\n");
- errno = save_errno;
- PyErr_SetFromErrnoWithFilename(PyExc_IOError,
- startup);
- PyErr_Print();
- PyErr_Clear();
+ } else {
+ int save_errno;
+ save_errno = errno;
+ PySys_WriteStderr("Could not open PYTHONSTARTUP\n");
+ errno = save_errno;
+ PyErr_SetFromErrnoWithFilename(PyExc_IOError,
+ startup);
+ PyErr_Print();
+ PyErr_Clear();
}
}
}
NL='\
'
-# Setup to link with extra libraries when makeing shared extensions.
+# Setup to link with extra libraries when making shared extensions.
# Currently, only Cygwin needs this baggage.
case `uname -s` in
CYGWIN*) if test $libdir = .
typedef struct {
PyObject_HEAD
char * data;
- size_t size;
- size_t pos; /* relative to offset */
+ Py_ssize_t size;
+ Py_ssize_t pos; /* relative to offset */
#ifdef MS_WINDOWS
PY_LONG_LONG offset;
#else
PyObject *unused)
{
CHECK_VALID(NULL);
- if (self->pos < self->size) {
- char value = self->data[self->pos];
- self->pos += 1;
- return Py_BuildValue("c", value);
- } else {
+ if (self->pos >= self->size) {
PyErr_SetString(PyExc_ValueError, "read byte out of range");
return NULL;
}
+ return PyString_FromStringAndSize(&self->data[self->pos++], 1);
}
static PyObject *
mmap_read_line_method(mmap_object *self,
PyObject *unused)
{
- char *start = self->data+self->pos;
- char *eof = self->data+self->size;
- char *eol;
+ Py_ssize_t remaining;
+ char *start, *eol;
PyObject *result;
CHECK_VALID(NULL);
- eol = memchr(start, '\n', self->size - self->pos);
+ remaining = (self->pos < self->size) ? self->size - self->pos : 0;
+ if (!remaining)
+ return PyString_FromString("");
+ start = self->data + self->pos;
+ eol = memchr(start, '\n', remaining);
if (!eol)
- eol = eof;
+ eol = self->data + self->size;
else
- ++eol; /* we're interested in the position after the
- newline. */
+ ++eol; /* advance past newline */
result = PyString_FromStringAndSize(start, (eol - start));
self->pos += (eol - start);
return result;
mmap_read_method(mmap_object *self,
PyObject *args)
{
- Py_ssize_t num_bytes, n;
+ Py_ssize_t num_bytes, remaining;
PyObject *result;
CHECK_VALID(NULL);
if (!PyArg_ParseTuple(args, "n:read", &num_bytes))
- return(NULL);
+ return NULL;
/* silently 'adjust' out-of-range requests */
- assert(self->size >= self->pos);
- n = self->size - self->pos;
- /* The difference can overflow, only if self->size is greater than
- * PY_SSIZE_T_MAX. But then the operation cannot possibly succeed,
- * because the mapped area and the returned string each need more
- * than half of the addressable memory. So we clip the size, and let
- * the code below raise MemoryError.
- */
- if (n < 0)
- n = PY_SSIZE_T_MAX;
- if (num_bytes < 0 || num_bytes > n) {
- num_bytes = n;
- }
- result = Py_BuildValue("s#", self->data+self->pos, num_bytes);
+ remaining = (self->pos < self->size) ? self->size - self->pos : 0;
+ if (num_bytes < 0 || num_bytes > remaining)
+ num_bytes = remaining;
+ result = PyString_FromStringAndSize(&self->data[self->pos], num_bytes);
self->pos += num_bytes;
return result;
}
start += self->size;
if (start < 0)
start = 0;
- else if ((size_t)start > self->size)
+ else if (start > self->size)
start = self->size;
if (end < 0)
end += self->size;
if (end < 0)
end = 0;
- else if ((size_t)end > self->size)
+ else if (end > self->size)
end = self->size;
start_p = self->data + start;
if (!is_writeable(self))
return NULL;
- if ((self->pos + length) > self->size) {
+ if (self->pos > self->size || self->size - self->pos < length) {
PyErr_SetString(PyExc_ValueError, "data out of range");
return NULL;
}
- memcpy(self->data+self->pos, data, length);
- self->pos = self->pos+length;
+ memcpy(&self->data[self->pos], data, length);
+ self->pos += length;
Py_INCREF(Py_None);
return Py_None;
}
return NULL;
if (self->pos < self->size) {
- *(self->data+self->pos) = value;
- self->pos += 1;
+ self->data[self->pos++] = value;
Py_INCREF(Py_None);
return Py_None;
}
if (!PyArg_ParseTuple(args, "n:resize", &new_size) ||
!is_resizeable(self)) {
return NULL;
+ }
+ if (new_size < 0 || PY_SSIZE_T_MAX - new_size < self->offset) {
+ PyErr_SetString(PyExc_ValueError, "new size out of range");
+ return NULL;
+ }
+
+ {
#ifdef MS_WINDOWS
- } else {
DWORD dwErrCode = 0;
DWORD off_hi, off_lo, newSizeLow, newSizeHigh;
/* First, unmap the file view */
#ifdef UNIX
#ifndef HAVE_MREMAP
- } else {
PyErr_SetString(PyExc_SystemError,
"mmap: resizing not available--no mremap()");
return NULL;
#else
- } else {
void *newmap;
- if (ftruncate(self->fd, self->offset + new_size) == -1) {
+ if (self->fd != -1 && ftruncate(self->fd, self->offset + new_size) == -1) {
PyErr_SetFromErrno(mmap_module_error);
return NULL;
}
#ifdef MREMAP_MAYMOVE
newmap = mremap(self->data, self->size, new_size, MREMAP_MAYMOVE);
#else
- #if defined(__NetBSD__)
- newmap = mremap(self->data, self->size, self->data, new_size, 0);
- #else
- newmap = mremap(self->data, self->size, new_size, 0);
- #endif /* __NetBSD__ */
+#if defined(__NetBSD__)
+ newmap = mremap(self->data, self->size, self->data, new_size, 0);
+#else
+ newmap = mremap(self->data, self->size, new_size, 0);
+#endif /* __NetBSD__ */
#endif
if (newmap == (void *)-1)
{
CHECK_VALID(NULL);
if (!PyArg_ParseTuple(args, "|nn:flush", &offset, &size))
return NULL;
- if ((size_t)(offset + size) > self->size) {
+ if (size < 0 || offset < 0 || self->size - offset < size) {
PyErr_SetString(PyExc_ValueError, "flush values out of range");
return NULL;
}
if (!PyArg_ParseTuple(args, "n|i:seek", &dist, &how))
return NULL;
else {
- size_t where;
+ Py_ssize_t where;
switch (how) {
case 0: /* relative to start */
- if (dist < 0)
- goto onoutofrange;
where = dist;
break;
case 1: /* relative to current position */
- if ((Py_ssize_t)self->pos + dist < 0)
+ if (PY_SSIZE_T_MAX - self->pos < dist)
goto onoutofrange;
where = self->pos + dist;
break;
case 2: /* relative to end */
- if ((Py_ssize_t)self->size + dist < 0)
+ if (PY_SSIZE_T_MAX - self->size < dist)
goto onoutofrange;
where = self->size + dist;
break;
PyErr_SetString(PyExc_ValueError, "unknown seek type");
return NULL;
}
- if (where > self->size)
+ if (where > self->size || where < 0)
goto onoutofrange;
self->pos = where;
Py_INCREF(Py_None);
static PyObject *
mmap_move_method(mmap_object *self, PyObject *args)
{
- unsigned long dest, src, cnt;
+ Py_ssize_t dest, src, cnt;
CHECK_VALID(NULL);
- if (!PyArg_ParseTuple(args, "kkk:move", &dest, &src, &cnt) ||
+ if (!PyArg_ParseTuple(args, "nnn:move", &dest, &src, &cnt) ||
!is_writeable(self)) {
return NULL;
} else {
/* bounds check the values */
- if (cnt < 0 || (cnt + dest) < cnt || (cnt + src) < cnt ||
- src < 0 || src > self->size || (src + cnt) > self->size ||
- dest < 0 || dest > self->size || (dest + cnt) > self->size) {
- PyErr_SetString(PyExc_ValueError,
- "source, destination, or count out of range");
- return NULL;
- }
- memmove(self->data+dest, self->data+src, cnt);
+ if (dest < 0 || src < 0 || cnt < 0)
+ goto bounds;
+ if (self->size - dest < cnt || self->size - src < cnt)
+ goto bounds;
+
+ memmove(&self->data[dest], &self->data[src], cnt);
+
Py_INCREF(Py_None);
return Py_None;
+
+ bounds:
+ PyErr_SetString(PyExc_ValueError,
+ "source, destination, or count out of range");
+ return NULL;
}
}
mmap_item(mmap_object *self, Py_ssize_t i)
{
CHECK_VALID(NULL);
- if (i < 0 || (size_t)i >= self->size) {
+ if (i < 0 || i >= self->size) {
PyErr_SetString(PyExc_IndexError, "mmap index out of range");
return NULL;
}
CHECK_VALID(NULL);
if (ilow < 0)
ilow = 0;
- else if ((size_t)ilow > self->size)
+ else if (ilow > self->size)
ilow = self->size;
if (ihigh < 0)
ihigh = 0;
if (ihigh < ilow)
ihigh = ilow;
- else if ((size_t)ihigh > self->size)
+ else if (ihigh > self->size)
ihigh = self->size;
return PyString_FromStringAndSize(self->data + ilow, ihigh-ilow);
return NULL;
if (i < 0)
i += self->size;
- if (i < 0 || (size_t)i >= self->size) {
+ if (i < 0 || i >= self->size) {
PyErr_SetString(PyExc_IndexError,
"mmap index out of range");
return NULL;
CHECK_VALID(-1);
if (ilow < 0)
ilow = 0;
- else if ((size_t)ilow > self->size)
+ else if (ilow > self->size)
ilow = self->size;
if (ihigh < 0)
ihigh = 0;
if (ihigh < ilow)
ihigh = ilow;
- else if ((size_t)ihigh > self->size)
+ else if (ihigh > self->size)
ihigh = self->size;
if (v == NULL) {
const char *buf;
CHECK_VALID(-1);
- if (i < 0 || (size_t)i >= self->size) {
+ if (i < 0 || i >= self->size) {
PyErr_SetString(PyExc_IndexError, "mmap index out of range");
return -1;
}
return -1;
if (i < 0)
i += self->size;
- if (i < 0 || (size_t)i >= self->size) {
+ if (i < 0 || i >= self->size) {
PyErr_SetString(PyExc_IndexError,
"mmap index out of range");
return -1;
};
-/* extract the map size from the given PyObject
-
- Returns -1 on error, with an appropriate Python exception raised. On
- success, the map size is returned. */
-static Py_ssize_t
-_GetMapSize(PyObject *o, const char* param)
-{
- if (o == NULL)
- return 0;
- if (PyIndex_Check(o)) {
- Py_ssize_t i = PyNumber_AsSsize_t(o, PyExc_OverflowError);
- if (i==-1 && PyErr_Occurred())
- return -1;
- if (i < 0) {
- PyErr_Format(PyExc_OverflowError,
- "memory mapped %s must be positive",
- param);
- return -1;
- }
- return i;
- }
-
- PyErr_SetString(PyExc_TypeError, "map size must be an integral value");
- return -1;
-}
-
#ifdef UNIX
#ifdef HAVE_LARGEFILE_SUPPORT
#define _Py_PARSE_OFF_T "L"
struct stat st;
#endif
mmap_object *m_obj;
- PyObject *map_size_obj = NULL;
Py_ssize_t map_size;
off_t offset = 0;
int fd, flags = MAP_SHARED, prot = PROT_WRITE | PROT_READ;
"flags", "prot",
"access", "offset", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iO|iii" _Py_PARSE_OFF_T, keywords,
- &fd, &map_size_obj, &flags, &prot,
+ if (!PyArg_ParseTupleAndKeywords(args, kwdict, "in|iii" _Py_PARSE_OFF_T, keywords,
+ &fd, &map_size, &flags, &prot,
&access, &offset))
return NULL;
- map_size = _GetMapSize(map_size_obj, "size");
- if (map_size < 0)
+ if (map_size < 0) {
+ PyErr_SetString(PyExc_OverflowError,
+ "memory mapped length must be postiive");
return NULL;
+ }
if (offset < 0) {
PyErr_SetString(PyExc_OverflowError,
"memory mapped offset must be positive");
return NULL;
}
map_size = (Py_ssize_t) (st.st_size - offset);
- } else if (offset + (size_t)map_size > st.st_size) {
+ } else if (offset > st.st_size || st.st_size - offset < map_size) {
PyErr_SetString(PyExc_ValueError,
"mmap length is greater than file size");
return NULL;
m_obj = (mmap_object *)type->tp_alloc(type, 0);
if (m_obj == NULL) {return NULL;}
m_obj->data = NULL;
- m_obj->size = (size_t) map_size;
- m_obj->pos = (size_t) 0;
+ m_obj->size = map_size;
+ m_obj->pos = 0;
m_obj->offset = offset;
if (fd == -1) {
m_obj->fd = -1;
new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
{
mmap_object *m_obj;
- PyObject *map_size_obj = NULL;
Py_ssize_t map_size;
PY_LONG_LONG offset = 0, size;
DWORD off_hi; /* upper 32 bits of offset */
"tagname",
"access", "offset", NULL };
- if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iO|ziL", keywords,
- &fileno, &map_size_obj,
+ if (!PyArg_ParseTupleAndKeywords(args, kwdict, "in|ziL", keywords,
+ &fileno, &map_size,
&tagname, &access, &offset)) {
return NULL;
}
"mmap invalid access parameter.");
}
- map_size = _GetMapSize(map_size_obj, "size");
- if (map_size < 0)
+ if (map_size < 0) {
+ PyErr_SetString(PyExc_OverflowError,
+ "memory mapped length must be postiive");
return NULL;
+ }
if (offset < 0) {
PyErr_SetString(PyExc_OverflowError,
"memory mapped offset must be positive");
methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
methodcallerobject *mc;
- PyObject *name, *newargs;
+ PyObject *name;
if (PyTuple_GET_SIZE(args) < 1) {
PyErr_SetString(PyExc_TypeError, "methodcaller needs at least "
if (mc == NULL)
return NULL;
- newargs = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
- if (newargs == NULL) {
- Py_DECREF(mc);
- return NULL;
- }
- mc->args = newargs;
-
name = PyTuple_GET_ITEM(args, 0);
Py_INCREF(name);
mc->name = name;
Py_XINCREF(kwds);
mc->kwds = kwds;
+ mc->args = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
+ if (mc->args == NULL) {
+ Py_DECREF(mc);
+ return NULL;
+ }
+
PyObject_GC_Track(mc);
return (PyObject *)mc;
}
PyObject *result;
#ifdef MS_WINDOWS
- PyUnicodeObject *po;
- if (PyArg_ParseTuple(args, wformat, &po)) {
- Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po);
-
+ Py_UNICODE *wpath;
+ if (PyArg_ParseTuple(args, wformat, &wpath)) {
Py_BEGIN_ALLOW_THREADS
- /* PyUnicode_AS_UNICODE result OK without
- thread lock as it is a simple dereference. */
res = wstatfunc(wpath, &st);
Py_END_ALLOW_THREADS
#ifdef MS_WINDOWS
DWORD attr;
- PyUnicodeObject *po;
- if (PyArg_ParseTuple(args, "Ui:access", &po, &mode)) {
+ Py_UNICODE *wpath;
+ if (PyArg_ParseTuple(args, "ui:access", &wpath, &mode)) {
Py_BEGIN_ALLOW_THREADS
- /* PyUnicode_AS_UNICODE OK without thread lock as
- it is a simple dereference. */
- attr = GetFileAttributesW(PyUnicode_AS_UNICODE(po));
+ attr = GetFileAttributesW(wpath);
Py_END_ALLOW_THREADS
goto finish;
}
int res;
#ifdef MS_WINDOWS
DWORD attr;
- PyUnicodeObject *po;
- if (PyArg_ParseTuple(args, "Ui|:chmod", &po, &i)) {
+ Py_UNICODE *wpath;
+ if (PyArg_ParseTuple(args, "ui|:chmod", &wpath, &i)) {
Py_BEGIN_ALLOW_THREADS
- attr = GetFileAttributesW(PyUnicode_AS_UNICODE(po));
+ attr = GetFileAttributesW(wpath);
if (attr != 0xFFFFFFFF) {
if (i & _S_IWRITE)
attr &= ~FILE_ATTRIBUTE_READONLY;
else
attr |= FILE_ATTRIBUTE_READONLY;
- res = SetFileAttributesW(PyUnicode_AS_UNICODE(po), attr);
+ res = SetFileAttributesW(wpath, attr);
}
else
res = 0;
Py_END_ALLOW_THREADS
if (!res)
- return win32_error_unicode("chmod",
- PyUnicode_AS_UNICODE(po));
+ return win32_error_unicode("chmod", wpath);
Py_INCREF(Py_None);
return Py_None;
}
char *bufptr = namebuf;
Py_ssize_t len = sizeof(namebuf)-5; /* only claim to have space for MAX_PATH */
- PyObject *po;
- if (PyArg_ParseTuple(args, "U:listdir", &po)) {
+ Py_UNICODE *wpath;
+ if (PyArg_ParseTuple(args, "u:listdir", &wpath)) {
WIN32_FIND_DATAW wFileData;
Py_UNICODE *wnamebuf;
/* Overallocate for \\*.*\0 */
- len = PyUnicode_GET_SIZE(po);
+ len = wcslen(wpath);
wnamebuf = malloc((len + 5) * sizeof(wchar_t));
if (!wnamebuf) {
PyErr_NoMemory();
return NULL;
}
- wcscpy(wnamebuf, PyUnicode_AS_UNICODE(po));
+ wcscpy(wnamebuf, wpath);
if (len > 0) {
Py_UNICODE wch = wnamebuf[len-1];
if (wch != L'/' && wch != L'\\' && wch != L':')
char outbuf[MAX_PATH*2];
char *temp;
- PyUnicodeObject *po;
- if (PyArg_ParseTuple(args, "U|:_getfullpathname", &po)) {
- Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po);
+ Py_UNICODE *wpath;
+ if (PyArg_ParseTuple(args, "u|:_getfullpathname", &wpath)) {
Py_UNICODE woutbuf[MAX_PATH*2], *woutbufp = woutbuf;
Py_UNICODE *wtemp;
DWORD result;
int mode = 0777;
#ifdef MS_WINDOWS
- PyUnicodeObject *po;
- if (PyArg_ParseTuple(args, "U|i:mkdir", &po, &mode)) {
+ Py_UNICODE *wpath;
+ if (PyArg_ParseTuple(args, "u|i:mkdir", &wpath, &mode)) {
Py_BEGIN_ALLOW_THREADS
- /* PyUnicode_AS_UNICODE OK without thread lock as
- it is a simple dereference. */
- res = CreateDirectoryW(PyUnicode_AS_UNICODE(po), NULL);
+ res = CreateDirectoryW(wpath, NULL);
Py_END_ALLOW_THREADS
if (!res)
- return win32_error_unicode("mkdir", PyUnicode_AS_UNICODE(po));
+ return win32_error_unicode("mkdir", wpath);
Py_INCREF(Py_None);
return Py_None;
}
Py_FileSystemDefaultEncoding, &path, &mode))
return NULL;
Py_BEGIN_ALLOW_THREADS
- /* PyUnicode_AS_UNICODE OK without thread lock as
- it is a simple dereference. */
res = CreateDirectoryA(path, NULL);
Py_END_ALLOW_THREADS
if (!res) {
posix_stat(PyObject *self, PyObject *args)
{
#ifdef MS_WINDOWS
- return posix_do_stat(self, args, "et:stat", STAT, "U:stat", win32_wstat);
+ return posix_do_stat(self, args, "et:stat", STAT, "u:stat", win32_wstat);
#else
return posix_do_stat(self, args, "et:stat", STAT, NULL, NULL);
#endif
{
#ifdef MS_WINDOWS
PyObject *arg;
- PyUnicodeObject *obwpath;
wchar_t *wpath = NULL;
char *apath = NULL;
HANDLE hFile;
FILETIME atime, mtime;
PyObject *result = NULL;
- if (PyArg_ParseTuple(args, "UO|:utime", &obwpath, &arg)) {
- wpath = PyUnicode_AS_UNICODE(obwpath);
+ if (PyArg_ParseTuple(args, "uO|:utime", &wpath, &arg)) {
Py_BEGIN_ALLOW_THREADS
hFile = CreateFileW(wpath, FILE_WRITE_ATTRIBUTES, 0,
NULL, OPEN_EXISTING,
static PyObject *
posix__isdir(PyObject *self, PyObject *args)
{
- PyObject *opath;
char *path;
- PyUnicodeObject *po;
+ Py_UNICODE *wpath;
DWORD attributes;
- if (PyArg_ParseTuple(args, "U|:_isdir", &po)) {
- Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po);
-
+ if (PyArg_ParseTuple(args, "u|:_isdir", &wpath)) {
attributes = GetFileAttributesW(wpath);
if (attributes == INVALID_FILE_ATTRIBUTES)
Py_RETURN_FALSE;
return posix_do_stat(self, args, "et:lstat", lstat, NULL, NULL);
#else /* !HAVE_LSTAT */
#ifdef MS_WINDOWS
- return posix_do_stat(self, args, "et:lstat", STAT, "U:lstat", win32_wstat);
+ return posix_do_stat(self, args, "et:lstat", STAT, "u:lstat", win32_wstat);
#else
return posix_do_stat(self, args, "et:lstat", STAT, NULL, NULL);
#endif
int fd;
#ifdef MS_WINDOWS
- PyUnicodeObject *po;
- if (PyArg_ParseTuple(args, "Ui|i:mkdir", &po, &flag, &mode)) {
+ Py_UNICODE *wpath;
+ if (PyArg_ParseTuple(args, "ui|i:mkdir", &wpath, &flag, &mode)) {
Py_BEGIN_ALLOW_THREADS
- /* PyUnicode_AS_UNICODE OK without thread
- lock as it is a simple dereference. */
- fd = _wopen(PyUnicode_AS_UNICODE(po), flag, mode);
+ fd = _wopen(wpath, flag, mode);
Py_END_ALLOW_THREADS
if (fd < 0)
return posix_error();
#endif
Py_END_ALLOW_THREADS
PyMem_FREE(mode);
- if (fp == NULL)
+ if (fp == NULL) {
+ Py_DECREF(f);
return posix_error();
+ }
/* We now know we will succeed, so initialize the file object. */
((PyFileObject *)f)->f_fp = fp;
PyFile_SetBufSize(f, bufsize);
win32_startfile(PyObject *self, PyObject *args)
{
char *filepath;
+ Py_UNICODE *wpath;
char *operation = NULL;
HINSTANCE rc;
- PyObject *unipath, *woperation = NULL;
- if (!PyArg_ParseTuple(args, "U|s:startfile",
- &unipath, &operation)) {
+ PyObject *woperation = NULL;
+ if (!PyArg_ParseTuple(args, "u|s:startfile",
+ &wpath, &operation)) {
PyErr_Clear();
goto normal;
}
Py_BEGIN_ALLOW_THREADS
rc = ShellExecuteW((HWND)0, woperation ? PyUnicode_AS_UNICODE(woperation) : 0,
- PyUnicode_AS_UNICODE(unipath),
+ wpath,
NULL, NULL, SW_SHOWNORMAL);
Py_END_ALLOW_THREADS
Py_XDECREF(woperation);
if (rc <= (HINSTANCE)32) {
- PyObject *errval = win32_error_unicode("startfile",
- PyUnicode_AS_UNICODE(unipath));
+ PyObject *errval = win32_error_unicode("startfile", wpath);
return errval;
}
Py_INCREF(Py_None);
static int libedit_history_start = 0;
#endif /* __APPLE__ */
+#ifdef HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK
static void
on_completion_display_matches_hook(char **matches,
int num_matches, int max_length);
-
+#endif
/* Memory allocated for rl_completer_word_break_characters
(see issue #17289 for the motivation). */
/* C function to call the Python completion_display_matches */
+#ifdef HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK
static void
on_completion_display_matches_hook(char **matches,
int num_matches, int max_length)
#endif
}
+#endif
#ifdef HAVE_RL_RESIZE_TERMINAL
static volatile sig_atomic_t sigwinch_received;
begidx = PyInt_FromLong(0L);
endidx = PyInt_FromLong(0L);
-#ifndef __APPLE__
- if (!isatty(STDOUT_FILENO)) {
- /* Issue #19884: stdout is not a terminal. Disable meta modifier
- keys to not write the ANSI sequence "\033[1034h" into stdout. On
- terminals supporting 8 bit characters like TERM=xterm-256color
- (which is now the default Fedora since Fedora 18), the meta key is
- used to enable support of 8 bit characters (ANSI sequence
- "\033[1034h").
-
- With libedit, this call makes readline() crash. */
- rl_variable_bind ("enable-meta-key", "off");
- }
+#ifdef __APPLE__
+ if (!using_libedit_emulation)
#endif
+ {
+ if (!isatty(STDOUT_FILENO)) {
+ /* Issue #19884: stdout is not a terminal. Disable meta modifier
+ keys to not write the ANSI sequence "\033[1034h" into stdout. On
+ terminals supporting 8 bit characters like TERM=xterm-256color
+ (which is now the default Fedora since Fedora 18), the meta key is
+ used to enable support of 8 bit characters (ANSI sequence
+ "\033[1034h").
+
+ With libedit, this call makes readline() crash. */
+ rl_variable_bind ("enable-meta-key", "off");
+ }
+ }
/* Initialize (allows .inputrc to override)
*
return NULL;
}
- /* We got an EOF, return a empty string. */
+ /* We got an EOF, return an empty string. */
if (p == NULL) {
p = PyMem_Malloc(1);
if (p != NULL)
r = PyTuple_New(2);
if (r == NULL)
- return NULL;
+ return NULL;
if(!(v = PyFloat_FromDouble(double_from_timeval(&iv->it_value)))) {
- Py_DECREF(r);
- return NULL;
+ Py_DECREF(r);
+ return NULL;
}
PyTuple_SET_ITEM(r, 0, v);
if(!(v = PyFloat_FromDouble(double_from_timeval(&iv->it_interval)))) {
- Py_DECREF(r);
- return NULL;
+ Py_DECREF(r);
+ return NULL;
}
PyTuple_SET_ITEM(r, 1, v);
struct itimerval new, old;
if(!PyArg_ParseTuple(args, "id|d:setitimer", &which, &first, &interval))
- return NULL;
+ return NULL;
timeval_from_double(first, &new.it_value);
timeval_from_double(interval, &new.it_interval);
/* Let OS check "which" value */
if (setitimer(which, &new, &old) != 0) {
- PyErr_SetFromErrno(ItimerError);
- return NULL;
+ PyErr_SetFromErrno(ItimerError);
+ return NULL;
}
return itimer_retval(&old);
struct itimerval old;
if (!PyArg_ParseTuple(args, "i:getitimer", &which))
- return NULL;
+ return NULL;
if (getitimer(which, &old) != 0) {
- PyErr_SetFromErrno(ItimerError);
- return NULL;
+ PyErr_SetFromErrno(ItimerError);
+ return NULL;
}
return itimer_retval(&old);
#if defined (HAVE_SETITIMER) || defined (HAVE_GETITIMER)
ItimerError = PyErr_NewException("signal.ItimerError",
- PyExc_IOError, NULL);
+ PyExc_IOError, NULL);
if (ItimerError != NULL)
- PyDict_SetItemString(d, "ItimerError", ItimerError);
+ PyDict_SetItemString(d, "ItimerError", ItimerError);
#endif
#ifdef CTRL_C_EVENT
#endif
#ifdef HAVE_GETHOSTBYNAME_R
-# if defined(_AIX) || defined(__osf__)
+# if defined(_AIX) && !defined(_LINUX_SOURCE_COMPAT) || defined(__osf__)
# define HAVE_GETHOSTBYNAME_R_3_ARG
# elif defined(__sun) || defined(__sgi)
# define HAVE_GETHOSTBYNAME_R_5_ARG
# elif defined(linux)
/* Rely on the configure script */
+# elif defined(_LINUX_SOURCE_COMPAT) /* Linux compatibility on AIX */
+# define HAVE_GETHOSTBYNAME_R_6_ARG
# else
# undef HAVE_GETHOSTBYNAME_R
# endif
*/
#define BEGIN_SELECT_LOOP(s) \
{ \
- double deadline, interval = s->sock_timeout; \
+ double deadline = 0, interval = s->sock_timeout; \
int has_timeout = s->sock_timeout > 0.0; \
if (has_timeout) { \
deadline = _PyTime_FloatTime() + s->sock_timeout; \
return 1;
}
#endif /* AF_UNIX */
+
#if defined(AF_NETLINK)
- case AF_NETLINK:
- {
- *len_ret = sizeof (struct sockaddr_nl);
- return 1;
- }
+ case AF_NETLINK:
+ {
+ *len_ret = sizeof (struct sockaddr_nl);
+ return 1;
+ }
#endif
case AF_INET:
int buf_len = (sizeof buf) - 1;
int errnop;
#endif
-#if defined(HAVE_GETHOSTBYNAME_R_3_ARG) || defined(HAVE_GETHOSTBYNAME_R_6_ARG)
+#ifdef HAVE_GETHOSTBYNAME_R_3_ARG
int result;
#endif
#endif /* HAVE_GETHOSTBYNAME_R */
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_GETHOSTBYNAME_R
#if defined(HAVE_GETHOSTBYNAME_R_6_ARG)
- result = gethostbyname_r(name, &hp_allocated, buf, buf_len,
+ gethostbyname_r(name, &hp_allocated, buf, buf_len,
&h, &errnop);
#elif defined(HAVE_GETHOSTBYNAME_R_5_ARG)
h = gethostbyname_r(name, &hp_allocated, buf, buf_len, &errnop);
int buf_len = (sizeof buf) - 1;
int errnop;
#endif
-#if defined(HAVE_GETHOSTBYNAME_R_3_ARG) || defined(HAVE_GETHOSTBYNAME_R_6_ARG)
+#ifdef HAVE_GETHOSTBYNAME_R_3_ARG
int result;
#endif
#endif /* HAVE_GETHOSTBYNAME_R */
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_GETHOSTBYNAME_R
#if defined(HAVE_GETHOSTBYNAME_R_6_ARG)
- result = gethostbyaddr_r(ap, al, af,
+ gethostbyaddr_r(ap, al, af,
&hp_allocated, buf, buf_len,
&h, &errnop);
#elif defined(HAVE_GETHOSTBYNAME_R_5_ARG)
{
if (PyErr_WarnPy3k("the timing module has been removed in "
"Python 3.0; use time.clock() instead", 2) < 0)
- return;
+ return;
(void)Py_InitModule("timing", timing_methods);
}
int
Tcl_AppInit(Tcl_Interp *interp)
{
+#ifdef WITH_MOREBUTTONS
Tk_Window main_window;
+#endif
const char *_tkinter_skip_tk_init;
#ifdef TKINTER_PROTECT_LOADTK
const char *_tkinter_tk_failed;
return TCL_ERROR;
}
+#ifdef WITH_MOREBUTTONS
main_window = Tk_MainWindow(interp);
+#else
+ Tk_MainWindow(interp);
+#endif
#ifdef TK_AQUA
TkMacOSXInitAppleEvents(interp);
if (!PyArg_ParseTuple(args, "s:zipimporter.get_filename",
&fullname))
- return NULL;
+ return NULL;
/* Deciding the filename requires working out where the code
would come from if the module was actually loaded */
code = get_module_code(self, fullname, &ispackage, &modpath);
if (code == NULL)
- return NULL;
+ return NULL;
Py_DECREF(code); /* Only need the path info */
return PyString_FromString(modpath);
A toc_entry is a tuple:
- (__file__, # value to use for __file__, available for all files
+ (__file__, # value to use for __file__, available for all files
compress, # compression kind; 0 for uncompressed
data_size, # size of compressed data on disk
file_size, # size of decompressed data
time, # mod time of file (in dos format)
date, # mod data of file (in dos format)
crc, # crc checksum of the data
- )
+ )
Directories can be recognized by the trailing SEP in the name,
data_size and file_offset are 0.
return code;
}
-/* Replace any occurances of "\r\n?" in the input string with "\n".
+/* Replace any occurrences of "\r\n?" in the input string with "\n".
This converts DOS and Mac line endings to Unix line endings.
Also append a trailing "\n" to be compatible with
PyParser_SimpleParseFile(). Returns a new reference. */
/* zlibmodule.c -- gzip-compatible data compression */
-/* See http://www.gzip.org/zlib/ */
+/* See http://zlib.net/ */
/* Windows users: read Python's PCbuild\readme.txt */
+#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "zlib.h"
return self;
}
+static void
+arrange_input_buffer(z_stream *zst, Py_ssize_t *remains)
+{
+ if ((size_t)*remains > UINT_MAX) {
+ zst->avail_in = UINT_MAX;
+ } else {
+ zst->avail_in = *remains;
+ }
+ *remains -= zst->avail_in;
+}
+
+static Py_ssize_t
+arrange_output_buffer_with_maximum(z_stream *zst, PyObject **buffer,
+ Py_ssize_t length,
+ Py_ssize_t max_length)
+{
+ Py_ssize_t occupied;
+
+ if (*buffer == NULL) {
+ if (!(*buffer = PyBytes_FromStringAndSize(NULL, length)))
+ return -1;
+ occupied = 0;
+ }
+ else {
+ occupied = zst->next_out - (Byte *)PyBytes_AS_STRING(*buffer);
+
+ if (length == occupied) {
+ Py_ssize_t new_length;
+ assert(length <= max_length);
+ /* can not scale the buffer over max_length */
+ if (length == max_length)
+ return -2;
+ if (length <= (max_length >> 1))
+ new_length = length << 1;
+ else
+ new_length = max_length;
+ if (_PyBytes_Resize(buffer, new_length) < 0)
+ return -1;
+ length = new_length;
+ }
+ }
+
+ if ((size_t)(length - occupied) > UINT_MAX) {
+ zst->avail_out = UINT_MAX;
+ } else {
+ zst->avail_out = length - occupied;
+ }
+ zst->next_out = (Byte *)PyBytes_AS_STRING(*buffer) + occupied;
+
+ return length;
+}
+
+static Py_ssize_t
+arrange_output_buffer(z_stream *zst, PyObject **buffer, Py_ssize_t length)
+{
+ Py_ssize_t ret;
+
+ ret = arrange_output_buffer_with_maximum(zst, buffer, length,
+ PY_SSIZE_T_MAX);
+ if (ret == -2)
+ PyErr_NoMemory();
+
+ return ret;
+}
+
PyDoc_STRVAR(compress__doc__,
"compress(string[, level]) -- Returned compressed string.\n"
"\n"
static PyObject *
PyZlib_compress(PyObject *self, PyObject *args)
{
- PyObject *ReturnVal = NULL;
- Byte *input, *output;
- int length, level=Z_DEFAULT_COMPRESSION, err;
+ PyObject *RetVal = NULL;
+ Byte *ibuf;
+ Py_ssize_t ibuflen, obuflen = DEFAULTALLOC;
+ int level=Z_DEFAULT_COMPRESSION;
+ int err, flush;
z_stream zst;
/* require Python string object, optional 'level' arg */
- if (!PyArg_ParseTuple(args, "s#|i:compress", &input, &length, &level))
- return NULL;
-
- zst.avail_out = length + length/1000 + 12 + 1;
-
- output = (Byte*)malloc(zst.avail_out);
- if (output == NULL) {
- PyErr_SetString(PyExc_MemoryError,
- "Can't allocate memory to compress data");
+ if (!PyArg_ParseTuple(args, "s#|i:compress", &ibuf, &ibuflen, &level))
return NULL;
- }
-
- /* Past the point of no return. From here on out, we need to make sure
- we clean up mallocs & INCREFs. */
zst.zalloc = (alloc_func)NULL;
zst.zfree = (free_func)Z_NULL;
- zst.next_out = (Byte *)output;
- zst.next_in = (Byte *)input;
- zst.avail_in = length;
+ zst.next_in = ibuf;
err = deflateInit(&zst, level);
- switch(err) {
- case(Z_OK):
+ switch (err) {
+ case Z_OK:
break;
- case(Z_MEM_ERROR):
+ case Z_MEM_ERROR:
PyErr_SetString(PyExc_MemoryError,
"Out of memory while compressing data");
goto error;
- case(Z_STREAM_ERROR):
- PyErr_SetString(ZlibError,
- "Bad compression level");
+ case Z_STREAM_ERROR:
+ PyErr_SetString(ZlibError, "Bad compression level");
goto error;
default:
deflateEnd(&zst);
goto error;
}
- Py_BEGIN_ALLOW_THREADS;
- err = deflate(&zst, Z_FINISH);
- Py_END_ALLOW_THREADS;
+ do {
+ arrange_input_buffer(&zst, &ibuflen);
+ flush = ibuflen == 0 ? Z_FINISH : Z_NO_FLUSH;
- if (err != Z_STREAM_END) {
- zlib_error(zst, err, "while compressing data");
- deflateEnd(&zst);
- goto error;
- }
+ do {
+ obuflen = arrange_output_buffer(&zst, &RetVal, obuflen);
+ if (obuflen < 0) {
+ deflateEnd(&zst);
+ goto error;
+ }
+
+ Py_BEGIN_ALLOW_THREADS
+ err = deflate(&zst, flush);
+ Py_END_ALLOW_THREADS
+
+ if (err == Z_STREAM_ERROR) {
+ deflateEnd(&zst);
+ zlib_error(zst, err, "while compressing data");
+ goto error;
+ }
+
+ } while (zst.avail_out == 0);
+ assert(zst.avail_in == 0);
- err=deflateEnd(&zst);
- if (err == Z_OK)
- ReturnVal = PyString_FromStringAndSize((char *)output,
- zst.total_out);
+ } while (flush != Z_FINISH);
+ assert(err == Z_STREAM_END);
+
+ err = deflateEnd(&zst);
+ if (err == Z_OK) {
+ if (_PyBytes_Resize(&RetVal, zst.next_out -
+ (Byte *)PyBytes_AS_STRING(RetVal)) < 0)
+ goto error;
+ return RetVal;
+ }
else
zlib_error(zst, err, "while finishing compression");
-
error:
- free(output);
-
- return ReturnVal;
+ Py_XDECREF(RetVal);
+ return NULL;
}
PyDoc_STRVAR(decompress__doc__,
static PyObject *
PyZlib_decompress(PyObject *self, PyObject *args)
{
- PyObject *result_str;
- Byte *input;
- int length, err;
+ PyObject *RetVal = NULL;
+ Byte *ibuf;
+ Py_ssize_t ibuflen;
+ int err, flush;
int wsize=DEF_WBITS;
Py_ssize_t r_strlen=DEFAULTALLOC;
z_stream zst;
if (!PyArg_ParseTuple(args, "s#|in:decompress",
- &input, &length, &wsize, &r_strlen))
+ &ibuf, &ibuflen, &wsize, &r_strlen))
return NULL;
- if (r_strlen <= 0)
+ if (r_strlen <= 0) {
r_strlen = 1;
-
- zst.avail_in = length;
- zst.avail_out = r_strlen;
-
- if (!(result_str = PyString_FromStringAndSize(NULL, r_strlen)))
- return NULL;
+ }
zst.zalloc = (alloc_func)NULL;
zst.zfree = (free_func)Z_NULL;
- zst.next_out = (Byte *)PyString_AS_STRING(result_str);
- zst.next_in = (Byte *)input;
+ zst.avail_in = 0;
+ zst.next_in = ibuf;
err = inflateInit2(&zst, wsize);
- switch(err) {
- case(Z_OK):
+ switch (err) {
+ case Z_OK:
break;
- case(Z_MEM_ERROR):
+ case Z_MEM_ERROR:
PyErr_SetString(PyExc_MemoryError,
"Out of memory while decompressing data");
goto error;
}
do {
- Py_BEGIN_ALLOW_THREADS
- err=inflate(&zst, Z_FINISH);
- Py_END_ALLOW_THREADS
+ arrange_input_buffer(&zst, &ibuflen);
+ flush = ibuflen == 0 ? Z_FINISH : Z_NO_FLUSH;
- switch(err) {
- case(Z_STREAM_END):
- break;
- case(Z_BUF_ERROR):
- /*
- * If there is at least 1 byte of room according to zst.avail_out
- * and we get this error, assume that it means zlib cannot
- * process the inflate call() due to an error in the data.
- */
- if (zst.avail_out > 0) {
- zlib_error(zst, err, "while decompressing data");
+ do {
+ r_strlen = arrange_output_buffer(&zst, &RetVal, r_strlen);
+ if (r_strlen < 0) {
inflateEnd(&zst);
goto error;
}
- /* fall through */
- case(Z_OK):
- /* need more memory */
- if (_PyString_Resize(&result_str, r_strlen << 1) < 0) {
+
+ Py_BEGIN_ALLOW_THREADS
+ err = inflate(&zst, flush);
+ Py_END_ALLOW_THREADS
+
+ switch (err) {
+ case Z_OK: /* fall through */
+ case Z_BUF_ERROR: /* fall through */
+ case Z_STREAM_END:
+ break;
+ case Z_MEM_ERROR:
inflateEnd(&zst);
+ PyErr_SetString(PyExc_MemoryError,
+ "Out of memory while decompressing data");
+ goto error;
+ default:
+ inflateEnd(&zst);
+ zlib_error(zst, err, "while decompressing data");
goto error;
}
- zst.next_out = (unsigned char *)PyString_AS_STRING(result_str) \
- + r_strlen;
- zst.avail_out = r_strlen;
- r_strlen = r_strlen << 1;
- break;
- default:
- inflateEnd(&zst);
- zlib_error(zst, err, "while decompressing data");
- goto error;
- }
- } while (err != Z_STREAM_END);
+
+ } while (zst.avail_out == 0);
+
+ } while (err != Z_STREAM_END && ibuflen != 0);
+
+
+ if (err != Z_STREAM_END) {
+ inflateEnd(&zst);
+ zlib_error(zst, err, "while decompressing data");
+ goto error;
+ }
err = inflateEnd(&zst);
if (err != Z_OK) {
goto error;
}
- _PyString_Resize(&result_str, zst.total_out);
- return result_str;
+ _PyString_Resize(&RetVal, zst.next_out -
+ (Byte *)PyBytes_AS_STRING(RetVal));
+ return RetVal;
error:
- Py_XDECREF(result_str);
+ Py_XDECREF(RetVal);
return NULL;
}
return NULL;
self = newcompobject(&Comptype);
- if (self==NULL)
+ if (self == NULL)
return(NULL);
self->zst.zalloc = (alloc_func)NULL;
self->zst.zfree = (free_func)Z_NULL;
self->zst.next_in = NULL;
self->zst.avail_in = 0;
err = deflateInit2(&self->zst, level, method, wbits, memLevel, strategy);
- switch(err) {
- case (Z_OK):
+ switch (err) {
+ case Z_OK:
self->is_initialised = 1;
- return (PyObject*)self;
- case (Z_MEM_ERROR):
+ return (PyObject *)self;
+ case Z_MEM_ERROR:
Py_DECREF(self);
PyErr_SetString(PyExc_MemoryError,
"Can't allocate memory for compression object");
return NULL;
- case(Z_STREAM_ERROR):
+ case Z_STREAM_ERROR:
Py_DECREF(self);
PyErr_SetString(PyExc_ValueError, "Invalid initialization option");
return NULL;
self = newcompobject(&Decomptype);
if (self == NULL)
- return(NULL);
+ return NULL;
self->zst.zalloc = (alloc_func)NULL;
self->zst.zfree = (free_func)Z_NULL;
self->zst.next_in = NULL;
self->zst.avail_in = 0;
err = inflateInit2(&self->zst, wbits);
- switch(err) {
- case (Z_OK):
+ switch (err) {
+ case Z_OK:
self->is_initialised = 1;
- return (PyObject*)self;
- case(Z_STREAM_ERROR):
+ return (PyObject *)self;
+ case Z_STREAM_ERROR:
Py_DECREF(self);
PyErr_SetString(PyExc_ValueError, "Invalid initialization option");
return NULL;
- case (Z_MEM_ERROR):
+ case Z_MEM_ERROR:
Py_DECREF(self);
PyErr_SetString(PyExc_MemoryError,
"Can't allocate memory for decompression object");
static PyObject *
PyZlib_objcompress(compobject *self, PyObject *args)
{
- int err, inplen;
- Py_ssize_t length = DEFAULTALLOC;
- PyObject *RetVal;
- Byte *input;
- unsigned long start_total_out;
-
- if (!PyArg_ParseTuple(args, "s#:compress", &input, &inplen))
- return NULL;
+ PyObject *RetVal = NULL;
+ Py_ssize_t ibuflen, obuflen = DEFAULTALLOC;
+ int err;
- if (!(RetVal = PyString_FromStringAndSize(NULL, length)))
+ if (!PyArg_ParseTuple(args, "s#:compress", &self->zst.next_in, &ibuflen))
return NULL;
ENTER_ZLIB
- start_total_out = self->zst.total_out;
- self->zst.avail_in = inplen;
- self->zst.next_in = input;
- self->zst.avail_out = length;
- self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal);
+ do {
+ arrange_input_buffer(&self->zst, &ibuflen);
- Py_BEGIN_ALLOW_THREADS
- err = deflate(&(self->zst), Z_NO_FLUSH);
- Py_END_ALLOW_THREADS
+ do {
+ obuflen = arrange_output_buffer(&self->zst, &RetVal, obuflen);
+ if (obuflen < 0)
+ goto error;
- /* while Z_OK and the output buffer is full, there might be more output,
- so extend the output buffer and try again */
- while (err == Z_OK && self->zst.avail_out == 0) {
- if (_PyString_Resize(&RetVal, length << 1) < 0)
- goto error;
- self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \
- + length;
- self->zst.avail_out = length;
- length = length << 1;
+ Py_BEGIN_ALLOW_THREADS
+ err = deflate(&self->zst, Z_NO_FLUSH);
+ Py_END_ALLOW_THREADS
- Py_BEGIN_ALLOW_THREADS
- err = deflate(&(self->zst), Z_NO_FLUSH);
- Py_END_ALLOW_THREADS
- }
- /* We will only get Z_BUF_ERROR if the output buffer was full but
- there wasn't more output when we tried again, so it is not an error
- condition.
- */
-
- if (err != Z_OK && err != Z_BUF_ERROR) {
- zlib_error(self->zst, err, "while compressing");
- Py_DECREF(RetVal);
- RetVal = NULL;
- goto error;
- }
- _PyString_Resize(&RetVal, self->zst.total_out - start_total_out);
+ if (err == Z_STREAM_ERROR) {
+ zlib_error(self->zst, err, "while compressing data");
+ goto error;
+ }
+
+ } while (self->zst.avail_out == 0);
+ assert(self->zst.avail_in == 0);
+
+ } while (ibuflen != 0);
+
+ _PyString_Resize(&RetVal, self->zst.next_out -
+ (Byte *)PyBytes_AS_STRING(RetVal));
+ goto success;
error:
+ Py_CLEAR(RetVal);
+ success:
LEAVE_ZLIB
return RetVal;
}
/* Helper for objdecompress() and unflush(). Saves any unconsumed input data in
self->unused_data or self->unconsumed_tail, as appropriate. */
static int
-save_unconsumed_input(compobject *self, int err)
+save_unconsumed_input(compobject *self, Byte *input, Py_ssize_t inplen,
+ int err)
{
if (err == Z_STREAM_END) {
/* The end of the compressed data has been reached. Store the leftover
input data in self->unused_data. */
if (self->zst.avail_in > 0) {
Py_ssize_t old_size = PyString_GET_SIZE(self->unused_data);
- Py_ssize_t new_size;
+ Py_ssize_t new_size, left_size;
PyObject *new_data;
- if (self->zst.avail_in > PY_SSIZE_T_MAX - old_size) {
+ left_size = input + inplen - self->zst.next_in;
+ if (left_size > (PY_SSIZE_T_MAX - old_size)) {
PyErr_NoMemory();
return -1;
}
- new_size = old_size + self->zst.avail_in;
+ new_size = old_size + left_size;
new_data = PyString_FromStringAndSize(NULL, new_size);
if (new_data == NULL)
return -1;
Py_MEMCPY(PyString_AS_STRING(new_data),
PyString_AS_STRING(self->unused_data), old_size);
Py_MEMCPY(PyString_AS_STRING(new_data) + old_size,
- self->zst.next_in, self->zst.avail_in);
+ self->zst.next_in, left_size);
Py_SETREF(self->unused_data, new_data);
self->zst.avail_in = 0;
}
}
+
if (self->zst.avail_in > 0 || PyString_GET_SIZE(self->unconsumed_tail)) {
/* This code handles two distinct cases:
1. Output limit was reached. Save leftover input in unconsumed_tail.
2. All input data was consumed. Clear unconsumed_tail. */
+ Py_ssize_t left_size = input + inplen - self->zst.next_in;
PyObject *new_data = PyString_FromStringAndSize(
- (char *)self->zst.next_in, self->zst.avail_in);
+ (char *)self->zst.next_in, left_size);
if (new_data == NULL)
return -1;
Py_SETREF(self->unconsumed_tail, new_data);
}
+
return 0;
}
static PyObject *
PyZlib_objdecompress(compobject *self, PyObject *args)
{
- int err, inplen, max_length = 0;
- Py_ssize_t old_length, length = DEFAULTALLOC;
- PyObject *RetVal;
+ int err = Z_OK;
+ Py_ssize_t inplen, max_length = 0;
+ Py_ssize_t ibuflen, obuflen = DEFAULTALLOC, hard_limit;
+ PyObject *RetVal = NULL;
Byte *input;
- unsigned long start_total_out;
- if (!PyArg_ParseTuple(args, "s#|i:decompress", &input,
+ if (!PyArg_ParseTuple(args, "s#|n:decompress", &input,
&inplen, &max_length))
return NULL;
if (max_length < 0) {
PyErr_SetString(PyExc_ValueError,
"max_length must be greater than zero");
return NULL;
- }
+ } else if (max_length == 0)
+ hard_limit = PY_SSIZE_T_MAX;
+ else
+ hard_limit = max_length;
+
+ self->zst.next_in = input;
+ ibuflen = inplen;
/* limit amount of data allocated to max_length */
- if (max_length && length > max_length)
- length = max_length;
- if (!(RetVal = PyString_FromStringAndSize(NULL, length)))
- return NULL;
+ if (max_length && obuflen > max_length)
+ obuflen = max_length;
ENTER_ZLIB
- start_total_out = self->zst.total_out;
- self->zst.avail_in = inplen;
- self->zst.next_in = input;
- self->zst.avail_out = length;
- self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal);
-
- Py_BEGIN_ALLOW_THREADS
- err = inflate(&(self->zst), Z_SYNC_FLUSH);
- Py_END_ALLOW_THREADS
-
- /* While Z_OK and the output buffer is full, there might be more output.
- So extend the output buffer and try again.
- */
- while (err == Z_OK && self->zst.avail_out == 0) {
- /* If max_length set, don't continue decompressing if we've already
- reached the limit.
- */
- if (max_length && length >= max_length)
- break;
+ do {
+ arrange_input_buffer(&self->zst, &ibuflen);
+
+ do {
+ obuflen = arrange_output_buffer_with_maximum(&self->zst, &RetVal,
+ obuflen, hard_limit);
+ if (obuflen == -2) {
+ if (max_length > 0) {
+ goto save;
+ }
+ PyErr_NoMemory();
+ }
+ if (obuflen < 0) {
+ goto abort;
+ }
- /* otherwise, ... */
- old_length = length;
- length = length << 1;
- if (max_length && length > max_length)
- length = max_length;
+ Py_BEGIN_ALLOW_THREADS
+ err = inflate(&self->zst, Z_SYNC_FLUSH);
+ Py_END_ALLOW_THREADS
+
+ switch (err) {
+ case Z_OK: /* fall through */
+ case Z_BUF_ERROR: /* fall through */
+ case Z_STREAM_END:
+ break;
+ default:
+ goto save;
+ }
- if (_PyString_Resize(&RetVal, length) < 0)
- goto error;
- self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \
- + old_length;
- self->zst.avail_out = length - old_length;
+ } while (self->zst.avail_out == 0);
- Py_BEGIN_ALLOW_THREADS
- err = inflate(&(self->zst), Z_SYNC_FLUSH);
- Py_END_ALLOW_THREADS
- }
+ } while (err != Z_STREAM_END && ibuflen != 0);
- if (save_unconsumed_input(self, err) < 0) {
- Py_DECREF(RetVal);
- RetVal = NULL;
- goto error;
- }
+ save:
+ if (save_unconsumed_input(self, input, inplen, err) < 0)
+ goto abort;
/* This is the logical place to call inflateEnd, but the old behaviour of
only calling it on flush() is preserved. */
not an error condition.
*/
zlib_error(self->zst, err, "while decompressing");
- Py_DECREF(RetVal);
- RetVal = NULL;
- goto error;
+ goto abort;
}
- _PyString_Resize(&RetVal, self->zst.total_out - start_total_out);
+ _PyString_Resize(&RetVal, self->zst.next_out -
+ (Byte *)PyBytes_AS_STRING(RetVal));
+ goto success;
- error:
+ abort:
+ Py_CLEAR(RetVal);
+ success:
LEAVE_ZLIB
return RetVal;
static PyObject *
PyZlib_flush(compobject *self, PyObject *args)
{
- int err, length = DEFAULTALLOC;
- PyObject *RetVal;
+ int err;
+ Py_ssize_t length = DEFAULTALLOC;
+ PyObject *RetVal = NULL;
int flushmode = Z_FINISH;
- unsigned long start_total_out;
if (!PyArg_ParseTuple(args, "|i:flush", &flushmode))
return NULL;
return PyString_FromStringAndSize(NULL, 0);
}
- if (!(RetVal = PyString_FromStringAndSize(NULL, length)))
- return NULL;
-
ENTER_ZLIB
- start_total_out = self->zst.total_out;
self->zst.avail_in = 0;
- self->zst.avail_out = length;
- self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal);
- Py_BEGIN_ALLOW_THREADS
- err = deflate(&(self->zst), flushmode);
- Py_END_ALLOW_THREADS
-
- /* while Z_OK and the output buffer is full, there might be more output,
- so extend the output buffer and try again */
- while (err == Z_OK && self->zst.avail_out == 0) {
- if (_PyString_Resize(&RetVal, length << 1) < 0)
+ do {
+ length = arrange_output_buffer(&self->zst, &RetVal, length);
+ if (length < 0) {
+ Py_CLEAR(RetVal);
goto error;
- self->zst.next_out = (unsigned char *)PyString_AS_STRING(RetVal) \
- + length;
- self->zst.avail_out = length;
- length = length << 1;
+ }
Py_BEGIN_ALLOW_THREADS
- err = deflate(&(self->zst), flushmode);
+ err = deflate(&self->zst, flushmode);
Py_END_ALLOW_THREADS
- }
+
+ if (err == Z_STREAM_ERROR) {
+ zlib_error(self->zst, err, "while flushing");
+ Py_CLEAR(RetVal);
+ goto error;
+ }
+ } while (self->zst.avail_out == 0);
+ assert(self->zst.avail_in == 0);
/* If flushmode is Z_FINISH, we also have to call deflateEnd() to free
various data structures. Note we should only get Z_STREAM_END when
flushmode is Z_FINISH, but checking both for safety*/
if (err == Z_STREAM_END && flushmode == Z_FINISH) {
- err = deflateEnd(&(self->zst));
+ err = deflateEnd(&self->zst);
if (err != Z_OK) {
zlib_error(self->zst, err, "from deflateEnd()");
- Py_DECREF(RetVal);
- RetVal = NULL;
+ Py_CLEAR(RetVal);
goto error;
}
else
but there wasn't more output when we tried again, so it is
not an error condition.
*/
- } else if (err!=Z_OK && err!=Z_BUF_ERROR) {
+ } else if (err != Z_OK && err != Z_BUF_ERROR) {
zlib_error(self->zst, err, "while flushing");
- Py_DECREF(RetVal);
- RetVal = NULL;
+ Py_CLEAR(RetVal);
goto error;
}
- _PyString_Resize(&RetVal, self->zst.total_out - start_total_out);
+ _PyString_Resize(&RetVal, self->zst.next_out -
+ (Byte *)PyBytes_AS_STRING(RetVal));
error:
LEAVE_ZLIB
-
return RetVal;
}
*/
ENTER_ZLIB
err = deflateCopy(&retval->zst, &self->zst);
- switch(err) {
- case(Z_OK):
+ switch (err) {
+ case Z_OK:
break;
- case(Z_STREAM_ERROR):
+ case Z_STREAM_ERROR:
PyErr_SetString(PyExc_ValueError, "Inconsistent stream state");
goto error;
- case(Z_MEM_ERROR):
+ case Z_MEM_ERROR:
PyErr_SetString(PyExc_MemoryError,
"Can't allocate memory for compression object");
goto error;
*/
ENTER_ZLIB
err = inflateCopy(&retval->zst, &self->zst);
- switch(err) {
- case(Z_OK):
+ switch (err) {
+ case Z_OK:
break;
- case(Z_STREAM_ERROR):
+ case Z_STREAM_ERROR:
PyErr_SetString(PyExc_ValueError, "Inconsistent stream state");
goto error;
- case(Z_MEM_ERROR):
+ case Z_MEM_ERROR:
PyErr_SetString(PyExc_MemoryError,
"Can't allocate memory for decompression object");
goto error;
static PyObject *
PyZlib_unflush(compobject *self, PyObject *args)
{
- int err, length = DEFAULTALLOC;
- PyObject * retval = NULL;
- unsigned long start_total_out;
+ Py_ssize_t length = DEFAULTALLOC;
+ int err, flush;
+ PyObject *RetVal = NULL;
+ Py_ssize_t ibuflen;
- if (!PyArg_ParseTuple(args, "|i:flush", &length))
+ if (!PyArg_ParseTuple(args, "|n:flush", &length))
return NULL;
if (length <= 0) {
PyErr_SetString(PyExc_ValueError, "length must be greater than zero");
return NULL;
}
- if (!(retval = PyString_FromStringAndSize(NULL, length)))
- return NULL;
-
ENTER_ZLIB
- start_total_out = self->zst.total_out;
- self->zst.avail_in = PyString_GET_SIZE(self->unconsumed_tail);
self->zst.next_in = (Byte *)PyString_AS_STRING(self->unconsumed_tail);
- self->zst.avail_out = length;
- self->zst.next_out = (Byte *)PyString_AS_STRING(retval);
+ ibuflen = PyString_GET_SIZE(self->unconsumed_tail);
- Py_BEGIN_ALLOW_THREADS
- err = inflate(&(self->zst), Z_FINISH);
- Py_END_ALLOW_THREADS
+ do {
+ arrange_input_buffer(&self->zst, &ibuflen);
+ flush = ibuflen == 0 ? Z_FINISH : Z_NO_FLUSH;
+
+ do {
+ length = arrange_output_buffer(&self->zst, &RetVal, length);
+ if (length < 0)
+ goto abort;
+
+ Py_BEGIN_ALLOW_THREADS
+ err = inflate(&self->zst, flush);
+ Py_END_ALLOW_THREADS
+
+ switch (err) {
+ case Z_OK: /* fall through */
+ case Z_BUF_ERROR: /* fall through */
+ case Z_STREAM_END:
+ break;
+ default:
+ goto save;
+ }
- /* while Z_OK and the output buffer is full, there might be more output,
- so extend the output buffer and try again */
- while ((err == Z_OK || err == Z_BUF_ERROR) && self->zst.avail_out == 0) {
- if (_PyString_Resize(&retval, length << 1) < 0)
- goto error;
- self->zst.next_out = (Byte *)PyString_AS_STRING(retval) + length;
- self->zst.avail_out = length;
- length = length << 1;
+ } while (self->zst.avail_out == 0);
- Py_BEGIN_ALLOW_THREADS
- err = inflate(&(self->zst), Z_FINISH);
- Py_END_ALLOW_THREADS
- }
+ } while (err != Z_STREAM_END && ibuflen != 0);
- if (save_unconsumed_input(self, err) < 0) {
- Py_DECREF(retval);
- retval = NULL;
- goto error;
- }
+ save:
+ if (save_unconsumed_input(self,
+ (Byte *)PyString_AS_STRING(self->unconsumed_tail),
+ PyString_GET_SIZE(self->unconsumed_tail), err) < 0)
+ goto abort;
/* If flushmode is Z_FINISH, we also have to call deflateEnd() to free
various data structures. Note we should only get Z_STREAM_END when
flushmode is Z_FINISH */
if (err == Z_STREAM_END) {
- err = inflateEnd(&(self->zst));
+ err = inflateEnd(&self->zst);
self->is_initialised = 0;
if (err != Z_OK) {
zlib_error(self->zst, err, "from inflateEnd()");
- Py_DECREF(retval);
- retval = NULL;
- goto error;
+ goto abort;
}
}
- _PyString_Resize(&retval, self->zst.total_out - start_total_out);
-
-error:
+ _PyString_Resize(&RetVal, self->zst.next_out -
+ (Byte *)PyBytes_AS_STRING(RetVal));
+ goto success;
+ abort:
+ Py_CLEAR(RetVal);
+ success:
LEAVE_ZLIB
-
- return retval;
+ return RetVal;
}
static PyMethodDef comp_methods[] =
{
unsigned int adler32val = 1; /* adler32(0L, Z_NULL, 0) */
Byte *buf;
- int len, signed_val;
+ Py_ssize_t len;
+ int signed_val;
if (!PyArg_ParseTuple(args, "s#|I:adler32", &buf, &len, &adler32val))
return NULL;
+
+ /* Avoid truncation of length for very large buffers. adler32() takes
+ length as an unsigned int, which may be narrower than Py_ssize_t. */
+ while ((size_t)len > UINT_MAX) {
+ adler32val = adler32(adler32val, buf, UINT_MAX);
+ buf += (size_t) UINT_MAX;
+ len -= (size_t) UINT_MAX;
+ }
/* In Python 2.x we return a signed integer regardless of native platform
* long size (the 32bit unsigned long is treated as 32-bit signed and sign
* extended into a 64-bit long inside the integer object). 3.0 does the
* right thing and returns unsigned. http://bugs.python.org/issue1202 */
- signed_val = adler32(adler32val, buf, len);
+ signed_val = adler32(adler32val, buf, (unsigned int)len);
return PyInt_FromLong(signed_val);
}
{
unsigned int crc32val = 0; /* crc32(0L, Z_NULL, 0) */
Byte *buf;
- int len, signed_val;
+ Py_ssize_t len;
+ int signed_val;
if (!PyArg_ParseTuple(args, "s#|I:crc32", &buf, &len, &crc32val))
return NULL;
+
+ /* Avoid truncation of length for very large buffers. crc32() takes
+ length as an unsigned int, which may be narrower than Py_ssize_t. */
+ while ((size_t)len > UINT_MAX) {
+ crc32val = crc32(crc32val, buf, UINT_MAX);
+ buf += (size_t) UINT_MAX;
+ len -= (size_t) UINT_MAX;
+ }
/* In Python 2.x we return a signed integer regardless of native platform
* long size (the 32bit unsigned long is treated as 32-bit signed and sign
* extended into a 64-bit long inside the integer object). 3.0 does the
* right thing and returns unsigned. http://bugs.python.org/issue1202 */
- signed_val = crc32(crc32val, buf, len);
+ signed_val = crc32(crc32val, buf, (unsigned int)len);
return PyInt_FromLong(signed_val);
}
}
return res;
}
- if (PyInt_Check(o)) { /* A int subclass without nb_int */
+ if (PyInt_Check(o)) { /* An int subclass without nb_int */
PyIntObject *io = (PyIntObject*)o;
return PyInt_FromLong(io->ob_ival);
}
break;
}
if (j >= n) {
- Py_ssize_t oldn = n;
+ size_t newn = (size_t)n;
/* The over-allocation strategy can grow a bit faster
than for lists because unlike lists the
over-allocation isn't permanent -- we reclaim
the excess before the end of this routine.
So, grow by ten and then add 25%.
*/
- n += 10;
- n += n >> 2;
- if (n < oldn) {
+ newn += 10u;
+ newn += newn >> 2;
+ if (newn > PY_SSIZE_T_MAX) {
/* Check for overflow */
PyErr_NoMemory();
Py_DECREF(item);
goto Fail;
}
+ n = (Py_ssize_t)newn;
if (_PyTuple_Resize(&result, n) != 0) {
Py_DECREF(item);
goto Fail;
PyObject *
PyByteArray_Concat(PyObject *a, PyObject *b)
{
- Py_ssize_t size;
Py_buffer va, vb;
PyByteArrayObject *result = NULL;
goto done;
}
- size = va.len + vb.len;
- if (size < 0) {
- PyErr_NoMemory();
- goto done;
+ if (va.len > PY_SSIZE_T_MAX - vb.len) {
+ PyErr_NoMemory();
+ goto done;
}
- result = (PyByteArrayObject *) PyByteArray_FromStringAndSize(NULL, size);
+ result = (PyByteArrayObject *) \
+ PyByteArray_FromStringAndSize(NULL, va.len + vb.len);
if (result != NULL) {
memcpy(result->ob_bytes, va.buf, va.len);
memcpy(result->ob_bytes + va.len, vb.buf, vb.len);
}
mysize = Py_SIZE(self);
- size = mysize + vo.len;
- if (size < 0) {
+ if (mysize > PY_SSIZE_T_MAX - vo.len) {
PyBuffer_Release(&vo);
return PyErr_NoMemory();
}
+ size = mysize + vo.len;
if (size < self->ob_alloc) {
Py_SIZE(self) = size;
self->ob_bytes[Py_SIZE(self)] = '\0'; /* Trailing null byte */
if (count < 0)
count = 0;
mysize = Py_SIZE(self);
- size = mysize * count;
- if (count != 0 && size / count != mysize)
+ if (count != 0 && mysize > PY_SSIZE_T_MAX / count)
return PyErr_NoMemory();
+ size = mysize * count;
result = (PyByteArrayObject *)PyByteArray_FromStringAndSize(NULL, size);
if (result != NULL && size != 0) {
if (mysize == 1)
if (count < 0)
count = 0;
mysize = Py_SIZE(self);
- size = mysize * count;
- if (count != 0 && size / count != mysize)
+ if (count != 0 && mysize > PY_SSIZE_T_MAX / count)
return PyErr_NoMemory();
+ size = mysize * count;
if (size < self->ob_alloc) {
Py_SIZE(self) = size;
self->ob_bytes[Py_SIZE(self)] = '\0'; /* Trailing null byte */
}
if (to_len == 0) {
- /* delete all occurances of 'from' bytes */
+ /* delete all occurrences of 'from' bytes */
if (from_len == 1) {
return replace_delete_single_character(
self, from_s[0], maxcount);
Py_DECREF(item);
if (len >= buf_size) {
- buf_size = len + (len >> 1) + 1;
+ Py_ssize_t addition;
+ if (len == PY_SSIZE_T_MAX) {
+ Py_DECREF(it);
+ Py_DECREF(bytearray_obj);
+ return PyErr_NoMemory();
+ }
+ addition = len >> 1;
+ if (addition > PY_SSIZE_T_MAX - len - 1)
+ buf_size = PY_SSIZE_T_MAX;
+ else
+ buf_size = len + addition + 1;
if (PyByteArray_Resize((PyObject *)bytearray_obj, buf_size) < 0) {
Py_DECREF(it);
Py_DECREF(bytearray_obj);
PyDoc_STRVAR(remove__doc__,
"B.remove(int) -> None\n\
\n\
-Remove the first occurance of a value in B.");
+Remove the first occurrence of a value in B.");
static PyObject *
bytearray_remove(PyByteArrayObject *self, PyObject *arg)
{
im = free_list;
if (im != NULL) {
free_list = (PyMethodObject *)(im->im_self);
- PyObject_INIT(im, &PyMethod_Type);
+ (void)PyObject_INIT(im, &PyMethod_Type);
numfree--;
}
else {
/* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */
static int
-all_name_chars(unsigned char *s)
+all_name_chars(PyObject *o)
{
static char ok_name_char[256];
- static unsigned char *name_chars = (unsigned char *)NAME_CHARS;
+ static const unsigned char *name_chars = (unsigned char *)NAME_CHARS;
+ const unsigned char *s, *e;
if (ok_name_char[*name_chars] == 0) {
- unsigned char *p;
+ const unsigned char *p;
for (p = name_chars; *p; p++)
ok_name_char[*p] = 1;
}
- while (*s) {
+ s = (unsigned char *)PyString_AS_STRING(o);
+ e = s + PyString_GET_SIZE(o);
+ while (s != e) {
if (ok_name_char[*s++] == 0)
return 0;
}
}
}
+/* Intern selected string constants */
+static int
+intern_string_constants(PyObject *tuple)
+{
+ int modified = 0;
+ Py_ssize_t i;
+
+ for (i = PyTuple_GET_SIZE(tuple); --i >= 0; ) {
+ PyObject *v = PyTuple_GET_ITEM(tuple, i);
+ if (PyString_CheckExact(v)) {
+ if (all_name_chars(v)) {
+ PyObject *w = v;
+ PyString_InternInPlace(&v);
+ if (w != v) {
+ PyTuple_SET_ITEM(tuple, i, v);
+ modified = 1;
+ }
+ }
+ }
+ else if (PyTuple_CheckExact(v)) {
+ intern_string_constants(v);
+ }
+ else if (PyFrozenSet_CheckExact(v)) {
+ PyObject *w = v;
+ PyObject *tmp = PySequence_Tuple(v);
+ if (tmp == NULL) {
+ PyErr_Clear();
+ continue;
+ }
+ if (intern_string_constants(tmp)) {
+ v = PyFrozenSet_New(tmp);
+ if (v == NULL) {
+ PyErr_Clear();
+ }
+ else {
+ PyTuple_SET_ITEM(tuple, i, v);
+ Py_DECREF(w);
+ modified = 1;
+ }
+ }
+ Py_DECREF(tmp);
+ }
+ }
+ return modified;
+}
+
PyCodeObject *
PyCode_New(int argcount, int nlocals, int stacksize, int flags,
PyObject *lnotab)
{
PyCodeObject *co;
- Py_ssize_t i;
/* Check argument types */
if (argcount < 0 || nlocals < 0 ||
code == NULL ||
intern_strings(varnames);
intern_strings(freevars);
intern_strings(cellvars);
- /* Intern selected string constants */
- for (i = PyTuple_Size(consts); --i >= 0; ) {
- PyObject *v = PyTuple_GetItem(consts, i);
- if (!PyString_Check(v))
- continue;
- if (!all_name_chars((unsigned char *)PyString_AS_STRING(v)))
- continue;
- PyString_InternInPlace(&PyTuple_GET_ITEM(consts, i));
- }
+ intern_string_constants(consts);
co = PyObject_NEW(PyCodeObject, &PyCode_Type);
if (co != NULL) {
co->co_argcount = argcount;
/* possible optimization: if f->f_lasti == instr_ub
(likely to be a common case) then we already know
instr_lb -- if we stored the matching value of p
- somwhere we could skip the first while loop. */
+ somewhere we could skip the first while loop. */
/* See lnotab_notes.txt for the description of
co_lnotab. A point to remember: increments to p
op = (PyComplexObject *) PyObject_MALLOC(sizeof(PyComplexObject));
if (op == NULL)
return PyErr_NoMemory();
- PyObject_INIT(op, &PyComplex_Type);
+ (void)PyObject_INIT(op, &PyComplex_Type);
op->cval = cval;
return (PyObject *) op;
}
pc->real = pc->imag = 0.0;
if (PyInt_Check(obj)) {
- pc->real = PyInt_AS_LONG(obj);
- return 0;
+ pc->real = PyInt_AS_LONG(obj);
+ return 0;
}
if (PyLong_Check(obj)) {
- pc->real = PyLong_AsDouble(obj);
- if (pc->real == -1.0 && PyErr_Occurred()) {
- *pobj = NULL;
- return -1;
- }
- return 0;
+ pc->real = PyLong_AsDouble(obj);
+ if (pc->real == -1.0 && PyErr_Occurred()) {
+ *pobj = NULL;
+ return -1;
+ }
+ return 0;
}
if (PyFloat_Check(obj)) {
- pc->real = PyFloat_AsDouble(obj);
- return 0;
+ pc->real = PyFloat_AsDouble(obj);
+ return 0;
}
Py_INCREF(Py_NotImplemented);
*pobj = Py_NotImplemented;
PyObject *format_spec;
if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
- return NULL;
+ return NULL;
if (PyBytes_Check(format_spec))
- return _PyComplex_FormatAdvanced(self,
- PyBytes_AS_STRING(format_spec),
- PyBytes_GET_SIZE(format_spec));
+ return _PyComplex_FormatAdvanced(self,
+ PyBytes_AS_STRING(format_spec),
+ PyBytes_GET_SIZE(format_spec));
if (PyUnicode_Check(format_spec)) {
- /* Convert format_spec to a str */
- PyObject *result;
- PyObject *str_spec = PyObject_Str(format_spec);
+ /* Convert format_spec to a str */
+ PyObject *result;
+ PyObject *str_spec = PyObject_Str(format_spec);
- if (str_spec == NULL)
- return NULL;
+ if (str_spec == NULL)
+ return NULL;
- result = _PyComplex_FormatAdvanced(self,
- PyBytes_AS_STRING(str_spec),
- PyBytes_GET_SIZE(str_spec));
+ result = _PyComplex_FormatAdvanced(self,
+ PyBytes_AS_STRING(str_spec),
+ PyBytes_GET_SIZE(str_spec));
- Py_DECREF(str_spec);
- return result;
+ Py_DECREF(str_spec);
+ return result;
}
PyErr_SetString(PyExc_TypeError, "__format__ requires str or unicode");
return NULL;
return PyUnicode_FromString("");
/* Get reason and encoding as strings, which they might not be if
- they've been modified after we were contructed. */
+ they've been modified after we were constructed. */
reason_str = PyObject_Str(uself->reason);
if (reason_str == NULL)
goto done;
return PyUnicode_FromString("");
/* Get reason and encoding as strings, which they might not be if
- they've been modified after we were contructed. */
+ they've been modified after we were constructed. */
reason_str = PyObject_Str(uself->reason);
if (reason_str == NULL)
goto done;
return PyUnicode_FromString("");
/* Get reason as a string, which it might not be if it's been
- modified after we were contructed. */
+ modified after we were constructed. */
reason_str = PyObject_Str(uself->reason);
if (reason_str == NULL)
goto done;
#ifdef MS_WINDOWS
if (PyArg_ParseTupleAndKeywords(args, kwds, "U|si:file",
- kwlist, &po, &mode, &bufsize)) {
+ kwlist, &po, &mode, &bufsize) &&
+ wcslen(PyUnicode_AS_UNICODE(po)) == (size_t)PyUnicode_GET_SIZE(po)) {
wideargument = 1;
if (fill_file_fields(foself, NULL, po, mode,
fclose) == NULL)
/* Inline PyObject_New */
op = free_list;
free_list = (PyFloatObject *)Py_TYPE(op);
- PyObject_INIT(op, &PyFloat_Type);
+ (void)PyObject_INIT(op, &PyFloat_Type);
op->ob_fval = fval;
return (PyObject *) op;
}
To declare a class method, use this idiom:
class C:
- def f(cls, arg1, arg2, ...): ...
- f = classmethod(f)
+ @classmethod
+ def f(cls, arg1, arg2, ...):
+ ...
It can be called either on the class (e.g. C.f()) or on an instance
(e.g. C().f()); the instance is ignored except for its class.
To declare a class method, use this idiom:\n\
\n\
class C:\n\
- def f(cls, arg1, arg2, ...): ...\n\
- f = classmethod(f)\n\
+ @classmethod\n\
+ def f(cls, arg1, arg2, ...):\n\
+ ...\n\
\n\
It can be called either on the class (e.g. C.f()) or on an instance\n\
(e.g. C().f()). The instance is ignored except for its class.\n\
To declare a static method, use this idiom:
class C:
- def f(arg1, arg2, ...): ...
- f = staticmethod(f)
+ @staticmethod
+ def f(arg1, arg2, ...):
+ ....
It can be called either on the class (e.g. C.f()) or on an instance
(e.g. C().f()); the instance is ignored except for its class.
To declare a static method, use this idiom:\n\
\n\
class C:\n\
- def f(arg1, arg2, ...): ...\n\
- f = staticmethod(f)\n\
+ @staticmethod\n\
+ def f(arg1, arg2, ...):\n\
+ ...\n\
\n\
It can be called either on the class (e.g. C.f()) or on an instance\n\
(e.g. C().f()). The instance is ignored except for its class.\n\
/* Inline PyObject_New */
v = free_list;
free_list = (PyIntObject *)Py_TYPE(v);
- PyObject_INIT(v, &PyInt_Type);
+ (void)PyObject_INIT(v, &PyInt_Type);
v->ob_ival = ival;
return (PyObject *) v;
}
Py_TYPE(v)->tp_free((PyObject *)v);
}
-static void
-int_free(PyIntObject *v)
-{
- Py_TYPE(v) = (struct _typeobject *)free_list;
- free_list = v;
-}
-
long
PyInt_AsLong(register PyObject *op)
{
0, /* tp_init */
0, /* tp_alloc */
int_new, /* tp_new */
- (freefunc)int_free, /* tp_free */
};
int
int ival;
#if NSMALLNEGINTS + NSMALLPOSINTS > 0
for (ival = -NSMALLNEGINTS; ival < NSMALLPOSINTS; ival++) {
- if (!free_list && (free_list = fill_free_list()) == NULL)
- return 0;
+ if (!free_list && (free_list = fill_free_list()) == NULL)
+ return 0;
/* PyObject_New is inlined */
v = free_list;
free_list = (PyIntObject *)Py_TYPE(v);
- PyObject_INIT(v, &PyInt_Type);
+ (void)PyObject_INIT(v, &PyInt_Type);
v->ob_ival = ival;
small_ints[ival + NSMALLNEGINTS] = v;
}
item = a->ob_item;
/* recycle the items that we are about to remove */
s = norig * sizeof(PyObject *);
- if (s > sizeof(recycle_on_stack)) {
- recycle = (PyObject **)PyMem_MALLOC(s);
- if (recycle == NULL) {
- PyErr_NoMemory();
- goto Error;
+ /* If norig == 0, item might be NULL, in which case we may not memcpy from it. */
+ if (s) {
+ if (s > sizeof(recycle_on_stack)) {
+ recycle = (PyObject **)PyMem_MALLOC(s);
+ if (recycle == NULL) {
+ PyErr_NoMemory();
+ goto Error;
+ }
}
+ memcpy(recycle, &item[ilow], s);
}
- memcpy(recycle, &item[ilow], s);
if (d < 0) { /* Delete -d items */
memmove(&item[ihigh+d], &item[ihigh],
But in CPython's case, comparisons are extraordinarily expensive compared to
moving data, and the details matter. Moving objects is just copying
-pointers. Comparisons can be arbitrarily expensive (can invoke arbitary
+pointers. Comparisons can be arbitrarily expensive (can invoke arbitrary
user-supplied Python code), but even in simple cases (like 3 < 4) _all_
decisions are made at runtime: what's the type of the left comparand? the
type of the right? do they need to be coerced to a common type? where's the
/* Checking for overflow in PyLong_AsLong is a PITA since C doesn't define
* anything about what happens when a signed integer operation overflows,
* and some compilers think they're doing you a favor by being "clever"
- * then. The bit pattern for the largest postive signed long is
+ * then. The bit pattern for the largest positive signed long is
* (unsigned long)LONG_MAX, and for the smallest negative signed long
* it is abs(LONG_MIN), which we could write -(unsigned long)LONG_MIN.
* However, some other compilers warn about applying unary minus to an
size_t i;
const unsigned char* p = pendbyte;
const int pincr = -incr; /* search MSB to LSB */
- const unsigned char insignficant = is_signed ? 0xff : 0x00;
+ const unsigned char insignificant = is_signed ? 0xff : 0x00;
for (i = 0; i < n; ++i, p += pincr) {
- if (*p != insignficant)
+ if (*p != insignificant)
break;
}
numsignificantbytes = n - i;
/* Round by directly modifying the low digit of x. */
mask = (digit)1 << (extra_bits - 1);
low = x->ob_digit[0] | inexact;
- if (low & mask && low & (3*mask-1))
+ if ((low & mask) && (low & (3U*mask-1U)))
low += mask;
- x->ob_digit[0] = low & ~(mask-1U);
+ x->ob_digit[0] = low & ~(2U*mask-1U);
/* Convert x to a double dx; the conversion is exact. */
dx = x->ob_digit[--x_size];
shiftby = PyLong_AsSsize_t((PyObject *)b);
if (shiftby == -1L && PyErr_Occurred())
- goto lshift_error;
+ goto out;
if (shiftby < 0) {
PyErr_SetString(PyExc_ValueError, "negative shift count");
- goto lshift_error;
+ goto out;
}
+
+ if (Py_SIZE(a) == 0) {
+ z = (PyLongObject *)PyLong_FromLong(0);
+ goto out;
+ }
+
/* wordshift, remshift = divmod(shiftby, PyLong_SHIFT) */
wordshift = shiftby / PyLong_SHIFT;
remshift = shiftby - wordshift * PyLong_SHIFT;
++newsize;
z = _PyLong_New(newsize);
if (z == NULL)
- goto lshift_error;
+ goto out;
if (a->ob_size < 0)
z->ob_size = -(z->ob_size);
for (i = 0; i < wordshift; i++)
else
assert(!accum);
z = long_normalize(z);
- lshift_error:
+ out:
Py_DECREF(a);
Py_DECREF(b);
return (PyObject *) z;
op = free_list;
if (op != NULL) {
free_list = (PyCFunctionObject *)(op->m_self);
- PyObject_INIT(op, &PyCFunction_Type);
+ (void)PyObject_INIT(op, &PyCFunction_Type);
numfree--;
}
else {
---------------------------------------------------------------*/
assert(step != 0);
if (step > 0 && lo < hi)
- return 1UL + (hi - 1UL - lo) / step;
+ return 1UL + (hi - 1UL - lo) / step;
else if (step < 0 && lo > hi)
- return 1UL + (lo - 1UL - hi) / (0UL - step);
+ return 1UL + (lo - 1UL - hi) / (0UL - step);
else
- return 0UL;
+ return 0UL;
}
/* Return a stop value suitable for reconstructing the xrange from
#if 0
-/* Occassionally useful for debugging. Should normally be commented out. */
+/* Occasionally useful for debugging. Should normally be commented out. */
static void
DEBUG_PRINT_FORMAT_SPEC(InternalFormatSpec *format)
{
op = (PyStringObject *)PyObject_MALLOC(PyStringObject_SIZE + size);
if (op == NULL)
return PyErr_NoMemory();
- PyObject_INIT_VAR(op, &PyString_Type, size);
+ (void)PyObject_INIT_VAR(op, &PyString_Type, size);
op->ob_shash = -1;
op->ob_sstate = SSTATE_NOT_INTERNED;
if (str != NULL)
op = (PyStringObject *)PyObject_MALLOC(PyStringObject_SIZE + size);
if (op == NULL)
return PyErr_NoMemory();
- PyObject_INIT_VAR(op, &PyString_Type, size);
+ (void)PyObject_INIT_VAR(op, &PyString_Type, size);
op->ob_shash = -1;
op->ob_sstate = SSTATE_NOT_INTERNED;
Py_MEMCPY(op->ob_sval, str, size+1);
fputc(quote, fp);
for (i = 0; i < str_len; i++) {
/* Since strings are immutable and the caller should have a
- reference, accessing the interal buffer should not be an issue
+ reference, accessing the internal buffer should not be an issue
with the GIL released. */
c = op->ob_sval[i];
if (c == quote || c == '\\')
Py_INCREF(a);
return (PyObject *)a;
}
- size = Py_SIZE(a) + Py_SIZE(b);
/* Check that string sizes are not negative, to prevent an
overflow in cases where we are passed incorrectly-created
strings with negative lengths (due to a bug in other code).
"strings are too large to concat");
return NULL;
}
+ size = Py_SIZE(a) + Py_SIZE(b);
/* Inline PyObject_NewVar */
if (size > PY_SSIZE_T_MAX - PyStringObject_SIZE) {
op = (PyStringObject *)PyObject_MALLOC(PyStringObject_SIZE + size);
if (op == NULL)
return PyErr_NoMemory();
- PyObject_INIT_VAR(op, &PyString_Type, size);
+ (void)PyObject_INIT_VAR(op, &PyString_Type, size);
op->ob_shash = -1;
op->ob_sstate = SSTATE_NOT_INTERNED;
Py_MEMCPY(op->ob_sval, a->ob_sval, Py_SIZE(a));
size_t nbytes;
if (n < 0)
n = 0;
- /* watch out for overflows: the size can overflow int,
+ /* watch out for overflows: the size can overflow Py_ssize_t,
* and the # of bytes needed can overflow size_t
*/
- size = Py_SIZE(a) * n;
- if (n && size / n != Py_SIZE(a)) {
+ if (n && Py_SIZE(a) > PY_SSIZE_T_MAX / n) {
PyErr_SetString(PyExc_OverflowError,
"repeated string is too long");
return NULL;
}
+ size = Py_SIZE(a) * n;
if (size == Py_SIZE(a) && PyString_CheckExact(a)) {
Py_INCREF(a);
return (PyObject *)a;
op = (PyStringObject *)PyObject_MALLOC(PyStringObject_SIZE + nbytes);
if (op == NULL)
return PyErr_NoMemory();
- PyObject_INIT_VAR(op, &PyString_Type, size);
+ (void)PyObject_INIT_VAR(op, &PyString_Type, size);
op->ob_shash = -1;
op->ob_sstate = SSTATE_NOT_INTERNED;
op->ob_sval[size] = '\0';
}
if (to_len == 0) {
- /* delete all occurances of 'from' string */
+ /* delete all occurrences of 'from' string */
if (from_len == 1) {
return replace_delete_single_character(
self, from_s[0], maxcount);
}
else
return PyString_FromStringAndSize(
- PyString_AS_STRING(self),
- PyString_GET_SIZE(self)
+ PyString_AS_STRING(self),
+ PyString_GET_SIZE(self)
);
}
_PyString_FormatLong(PyObject *val, int flags, int prec, int type,
char **pbuf, int *plen)
{
- PyObject *result = NULL;
+ PyObject *result = NULL, *r1;
+ const char *s;
char *buf;
Py_ssize_t i;
int sign; /* 1 if '-', else 0 */
int len; /* number of characters */
Py_ssize_t llen;
- int numdigits; /* len == numnondigits + numdigits */
- int numnondigits = 0;
+ int numdigits; /* len == numnondigits + skipped + numdigits */
+ int numnondigits, skipped, filled;
+ const char *method;
switch (type) {
case 'd':
case 'u':
+ method = "str";
result = Py_TYPE(val)->tp_str(val);
break;
case 'o':
+ method = "oct";
result = Py_TYPE(val)->tp_as_number->nb_oct(val);
break;
case 'x':
case 'X':
- numnondigits = 2;
+ method = "hex";
result = Py_TYPE(val)->tp_as_number->nb_hex(val);
break;
default:
if (!result)
return NULL;
- buf = PyString_AsString(result);
- if (!buf) {
+ if (PyString_AsStringAndSize(result, (char **)&s, &llen) < 0) {
Py_DECREF(result);
return NULL;
}
-
- /* To modify the string in-place, there can only be one reference. */
- if (Py_REFCNT(result) != 1) {
- PyErr_BadInternalCall();
- return NULL;
- }
- llen = PyString_Size(result);
if (llen > INT_MAX) {
PyErr_SetString(PyExc_ValueError, "string too large in _PyString_FormatLong");
+ Py_DECREF(result);
return NULL;
}
len = (int)llen;
- if (buf[len-1] == 'L') {
+ if (len > 0 && s[len-1] == 'L') {
--len;
- buf[len] = '\0';
- }
- sign = buf[0] == '-';
- numnondigits += sign;
- numdigits = len - numnondigits;
- assert(numdigits > 0);
-
- /* Get rid of base marker unless F_ALT */
- if ((flags & F_ALT) == 0) {
- /* Need to skip 0x, 0X or 0. */
- int skipped = 0;
- switch (type) {
- case 'o':
- assert(buf[sign] == '0');
- /* If 0 is only digit, leave it alone. */
- if (numdigits > 1) {
- skipped = 1;
- --numdigits;
- }
- break;
- case 'x':
- case 'X':
- assert(buf[sign] == '0');
- assert(buf[sign + 1] == 'x');
+ if (len == 0)
+ goto error;
+ }
+ sign = s[0] == '-';
+ numnondigits = sign;
+
+ /* Need to skip 0x, 0X or 0. */
+ skipped = 0;
+ switch (type) {
+ case 'o':
+ if (s[sign] != '0')
+ goto error;
+ /* If 0 is only digit, leave it alone. */
+ if ((flags & F_ALT) == 0 && len - sign > 1)
+ skipped = 1;
+ break;
+ case 'x':
+ case 'X':
+ if (s[sign] != '0' || (s[sign + 1] != 'x' && s[sign + 1] != 'X'))
+ goto error;
+ if ((flags & F_ALT) == 0)
skipped = 2;
- numnondigits -= 2;
- break;
- }
- if (skipped) {
- buf += skipped;
- len -= skipped;
- if (sign)
- buf[0] = '-';
- }
- assert(len == numnondigits + numdigits);
- assert(numdigits > 0);
+ else
+ numnondigits += 2;
+ break;
}
+ numdigits = len - numnondigits - skipped;
+ if (numdigits <= 0)
+ goto error;
+
+ filled = prec - numdigits;
+ if (filled < 0)
+ filled = 0;
+ len = numnondigits + filled + numdigits;
- /* Fill with leading zeroes to meet minimum width. */
- if (prec > numdigits) {
- PyObject *r1 = PyString_FromStringAndSize(NULL,
- numnondigits + prec);
- char *b1;
- if (!r1) {
- Py_DECREF(result);
+ /* To modify the string in-place, there can only be one reference. */
+ if (skipped >= filled &&
+ PyString_CheckExact(result) &&
+ Py_REFCNT(result) == 1 &&
+ !PyString_CHECK_INTERNED(result))
+ {
+ r1 = NULL;
+ buf = (char *)s + skipped - filled;
+ }
+ else {
+ r1 = result;
+ result = PyString_FromStringAndSize(NULL, len);
+ if (!result) {
+ Py_DECREF(r1);
return NULL;
}
- b1 = PyString_AS_STRING(r1);
- for (i = 0; i < numnondigits; ++i)
- *b1++ = *buf++;
- for (i = 0; i < prec - numdigits; i++)
- *b1++ = '0';
- for (i = 0; i < numdigits; i++)
- *b1++ = *buf++;
- *b1 = '\0';
- Py_DECREF(result);
- result = r1;
buf = PyString_AS_STRING(result);
- len = numnondigits + prec;
}
+ for (i = numnondigits; --i >= 0;)
+ buf[i] = s[i];
+ buf += numnondigits;
+ s += numnondigits + skipped;
+ for (i = 0; i < filled; i++)
+ *buf++ = '0';
+ if (r1 == NULL) {
+ assert(buf == s);
+ buf += numdigits;
+ }
+ else {
+ for (i = 0; i < numdigits; i++)
+ *buf++ = *s++;
+ }
+ *buf = '\0';
+ buf -= len;
+ Py_XDECREF(r1);
+
/* Fix up case for hex conversions. */
if (type == 'X') {
/* Need to convert all lower case letters to upper case.
and need to convert 0x to 0X (and -0x to -0X). */
- for (i = 0; i < len; i++)
- if (buf[i] >= 'a' && buf[i] <= 'x')
+ for (i = 0; i < len; i++) {
+ if (buf[i] >= 'a' && buf[i] <= 'z')
buf[i] -= 'a'-'A';
+ }
}
*pbuf = buf;
*plen = len;
return result;
+
+error:
+ PyErr_Format(PyExc_ValueError,
+ "%%%c format: invalid result of __%s__ (type=%.200s)",
+ type, method, Py_TYPE(val)->tp_name);
+ Py_DECREF(result);
+ return NULL;
}
Py_LOCAL_INLINE(int)
Py_INCREF(type);
if (type->tp_itemsize == 0)
- PyObject_INIT(obj, type);
+ (void)PyObject_INIT(obj, type);
else
(void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems);
va_end(va);
- if (args == NULL)
+ if (args == NULL) {
+ Py_DECREF(func);
return NULL;
+ }
assert(PyTuple_Check(args));
retval = PyObject_Call(func, args, NULL);
va_end(va);
- if (args == NULL)
+ if (args == NULL) {
+ Py_DECREF(func);
return NULL;
+ }
assert(PyTuple_Check(args));
retval = PyObject_Call(func, args, NULL);
The next three properties are the 3 constraints in "C3".
- Local precendece order.
+ Local precedence order.
If A precedes B in C's MRO, then A will precede B in the MRO of all
subclasses of C.
/* Look in tp_dict of types in MRO */
mro = type->tp_mro;
- /* If mro is NULL, the type is either not yet initialized
- by PyType_Ready(), or already cleared by type_clear().
- Either way the safest thing to do is to return NULL. */
- if (mro == NULL)
- return NULL;
+ if (mro == NULL) {
+ if ((type->tp_flags & Py_TPFLAGS_READYING) == 0 &&
+ PyType_Ready(type) < 0) {
+ /* It's not ideal to clear the error condition,
+ but this function is documented as not setting
+ an exception, and I don't want to change that.
+ When PyType_Ready() can't proceed, it won't
+ set the "ready" flag, so future attempts to ready
+ the same type will call it again -- hopefully
+ in a context that propagates the exception out.
+ */
+ PyErr_Clear();
+ return NULL;
+ }
+ mro = type->tp_mro;
+ if (mro == NULL) {
+ return NULL;
+ }
+ }
res = NULL;
assert(PyTuple_Check(mro));
PyErr_Format(PyExc_TypeError,
"can't pickle %.200s objects",
((PyTypeObject *)cls)->tp_name);
- return NULL;
+ goto end;
}
getnewargs = PyObject_GetAttrString(obj, "__getnewargs__");
descr = PyDescr_NewMember(type, memb);
if (descr == NULL)
return -1;
- if (PyDict_SetItemString(dict, memb->name, descr) < 0)
+ if (PyDict_SetItemString(dict, memb->name, descr) < 0) {
+ Py_DECREF(descr);
return -1;
+ }
Py_DECREF(descr);
}
return 0;
if (descr == NULL)
return -1;
- if (PyDict_SetItemString(dict, gsp->name, descr) < 0)
+ if (PyDict_SetItemString(dict, gsp->name, descr) < 0) {
+ Py_DECREF(descr);
return -1;
+ }
Py_DECREF(descr);
}
return 0;
_Py_AddToAllObjects((PyObject *)type, 0);
#endif
+ if (type->tp_name == NULL) {
+ PyErr_Format(PyExc_SystemError,
+ "Type does not define the tp_name field.");
+ goto error;
+ }
+
/* Initialize tp_base (defaults to BaseObject unless that's us) */
base = type->tp_base;
if (base == NULL && type != &PyBaseObject_Type) {
descr = PyDescr_NewWrapper(type, p, *ptr);
if (descr == NULL)
return -1;
- if (PyDict_SetItem(dict, p->name_strobj, descr) < 0)
+ if (PyDict_SetItem(dict, p->name_strobj, descr) < 0) {
+ Py_DECREF(descr);
return -1;
+ }
Py_DECREF(descr);
}
}
size_t new_size = sizeof(Py_UNICODE) * ((size_t)length + 1);
unicode->str = (Py_UNICODE*) PyObject_MALLOC(new_size);
}
- PyObject_INIT(unicode, &PyUnicode_Type);
+ (void)PyObject_INIT(unicode, &PyUnicode_Type);
}
else {
size_t new_size;
stream as-is (giving a ZWNBSP character). */
if (bo == 0) {
if (size >= 4) {
- const Py_UCS4 bom = (q[iorder[3]] << 24) | (q[iorder[2]] << 16) |
+ const Py_UCS4 bom = ((unsigned int)q[iorder[3]] << 24) | (q[iorder[2]] << 16) |
(q[iorder[1]] << 8) | q[iorder[0]];
#ifdef BYTEORDER_IS_LITTLE_ENDIAN
if (bom == 0x0000FEFF) {
/* The remaining input chars are ignored if the callback
chooses to skip the input */
}
- ch = (q[iorder[3]] << 24) | (q[iorder[2]] << 16) |
+ ch = ((unsigned int)q[iorder[3]] << 24) | (q[iorder[2]] << 16) |
(q[iorder[1]] << 8) | q[iorder[0]];
if (ch >= 0x110000)
return (PyObject *)v;
}
+ if (u->length > PY_SSIZE_T_MAX - v->length) {
+ PyErr_SetString(PyExc_OverflowError,
+ "strings are too large to concat");
+ goto onError;
+ }
+
/* Concat the two Unicode strings */
w = _PyUnicode_New(u->length + v->length);
if (w == NULL)
return (PyObject*) str;
}
- /* ensure # of chars needed doesn't overflow int and # of bytes
+ /* ensure # of chars needed doesn't overflow Py_ssize_t and # of bytes
* needed doesn't overflow size_t
*/
- nchars = len * str->length;
- if (len && nchars / len != str->length) {
+ if (len && str->length > PY_SSIZE_T_MAX / len) {
PyErr_SetString(PyExc_OverflowError,
"repeated string is too long");
return NULL;
}
- nbytes = (nchars + 1) * sizeof(Py_UNICODE);
- if (nbytes / sizeof(Py_UNICODE) != (size_t)(nchars + 1)) {
+ nchars = len * str->length;
+ nbytes = ((size_t)nchars + 1u) * sizeof(Py_UNICODE);
+ if (nbytes / sizeof(Py_UNICODE) != ((size_t)nchars + 1u)) {
PyErr_SetString(PyExc_OverflowError,
"repeated string is too long");
return NULL;
from __future__ import with_statement
import os, sys, re, shutil
+import subprocess
# Find all "foo.exe" files on the PATH.
def find_all_on_path(filename, extras = None):
# is available.
def find_working_perl(perls):
for perl in perls:
- fh = os.popen('"%s" -e "use Win32;"' % perl)
- fh.read()
- rc = fh.close()
- if rc:
+ try:
+ subprocess.check_output([perl, "-e", "use win32;"])
+ except Subprocess.CalledProcessError:
continue
- return perl
+ else:
+ return perl
print("Can not find a suitable PERL:")
if perls:
print(" the following perl interpreters were found:")
perl = find_working_perl(perls)
if perl:
print("Found a working perl at '%s'" % (perl,))
+ # Set PERL for the makefile to find it
+ os.environ["PERL"] = perl
else:
print("No Perl installation was found. Existing Makefiles are used.")
sys.stdout.flush()
/>\r
<UserMacro\r
Name="sqlite3Dir"\r
- Value="$(externalsDir)\sqlite-3.6.21"\r
+ Value="$(externalsDir)\sqlite-3.8.11.0"\r
/>\r
<UserMacro\r
Name="bz2Dir"\r
/>\r
<UserMacro\r
Name="opensslDir"\r
- Value="$(externalsDir)\openssl-1.0.2h"\r
+ Value="$(externalsDir)\openssl-1.0.2j"\r
/>\r
<UserMacro\r
Name="tcltkDir"\r
Wraps Berkeley DB 4.7.25, which is currently built by _bsddb.vcproj.\r
project.\r
_sqlite3\r
- Wraps SQLite 3.6.21, which is currently built by sqlite3.vcproj.\r
+ Wraps SQLite 3.8.11.0, which is currently built by sqlite3.vcproj.\r
_tkinter\r
Wraps the Tk windowing system. Unlike _bsddb and _sqlite3, there's no\r
corresponding tcltk.vcproj-type project that builds Tcl/Tk from vcproj's\r
\r
Get the source code through\r
\r
- svn export http://svn.python.org/projects/external/openssl-1.0.2h\r
+ svn export http://svn.python.org/projects/external/openssl-1.0.2j\r
\r
** NOTE: if you use the PCbuild\get_externals.bat approach for\r
obtaining external sources then you don't need to manually get the source\r
0, /*tp_is_gc*/
};
+#define Py_NOT_PERSIST(x, flag) \
+ (x != (int)(flag) && \
+ x != ((int)(flag) | MSIDBOPEN_PATCHFILE))
+
+#define Py_INVALID_PERSIST(x) \
+ (Py_NOT_PERSIST(x, MSIDBOPEN_READONLY) && \
+ Py_NOT_PERSIST(x, MSIDBOPEN_TRANSACT) && \
+ Py_NOT_PERSIST(x, MSIDBOPEN_DIRECT) && \
+ Py_NOT_PERSIST(x, MSIDBOPEN_CREATE) && \
+ Py_NOT_PERSIST(x, MSIDBOPEN_CREATEDIRECT))
+
static PyObject* msiopendb(PyObject *obj, PyObject *args)
{
int status;
int persist;
MSIHANDLE h;
msiobj *result;
-
if (!PyArg_ParseTuple(args, "si:MSIOpenDatabase", &path, &persist))
return NULL;
-
- status = MsiOpenDatabase(path, (LPCSTR)persist, &h);
+ /* We need to validate that persist is a valid MSIDBOPEN_* value. Otherwise,
+ MsiOpenDatabase may treat the value as a pointer, leading to unexpected
+ behavior. */
+ if (Py_INVALID_PERSIST(persist))
+ return msierror(ERROR_INVALID_PARAMETER);
+ status = MsiOpenDatabase(path, (LPCSTR)persist, &h);
if (status != ERROR_SUCCESS)
return msierror(status);
PropSheet_SetWizButtons(GetParent(hwnd),
PSWIZB_BACK | PSWIZB_NEXT);
/* Get the python directory */
- ivi = (InstalledVersionInfo *)
+ ivi = (InstalledVersionInfo *)
SendDlgItemMessage(hwnd,
- IDC_VERSIONS_LIST,
- LB_GETITEMDATA,
- id,
- 0);
- hkey_root = ivi->hkey;
- strcpy(python_dir, ivi->prefix);
- SetDlgItemText(hwnd, IDC_PATH, python_dir);
- /* retrieve the python version and pythondll to use */
+ IDC_VERSIONS_LIST,
+ LB_GETITEMDATA,
+ id,
+ 0);
+ hkey_root = ivi->hkey;
+ strcpy(python_dir, ivi->prefix);
+ SetDlgItemText(hwnd, IDC_PATH, python_dir);
+ /* retrieve the python version and pythondll to use */
result = SendDlgItemMessage(hwnd, IDC_VERSIONS_LIST,
LB_GETTEXTLEN, (WPARAM)id, 0);
pbuf = (char *)malloc(result + 1);
if (handle == -1)
return PyErr_SetFromErrno(PyExc_IOError);
- /* technically 'handle' is not a pointer, but a integer as
+ /* technically 'handle' is not a pointer, but an integer as
large as a pointer, Python's *VoidPtr interface is the
most appropriate here */
return PyLong_FromVoidPtr((void*)handle);
CFLAGS+= -DPREFIX=$(DQUOTE)$(LIB_DIR)$(DQUOTE)
endif
-# We're using the OMF format since EMX's ld has a obscure bug
+# We're using the OMF format since EMX's ld has an obscure bug
# because of which it sometimes fails to build relocations
# in .data segment that point to another .data locations
# (except for the final linking if the .EXEs)
pythonhome = NULL;
}
else {
- char *delim;
+ char *delim;
strcpy(prefix, pythonhome);
- /* Extract Any Optional Trailing EXEC_PREFIX */
- /* e.g. PYTHONHOME=<prefix>:<exec_prefix> */
- delim = strchr(prefix, DELIM);
- if (delim) {
- *delim = '\0';
- strcpy(exec_prefix, delim+1);
- } else
- strcpy(exec_prefix, EXEC_PREFIX);
+ /* Extract Any Optional Trailing EXEC_PREFIX */
+ /* e.g. PYTHONHOME=<prefix>:<exec_prefix> */
+ delim = strchr(prefix, DELIM);
+ if (delim) {
+ *delim = '\0';
+ strcpy(exec_prefix, delim+1);
+ } else
+ strcpy(exec_prefix, EXEC_PREFIX);
}
if (envpath && *envpath == '\0')
int length;
int ok;
- if(!PyArg_ParseTuple(args,"z#i:PlaySound",&sound,&length,&flags)) {
- return NULL;
+ if (!PyArg_ParseTuple(args, "z#i:PlaySound", &sound, &length, &flags)) {
+ return NULL;
}
- if(flags&SND_ASYNC && flags &SND_MEMORY) {
- /* Sidestep reference counting headache; unfortunately this also
- prevent SND_LOOP from memory. */
- PyErr_SetString(PyExc_RuntimeError,"Cannot play asynchronously from memory");
- return NULL;
+ if (flags & SND_ASYNC && flags & SND_MEMORY) {
+ /* Sidestep reference counting headache; unfortunately this also
+ prevent SND_LOOP from memory. */
+ PyErr_SetString(PyExc_RuntimeError, "Cannot play asynchronously from memory");
+ return NULL;
}
Py_BEGIN_ALLOW_THREADS
- ok = PlaySound(sound,NULL,flags);
+ ok = PlaySound(sound, NULL, flags);
Py_END_ALLOW_THREADS
- if(!ok)
- {
- PyErr_SetString(PyExc_RuntimeError,"Failed to play sound");
- return NULL;
+ if (!ok) {
+ PyErr_SetString(PyExc_RuntimeError, "Failed to play sound");
+ return NULL;
}
Py_INCREF(Py_None);
static void
add_define(PyObject *dict, const char *key, long value)
{
- PyObject *k=PyString_FromString(key);
- PyObject *v=PyLong_FromLong(value);
- if(v&&k)
- {
- PyDict_SetItem(dict,k,v);
+ PyObject *k = PyString_FromString(key);
+ PyObject *v = PyLong_FromLong(value);
+ if (v && k) {
+ PyDict_SetItem(dict, k, v);
}
Py_XDECREF(k);
Py_XDECREF(v);
set libraries=%libraries% bzip2-1.0.6\r
if NOT "%IncludeBsddb%"=="false" set libraries=%libraries% db-4.7.25.0\r
if NOT "%IncludeSSL%"=="false" set libraries=%libraries% nasm-2.11.06\r
-if NOT "%IncludeSSL%"=="false" set libraries=%libraries% openssl-1.0.2h\r
+if NOT "%IncludeSSL%"=="false" set libraries=%libraries% openssl-1.0.2j\r
set libraries=%libraries% sqlite-3.8.11.0\r
if NOT "%IncludeTkinter%"=="false" set libraries=%libraries% tcl-8.5.15.0\r
if NOT "%IncludeTkinter%"=="false" set libraries=%libraries% tk-8.5.15.0\r
--- /dev/null
+#! /usr/bin/env python3
+# Script for preparing OpenSSL for building on Windows.
+# Uses Perl to create nmake makefiles and otherwise prepare the way
+# for building on 32 or 64 bit platforms.
+
+# Script originally authored by Mark Hammond.
+# Major revisions by:
+# Martin v. Löwis
+# Christian Heimes
+# Zachary Ware
+
+# THEORETICALLY, you can:
+# * Unpack the latest OpenSSL release where $(opensslDir) in
+# PCbuild\pyproject.props expects it to be.
+# * Install ActivePerl and ensure it is somewhere on your path.
+# * Run this script with the OpenSSL source dir as the only argument.
+#
+# it should configure OpenSSL such that it is ready to be built by
+# ssl.vcxproj on 32 or 64 bit platforms.
+
+from __future__ import print_function
+
+import os
+import re
+import sys
+import subprocess
+from shutil import copy
+
+# Find all "foo.exe" files on the PATH.
+def find_all_on_path(filename, extras=None):
+ entries = os.environ["PATH"].split(os.pathsep)
+ ret = []
+ for p in entries:
+ fname = os.path.abspath(os.path.join(p, filename))
+ if os.path.isfile(fname) and fname not in ret:
+ ret.append(fname)
+ if extras:
+ for p in extras:
+ fname = os.path.abspath(os.path.join(p, filename))
+ if os.path.isfile(fname) and fname not in ret:
+ ret.append(fname)
+ return ret
+
+
+# Find a suitable Perl installation for OpenSSL.
+# cygwin perl does *not* work. ActivePerl does.
+# Being a Perl dummy, the simplest way I can check is if the "Win32" package
+# is available.
+def find_working_perl(perls):
+ for perl in perls:
+ try:
+ subprocess.check_output([perl, "-e", "use Win32;"])
+ except subprocess.CalledProcessError:
+ continue
+ else:
+ return perl
+
+ if perls:
+ print("The following perl interpreters were found:")
+ for p in perls:
+ print(" ", p)
+ print(" None of these versions appear suitable for building OpenSSL")
+ else:
+ print("NO perl interpreters were found on this machine at all!")
+ print(" Please install ActivePerl and ensure it appears on your path")
+
+
+def create_asms(makefile, tmp_d):
+ #create a custom makefile out of the provided one
+ asm_makefile = os.path.splitext(makefile)[0] + '.asm.mak'
+ with open(makefile) as fin, open(asm_makefile, 'w') as fout:
+ for line in fin:
+ # Keep everything up to the install target (it's convenient)
+ if line.startswith('install: all'):
+ break
+ fout.write(line)
+ asms = []
+ for line in fin:
+ if '.asm' in line and line.strip().endswith('.pl'):
+ asms.append(line.split(':')[0])
+ while line.strip():
+ fout.write(line)
+ line = next(fin)
+ fout.write('\n')
+
+ fout.write('asms: $(TMP_D) ')
+ fout.write(' '.join(asms))
+ fout.write('\n')
+ os.system('nmake /f {} PERL=perl TMP_D={} asms'.format(asm_makefile, tmp_d))
+
+
+def copy_includes(makefile, suffix):
+ dir = 'include'+suffix+'\\openssl'
+ try:
+ os.makedirs(dir)
+ except OSError:
+ pass
+ copy_if_different = r'$(PERL) $(SRC_D)\util\copy-if-different.pl'
+ with open(makefile) as fin:
+ for line in fin:
+ if copy_if_different in line:
+ perl, script, src, dest = line.split()
+ if not '$(INCO_D)' in dest:
+ continue
+ # We're in the root of the source tree
+ src = src.replace('$(SRC_D)', '.').strip('"')
+ dest = dest.strip('"').replace('$(INCO_D)', dir)
+ print('copying', src, 'to', dest)
+ copy(src, dest)
+
+
+def run_configure(configure, do_script):
+ print("perl Configure "+configure+" no-idea no-mdc2")
+ os.system("perl Configure "+configure+" no-idea no-mdc2")
+ print(do_script)
+ os.system(do_script)
+
+
+def prep(arch):
+ makefile_template = "ms\\nt{}.mak"
+ generated_makefile = makefile_template.format('')
+ if arch == "x86":
+ configure = "VC-WIN32"
+ do_script = "ms\\do_nasm"
+ suffix = "32"
+ elif arch == "amd64":
+ configure = "VC-WIN64A"
+ do_script = "ms\\do_win64a"
+ suffix = "64"
+ #os.environ["VSEXTCOMP_USECL"] = "MS_OPTERON"
+ else:
+ raise ValueError('Unrecognized platform: %s' % arch)
+
+ print("Creating the makefiles...")
+ sys.stdout.flush()
+ # run configure, copy includes, create asms
+ run_configure(configure, do_script)
+ makefile = makefile_template.format(suffix)
+ try:
+ os.unlink(makefile)
+ except FileNotFoundError:
+ pass
+ os.rename(generated_makefile, makefile)
+ copy_includes(makefile, suffix)
+
+ print('creating asms...')
+ create_asms(makefile, 'tmp'+suffix)
+
+
+def main():
+ if len(sys.argv) == 1:
+ print("Not enough arguments: directory containing OpenSSL",
+ "sources must be supplied")
+ sys.exit(1)
+
+ if len(sys.argv) > 2:
+ print("Too many arguments supplied, all we need is the directory",
+ "containing OpenSSL sources")
+ sys.exit(1)
+
+ ssl_dir = sys.argv[1]
+
+ if not os.path.isdir(ssl_dir):
+ print(ssl_dir, "is not an existing directory!")
+ sys.exit(1)
+
+ # perl should be on the path, but we also look in "\perl" and "c:\\perl"
+ # as "well known" locations
+ perls = find_all_on_path("perl.exe", [r"\perl\bin",
+ r"C:\perl\bin",
+ r"\perl64\bin",
+ r"C:\perl64\bin",
+ ])
+ perl = find_working_perl(perls)
+ if perl:
+ print("Found a working perl at '%s'" % (perl,))
+ else:
+ sys.exit(1)
+ if not find_all_on_path('nmake.exe'):
+ print('Could not find nmake.exe, try running env.bat')
+ sys.exit(1)
+ if not find_all_on_path('nasm.exe'):
+ print('Could not find nasm.exe, please add to PATH')
+ sys.exit(1)
+ sys.stdout.flush()
+
+ # Put our working Perl at the front of our path
+ os.environ["PATH"] = os.path.dirname(perl) + \
+ os.pathsep + \
+ os.environ["PATH"]
+
+ old_cwd = os.getcwd()
+ try:
+ os.chdir(ssl_dir)
+ for arch in ['amd64', 'x86']:
+ prep(arch)
+ finally:
+ os.chdir(old_cwd)
+
+if __name__=='__main__':
+ main()
<IntDir Condition="'$(Configuration)' == 'PGInstrument' or '$(Configuration)' == 'PGUpdate'">$(SolutionDir)obj\$(ArchName)\$(ProjectName)\</IntDir>
<TargetName Condition="'$(TargetName)' == ''">$(ProjectName)</TargetName>
<TargetName>$(TargetName)$(PyDebugExt)</TargetName>
- <GenerateManifest Condition="'$(GenerateManifest)' == ''">false</GenerateManifest>
- <EmbedManifest Condition="'$(EmbedManifest)' == ''">false</EmbedManifest>
- <!-- For VS2008, we have to embed the manifest to be able to run -->
+ <GenerateManifest>false</GenerateManifest>
+ <EmbedManifest>false</EmbedManifest>
<!-- BasePlatformToolset is for ICC support -->
- <GenerateManifest Condition="'$(PlatformToolset)' == 'v90' or '$(BasePlatformToolset)' == 'v90'">true</GenerateManifest>
- <EmbedManifest Condition="'$(PlatformToolset)' == 'v90' or '$(BasePlatformToolset)' == 'v90'">true</EmbedManifest>
<SupportPGO Condition="'$(SupportPGO)' == ''">true</SupportPGO>
<SupportSigning Condition="'$(SupportSigning)' == ''">true</SupportSigning>
<SupportSigning Condition="'$(Configuration)' == 'Debug'">false</SupportSigning>
<sqlite3Dir>$(ExternalsDir)sqlite-3.8.11.0\</sqlite3Dir>
<bz2Dir>$(ExternalsDir)bzip2-1.0.6\</bz2Dir>
<bsddbDir>$(ExternalsDir)db-4.7.25.0</bsddbDir>
- <opensslDir>$(ExternalsDir)openssl-1.0.2h\</opensslDir>
+ <opensslDir>$(ExternalsDir)openssl-1.0.2j\</opensslDir>
<opensslIncludeDir>$(opensslDir)include32</opensslIncludeDir>
<opensslIncludeDir Condition="'$(ArchName)' == 'amd64'">$(opensslDir)include64</opensslIncludeDir>
<nasmDir>$(ExternalsDir)\nasm-2.11.06\</nasmDir>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+ <!-- For VS2008, we have to embed the manifest to be able to run -->
+ <GenerateManifest Condition="'$(PlatformToolset)' == 'v90' or '$(BasePlatformToolset)' == 'v90'">true</GenerateManifest>
+ <EmbedManifest Condition="'$(PlatformToolset)' == 'v90' or '$(BasePlatformToolset)' == 'v90'">true</EmbedManifest>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<TargetName>$(PyDllName)</TargetName>
+ <!-- For VS2008, we have to embed the manifest to be able to run -->
+ <GenerateManifest Condition="'$(PlatformToolset)' == 'v90' or '$(BasePlatformToolset)' == 'v90'">true</GenerateManifest>
+ <EmbedManifest Condition="'$(PlatformToolset)' == 'v90' or '$(BasePlatformToolset)' == 'v90'">true</EmbedManifest>
</PropertyGroup>
<PropertyGroup>
<CustomBuildBeforeTargets>Link</CustomBuildBeforeTargets>
<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
+ <!-- For VS2008, we have to embed the manifest to be able to run -->
+ <GenerateManifest Condition="'$(PlatformToolset)' == 'v90' or '$(BasePlatformToolset)' == 'v90'">true</GenerateManifest>
+ <EmbedManifest Condition="'$(PlatformToolset)' == 'v90' or '$(BasePlatformToolset)' == 'v90'">true</EmbedManifest>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+ <!-- For VS2008, we have to embed the manifest to be able to run -->
+ <GenerateManifest Condition="'$(PlatformToolset)' == 'v90' or '$(BasePlatformToolset)' == 'v90'">true</GenerateManifest>
+ <EmbedManifest Condition="'$(PlatformToolset)' == 'v90' or '$(BasePlatformToolset)' == 'v90'">true</EmbedManifest>
</PropertyGroup>
<ItemDefinitionGroup>
<Link>
Homepage:\r
http://www.bzip.org/\r
_ssl\r
- Python wrapper for version 1.0.2h of the OpenSSL secure sockets\r
+ Python wrapper for version 1.0.2j of the OpenSSL secure sockets\r
library, which is built by ssl.vcxproj\r
Homepage:\r
http://www.openssl.org/\r
"version ::= Id String"
if version.value != "version":
raise ASDLSyntaxError(version.lineno,
- msg="expected 'version', found %" % version)
+ msg="expected 'version', found %s" % version)
return V
def p_definition_0(self, (definition,)):
class StructVisitor(EmitVisitor):
- """Visitor to generate typdefs for AST."""
+ """Visitor to generate typedefs for AST."""
def visitModule(self, mod):
for dfn in mod.dfns:
self.emit("res = obj2ast_%s(PyList_GET_ITEM(tmp, i), &value, arena);" %
field.type, depth+2, reflow=False)
self.emit("if (res != 0) goto failed;", depth+2)
+ self.emit("if (len != PyList_GET_SIZE(tmp)) {", depth+2)
+ self.emit("PyErr_SetString(PyExc_RuntimeError, \"%s field \\\"%s\\\" "
+ "changed size during iteration\");" %
+ (name, field.name),
+ depth+3, reflow=False)
+ self.emit("goto failed;", depth+3)
+ self.emit("}", depth+2)
self.emit("asdl_seq_SET(%s, i, value);" % field.name, depth+2)
self.emit("}", depth+1)
else:
static char REQNFMT[] = "metacompile: less than %d children\n";
-#define REQN(i, count) \
+#define REQN(i, count) do { \
if (i < count) { \
fprintf(stderr, REQNFMT, count); \
Py_FatalError("REQN"); \
- } else
+ } \
+} while (0)
#else
#define REQN(i, count) /* empty */
REQ(n, ATOM);
i = n->n_nchildren;
+ (void)i; /* Don't warn about set but unused */
REQN(i, 1);
n = n->n_child;
if (n->n_type == LPAR) {
else {
tok->done = E_OK;
tok->inp = strchr(tok->buf, '\0');
- done = tok->inp[-1] == '\n';
+ done = tok->inp == tok->buf || tok->inp[-1] == '\n';
}
}
else {
stmt_ty value;
res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(body, i, value);
}
Py_XDECREF(tmp);
stmt_ty value;
res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(body, i, value);
}
Py_XDECREF(tmp);
stmt_ty value;
res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(body, i, value);
}
Py_XDECREF(tmp);
stmt_ty value;
res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(body, i, value);
}
Py_XDECREF(tmp);
expr_ty value;
res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(decorator_list, i, value);
}
Py_XDECREF(tmp);
expr_ty value;
res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(bases, i, value);
}
Py_XDECREF(tmp);
stmt_ty value;
res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(body, i, value);
}
Py_XDECREF(tmp);
expr_ty value;
res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(decorator_list, i, value);
}
Py_XDECREF(tmp);
expr_ty value;
res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(targets, i, value);
}
Py_XDECREF(tmp);
expr_ty value;
res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(targets, i, value);
}
Py_XDECREF(tmp);
expr_ty value;
res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "Print field \"values\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(values, i, value);
}
Py_XDECREF(tmp);
stmt_ty value;
res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(body, i, value);
}
Py_XDECREF(tmp);
stmt_ty value;
res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(orelse, i, value);
}
Py_XDECREF(tmp);
stmt_ty value;
res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(body, i, value);
}
Py_XDECREF(tmp);
stmt_ty value;
res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(orelse, i, value);
}
Py_XDECREF(tmp);
stmt_ty value;
res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(body, i, value);
}
Py_XDECREF(tmp);
stmt_ty value;
res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(orelse, i, value);
}
Py_XDECREF(tmp);
stmt_ty value;
res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(body, i, value);
}
Py_XDECREF(tmp);
stmt_ty value;
res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "TryExcept field \"body\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(body, i, value);
}
Py_XDECREF(tmp);
excepthandler_ty value;
res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "TryExcept field \"handlers\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(handlers, i, value);
}
Py_XDECREF(tmp);
stmt_ty value;
res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "TryExcept field \"orelse\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(orelse, i, value);
}
Py_XDECREF(tmp);
stmt_ty value;
res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "TryFinally field \"body\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(body, i, value);
}
Py_XDECREF(tmp);
stmt_ty value;
res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "TryFinally field \"finalbody\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(finalbody, i, value);
}
Py_XDECREF(tmp);
alias_ty value;
res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(names, i, value);
}
Py_XDECREF(tmp);
alias_ty value;
res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(names, i, value);
}
Py_XDECREF(tmp);
identifier value;
res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(names, i, value);
}
Py_XDECREF(tmp);
expr_ty value;
res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(values, i, value);
}
Py_XDECREF(tmp);
expr_ty value;
res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(keys, i, value);
}
Py_XDECREF(tmp);
expr_ty value;
res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(values, i, value);
}
Py_XDECREF(tmp);
expr_ty value;
res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(elts, i, value);
}
Py_XDECREF(tmp);
comprehension_ty value;
res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(generators, i, value);
}
Py_XDECREF(tmp);
comprehension_ty value;
res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(generators, i, value);
}
Py_XDECREF(tmp);
comprehension_ty value;
res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(generators, i, value);
}
Py_XDECREF(tmp);
comprehension_ty value;
res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(generators, i, value);
}
Py_XDECREF(tmp);
cmpop_ty value;
res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(ops, i, value);
}
Py_XDECREF(tmp);
expr_ty value;
res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(comparators, i, value);
}
Py_XDECREF(tmp);
expr_ty value;
res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(args, i, value);
}
Py_XDECREF(tmp);
keyword_ty value;
res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(keywords, i, value);
}
Py_XDECREF(tmp);
expr_ty value;
res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(elts, i, value);
}
Py_XDECREF(tmp);
expr_ty value;
res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(elts, i, value);
}
Py_XDECREF(tmp);
slice_ty value;
res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(dims, i, value);
}
Py_XDECREF(tmp);
expr_ty value;
res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(ifs, i, value);
}
Py_XDECREF(tmp);
stmt_ty value;
res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(body, i, value);
}
Py_XDECREF(tmp);
expr_ty value;
res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(args, i, value);
}
Py_XDECREF(tmp);
expr_ty value;
res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena);
if (res != 0) goto failed;
+ if (len != PyList_GET_SIZE(tmp)) {
+ PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
+ goto failed;
+ }
asdl_seq_SET(defaults, i, value);
}
Py_XDECREF(tmp);
testlist: test (',' test)* [',']
augassign: '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^='
| '<<=' | '>>=' | '**=' | '//='
- test: ... here starts the operator precendence dance
+ test: ... here starts the operator precedence dance
*/
if (NCH(n) == 1) {
dest = ast_for_expr(c, CHILD(n, 2));
if (!dest)
return NULL;
- start = 4;
+ start = 4;
}
values_count = (NCH(n) + 1 - start) / 2;
if (values_count) {
if (need<2*outlen) {
need = 2*outlen;
- }
- if (_PyString_Resize(&result, need)) {
- Py_DECREF(item);
- return NULL;
- }
- outlen = need;
- }
- memcpy(
- PyString_AS_STRING(result) + j,
- PyString_AS_STRING(item),
- reslen
- );
- j += reslen;
}
+ if (_PyString_Resize(&result, need)) {
+ Py_DECREF(item);
+ return NULL;
+ }
+ outlen = need;
+ }
+ memcpy(
+ PyString_AS_STRING(result) + j,
+ PyString_AS_STRING(item),
+ reslen
+ );
+ j += reslen;
+ }
}
Py_DECREF(item);
if (ok < 0)
assert(outlen >= 0);
if (need > outlen) {
- /* overallocate,
- to avoid reallocations */
+ /* overallocate, to avoid reallocations */
if (need < 2 * outlen) {
- if (outlen > PY_SSIZE_T_MAX / 2) {
- Py_DECREF(item);
- return NULL;
- } else {
- need = 2 * outlen;
- }
- }
-
- if (PyUnicode_Resize(
- &result, need) < 0) {
- Py_DECREF(item);
- goto Fail_1;
- }
- outlen = need;
- }
- memcpy(PyUnicode_AS_UNICODE(result) + j,
- PyUnicode_AS_UNICODE(item),
- reslen*sizeof(Py_UNICODE));
- j += reslen;
+ if (outlen > PY_SSIZE_T_MAX / 2) {
+ Py_DECREF(item);
+ return NULL;
+ } else {
+ need = 2 * outlen;
+ }
}
+
+ if (PyUnicode_Resize(&result, need) < 0) {
+ Py_DECREF(item);
+ goto Fail_1;
+ }
+ outlen = need;
+ }
+ memcpy(PyUnicode_AS_UNICODE(result) + j,
+ PyUnicode_AS_UNICODE(item),
+ reslen*sizeof(Py_UNICODE));
+ j += reslen;
+ }
}
Py_DECREF(item);
if (ok < 0)
TARGET(BUILD_SET)
{
+ int i;
x = PySet_New(NULL);
if (x != NULL) {
- for (; --oparg >= 0;) {
- w = POP();
+ for (i = oparg; i > 0; i--) {
+ w = PEEK(i);
if (err == 0)
err = PySet_Add(x, w);
Py_DECREF(w);
}
+ STACKADJ(-oparg);
if (err != 0) {
Py_DECREF(x);
break;
attr = PyString_FromStringAndSize(src,
dot ? dot - src : strlen(src));
if (!attr)
- return -1;
+ return 0;
ADDOP_O(c, LOAD_ATTR, attr, names);
Py_DECREF(attr);
src = dot + 1;
{
struct fblockinfo *f;
if (c->u->u_nfblocks >= CO_MAXBLOCKS) {
- PyErr_SetString(PyExc_SystemError,
+ PyErr_SetString(PyExc_SyntaxError,
"too many statically nested blocks");
return 0;
}
return 0;
}
+#ifdef Py_USING_UNICODE
+static size_t
+_ustrlen(Py_UNICODE *u)
+{
+ size_t i = 0;
+ Py_UNICODE *v = u;
+ while (*v != 0) { i++; v++; }
+ return i;
+}
+#endif
+
/* Convert a non-tuple argument. Return NULL if conversion went OK,
or a string with a message describing the failure. The message is
formatted as "must be <desired type>, not <actual type>".
format++;
} else {
Py_UNICODE **p = va_arg(*p_va, Py_UNICODE **);
- if (PyUnicode_Check(arg))
+ if (PyUnicode_Check(arg)) {
*p = PyUnicode_AS_UNICODE(arg);
+ if (_ustrlen(*p) != (size_t)PyUnicode_GET_SIZE(arg)) {
+ return converterr(
+ "unicode without null characters",
+ arg, msgbuf, bufsize);
+ }
+ }
else
return converterr("unicode", arg, msgbuf, bufsize);
}
if (parent == NULL)
goto error_exit;
+ Py_INCREF(parent);
head = load_next(parent, level < 0 ? Py_None : parent, &name, buf,
&buflen);
+ Py_DECREF(parent);
if (head == NULL)
goto error_exit;
return 0;
}
if (!PyString_Check(item)) {
- PyErr_SetString(PyExc_TypeError,
- "Item in ``from list'' not a string");
+ PyErr_Format(PyExc_TypeError,
+ "Item in ``from list'' must be str, not %.200s",
+ Py_TYPE(item)->tp_name);
Py_DECREF(item);
return 0;
}
}
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
OSErr
PyMac_GetFullPathname(FSSpec *fss, char *path, int len)
{
Py_XDECREF(fs);
return err;
}
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
/* Convert a 4-char string object argument to an OSType value */
int
\
PyObject *routinename(object cobj) { \
if (!PyMacGluePtr_##routinename) { \
- if (!PyImport_ImportModule(module)) return NULL; \
- if (!PyMacGluePtr_##routinename) { \
- PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \
- return NULL; \
- } \
+ if (!PyImport_ImportModule(module)) return NULL; \
+ if (!PyMacGluePtr_##routinename) { \
+ PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \
+ return NULL; \
+ } \
} \
return (*PyMacGluePtr_##routinename)(cobj); \
}
\
int routinename(PyObject *pyobj, object *cobj) { \
if (!PyMacGluePtr_##routinename) { \
- if (!PyImport_ImportModule(module)) return 0; \
- if (!PyMacGluePtr_##routinename) { \
- PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \
- return 0; \
- } \
+ if (!PyImport_ImportModule(module)) return 0; \
+ if (!PyMacGluePtr_##routinename) { \
+ PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \
+ return 0; \
+ } \
} \
return (*PyMacGluePtr_##routinename)(pyobj, cobj); \
}
GLUE_NEW(GWorldPtr, GWorldObj_New, "Carbon.Qdoffs")
GLUE_CONVERT(GWorldPtr, GWorldObj_Convert, "Carbon.Qdoffs")
-#ifndef __LP64__
+#if APPLE_SUPPORTS_QUICKTIME
GLUE_NEW(Track, TrackObj_New, "Carbon.Qt")
GLUE_CONVERT(Track, TrackObj_Convert, "Carbon.Qt")
GLUE_NEW(Movie, MovieObj_New, "Carbon.Qt")
GLUE_CONVERT(UserData, UserDataObj_Convert, "Carbon.Qt")
GLUE_NEW(Media, MediaObj_New, "Carbon.Qt")
GLUE_CONVERT(Media, MediaObj_Convert, "Carbon.Qt")
-#endif /* !__LP64__ */
+#endif /* APPLE_SUPPORTS_QUICKTIME */
GLUE_NEW(Handle, ResObj_New, "Carbon.Res")
GLUE_CONVERT(Handle, ResObj_Convert, "Carbon.Res")
/* High water mark to determine when the marshalled object is dangerously deep
* and risks coring the interpreter. When the object stack gets this deep,
* raise an exception instead of continuing.
+ * On Windows debug builds, reduce this value.
*/
+#if defined(MS_WINDOWS) && defined(_DEBUG)
+#define MAX_MARSHAL_STACK_DEPTH 1000
+#else
#define MAX_MARSHAL_STACK_DEPTH 2000
+#endif
#define TYPE_NULL '0'
#define TYPE_NONE 'N'
absx = fabs(x);
y = floor(absx);
if (absx - y >= 0.5)
- y += 1.0;
+ y += 1.0;
return copysign(y, x);
}
#endif /* HAVE_ROUND */
#include <windows.h>
#else
#include <fcntl.h>
+#if defined(HAVE_GETRANDOM) || defined(HAVE_GETENTROPY)
+#include <sys/random.h>
+#endif
#endif
#ifdef Py_DEBUG
}
else {
if (st->st_cur->ste_type != ModuleBlock) {
- int lineno = st->st_cur->ste_lineno;
- if (!symtable_warn(st, IMPORT_STAR_WARNING, lineno)) {
- Py_DECREF(store_name);
- return 0;
- }
+ int lineno = st->st_cur->ste_lineno;
+ if (!symtable_warn(st, IMPORT_STAR_WARNING, lineno)) {
+ Py_DECREF(store_name);
+ return 0;
+ }
}
st->st_cur->ste_unoptimized |= OPT_IMPORT_STAR;
Py_DECREF(store_name);
{"major", "Major release number"},
{"minor", "Minor release number"},
{"micro", "Patch release number"},
- {"releaselevel", "'alpha', 'beta', 'candidate', or 'release'"},
+ {"releaselevel", "'alpha', 'beta', 'candidate', or 'final'"},
{"serial", "Serial release number"},
{0}
};
threads.
This is valid for HP-UX 11.23 running on an ia64 system. If needed, add
- a check of __ia64 to verify that we're running on a ia64 system instead
+ a check of __ia64 to verify that we're running on an ia64 system instead
of a pa-risc system.
*/
#ifdef __hpux
dprintf(("PyThread_allocate_lock called\n"));
if (!initialized)
- PyThread_init_thread();
+ PyThread_init_thread();
aLock = CreateEvent(NULL, /* Security attributes */
- 0, /* Manual-Reset */
+ 0, /* Manual-Reset */
1, /* Is initially signalled */
- NULL); /* Name of event */
+ NULL); /* Name of event */
dprintf(("%ld: PyThread_allocate_lock() -> %p\n", PyThread_get_thread_ident(), aLock));
#endif
if (waitResult != WAIT_OBJECT_0) {
- success = 0; /* We failed */
+ success = 0; /* We failed */
}
dprintf(("%ld: PyThread_acquire_lock(%p, %d) -> %d\n", PyThread_get_thread_ident(),aLock, waitflag, success));
dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock));
if (!SetEvent(aLock))
- dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n", PyThread_get_thread_ident(), aLock, GetLastError()));
+ dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n", PyThread_get_thread_ident(), aLock, GetLastError()));
}
-This is Python version 2.7.12
+This is Python version 2.7.13
=============================
Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
build your desired target. The interpreter executable is built in the
top level directory.
-If you need an optimized version of Python, you type "make profile-opt"
-in the top level directory. This will rebuild the interpreter executable
-using Profile Guided Optimization (PGO). For more details, see the
-section below.
+To get an optimized build of Python, "configure --enable-optimizations" before
+you run make. This sets the default make targets up to enable Profile Guided
+Optimization (PGO) and may be used to auto-enable Link Time Optimization (LTO)
+on some platforms. For more details, see the sections bellow.
Once you have built a Python interpreter, see the subsections below on
testing and installation. If you run into trouble, see the next
---------------------------
PGO takes advantage of recent versions of the GCC or Clang compilers.
-If ran, the "profile-opt" rule will do several steps.
+If ran, "make profile-opt" will do several steps.
First, the entire Python directory is cleaned of temporary files that
may have resulted in a previous compilation.
After this instrumented version of the interpreter is built, the Makefile
will automatically run a training workload. This is necessary in order to
profile the interpreter execution. Note also that any output, both stdout
-and stderr, that may appear at this step is supressed.
+and stderr, that may appear at this step is suppressed.
Finally, the last step is to rebuild the interpreter, using the information
collected in the previous one. The end result will be a Python binary
that is optimized and suitable for distribution or production installation.
+Link Time Optimization
+----------------------
+
+Enabled via configure's --with-lto flag. LTO takes advantages of recent
+compiler toolchains ability to optimize across the otherwise arbitrary .o file
+boundary when building final executables or shared libraries for additional
+performance gains.
+
+
Troubleshooting
---------------
{
char *path1, *path2;
if (!PyArg_ParseTuple(args, "ss:rename", &path1, &path2))
- return NULL;
+ return NULL;
if (rename(path1,path2)) return PyErr_SetFromErrno(PyExc_OSError);
Py_INCREF(Py_None);
return Py_None;
except getopt.error, msg:
usage('getopt error: ' + str(msg))
- # proces option arguments
+ # process option arguments
for o, a in opts:
if o == '-h':
print __doc__
print "<<"
print
print "clean:"
- print "\t-rm -f *.obj"
- print "\t-rm -f $(target).exe"
+ print "\t-del /f *.obj"
+ print "\t-del /f $(target).exe"
'# File: %(filename)s, line: %(lineno)d') % d
elif options.locationstyle == options.GNU:
# fit as many locations on one line, as long as the
- # resulting line length doesn't exceeds 'options.width'
+ # resulting line length doesn't exceed 'options.width'
locline = '#:'
for filename, lineno in v:
d = {'filename': filename, 'lineno': lineno}
# the installed/uninstalled state according to both the
# Extensions and TclTk features.
add_data(db, "Binary", [("Script", msilib.Binary("msisupport.dll"))])
+ add_data(db, "Binary", [("WixCA", msilib.Binary("WixCA.blob"))])
# See "Custom Action Type 1"
if msilib.Win64:
CheckDir = "CheckDir"
("VerdanaRed9", "Verdana", 9, 255, 0),
])
- compileargs = r'-Wi "[TARGETDIR]Lib\compileall.py" -f -x "bad_coding|badsyntax|site-packages|py3_" "[TARGETDIR]Lib"'
- lib2to3args = r'-c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"'
- updatepipargs = r'-m ensurepip -U --default-pip'
- removepipargs = r'-B -m ensurepip._uninstall'
+ compileargs = r'"[#python.exe]" -Wi "[TARGETDIR]Lib\compileall.py" -f -x "bad_coding|badsyntax|site-packages|py3_" "[TARGETDIR]Lib"'
+ compileoargs = r'"[#python.exe]" -O -Wi "[TARGETDIR]Lib\compileall.py" -f -x "bad_coding|badsyntax|site-packages|py3_" "[TARGETDIR]Lib"'
+ lib2to3args = r'"[#python.exe]" -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"'
+ updatepipargs = r'"[#python.exe]" -m ensurepip -U --default-pip'
+ removepipargs = r'"[#python.exe]" -B -m ensurepip._uninstall'
# See "CustomAction Table"
add_data(db, "CustomAction", [
# msidbCustomActionTypeFirstSequence + msidbCustomActionTypeTextData + msidbCustomActionTypeProperty
# See "Custom Action Type 18"
# msidbCustomActionTypeInScript (1024); run during actual installation
# msidbCustomActionTypeNoImpersonate (2048); run action in system account, not user account
- ("CompilePyc", 18+1024+2048, "python.exe", compileargs),
- ("CompilePyo", 18+1024+2048, "python.exe", "-O "+compileargs),
- ("CompileGrammar", 18+1024+2048, "python.exe", lib2to3args),
- ("UpdatePip", 18+1024+2048, "python.exe", updatepipargs),
- ("RemovePip", 18+1024+2048, "python.exe", removepipargs),
+ ("SetCompilePycCommandLine", 51, "CompilePyc", compileargs),
+ ("SetCompilePyoCommandLine", 51, "CompilePyo", compileoargs),
+ ("SetCompileGrammarCommandLine", 51, "CompileGrammar", lib2to3args),
+ ("CompilePyc", 1+64+1024, "WixCA", "CAQuietExec"),
+ ("CompilePyo", 1+64+1024, "WixCA", "CAQuietExec"),
+ ("CompileGrammar", 1+64+1024, "WixCA", "CAQuietExec"),
+ ("SetUpdatePipCommandLine", 51, "UpdatePip", updatepipargs),
+ ("UpdatePip", 1+64+1024, "WixCA", "CAQuietExec"),
+ ("SetRemovePipCommandLine", 51, "RemovePip", removepipargs),
+ ("RemovePip", 1+64+1024, "WixCA", "CAQuietExec"),
])
# UI Sequences, see "InstallUISequence Table", "Using a Sequence Table"
("SetDLLDirToSystem32", 'DLLDIR="" and ' + sys32cond, 751),
("SetDLLDirToTarget", 'DLLDIR="" and not ' + sys32cond, 752),
("UpdateEditIDLE", None, 1050),
- # run command if install state of pip changes to INSTALLSTATE_LOCAL
- # run after InstallFiles
- ("UpdatePip", "&pip_feature=3", 4001),
# remove pip when state changes to INSTALLSTATE_ABSENT
# run before RemoveFiles
- ("RemovePip", "&pip_feature=2", 3499),
- ("CompilePyc", "COMPILEALL", 4002),
- ("CompilePyo", "COMPILEALL", 4003),
- ("CompileGrammar", "COMPILEALL", 4004),
+ ("SetRemovePipCommandLine", "&pip_feature=2 and !pip_feature=3", 3498),
+ ("RemovePip", "RemovePip", 3499),
+ # run command if install state of pip changes to INSTALLSTATE_LOCAL
+ # run after InstallFiles
+ ("SetUpdatePipCommandLine", "&pip_feature=3 and not !pip_feature=3", 4001),
+ ("UpdatePip", "UpdatePip", 4002),
+ ("SetCompilePycCommandLine", "COMPILEALL", 4003),
+ ("SetCompilePyoCommandLine", "COMPILEALL", 4004),
+ ("SetCompileGrammarCommandLine", "COMPILEALL", 4005),
+ ("CompilePyc", "CompilePyc", 4006),
+ ("CompilePyo", "CompilePyo", 4007),
+ ("CompileGrammar", "CompileGrammar", 4008),
])
add_data(db, "AdminExecuteSequence",
[("InitialTargetDir", 'TARGETDIR=""', 750),
lib.add_file("sgml_input.html")
lib.add_file("testtar.tar")
lib.add_file("test_difflib_expect.html")
- lib.add_file("check_soundcard.vbs")
lib.add_file("empty.vbs")
lib.add_file("Sine-1000Hz-300ms.aif")
lib.add_file("revocation.crl")
if dir=='idlelib':
lib.glob("*.def")
lib.add_file("idle.bat")
+ lib.add_file("help.html")
if dir=="Icons":
lib.glob("*.gif")
lib.glob("*.ico")
(u'CustomAction',u'Source',u'Y',None, None, None, None, u'CustomSource',None, u'The table reference of the source of the code.',),
(u'CustomAction',u'Target',u'Y',None, None, None, None, u'Formatted',None, u'Execution parameter, depends on the type of custom action',),
(u'DrLocator',u'Signature_',u'N',None, None, None, None, u'Identifier',None, u'The Signature_ represents a unique file signature and is also the foreign key in the Signature table.',),
-(u'DrLocator',u'Path',u'Y',None, None, None, None, u'AnyPath',None, u'The path on the user system. This is a either a subpath below the value of the Parent or a full path. The path may contain properties enclosed within [ ] that will be expanded.',),
+(u'DrLocator',u'Path',u'Y',None, None, None, None, u'AnyPath',None, u'The path on the user system. This is either a subpath below the value of the Parent or a full path. The path may contain properties enclosed within [ ] that will be expanded.',),
(u'DrLocator',u'Depth',u'Y',0,32767,None, None, None, None, u'The depth below the path to which the Signature_ is recursively searched. If absent, the depth is assumed to be 0.',),
(u'DrLocator',u'Parent',u'Y',None, None, None, None, u'Identifier',None, u'The parent file signature. It is also a foreign key in the Signature table. If null and the Path column does not expand to a full path, then all the fixed drives of the user system are searched using the Path.',),
(u'DuplicateFile',u'File_',u'N',None, None, u'File',1,u'Identifier',None, u'Foreign key referencing the source file to be duplicated.',),
(u'CustomAction', u'Source', u'Y', None, None, None, None, u'CustomSource', None, u'The table reference of the source of the code.'),
(u'CustomAction', u'Target', u'Y', None, None, None, None, u'Formatted', None, u'Execution parameter, depends on the type of custom action'),
(u'DrLocator', u'Signature_', u'N', None, None, None, None, u'Identifier', None, u'The Signature_ represents a unique file signature and is also the foreign key in the Signature table.'),
-(u'DrLocator', u'Path', u'Y', None, None, None, None, u'AnyPath', None, u'The path on the user system. This is a either a subpath below the value of the Parent or a full path. The path may contain properties enclosed within [ ] that will be expanded.'),
+(u'DrLocator', u'Path', u'Y', None, None, None, None, u'AnyPath', None, u'The path on the user system. This is either a subpath below the value of the Parent or a full path. The path may contain properties enclosed within [ ] that will be expanded.'),
(u'DrLocator', u'Depth', u'Y', 0, 32767, None, None, None, None, u'The depth below the path to which the Signature_ is recursively searched. If absent, the depth is assumed to be 0.'),
(u'DrLocator', u'Parent', u'Y', None, None, None, None, u'Identifier', None, u'The parent file signature. It is also a foreign key in the Signature table. If null and the Path column does not expand to a full path, then all the fixed drives of the user system are searched using the Path.'),
(u'DuplicateFile', u'File_', u'N', None, None, u'File', 1, u'Identifier', None, u'Foreign key referencing the source file to be duplicated.'),
--- /dev/null
+@echo off\r
+setlocal\r
+set D=%~dp0\r
+set PCBUILD=%D%..\..\PCBuild\\r
+\r
+set BUILDX86=\r
+set BUILDX64=\r
+set REBUILD=\r
+set OUTPUT=\r
+set PACKAGES=\r
+\r
+:CheckOpts\r
+if "%~1" EQU "-h" goto Help\r
+if "%~1" EQU "-x86" (set BUILDX86=1) && shift && goto CheckOpts\r
+if "%~1" EQU "-x64" (set BUILDX64=1) && shift && goto CheckOpts\r
+if "%~1" EQU "-r" (set REBUILD=-r) && shift && goto CheckOpts\r
+if "%~1" EQU "-o" (set OUTPUT="/p:OutputPath=%~2") && shift && shift && goto CheckOpts\r
+if "%~1" EQU "--out" (set OUTPUT="/p:OutputPath=%~2") && shift && shift && goto CheckOpts\r
+if "%~1" EQU "-p" (set PACKAGES=%PACKAGES% %~2) && shift && shift && goto CheckOpts\r
+\r
+if not defined BUILDX86 if not defined BUILDX64 (set BUILDX86=1) && (set BUILDX64=1)\r
+\r
+if not defined NUGET where nuget -q || echo Cannot find nuget.exe on PATH and NUGET is not set. && exit /B 1\r
+if not defined PYTHON set PYTHON=py -3\r
+\r
+@%PYTHON% -c "" >nul 2>nul\r
+@if errorlevel 1 (\r
+ %NUGET% install python -OutputDirectory "%D%obj" -ExcludeVersion -NonInteractive\r
+ set PYTHON="%D%obj\python\tools\python.exe"\r
+)\r
+\r
+call "%PCBUILD%env.bat" x86\r
+\r
+if defined PACKAGES set PACKAGES="/p:Packages=%PACKAGES%"\r
+\r
+if defined BUILDX86 (\r
+ if defined REBUILD ( call "%PCBUILD%build.bat" -e -r\r
+ ) else if not exist "%PCBUILD%python.exe" call "%PCBUILD%build.bat" -e\r
+ if errorlevel 1 goto :eof\r
+\r
+ msbuild "%D%make_pkg.proj" /p:Configuration=Release /p:Platform=x86 %OUTPUT% %PACKAGES%\r
+ if errorlevel 1 goto :eof\r
+)\r
+\r
+if defined BUILDX64 (\r
+ if defined REBUILD ( call "%PCBUILD%build.bat" -p x64 -e -r\r
+ ) else if not exist "%PCBUILD%amd64\python.exe" call "%PCBUILD%build.bat" -p x64 -e\r
+ if errorlevel 1 goto :eof\r
+\r
+ msbuild "%D%make_pkg.proj" /p:Configuration=Release /p:Platform=x64 %OUTPUT% %PACKAGES%\r
+ if errorlevel 1 goto :eof\r
+)\r
+\r
+exit /B 0\r
+\r
+:Help\r
+echo build.bat [-x86] [-x64] [--out DIR] [-r] [-h]\r
+echo.\r
+echo -x86 Build x86 installers\r
+echo -x64 Build x64 installers\r
+echo -r Rebuild rather than incremental build\r
+echo --out [DIR] Override output directory\r
+echo -h Show usage\r
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <ProjectGuid>{6BA7092C-0093-47F0-9ED2-282AEE981E14}</ProjectGuid>
+ <OutputName>python2</OutputName>
+ <OutputName Condition="$(Platform) == 'x86' or $(Platform) == 'Win32' or $(Platform) == ''">$(OutputName)x86</OutputName>
+ <OutputPath Condition="$(OutputPath) == ''">$(MSBuildThisFileDirectory)</OutputPath>
+ <OutputSuffix></OutputSuffix>
+ <SupportSigning>false</SupportSigning>
+ <BuildForRelease Condition="$(BuildForRelease) == ''">true</BuildForRelease>
+ </PropertyGroup>
+
+ <Import Project="..\..\PCBuild\python.props" />
+
+ <PropertyGroup>
+ <NuspecVersion>$(MajorVersionNumber).$(MinorVersionNumber).$(MicroVersionNumber)</NuspecVersion>
+ <SignOutput>false</SignOutput>
+ <TargetName>$(OutputName).$(NuspecVersion)</TargetName>
+ <TargetExt>.nupkg</TargetExt>
+ <TargetPath>$(OutputPath)\$(TargetName)$(TargetExt)</TargetPath>
+ <IntermediateOutputPath>$(MSBuildThisFileDirectory)\obj_$(ArchName)</IntermediateOutputPath>
+
+ <CleanCommand>rmdir /q/s "$(IntermediateOutputPath)"</CleanCommand>
+
+ <Python Condition="$(Python) == ''">py</Python>
+ <PythonArguments>"$(Python)" "$(MSBuildThisFileDirectory)\make_zip.py"</PythonArguments>
+ <PythonArguments>$(PythonArguments) -s "$(PySourcePath.Trim('\'))" -t "$(IntermediateOutputPath)" -a $(ArchName)</PythonArguments>
+
+ <PipArguments>"$(IntermediateOutputPath)\python.exe" -B -c "import sys; sys.path.append(r'$(PySourcePath)\Lib'); import ensurepip; ensurepip._main()"</PipArguments>
+ <PackageArguments Condition="$(Packages) != ''">"$(IntermediateOutputPath)\python.exe" -B -m pip install -U $(Packages)</PackageArguments>
+
+ <NugetArguments>"$(Nuget)" pack "$(MSBuildThisFileDirectory)\$(OutputName).nuspec"</NugetArguments>
+ <NugetArguments>$(NugetArguments) -BasePath "$(IntermediateOutputPath)"</NugetArguments>
+ <NugetArguments>$(NugetArguments) -OutputDirectory "$(OutputPath.Trim(`\`))"</NugetArguments>
+ <NugetArguments>$(NugetArguments) -Version "$(NuspecVersion)"</NugetArguments>
+ <NugetArguments>$(NugetArguments) -NoPackageAnalysis -NonInteractive</NugetArguments>
+ </PropertyGroup>
+
+ <Target Name="_NugetMissing" BeforeTargets="_Build" Condition="!Exists($(Nuget))">
+ <Error Text="$$(Nuget) could not be found. Specify a valid path on the command line." />
+ </Target>
+
+ <Target Name="_Build">
+ <Exec Command="$(CleanCommand)" />
+ <Exec Command="$(PythonArguments)" />
+ <Exec Command="$(PipArguments)" />
+ <Exec Command="$(PackageArguments)" Condition="$(PackageArguments) != ''" />
+ <Exec Command="$(NugetArguments)" />
+ </Target>
+
+ <Target Name="AfterBuild" />
+ <Target Name="Build" DependsOnTargets="_Build;AfterBuild" />
+</Project>
--- /dev/null
+#! /usr/bin/python3
+
+import argparse
+import py_compile
+import re
+import sys
+import shutil
+import stat
+import os
+import tempfile
+
+from pathlib import Path
+from zipfile import ZipFile, ZIP_DEFLATED
+import subprocess
+
+TKTCL_RE = re.compile(r'^(_?tk|tcl).+\.(pyd|dll)', re.IGNORECASE)
+DEBUG_RE = re.compile(r'_d\.(pyd|dll|exe|pdb|lib)$', re.IGNORECASE)
+PYTHON_DLL_RE = re.compile(r'python\d\d?\.dll$', re.IGNORECASE)
+
+DEBUG_FILES = {
+ '_ctypes_test',
+ '_testbuffer',
+ '_testcapi',
+ '_testimportmultiple',
+ '_testmultiphase',
+ 'xxlimited',
+ 'python3_dstub',
+}
+
+EXCLUDE_FROM_LIBRARY = {
+ '__pycache__',
+ 'ensurepip',
+ 'idlelib',
+ 'pydoc_data',
+ 'site-packages',
+ 'tkinter',
+ 'turtledemo',
+ 'venv',
+}
+
+EXCLUDE_FILE_FROM_LIBRARY = {
+ 'bdist_wininst.py',
+}
+
+EXCLUDE_FILE_FROM_LIBS = {
+ 'ssleay',
+ 'libeay',
+ 'python3stub',
+}
+
+def is_not_debug(p):
+ if DEBUG_RE.search(p.name):
+ return False
+
+ if TKTCL_RE.search(p.name):
+ return False
+
+ return p.stem.lower() not in DEBUG_FILES
+
+def is_not_debug_or_python(p):
+ return is_not_debug(p) and not PYTHON_DLL_RE.search(p.name)
+
+def include_in_lib(p):
+ name = p.name.lower()
+ if p.is_dir():
+ if name in EXCLUDE_FROM_LIBRARY:
+ return False
+ if name.startswith('plat-'):
+ return False
+ if name == 'test' and p.parts[-2].lower() == 'lib':
+ return False
+ if name in {'test', 'tests'} and p.parts[-3].lower() == 'lib':
+ return False
+ return True
+
+ if name in EXCLUDE_FILE_FROM_LIBRARY:
+ return False
+
+ suffix = p.suffix.lower()
+ return suffix not in {'.pyc', '.pyo', '.exe'}
+
+def include_in_libs(p):
+ if not is_not_debug(p):
+ return False
+
+ return p.stem.lower() not in EXCLUDE_FILE_FROM_LIBS
+
+def include_in_tools(p):
+ if p.is_dir() and p.name.lower() in {'scripts', 'i18n', 'pynche', 'demo', 'parser'}:
+ return True
+
+ return p.suffix.lower() in {'.py', '.pyw', '.txt'}
+
+FULL_LAYOUT = [
+ ('/', 'PCBuild/$arch', 'python.exe', is_not_debug),
+ ('/', 'PCBuild/$arch', 'pythonw.exe', is_not_debug),
+ ('/', 'PCBuild/$arch', 'python27.dll', None),
+ ('DLLs/', 'PCBuild/$arch', '*.pyd', is_not_debug),
+ ('DLLs/', 'PCBuild/$arch', '*.dll', is_not_debug_or_python),
+ ('include/', 'include', '*.h', None),
+ ('include/', 'PC', 'pyconfig.h', None),
+ ('Lib/', 'Lib', '**/*', include_in_lib),
+ ('libs/', 'PCBuild/$arch', '*.lib', include_in_libs),
+ ('Tools/', 'Tools', '**/*', include_in_tools),
+]
+
+EMBED_LAYOUT = [
+ ('/', 'PCBuild/$arch', 'python*.exe', is_not_debug),
+ ('/', 'PCBuild/$arch', '*.pyd', is_not_debug),
+ ('/', 'PCBuild/$arch', '*.dll', is_not_debug),
+ ('python{0.major}{0.minor}.zip'.format(sys.version_info), 'Lib', '**/*', include_in_lib),
+]
+
+if os.getenv('DOC_FILENAME'):
+ FULL_LAYOUT.append(('Doc/', 'Doc/build/htmlhelp', os.getenv('DOC_FILENAME'), None))
+if os.getenv('VCREDIST_PATH'):
+ FULL_LAYOUT.append(('/', os.getenv('VCREDIST_PATH'), 'vcruntime*.dll', None))
+ EMBED_LAYOUT.append(('/', os.getenv('VCREDIST_PATH'), 'vcruntime*.dll', None))
+
+def copy_to_layout(target, rel_sources):
+ count = 0
+
+ if target.suffix.lower() == '.zip':
+ if target.exists():
+ target.unlink()
+
+ with ZipFile(str(target), 'w', ZIP_DEFLATED) as f:
+ with tempfile.TemporaryDirectory() as tmpdir:
+ for s, rel in rel_sources:
+ if rel.suffix.lower() == '.py':
+ pyc = Path(tmpdir) / rel.with_suffix('.pyc').name
+ try:
+ py_compile.compile(str(s), str(pyc), str(rel), doraise=True, optimize=2)
+ except py_compile.PyCompileError:
+ f.write(str(s), str(rel))
+ else:
+ f.write(str(pyc), str(rel.with_suffix('.pyc')))
+ else:
+ f.write(str(s), str(rel))
+ count += 1
+
+ else:
+ for s, rel in rel_sources:
+ dest = target / rel
+ try:
+ dest.parent.mkdir(parents=True)
+ except FileExistsError:
+ pass
+ if dest.is_file():
+ dest.chmod(stat.S_IWRITE)
+ shutil.copy(str(s), str(dest))
+ if dest.is_file():
+ dest.chmod(stat.S_IWRITE)
+ count += 1
+
+ return count
+
+def rglob(root, pattern, condition):
+ dirs = [root]
+ recurse = pattern[:3] in {'**/', '**\\'}
+ while dirs:
+ d = dirs.pop(0)
+ for f in d.glob(pattern[3:] if recurse else pattern):
+ if recurse and f.is_dir() and (not condition or condition(f)):
+ dirs.append(f)
+ elif f.is_file() and (not condition or condition(f)):
+ yield f, f.relative_to(root)
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-s', '--source', metavar='dir', help='The directory containing the repository root', type=Path)
+ parser.add_argument('-o', '--out', metavar='file', help='The name of the output self-extracting archive', type=Path, default=None)
+ parser.add_argument('-t', '--temp', metavar='dir', help='A directory to temporarily extract files into', type=Path, default=None)
+ parser.add_argument('-e', '--embed', help='Create an embedding layout', action='store_true', default=False)
+ parser.add_argument('-a', '--arch', help='Specify the architecture to use (win32/amd64)', type=str, default="win32")
+ ns = parser.parse_args()
+
+ source = ns.source or (Path(__file__).resolve().parent.parent.parent)
+ out = ns.out
+ arch = '' if ns.arch == 'win32' else ns.arch
+ assert isinstance(source, Path)
+ assert not out or isinstance(out, Path)
+ assert isinstance(arch, str)
+
+ if ns.temp:
+ temp = ns.temp
+ delete_temp = False
+ else:
+ temp = Path(tempfile.mkdtemp())
+ delete_temp = True
+
+ if out:
+ try:
+ out.parent.mkdir(parents=True)
+ except FileExistsError:
+ pass
+ try:
+ temp.mkdir(parents=True)
+ except FileExistsError:
+ pass
+
+ layout = EMBED_LAYOUT if ns.embed else FULL_LAYOUT
+
+ try:
+ for t, s, p, c in layout:
+ s = source / s.replace("$arch", arch)
+ copied = copy_to_layout(temp / t.rstrip('/'), rglob(s, p, c))
+ print('Copied {} files'.format(copied))
+
+ if out:
+ total = copy_to_layout(out, rglob(temp, '**/*', None))
+ print('Wrote {} files to {}'.format(total, out))
+ finally:
+ if delete_temp:
+ shutil.rmtree(temp, True)
+
+
+if __name__ == "__main__":
+ sys.exit(int(main() or 0))
--- /dev/null
+<?xml version="1.0"?>
+<package >
+ <metadata>
+ <id>python2</id>
+ <title>Python 2.7</title>
+ <version>0.0.0.0</version>
+ <authors>Python Software Foundation</authors>
+ <licenseUrl>https://docs.python.org/2.7/license.html</licenseUrl>
+ <projectUrl>https://www.python.org/</projectUrl>
+ <requireLicenseAcceptance>false</requireLicenseAcceptance>
+ <description>Installs 64-bit Python 2.7 for use in build scenarios.</description>
+ <iconUrl>https://www.python.org/static/favicon.ico</iconUrl>
+ <tags>python</tags>
+ </metadata>
+ <files>
+ <file src="**\*" target="tools" />
+ </files>
+</package>
--- /dev/null
+<?xml version="1.0"?>
+<package >
+ <metadata>
+ <id>python2x86</id>
+ <title>Python 2.7 (32-bit)</title>
+ <authors>Python Software Foundation</authors>
+ <version>0.0.0.0</version>
+ <licenseUrl>https://docs.python.org/2.7/license.html</licenseUrl>
+ <projectUrl>https://www.python.org/</projectUrl>
+ <requireLicenseAcceptance>false</requireLicenseAcceptance>
+ <description>Installs 32-bit Python 2.7 for use in build scenarios.</description>
+ <iconUrl>https://www.python.org/static/favicon.ico</iconUrl>
+ <tags>python</tags>
+ </metadata>
+ <files>
+ <file src="**\*" target="tools" />
+ </files>
+</package>
sys.exit(bad)
# Change this regular expression to select a different set of files
-Wanted = '^[a-zA-Z0-9_]+\.[ch]$'
+Wanted = r'^[a-zA-Z0-9_]+\.[ch]$'
def wanted(name):
- return re.match(Wanted, name) >= 0
+ return re.match(Wanted, name)
def recursedown(dirname):
dbg('recursedown(%r)\n' % (dirname,))
if filename == '-': return 0 # Done in filter mode
f.close()
if not g: return 0 # No changes
+ g.close()
# Finishing touch -- move files
# Tokenizing ANSI C (partly)
-Identifier = '\(struct \)?[a-zA-Z_][a-zA-Z0-9_]+'
-String = '"\([^\n\\"]\|\\\\.\)*"'
-Char = '\'\([^\n\\\']\|\\\\.\)*\''
-CommentStart = '/\*'
-CommentEnd = '\*/'
+Identifier = '(struct )?[a-zA-Z_][a-zA-Z0-9_]+'
+String = r'"([^\n\\"]|\\.)*"'
+Char = r"'([^\n\\']|\\.)*'"
+CommentStart = r'/\*'
+CommentEnd = r'\*/'
Hexnumber = '0[xX][0-9a-fA-F]*[uUlL]*'
Octnumber = '0[0-7]*[uUlL]*'
Decnumber = '[1-9][0-9]*[uUlL]*'
-Intnumber = Hexnumber + '\|' + Octnumber + '\|' + Decnumber
+Intnumber = Hexnumber + '|' + Octnumber + '|' + Decnumber
Exponent = '[eE][-+]?[0-9]+'
-Pointfloat = '\([0-9]+\.[0-9]*\|\.[0-9]+\)\(' + Exponent + '\)?'
+Pointfloat = r'([0-9]+\.[0-9]*|\.[0-9]+)(' + Exponent + r')?'
Expfloat = '[0-9]+' + Exponent
-Floatnumber = Pointfloat + '\|' + Expfloat
-Number = Floatnumber + '\|' + Intnumber
+Floatnumber = Pointfloat + '|' + Expfloat
+Number = Floatnumber + '|' + Intnumber
# Anything else is an operator -- don't list this explicitly because of '/*'
## print '-->', repr(line)
i = 0
while i < len(line):
- i = Program.search(line, i)
- if i < 0: break
- found = Program.group(0)
+ match = Program.search(line, i)
+ if match is None: break
+ i = match.start()
+ found = match.group(0)
## if Program is InsideCommentProgram: print '...',
## else: print ' ',
## print found
elif found == '*/':
Program = OutsideCommentProgram
n = len(found)
- if Dict.has_key(found):
+ if found in Dict:
subst = Dict[found]
if Program is InsideCommentProgram:
if not Docomments:
print 'Found in comment:', found
i = i + n
continue
- if NotInComment.has_key(found):
+ if found in NotInComment:
## print 'Ignored in comment:',
## print found, '-->', subst
## print 'Line:', line,
if not words: continue
if len(words) == 3 and words[0] == 'struct':
words[:2] = [words[0] + ' ' + words[1]]
- elif len(words) <> 2:
+ elif len(words) != 2:
err(substfile + '%s:%r: warning: bad line: %r' % (substfile, lineno, line))
continue
if Reverse:
if key[0] == '*':
key = key[1:]
NotInComment[key] = value
- if Dict.has_key(key):
+ if key in Dict:
err('%s:%r: warning: overriding: %r %r\n' % (substfile, lineno, key, value))
err('%s:%r: warning: previous: %r\n' % (substfile, lineno, Dict[key]))
Dict[key] = value
#!/usr/bin/env python
-"""Basic regular expression demostration facility (Perl style syntax)."""
+"""Basic regular expression demonstration facility (Perl style syntax)."""
from Tkinter import *
import re
-# generated automatically by aclocal 1.14.1 -*- Autoconf -*-
+# generated automatically by aclocal 1.15 -*- Autoconf -*-
-# Copyright (C) 1996-2013 Free Software Foundation, Inc.
+# Copyright (C) 1996-2014 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# PARTICULAR PURPOSE.
m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
-# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
-# serial 1 (pkg-config-0.24)
-#
-# Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-# As a special exception to the GNU General Public License, if you
-# distribute this file as part of a program that contains a
-# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
-
-# PKG_PROG_PKG_CONFIG([MIN-VERSION])
-# ----------------------------------
+dnl pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
+dnl serial 11 (pkg-config-0.29.1)
+dnl
+dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
+dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
+dnl
+dnl This program is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 2 of the License, or
+dnl (at your option) any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful, but
+dnl WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+dnl General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; if not, write to the Free Software
+dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+dnl 02111-1307, USA.
+dnl
+dnl As a special exception to the GNU General Public License, if you
+dnl distribute this file as part of a program that contains a
+dnl configuration script generated by Autoconf, you may include it under
+dnl the same distribution terms that you use for the rest of that
+dnl program.
+
+dnl PKG_PREREQ(MIN-VERSION)
+dnl -----------------------
+dnl Since: 0.29
+dnl
+dnl Verify that the version of the pkg-config macros are at least
+dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's
+dnl installed version of pkg-config, this checks the developer's version
+dnl of pkg.m4 when generating configure.
+dnl
+dnl To ensure that this macro is defined, also add:
+dnl m4_ifndef([PKG_PREREQ],
+dnl [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])
+dnl
+dnl See the "Since" comment for each macro you use to see what version
+dnl of the macros you require.
+m4_defun([PKG_PREREQ],
+[m4_define([PKG_MACROS_VERSION], [0.29.1])
+m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
+ [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
+])dnl PKG_PREREQ
+
+dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
+dnl ----------------------------------
+dnl Since: 0.16
+dnl
+dnl Search for the pkg-config tool and set the PKG_CONFIG variable to
+dnl first found in the path. Checks that the version of pkg-config found
+dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.9.0 is
+dnl used since that's the first version where most current features of
+dnl pkg-config existed.
AC_DEFUN([PKG_PROG_PKG_CONFIG],
[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
PKG_CONFIG=""
fi
fi[]dnl
-])# PKG_PROG_PKG_CONFIG
-
-# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
-#
-# Check to see whether a particular set of modules exists. Similar
-# to PKG_CHECK_MODULES(), but does not set variables or print errors.
-#
-# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
-# only at the first occurence in configure.ac, so if the first place
-# it's called might be skipped (such as if it is within an "if", you
-# have to call PKG_CHECK_EXISTS manually
-# --------------------------------------------------------------
+])dnl PKG_PROG_PKG_CONFIG
+
+dnl PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+dnl -------------------------------------------------------------------
+dnl Since: 0.18
+dnl
+dnl Check to see whether a particular set of modules exists. Similar to
+dnl PKG_CHECK_MODULES(), but does not set variables or print errors.
+dnl
+dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
+dnl only at the first occurence in configure.ac, so if the first place
+dnl it's called might be skipped (such as if it is within an "if", you
+dnl have to call PKG_CHECK_EXISTS manually
AC_DEFUN([PKG_CHECK_EXISTS],
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
if test -n "$PKG_CONFIG" && \
$3])dnl
fi])
-# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
-# ---------------------------------------------
+dnl _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
+dnl ---------------------------------------------
+dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting
+dnl pkg_failed based on the result.
m4_define([_PKG_CONFIG],
[if test -n "$$1"; then
pkg_cv_[]$1="$$1"
else
pkg_failed=untried
fi[]dnl
-])# _PKG_CONFIG
+])dnl _PKG_CONFIG
-# _PKG_SHORT_ERRORS_SUPPORTED
-# -----------------------------
+dnl _PKG_SHORT_ERRORS_SUPPORTED
+dnl ---------------------------
+dnl Internal check to see if pkg-config supports short errors.
AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
else
_pkg_short_errors_supported=no
fi[]dnl
-])# _PKG_SHORT_ERRORS_SUPPORTED
-
-
-# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
-# [ACTION-IF-NOT-FOUND])
-#
-#
-# Note that if there is a possibility the first call to
-# PKG_CHECK_MODULES might not happen, you should be sure to include an
-# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
-#
-#
-# --------------------------------------------------------------
+])dnl _PKG_SHORT_ERRORS_SUPPORTED
+
+
+dnl PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
+dnl [ACTION-IF-NOT-FOUND])
+dnl --------------------------------------------------------------
+dnl Since: 0.4.0
+dnl
+dnl Note that if there is a possibility the first call to
+dnl PKG_CHECK_MODULES might not happen, you should be sure to include an
+dnl explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
AC_DEFUN([PKG_CHECK_MODULES],
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
AC_MSG_RESULT([yes])
$3
fi[]dnl
-])# PKG_CHECK_MODULES
+])dnl PKG_CHECK_MODULES
+
+
+dnl PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
+dnl [ACTION-IF-NOT-FOUND])
+dnl ---------------------------------------------------------------------
+dnl Since: 0.29
+dnl
+dnl Checks for existence of MODULES and gathers its build flags with
+dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags
+dnl and VARIABLE-PREFIX_LIBS from --libs.
+dnl
+dnl Note that if there is a possibility the first call to
+dnl PKG_CHECK_MODULES_STATIC might not happen, you should be sure to
+dnl include an explicit call to PKG_PROG_PKG_CONFIG in your
+dnl configure.ac.
+AC_DEFUN([PKG_CHECK_MODULES_STATIC],
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
+_save_PKG_CONFIG=$PKG_CONFIG
+PKG_CONFIG="$PKG_CONFIG --static"
+PKG_CHECK_MODULES($@)
+PKG_CONFIG=$_save_PKG_CONFIG[]dnl
+])dnl PKG_CHECK_MODULES_STATIC
-# PKG_INSTALLDIR(DIRECTORY)
-# -------------------------
-# Substitutes the variable pkgconfigdir as the location where a module
-# should install pkg-config .pc files. By default the directory is
-# $libdir/pkgconfig, but the default can be changed by passing
-# DIRECTORY. The user can override through the --with-pkgconfigdir
-# parameter.
+dnl PKG_INSTALLDIR([DIRECTORY])
+dnl -------------------------
+dnl Since: 0.27
+dnl
+dnl Substitutes the variable pkgconfigdir as the location where a module
+dnl should install pkg-config .pc files. By default the directory is
+dnl $libdir/pkgconfig, but the default can be changed by passing
+dnl DIRECTORY. The user can override through the --with-pkgconfigdir
+dnl parameter.
AC_DEFUN([PKG_INSTALLDIR],
[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
m4_pushdef([pkg_description],
AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
m4_popdef([pkg_default])
m4_popdef([pkg_description])
-]) dnl PKG_INSTALLDIR
+])dnl PKG_INSTALLDIR
-# PKG_NOARCH_INSTALLDIR(DIRECTORY)
-# -------------------------
-# Substitutes the variable noarch_pkgconfigdir as the location where a
-# module should install arch-independent pkg-config .pc files. By
-# default the directory is $datadir/pkgconfig, but the default can be
-# changed by passing DIRECTORY. The user can override through the
-# --with-noarch-pkgconfigdir parameter.
+dnl PKG_NOARCH_INSTALLDIR([DIRECTORY])
+dnl --------------------------------
+dnl Since: 0.27
+dnl
+dnl Substitutes the variable noarch_pkgconfigdir as the location where a
+dnl module should install arch-independent pkg-config .pc files. By
+dnl default the directory is $datadir/pkgconfig, but the default can be
+dnl changed by passing DIRECTORY. The user can override through the
+dnl --with-noarch-pkgconfigdir parameter.
AC_DEFUN([PKG_NOARCH_INSTALLDIR],
[m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
m4_pushdef([pkg_description],
AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
m4_popdef([pkg_default])
m4_popdef([pkg_description])
-]) dnl PKG_NOARCH_INSTALLDIR
+])dnl PKG_NOARCH_INSTALLDIR
-# PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
-# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
-# -------------------------------------------
-# Retrieves the value of the pkg-config variable for the given module.
+dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
+dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+dnl -------------------------------------------
+dnl Since: 0.28
+dnl
+dnl Retrieves the value of the pkg-config variable for the given module.
AC_DEFUN([PKG_CHECK_VAR],
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
AS_VAR_COPY([$1], [pkg_cv_][$1])
AS_VAR_IF([$1], [""], [$5], [$4])dnl
-])# PKG_CHECK_VAR
+])dnl PKG_CHECK_VAR
#! /bin/sh
# Attempt to guess a canonical system name.
-# Copyright 1992-2014 Free Software Foundation, Inc.
+# Copyright 1992-2016 Free Software Foundation, Inc.
-timestamp='2014-03-23'
+timestamp='2016-10-02'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# program. This Exception is an additional permission under section 7
# of the GNU General Public License, version 3 ("GPLv3").
#
-# Originally written by Per Bothner.
+# Originally written by Per Bothner; maintained since 2000 by Ben Elliston.
#
# You can get the latest version of this script from:
-# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess
#
-# Please send patches with a ChangeLog entry to config-patches@gnu.org.
+# Please send patches to <config-patches@gnu.org>.
me=`echo "$0" | sed -e 's,.*/,,'`
GNU config.guess ($timestamp)
Originally written by Per Bothner.
-Copyright 1992-2014 Free Software Foundation, Inc.
+Copyright 1992-2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
# Note: NetBSD doesn't particularly care about the vendor
# portion of the name. We always set it to "unknown".
sysctl="sysctl -n hw.machine_arch"
- UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \
- /usr/sbin/$sysctl 2>/dev/null || echo unknown)`
+ UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \
+ /sbin/$sysctl 2>/dev/null || \
+ /usr/sbin/$sysctl 2>/dev/null || \
+ echo unknown)`
case "${UNAME_MACHINE_ARCH}" in
armeb) machine=armeb-unknown ;;
arm*) machine=arm-unknown ;;
sh3el) machine=shl-unknown ;;
sh3eb) machine=sh-unknown ;;
sh5el) machine=sh5le-unknown ;;
+ earmv*)
+ arch=`echo ${UNAME_MACHINE_ARCH} | sed -e 's,^e\(armv[0-9]\).*$,\1,'`
+ endian=`echo ${UNAME_MACHINE_ARCH} | sed -ne 's,^.*\(eb\)$,\1,p'`
+ machine=${arch}${endian}-unknown
+ ;;
*) machine=${UNAME_MACHINE_ARCH}-unknown ;;
esac
# The Operating System including object format, if it has switched
- # to ELF recently, or will in the future.
+ # to ELF recently (or will in the future) and ABI.
case "${UNAME_MACHINE_ARCH}" in
+ earm*)
+ os=netbsdelf
+ ;;
arm*|i386|m68k|ns32k|sh3*|sparc|vax)
eval $set_cc_for_build
if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
os=netbsd
;;
esac
+ # Determine ABI tags.
+ case "${UNAME_MACHINE_ARCH}" in
+ earm*)
+ expr='s/^earmv[0-9]/-eabi/;s/eb$//'
+ abi=`echo ${UNAME_MACHINE_ARCH} | sed -e "$expr"`
+ ;;
+ esac
# The OS release
# Debian GNU/NetBSD machines have a different userland, and
# thus, need a distinct triplet. However, they do not need
release='-gnu'
;;
*)
- release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+ release=`echo ${UNAME_RELEASE} | sed -e 's/[-_].*//' | cut -d. -f1,2`
;;
esac
# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
# contains redundant information, the shorter form:
# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
- echo "${machine}-${os}${release}"
+ echo "${machine}-${os}${release}${abi}"
exit ;;
*:Bitrig:*:*)
UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'`
UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
exit ;;
+ *:LibertyBSD:*:*)
+ UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'`
+ echo ${UNAME_MACHINE_ARCH}-unknown-libertybsd${UNAME_RELEASE}
+ exit ;;
*:ekkoBSD:*:*)
echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
exit ;;
*:MirBSD:*:*)
echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
exit ;;
+ *:Sortix:*:*)
+ echo ${UNAME_MACHINE}-unknown-sortix
+ exit ;;
alpha:OSF1:*:*)
case $UNAME_RELEASE in
*4.0)
ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1`
case "$ALPHA_CPU_TYPE" in
"EV4 (21064)")
- UNAME_MACHINE="alpha" ;;
+ UNAME_MACHINE=alpha ;;
"EV4.5 (21064)")
- UNAME_MACHINE="alpha" ;;
+ UNAME_MACHINE=alpha ;;
"LCA4 (21066/21068)")
- UNAME_MACHINE="alpha" ;;
+ UNAME_MACHINE=alpha ;;
"EV5 (21164)")
- UNAME_MACHINE="alphaev5" ;;
+ UNAME_MACHINE=alphaev5 ;;
"EV5.6 (21164A)")
- UNAME_MACHINE="alphaev56" ;;
+ UNAME_MACHINE=alphaev56 ;;
"EV5.6 (21164PC)")
- UNAME_MACHINE="alphapca56" ;;
+ UNAME_MACHINE=alphapca56 ;;
"EV5.7 (21164PC)")
- UNAME_MACHINE="alphapca57" ;;
+ UNAME_MACHINE=alphapca57 ;;
"EV6 (21264)")
- UNAME_MACHINE="alphaev6" ;;
+ UNAME_MACHINE=alphaev6 ;;
"EV6.7 (21264A)")
- UNAME_MACHINE="alphaev67" ;;
+ UNAME_MACHINE=alphaev67 ;;
"EV6.8CB (21264C)")
- UNAME_MACHINE="alphaev68" ;;
+ UNAME_MACHINE=alphaev68 ;;
"EV6.8AL (21264B)")
- UNAME_MACHINE="alphaev68" ;;
+ UNAME_MACHINE=alphaev68 ;;
"EV6.8CX (21264D)")
- UNAME_MACHINE="alphaev68" ;;
+ UNAME_MACHINE=alphaev68 ;;
"EV6.9A (21264/EV69A)")
- UNAME_MACHINE="alphaev69" ;;
+ UNAME_MACHINE=alphaev69 ;;
"EV7 (21364)")
- UNAME_MACHINE="alphaev7" ;;
+ UNAME_MACHINE=alphaev7 ;;
"EV7.9 (21364A)")
- UNAME_MACHINE="alphaev79" ;;
+ UNAME_MACHINE=alphaev79 ;;
esac
# A Pn.n version is a patched version.
# A Vn.n version is a released version.
# A Tn.n version is a released field test version.
# A Xn.n version is an unreleased experimental baselevel.
# 1.2 uses "1.2" for uname -r.
- echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+ echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
# Reset EXIT trap before exiting to avoid spurious non-zero exit code.
exitcode=$?
trap '' 0
exit ;;
i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
eval $set_cc_for_build
- SUN_ARCH="i386"
+ SUN_ARCH=i386
# If there is a compiler, see if it is configured for 64-bit objects.
# Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
# This test works for both compilers.
- if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
+ if [ "$CC_FOR_BUILD" != no_compiler_found ]; then
if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
- (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
grep IS_64BIT_ARCH >/dev/null
then
- SUN_ARCH="x86_64"
+ SUN_ARCH=x86_64
fi
fi
echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
exit ;;
sun*:*:4.2BSD:*)
UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
- test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
+ test "x${UNAME_RELEASE}" = x && UNAME_RELEASE=3
case "`/bin/arch`" in
sun3)
echo m68k-sun-sunos${UNAME_RELEASE}
else
IBM_ARCH=powerpc
fi
- if [ -x /usr/bin/oslevel ] ; then
- IBM_REV=`/usr/bin/oslevel`
+ if [ -x /usr/bin/lslpp ] ; then
+ IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc |
+ awk -F: '{ print $3 }' | sed s/[0-9]*$/0/`
else
IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
fi
sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
case "${sc_cpu_version}" in
- 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
- 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
+ 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0
+ 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1
532) # CPU_PA_RISC2_0
case "${sc_kernel_bits}" in
- 32) HP_ARCH="hppa2.0n" ;;
- 64) HP_ARCH="hppa2.0w" ;;
- '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20
+ 32) HP_ARCH=hppa2.0n ;;
+ 64) HP_ARCH=hppa2.0w ;;
+ '') HP_ARCH=hppa2.0 ;; # HP-UX 10.20
esac ;;
esac
fi
exit (0);
}
EOF
- (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
+ (CCOPTS="" $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
test -z "$HP_ARCH" && HP_ARCH=hppa
fi ;;
esac
- if [ ${HP_ARCH} = "hppa2.0w" ]
+ if [ ${HP_ARCH} = hppa2.0w ]
then
eval $set_cc_for_build
# $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
# => hppa64-hp-hpux11.23
- if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
+ if echo __LP64__ | (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) |
grep -q __LP64__
then
- HP_ARCH="hppa2.0w"
+ HP_ARCH=hppa2.0w
else
- HP_ARCH="hppa64"
+ HP_ARCH=hppa64
fi
fi
echo ${HP_ARCH}-hp-hpux${HPUX_REV}
echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
exit ;;
F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
- FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
- FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+ FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
+ FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'`
FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit ;;
5000:UNIX_System_V:4.*:*)
- FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
- FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
+ FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'`
+ FUJITSU_REL=`echo ${UNAME_RELEASE} | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'`
echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
exit ;;
i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
exit ;;
*:GNU/*:*:*)
# other systems with GNU libc and userland
- echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC}
+ echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC}
exit ;;
i*86:Minix:*:*)
echo ${UNAME_MACHINE}-pc-minix
EV68*) UNAME_MACHINE=alphaev68 ;;
esac
objdump --private-headers /bin/sh | grep -q ld.so.1
- if test "$?" = 0 ; then LIBC="gnulibc1" ; fi
+ if test "$?" = 0 ; then LIBC=gnulibc1 ; fi
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
arc:Linux:*:* | arceb:Linux:*:*)
crisv32:Linux:*:*)
echo ${UNAME_MACHINE}-axis-linux-${LIBC}
exit ;;
+ e2k:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
frv:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
ia64:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
+ k1om:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
m32r*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
exit ;;
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; }
;;
+ mips64el:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
openrisc*:Linux:*:*)
echo or1k-unknown-linux-${LIBC}
exit ;;
ppcle:Linux:*:*)
echo powerpcle-unknown-linux-${LIBC}
exit ;;
+ riscv32:Linux:*:* | riscv64:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
s390:Linux:*:* | s390x:Linux:*:*)
echo ${UNAME_MACHINE}-ibm-linux-${LIBC}
exit ;;
echo ${UNAME_MACHINE}-dec-linux-${LIBC}
exit ;;
x86_64:Linux:*:*)
- echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ echo ${UNAME_MACHINE}-pc-linux-${LIBC}
exit ;;
xtensa*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
# uname -m prints for DJGPP always 'pc', but it prints nothing about
# the processor, so we play safe by assuming i586.
# Note: whatever this is, it MUST be the same as what config.sub
- # prints for the "djgpp" host, or else GDB configury will decide that
+ # prints for the "djgpp" host, or else GDB configure will decide that
# this is a cross-build.
echo i586-pc-msdosdjgpp
exit ;;
SX-8R:SUPER-UX:*:*)
echo sx8r-nec-superux${UNAME_RELEASE}
exit ;;
+ SX-ACE:SUPER-UX:*:*)
+ echo sxace-nec-superux${UNAME_RELEASE}
+ exit ;;
Power*:Rhapsody:*:*)
echo powerpc-apple-rhapsody${UNAME_RELEASE}
exit ;;
UNAME_PROCESSOR=powerpc
fi
if test `echo "$UNAME_RELEASE" | sed -e 's/\..*//'` -le 10 ; then
- if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
+ if [ "$CC_FOR_BUILD" != no_compiler_found ]; then
if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
- (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
grep IS_64BIT_ARCH >/dev/null
then
case $UNAME_PROCESSOR in
exit ;;
*:procnto*:*:* | *:QNX:[0123456789]*:*)
UNAME_PROCESSOR=`uname -p`
- if test "$UNAME_PROCESSOR" = "x86"; then
+ if test "$UNAME_PROCESSOR" = x86; then
UNAME_PROCESSOR=i386
UNAME_MACHINE=pc
fi
# "uname -m" is not consistent, so use $cputype instead. 386
# is converted to i386 for consistency with other x86
# operating systems.
- if test "$cputype" = "386"; then
+ if test "$cputype" = 386; then
UNAME_MACHINE=i386
else
UNAME_MACHINE="$cputype"
echo i386-pc-xenix
exit ;;
i*86:skyos:*:*)
- echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
+ echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE} | sed -e 's/ .*$//'`
exit ;;
i*86:rdos:*:*)
echo ${UNAME_MACHINE}-pc-rdos
x86_64:VMkernel:*:*)
echo ${UNAME_MACHINE}-unknown-esx
exit ;;
+ amd64:Isilon\ OneFS:*:*)
+ echo x86_64-unknown-onefs
+ exit ;;
esac
cat >&2 <<EOF
$0: unable to guess system type
-This script, last modified $timestamp, has failed to recognize
-the operating system you are using. It is advised that you
-download the most up to date version of the config scripts from
+This script (version $timestamp), has failed to recognize the
+operating system you are using. If your script is old, overwrite
+config.guess and config.sub with the latest versions from:
- http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+ http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess
and
- http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+ http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
-If the version you run ($0) is already up to date, please
-send the following data and any information you think might be
-pertinent to <config-patches@gnu.org> in order to provide the needed
-information to handle your system.
+If $0 has already been updated, send the following data and any
+information you think might be pertinent to config-patches@gnu.org to
+provide the necessary information to handle your system.
config.guess timestamp = $timestamp
#! /bin/sh
# Configuration validation subroutine script.
-# Copyright 1992-2014 Free Software Foundation, Inc.
+# Copyright 1992-2016 Free Software Foundation, Inc.
-timestamp='2014-05-01'
+timestamp='2016-11-19'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# of the GNU General Public License, version 3 ("GPLv3").
-# Please send patches with a ChangeLog entry to config-patches@gnu.org.
+# Please send patches to <config-patches@gnu.org>.
#
# Configuration subroutine to validate and canonicalize a configuration type.
# Supply the specified configuration type as an argument.
# Otherwise, we print the canonical config type on stdout and succeed.
# You can get the latest version of this script from:
-# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
# This file is supposed to be the same for all GNU packages
# and recognize all the CPU types, system types and aliases
me=`echo "$0" | sed -e 's,.*/,,'`
usage="\
-Usage: $0 [OPTION] CPU-MFR-OPSYS
- $0 [OPTION] ALIAS
+Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS
Canonicalize a configuration name.
version="\
GNU config.sub ($timestamp)
-Copyright 1992-2014 Free Software Foundation, Inc.
+Copyright 1992-2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
case $maybe_os in
nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
- knetbsd*-gnu* | netbsd*-gnu* | \
- kopensolaris*-gnu* | \
+ knetbsd*-gnu* | netbsd*-gnu* | netbsd*-eabi* | \
+ kopensolaris*-gnu* | cloudabi*-eabi* | \
storm-chaos* | os2-emx* | rtmk-nova*)
os=-$maybe_os
basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
| arc | arceb \
| arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
| avr | avr32 \
+ | ba \
| be32 | be64 \
| bfin \
| c4x | c8051 | clipper \
| d10v | d30v | dlx | dsp16xx \
- | epiphany \
- | fido | fr30 | frv \
+ | e2k | epiphany \
+ | fido | fr30 | frv | ft32 \
| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
| hexagon \
| i370 | i860 | i960 | ia64 \
| open8 | or1k | or1knd | or32 \
| pdp10 | pdp11 | pj | pjl \
| powerpc | powerpc64 | powerpc64le | powerpcle \
+ | pru \
| pyramid \
+ | riscv32 | riscv64 \
| rl78 | rx \
| score \
- | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
+ | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[234]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
| sh64 | sh64le \
| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
| tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
| ubicom32 \
| v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
+ | visium \
| we32k \
| x86 | xc16x | xstormy16 | xtensa \
| z8k | z80)
c6x)
basic_machine=tic6x-unknown
;;
+ leon|leon[3-9])
+ basic_machine=sparc-$basic_machine
+ ;;
m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip)
basic_machine=$basic_machine-unknown
os=-none
| alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \
| arm-* | armbe-* | armle-* | armeb-* | armv*-* \
| avr-* | avr32-* \
+ | ba-* \
| be32-* | be64-* \
| bfin-* | bs2000-* \
| c[123]* | c30-* | [cjt]90-* | c4x-* \
| c8051-* | clipper-* | craynv-* | cydra-* \
| d10v-* | d30v-* | dlx-* \
- | elxsi-* \
+ | e2k-* | elxsi-* \
| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
| h8300-* | h8500-* \
| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
| orion-* \
| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
+ | pru-* \
| pyramid-* \
+ | riscv32-* | riscv64-* \
| rl78-* | romp-* | rs6000-* | rx-* \
| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
| sparclite-* \
- | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \
+ | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx*-* \
| tahoe-* \
| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
| tile*-* \
| ubicom32-* \
| v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
| vax-* \
+ | visium-* \
| we32k-* \
| x86-* | x86_64-* | xc16x-* | xps100-* \
| xstormy16-* | xtensa*-* \
basic_machine=i386-pc
os=-aros
;;
+ asmjs)
+ basic_machine=asmjs-unknown
+ ;;
aux)
basic_machine=m68k-apple
os=-aux
basic_machine=m68k-bull
os=-sysv3
;;
+ e500v[12])
+ basic_machine=powerpc-unknown
+ os=$os"spe"
+ ;;
+ e500v[12]-*)
+ basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+ os=$os"spe"
+ ;;
ebmon29k)
basic_machine=a29k-amd
os=-ebmon
basic_machine=m68k-isi
os=-sysv
;;
+ leon-*|leon[3-9]-*)
+ basic_machine=sparc-`echo $basic_machine | sed 's/-.*//'`
+ ;;
m68knommu)
basic_machine=m68k-unknown
os=-linux
basic_machine=powerpc-unknown
os=-morphos
;;
+ moxiebox)
+ basic_machine=moxie-unknown
+ os=-moxiebox
+ ;;
msdos)
basic_machine=i386-pc
os=-msdos
ppc-* | ppcbe-*)
basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
- ppcle | powerpclittle | ppc-le | powerpc-little)
+ ppcle | powerpclittle)
basic_machine=powerpcle-unknown
;;
ppcle-* | powerpclittle-*)
;;
ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
- ppc64le | powerpc64little | ppc64-le | powerpc64-little)
+ ppc64le | powerpc64little)
basic_machine=powerpc64le-unknown
;;
ppc64le-* | powerpc64little-*)
| -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
| -sym* | -kopensolaris* | -plan9* \
| -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
- | -aos* | -aros* \
+ | -aos* | -aros* | -cloudabi* | -sortix* \
| -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
| -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
| -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
- | -bitrig* | -openbsd* | -solidbsd* \
+ | -bitrig* | -openbsd* | -solidbsd* | -libertybsd* \
| -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
| -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
| -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
| -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
- | -chorusos* | -chorusrdb* | -cegcc* \
+ | -chorusos* | -chorusrdb* | -cegcc* | -glidix* \
| -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
- | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
+ | -midipix* | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
| -linux-newlib* | -linux-musl* | -linux-uclibc* \
- | -uxpv* | -beos* | -mpeix* | -udk* \
+ | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \
| -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
| -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
| -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
| -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
| -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
| -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
- | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* | -tirtos*)
+ | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* \
+ | -onefs* | -tirtos* | -phoenix* | -fuchsia*)
# Remember, each alternative MUST END IN *, to match a version number.
;;
-qnx*)
;;
-nacl*)
;;
+ -ios)
+ ;;
-none)
;;
*)
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for python 2.7.
#
-# Report bugs to <http://bugs.python.org/>.
+# Report bugs to <https://bugs.python.org/>.
#
#
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
$as_echo "$0: be upgraded to zsh 4.3.4 or later."
else
$as_echo "$0: Please tell bug-autoconf@gnu.org and
-$0: http://bugs.python.org/ about your system, including
+$0: https://bugs.python.org/ about your system, including
$0: any error possibly output before this message. Then
$0: install a modern shell, or manually run the script
$0: under such a shell if you do have one."
PACKAGE_TARNAME='python'
PACKAGE_VERSION='2.7'
PACKAGE_STRING='python 2.7'
-PACKAGE_BUGREPORT='http://bugs.python.org/'
+PACKAGE_BUGREPORT='https://bugs.python.org/'
PACKAGE_URL=''
ac_unique_file="Include/object.h"
LIBTOOL_CRUFT
OTHER_LIBTOOL_OPT
LLVM_PROF_FOUND
+target_os
+target_vendor
+target_cpu
+target
+LLVM_PROFDATA
LLVM_PROF_ERR
LLVM_PROF_FILE
LLVM_PROF_MERGER
PGO_PROF_USE_FLAG
PGO_PROF_GEN_FLAG
LTOFLAGS
+DEF_MAKE_RULE
+DEF_MAKE_ALL_RULE
UNIVERSAL_ARCH_FLAGS
BASECFLAGS
OPT
HGBRANCH
HGTAG
HGVERSION
-BASECPPFLAGS
SVNVERSION
ARFLAGS
ac_ct_AR
CONFIG_ARGS
SOVERSION
VERSION
+GENERATED_COMMENT
PYTHON_FOR_BUILD
host_os
host_vendor
build_vendor
build_cpu
build
-cross_compiling
target_alias
host_alias
build_alias
docdir
oldincludedir
includedir
+runstatedir
localstatedir
sharedstatedir
sysconfdir
enable_shared
enable_profiling
with_pydebug
+enable_optimizations
with_lto
enable_toolbox_glue
with_libs
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
+runstatedir='${localstatedir}/run'
includedir='${prefix}/include'
oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
| -silent | --silent | --silen | --sile | --sil)
silent=yes ;;
+ -runstatedir | --runstatedir | --runstatedi | --runstated \
+ | --runstate | --runstat | --runsta | --runst | --runs \
+ | --run | --ru | --r)
+ ac_prev=runstatedir ;;
+ -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
+ | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
+ | --run=* | --ru=* | --r=*)
+ runstatedir=$ac_optarg ;;
+
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
ac_prev=sbindir ;;
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
datadir sysconfdir sharedstatedir localstatedir includedir \
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
- libdir localedir mandir
+ libdir localedir mandir runstatedir
do
eval ac_val=\$$ac_var
# Remove trailing slashes.
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
+ --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]
+ --target=TARGET configure for building compilers for TARGET [HOST]
_ACEOF
fi
Build (MacOSX|Darwin) framework
--enable-shared disable/enable building shared python library
--enable-profiling enable C-level code profiling
+ --enable-optimizations Enable expensive optimizations (PGO, maybe LTO,
+ etc). Disabled by default.
--enable-toolbox-glue disable/enable MacOSX glue code for extensions
--enable-ipv6 Enable ipv6 (with ipv4) support
--disable-ipv6 Disable ipv6 support
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
-Report bugs to <http://bugs.python.org/>.
+Report bugs to <https://bugs.python.org/>.
_ACEOF
ac_status=$?
fi
$as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;}
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
-( $as_echo "## -------------------------------------- ##
-## Report this to http://bugs.python.org/ ##
-## -------------------------------------- ##"
+( $as_echo "## --------------------------------------- ##
+## Report this to https://bugs.python.org/ ##
+## --------------------------------------- ##"
) | sed "s/^/$as_me: WARNING: /" >&2
;;
esac
$as_echo "$interp" >&6; }
PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(srcdir)/Lib:$(srcdir)/Lib/$(PLATDIR) '$interp
fi
+ # Used to comment out stuff for rebuilding generated files
+ GENERATED_COMMENT='#'
elif test "$cross_compiling" = maybe; then
as_fn_error $? "Cross compiling required --host=HOST-TUPLE and --build=ARCH" "$LINENO" 5
else
PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E'
+ GENERATED_COMMENT=''
fi
+
if test "$prefix" != "/"; then
prefix=`echo "$prefix" | sed -e 's/\/$//g'`
fi
fi
-if test "$abs_srcdir" != "$abs_builddir"; then
- # If we're building out-of-tree make sure Include (in the current dir)
- # gets picked up before its $srcdir counterpart in order for Python-ast.h
- # and graminit.h to get picked up from the correct directory.
- # (A side effect of this is that these resources will automatically be
- # regenerated when building out-of-tree, regardless of whether or not
- # the $srcdir counterpart is up-to-date. This is an acceptable trade
- # off.)
- BASECPPFLAGS="-IInclude"
-else
- BASECPPFLAGS=""
-fi
-
-
# Extract the first word of "hg", so it can be a program name with args.
fi
+# Enable optimization flags
+
+
+Py_OPT='false'
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --enable-optimizations" >&5
+$as_echo_n "checking for --enable-optimizations... " >&6; }
+# Check whether --enable-optimizations was given.
+if test "${enable_optimizations+set}" = set; then :
+ enableval=$enable_optimizations;
+if test "$withval" != no
+then
+ Py_OPT='true'
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; };
+else
+ Py_OPT='false'
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; };
+fi
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+if test "$Py_OPT" = 'true' ; then
+ # Intentionally not forcing Py_LTO='true' here. Too many toolchains do not
+ # compile working code using it and both test_distutils and test_gdb are
+ # broken when you do managed to get a toolchain that works with it. People
+ # who want LTO need to use --with-lto themselves.
+ Py_LTO='true'
+ DEF_MAKE_ALL_RULE="profile-opt"
+ REQUIRE_PGO="yes"
+ DEF_MAKE_RULE="build_all"
+else
+ DEF_MAKE_ALL_RULE="build_all"
+ REQUIRE_PGO="no"
+ DEF_MAKE_RULE="all"
+fi
+
+
# Enable LTO flags
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-lto" >&5
+# Make this work on systems where llvm tools are not installed with their
+# normal names in the default $PATH (ie: Ubuntu). They exist under the
+# non-suffixed name in their versioned llvm directory.
+llvm_bin_dir=''
+llvm_path="${PATH}"
+if test "${CC}" = "clang"
+then
+ clang_bin=`which clang`
+ # Some systems install clang elsewhere as a symlink to the real path
+ # which is where the related llvm tools are located.
+ if test -L "${clang_bin}"
+ then
+ clang_dir=`dirname "${clang_bin}"`
+ clang_bin=`readlink "${clang_bin}"`
+ llvm_bin_dir="${clang_dir}/"`dirname "${clang_bin}"`
+ llvm_path="${llvm_path}${PATH_SEPARATOR}${llvm_bin_dir}"
+ fi
+fi
-# Extract the first word of "llvm-profdata", so it can be a program name with args.
-set dummy llvm-profdata; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking target system type" >&5
+$as_echo_n "checking target system type... " >&6; }
+if ${ac_cv_target+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test "x$target_alias" = x; then
+ ac_cv_target=$ac_cv_host
+else
+ ac_cv_target=`$SHELL "$ac_aux_dir/config.sub" $target_alias` ||
+ as_fn_error $? "$SHELL $ac_aux_dir/config.sub $target_alias failed" "$LINENO" 5
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_target" >&5
+$as_echo "$ac_cv_target" >&6; }
+case $ac_cv_target in
+*-*-*) ;;
+*) as_fn_error $? "invalid value of canonical target" "$LINENO" 5;;
+esac
+target=$ac_cv_target
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_target
+shift
+target_cpu=$1
+target_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+target_os=$*
+IFS=$ac_save_IFS
+case $target_os in *\ *) target_os=`echo "$target_os" | sed 's/ /-/g'`;; esac
+
+
+# The aliases save the names the user supplied, while $host etc.
+# will get canonicalized.
+test -n "$target_alias" &&
+ test "$program_prefix$program_suffix$program_transform_name" = \
+ NONENONEs,x,x, &&
+ program_prefix=${target_alias}-
+# Extract the first word of "$target_alias-llvm-profdata", so it can be a program name with args.
+set dummy $target_alias-llvm-profdata; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_LLVM_PROF_FOUND+:} false; then :
+if ${ac_cv_path_LLVM_PROFDATA+:} false; then :
$as_echo_n "(cached) " >&6
else
- if test -n "$LLVM_PROF_FOUND"; then
- ac_cv_prog_LLVM_PROF_FOUND="$LLVM_PROF_FOUND" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
+ case $LLVM_PROFDATA in
+ [\\/]* | ?:[\\/]*)
+ ac_cv_path_LLVM_PROFDATA="$LLVM_PROFDATA" # Let the user override the test with a path.
+ ;;
+ *)
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in ${llvm_path}
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
- ac_cv_prog_LLVM_PROF_FOUND="found"
+ ac_cv_path_LLVM_PROFDATA="$as_dir/$ac_word$ac_exec_ext"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
IFS=$as_save_IFS
- test -z "$ac_cv_prog_LLVM_PROF_FOUND" && ac_cv_prog_LLVM_PROF_FOUND="not-found"
+ ;;
+esac
+fi
+LLVM_PROFDATA=$ac_cv_path_LLVM_PROFDATA
+if test -n "$LLVM_PROFDATA"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LLVM_PROFDATA" >&5
+$as_echo "$LLVM_PROFDATA" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
fi
+
+
+if test -z "$ac_cv_path_LLVM_PROFDATA"; then
+ if test "$build" = "$target"; then
+ ac_pt_LLVM_PROFDATA=$LLVM_PROFDATA
+ # Extract the first word of "llvm-profdata", so it can be a program name with args.
+set dummy llvm-profdata; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_ac_pt_LLVM_PROFDATA+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ case $ac_pt_LLVM_PROFDATA in
+ [\\/]* | ?:[\\/]*)
+ ac_cv_path_ac_pt_LLVM_PROFDATA="$ac_pt_LLVM_PROFDATA" # Let the user override the test with a path.
+ ;;
+ *)
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in ${llvm_path}
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_path_ac_pt_LLVM_PROFDATA="$as_dir/$ac_word$ac_exec_ext"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+ test -z "$ac_cv_path_ac_pt_LLVM_PROFDATA" && ac_cv_path_ac_pt_LLVM_PROFDATA="''"
+ ;;
+esac
fi
-LLVM_PROF_FOUND=$ac_cv_prog_LLVM_PROF_FOUND
-if test -n "$LLVM_PROF_FOUND"; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LLVM_PROF_FOUND" >&5
-$as_echo "$LLVM_PROF_FOUND" >&6; }
+ac_pt_LLVM_PROFDATA=$ac_cv_path_ac_pt_LLVM_PROFDATA
+if test -n "$ac_pt_LLVM_PROFDATA"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_pt_LLVM_PROFDATA" >&5
+$as_echo "$ac_pt_LLVM_PROFDATA" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
+ LLVM_PROFDATA=$ac_pt_LLVM_PROFDATA
+ else
+ LLVM_PROFDATA="''"
+ fi
+else
+ LLVM_PROFDATA="$ac_cv_path_LLVM_PROFDATA"
+fi
+
+if test -n "${LLVM_PROFDATA}" -a -x "${LLVM_PROFDATA}"
+then
+ LLVM_PROF_FOUND="found"
+else
+ LLVM_PROF_FOUND="not-found"
+fi
+if test "$ac_sys_system" = "Darwin" -a "${LLVM_PROF_FOUND}" = "not-found"
+then
+ found_llvm_profdata=`/usr/bin/xcrun -find llvm-profdata 2>/dev/null`
+ if test -n "${found_llvm_profdata}"
+ then
+ # llvm-profdata isn't directly in $PATH in some cases.
+ # https://apple.stackexchange.com/questions/197053/
+ LLVM_PROFDATA='/usr/bin/xcrun llvm-profdata'
+ LLVM_PROF_FOUND=found
+ { $as_echo "$as_me:${as_lineno-$LINENO}: llvm-profdata found via xcrun: ${LLVM_PROFDATA}" >&5
+$as_echo "$as_me: llvm-profdata found via xcrun: ${LLVM_PROFDATA}" >&6;}
+ fi
+fi
LLVM_PROF_ERR=no
case $CC in
*clang*)
# Any changes made here should be reflected in the GCC+Darwin case below
PGO_PROF_GEN_FLAG="-fprofile-instr-generate"
PGO_PROF_USE_FLAG="-fprofile-instr-use=code.profclangd"
- LLVM_PROF_MERGER="llvm-profdata merge -output=code.profclangd *.profclangr"
+ LLVM_PROF_MERGER="${LLVM_PROFDATA} merge -output=code.profclangd *.profclangr"
LLVM_PROF_FILE="LLVM_PROFILE_FILE=\"code-%p.profclangr\""
if test $LLVM_PROF_FOUND = not-found
then
LLVM_PROF_ERR=yes
+ if test "${REQUIRE_PGO}" = "yes"
+ then
+ as_fn_error $? "llvm-profdata is required for a --enable-optimizations build but could not be found." "$LINENO" 5
+ fi
fi
;;
*gcc*)
Darwin*)
PGO_PROF_GEN_FLAG="-fprofile-instr-generate"
PGO_PROF_USE_FLAG="-fprofile-instr-use=code.profclangd"
- LLVM_PROF_MERGER="llvm-profdata merge -output=code.profclangd *.profclangr"
+ LLVM_PROF_MERGER="${LLVM_PROFDATA} merge -output=code.profclangd *.profclangr"
LLVM_PROF_FILE="LLVM_PROFILE_FILE=\"code-%p.profclangr\""
- if test $LLVM_PROF_FOUND = not-found
+ if test "${LLVM_PROF_FOUND}" = "not-found"
then
LLVM_PROF_ERR=yes
+ if test "${REQUIRE_PGO}" = "yes"
+ then
+ as_fn_error $? "llvm-profdata is required for a --enable-optimizations build but could not be found." "$LINENO" 5
+ fi
fi
;;
*)
then
case $ac_sys_system/$ac_sys_release in
AIX*)
- BLDSHARED="\$(srcdir)/Modules/ld_so_aix \$(CC) -bI:\$(srcdir)/Modules/python.exp"
+ BLDSHARED="Modules/ld_so_aix \$(CC) -bI:Modules/python.exp"
LDSHARED="\$(BINLIBDEST)/config/ld_so_aix \$(CC) -bI:\$(BINLIBDEST)/config/python.exp"
;;
BeOS*)
fi
# Dynamic linking for HP-UX
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for RAND_egd in -lcrypto" >&5
-$as_echo_n "checking for RAND_egd in -lcrypto... " >&6; }
-if ${ac_cv_lib_crypto_RAND_egd+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- ac_check_lib_save_LIBS=$LIBS
-LIBS="-lcrypto $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-
-/* Override any GCC internal prototype to avoid an error.
- Use char because int might match the return type of a GCC
- builtin and then its argument prototype would still apply. */
-#ifdef __cplusplus
-extern "C"
-#endif
-char RAND_egd ();
-int
-main ()
-{
-return RAND_egd ();
- ;
- return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
- ac_cv_lib_crypto_RAND_egd=yes
-else
- ac_cv_lib_crypto_RAND_egd=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
- conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_crypto_RAND_egd" >&5
-$as_echo "$ac_cv_lib_crypto_RAND_egd" >&6; }
-if test "x$ac_cv_lib_crypto_RAND_egd" = xyes; then :
-
-$as_echo "#define HAVE_RAND_EGD 1" >>confdefs.h
-
-fi
-
# only check for sem_init if thread support is requested
if test "$with_threads" = "yes" -o -z "$with_threads"; then
break;
}
}
+ freeaddrinfo(aitop);
+ aitop = NULL;
}
if (!(inet4 == 0 || inet4 == 2))
Configuration headers:
$config_headers
-Report bugs to <http://bugs.python.org/>."
+Report bugs to <https://bugs.python.org/>."
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
esac
mv config.c Modules
+
+if test "$Py_OPT" = 'false' -a "$Py_DEBUG" != 'true'; then
+ echo "" >&6
+ echo "" >&6
+ echo "If you want a release build with all optimizations active (LTO, PGO, etc),"
+ echo "please run ./configure --enable-optimizations" >&6
+ echo "" >&6
+ echo "" >&6
+fi
AC_PREREQ(2.65)
AC_REVISION($Revision$)
-AC_INIT(python, PYTHON_VERSION, http://bugs.python.org/)
+AC_INIT(python, PYTHON_VERSION, https://bugs.python.org/)
AC_CONFIG_SRCDIR([Include/object.h])
AC_CONFIG_HEADER(pyconfig.h)
-AC_SUBST(cross_compiling)
AC_CANONICAL_HOST
AC_SUBST(build)
AC_SUBST(host)
AC_MSG_RESULT($interp)
PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(srcdir)/Lib:$(srcdir)/Lib/$(PLATDIR) '$interp
fi
+ # Used to comment out stuff for rebuilding generated files
+ GENERATED_COMMENT='#'
elif test "$cross_compiling" = maybe; then
AC_MSG_ERROR([Cross compiling required --host=HOST-TUPLE and --build=ARCH])
else
PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E'
+ GENERATED_COMMENT=''
fi
AC_SUBST(PYTHON_FOR_BUILD)
+AC_SUBST(GENERATED_COMMENT)
dnl Ensure that if prefix is specified, it does not end in a slash. If
dnl it does, we get path names containing '//' which is both ugly and
SVNVERSION="echo Unversioned directory"
fi
-AC_SUBST(BASECPPFLAGS)
-if test "$abs_srcdir" != "$abs_builddir"; then
- # If we're building out-of-tree make sure Include (in the current dir)
- # gets picked up before its $srcdir counterpart in order for Python-ast.h
- # and graminit.h to get picked up from the correct directory.
- # (A side effect of this is that these resources will automatically be
- # regenerated when building out-of-tree, regardless of whether or not
- # the $srcdir counterpart is up-to-date. This is an acceptable trade
- # off.)
- BASECPPFLAGS="-IInclude"
-else
- BASECPPFLAGS=""
-fi
-
AC_SUBST(HGVERSION)
AC_SUBST(HGTAG)
AC_SUBST(HGBRANCH)
fi
+# Enable optimization flags
+AC_SUBST(DEF_MAKE_ALL_RULE)
+AC_SUBST(DEF_MAKE_RULE)
+Py_OPT='false'
+AC_MSG_CHECKING(for --enable-optimizations)
+AC_ARG_ENABLE(optimizations, AS_HELP_STRING([--enable-optimizations], [Enable expensive optimizations (PGO, maybe LTO, etc). Disabled by default.]),
+[
+if test "$withval" != no
+then
+ Py_OPT='true'
+ AC_MSG_RESULT(yes);
+else
+ Py_OPT='false'
+ AC_MSG_RESULT(no);
+fi],
+[AC_MSG_RESULT(no)])
+if test "$Py_OPT" = 'true' ; then
+ # Intentionally not forcing Py_LTO='true' here. Too many toolchains do not
+ # compile working code using it and both test_distutils and test_gdb are
+ # broken when you do managed to get a toolchain that works with it. People
+ # who want LTO need to use --with-lto themselves.
+ Py_LTO='true'
+ DEF_MAKE_ALL_RULE="profile-opt"
+ REQUIRE_PGO="yes"
+ DEF_MAKE_RULE="build_all"
+else
+ DEF_MAKE_ALL_RULE="build_all"
+ REQUIRE_PGO="no"
+ DEF_MAKE_RULE="all"
+fi
+
+
# Enable LTO flags
AC_SUBST(LTOFLAGS)
AC_MSG_CHECKING(for --with-lto)
AC_SUBST(LLVM_PROF_MERGER)
AC_SUBST(LLVM_PROF_FILE)
AC_SUBST(LLVM_PROF_ERR)
+# Make this work on systems where llvm tools are not installed with their
+# normal names in the default $PATH (ie: Ubuntu). They exist under the
+# non-suffixed name in their versioned llvm directory.
+llvm_bin_dir=''
+llvm_path="${PATH}"
+if test "${CC}" = "clang"
+then
+ clang_bin=`which clang`
+ # Some systems install clang elsewhere as a symlink to the real path
+ # which is where the related llvm tools are located.
+ if test -L "${clang_bin}"
+ then
+ clang_dir=`dirname "${clang_bin}"`
+ clang_bin=`readlink "${clang_bin}"`
+ llvm_bin_dir="${clang_dir}/"`dirname "${clang_bin}"`
+ llvm_path="${llvm_path}${PATH_SEPARATOR}${llvm_bin_dir}"
+ fi
+fi
+AC_SUBST(LLVM_PROFDATA)
+AC_PATH_TARGET_TOOL(LLVM_PROFDATA, llvm-profdata, '', ${llvm_path})
AC_SUBST(LLVM_PROF_FOUND)
-AC_CHECK_PROG(LLVM_PROF_FOUND, llvm-profdata, found, not-found)
+if test -n "${LLVM_PROFDATA}" -a -x "${LLVM_PROFDATA}"
+then
+ LLVM_PROF_FOUND="found"
+else
+ LLVM_PROF_FOUND="not-found"
+fi
+if test "$ac_sys_system" = "Darwin" -a "${LLVM_PROF_FOUND}" = "not-found"
+then
+ found_llvm_profdata=`/usr/bin/xcrun -find llvm-profdata 2>/dev/null`
+ if test -n "${found_llvm_profdata}"
+ then
+ # llvm-profdata isn't directly in $PATH in some cases.
+ # https://apple.stackexchange.com/questions/197053/
+ LLVM_PROFDATA='/usr/bin/xcrun llvm-profdata'
+ LLVM_PROF_FOUND=found
+ AC_MSG_NOTICE([llvm-profdata found via xcrun: ${LLVM_PROFDATA}])
+ fi
+fi
LLVM_PROF_ERR=no
case $CC in
*clang*)
# Any changes made here should be reflected in the GCC+Darwin case below
PGO_PROF_GEN_FLAG="-fprofile-instr-generate"
PGO_PROF_USE_FLAG="-fprofile-instr-use=code.profclangd"
- LLVM_PROF_MERGER="llvm-profdata merge -output=code.profclangd *.profclangr"
+ LLVM_PROF_MERGER="${LLVM_PROFDATA} merge -output=code.profclangd *.profclangr"
LLVM_PROF_FILE="LLVM_PROFILE_FILE=\"code-%p.profclangr\""
if test $LLVM_PROF_FOUND = not-found
then
LLVM_PROF_ERR=yes
+ if test "${REQUIRE_PGO}" = "yes"
+ then
+ AC_MSG_ERROR([llvm-profdata is required for a --enable-optimizations build but could not be found.])
+ fi
fi
;;
*gcc*)
Darwin*)
PGO_PROF_GEN_FLAG="-fprofile-instr-generate"
PGO_PROF_USE_FLAG="-fprofile-instr-use=code.profclangd"
- LLVM_PROF_MERGER="llvm-profdata merge -output=code.profclangd *.profclangr"
+ LLVM_PROF_MERGER="${LLVM_PROFDATA} merge -output=code.profclangd *.profclangr"
LLVM_PROF_FILE="LLVM_PROFILE_FILE=\"code-%p.profclangr\""
- if test $LLVM_PROF_FOUND = not-found
+ if test "${LLVM_PROF_FOUND}" = "not-found"
then
LLVM_PROF_ERR=yes
+ if test "${REQUIRE_PGO}" = "yes"
+ then
+ AC_MSG_ERROR([llvm-profdata is required for a --enable-optimizations build but could not be found.])
+ fi
fi
;;
*)
then
case $ac_sys_system/$ac_sys_release in
AIX*)
- BLDSHARED="\$(srcdir)/Modules/ld_so_aix \$(CC) -bI:\$(srcdir)/Modules/python.exp"
+ BLDSHARED="Modules/ld_so_aix \$(CC) -bI:Modules/python.exp"
LDSHARED="\$(BINLIBDEST)/config/ld_so_aix \$(CC) -bI:\$(BINLIBDEST)/config/python.exp"
;;
BeOS*)
# checks for libraries
AC_CHECK_LIB(dl, dlopen) # Dynamic linking for SunOS/Solaris and SYSV
AC_CHECK_LIB(dld, shl_load) # Dynamic linking for HP-UX
-AC_CHECK_LIB(crypto, RAND_egd,
- AC_DEFINE(HAVE_RAND_EGD, 1,
- [Define if the libcrypto has RAND_egd]))
# only check for sem_init if thread support is requested
if test "$with_threads" = "yes" -o -z "$with_threads"; then
break;
}
}
+ freeaddrinfo(aitop);
+ aitop = NULL;
}
if (!(inet4 == 0 || inet4 == 2))
esac
mv config.c Modules
+
+if test "$Py_OPT" = 'false' -a "$Py_DEBUG" != 'true'; then
+ echo "" >&AS_MESSAGE_FD
+ echo "" >&AS_MESSAGE_FD
+ echo "If you want a release build with all optimizations active (LTO, PGO, etc),"
+ echo "please run ./configure --enable-optimizations" >&AS_MESSAGE_FD
+ echo "" >&AS_MESSAGE_FD
+ echo "" >&AS_MESSAGE_FD
+fi
/* Define to 1 if you have the `putenv' function. */
#undef HAVE_PUTENV
-/* Define if the libcrypto has RAND_egd */
-#undef HAVE_RAND_EGD
-
/* Define to 1 if you have the `readlink' function. */
#undef HAVE_READLINK
if int(os.uname()[2].split('.')[0]) >= 8:
# We're on Mac OS X 10.4 or later, the compiler should
# support '-Wno-deprecated-declarations'. This will
- # surpress deprecation warnings for the Carbon extensions,
+ # suppress deprecation warnings for the Carbon extensions,
# these extensions wrap the Carbon APIs and even those
# parts that are deprecated.
carbon_extra_compile_args = ['-Wno-deprecated-declarations']
ffi_inc = find_file('ffi.h', [], inc_dirs)
if ffi_inc is not None:
ffi_h = ffi_inc[0] + '/ffi.h'
- fp = open(ffi_h)
- while 1:
- line = fp.readline()
- if not line:
+ with open(ffi_h) as f:
+ for line in f:
+ line = line.strip()
+ if line.startswith(('#define LIBFFI_H',
+ '#define ffi_wrapper_h')):
+ break
+ else:
ffi_inc = None
- break
- if line.startswith('#define LIBFFI_H'):
- break
+ print('Header file {} does not define LIBFFI_H or '
+ 'ffi_wrapper_h'.format(ffi_h))
ffi_lib = None
if ffi_inc is not None:
for lib_name in ('ffi_convenience', 'ffi_pic', 'ffi'):